From 75e192d5264c313c12467e976c8a70bddce0619f Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Tue, 19 Dec 2023 21:04:58 +0600 Subject: [PATCH] :art: Used table name constant for topic sqlite repository queries --- internal/topic/repository/sqlite/sqlite_topic.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/topic/repository/sqlite/sqlite_topic.go b/internal/topic/repository/sqlite/sqlite_topic.go index 3cd372a..fd6db91 100644 --- a/internal/topic/repository/sqlite/sqlite_topic.go +++ b/internal/topic/repository/sqlite/sqlite_topic.go @@ -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) {