🎨 Used table name constant for topic sqlite repository queries

This commit is contained in:
Maxim Lebedev 2023-12-19 21:04:58 +06:00
parent 0828c0783a
commit 75e192d526
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 8 additions and 7 deletions

View File

@ -44,24 +44,25 @@ type (
)
const (
queryTable string = `CREATE TABLE IF NOT EXISTS topics (
table string = "topics"
queryTable string = `CREATE TABLE IF NOT EXISTS ` + table + ` (
created_at DATETIME,
updated_at DATETIME,
url TEXT PRIMARY KEY,
content_type TEXT,
content BLOB
)`
queryIndex string = `CREATE INDEX urls ON topics (url);`
queryCreate string = `INSERT INTO topics (created_at, updated_at, url, content_type, content)
queryIndex string = `CREATE INDEX urls ON ` + table + ` (url);`
queryCreate string = `INSERT INTO ` + table + ` (created_at, updated_at, url, content_type, content)
VALUES (:created_at, :updated_at, :url, :content_type, :content);`
queryFetch string = `SELECT * FROM topics;`
queryRead string = `SELECT * FROM topics WHERE url = ?;`
queryUpdate string = `UPDATE topics
queryFetch string = `SELECT * FROM ` + table + `;`
queryRead string = `SELECT * FROM ` + table + ` WHERE url = ?;`
queryUpdate string = `UPDATE ` + table + `
SET updated_at = :updated_at,
content_type = :content_type,
content = :content
WHERE url = :url;`
queryDelete string = `DELETE FROM topics WHERE url = ?;`
queryDelete string = `DELETE FROM ` + table + ` WHERE url = ?;`
)
func NewSQLiteTopicRepository(db *sqlx.DB) (topic.Repository, error) {