summaryrefslogtreecommitdiff
path: root/golang/pkg/database
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--golang/pkg/database/db.go19
-rw-r--r--golang/pkg/database/migrations.go5
-rw-r--r--golang/pkg/database/tokens.go7
3 files changed, 23 insertions, 8 deletions
diff --git a/golang/pkg/database/db.go b/golang/pkg/database/db.go
new file mode 100644
index 0000000..3e07db3
--- /dev/null
+++ b/golang/pkg/database/db.go
@@ -0,0 +1,19 @@
+package database
+
+import (
+ "context"
+ "database/sql"
+)
+
+type DB struct {
+ ctx context.Context
+ db *sql.DB
+}
+
+func (db *DB) Exec(query string, args ...any) (sql.Result, error) {
+ return db.db.ExecContext(db.ctx, query, args...)
+}
+
+func (db *DB) QueryRow(query string, args ...any) *sql.Row {
+ return db.db.QueryRowContext(db.ctx, query, args...)
+}
diff --git a/golang/pkg/database/migrations.go b/golang/pkg/database/migrations.go
index 81cebaa..b167087 100644
--- a/golang/pkg/database/migrations.go
+++ b/golang/pkg/database/migrations.go
@@ -9,11 +9,6 @@ import (
_ "github.com/mattn/go-sqlite3"
)
-type DB struct {
- ctx context.Context
- db *sql.DB
-}
-
//go:embed sql/*.sql
var schemaFiles embed.FS
diff --git a/golang/pkg/database/tokens.go b/golang/pkg/database/tokens.go
index 0787b5c..0356cb2 100644
--- a/golang/pkg/database/tokens.go
+++ b/golang/pkg/database/tokens.go
@@ -1,11 +1,12 @@
package database
func (db *DB) AddToken(token string) error {
- _, err := db.db.ExecContext(db.ctx, `INSERT INTO tokens(data) VALUES (?);`, token)
+ _, err := db.Exec(`INSERT INTO tokens(data) VALUES (?);`, token)
return err
}
-func (db *DB) GetToken() (token string, err error) {
- err = db.db.QueryRowContext(db.ctx, `SELECT data FROM tokens;`).Scan(&token)
+func (db *DB) GetToken() (string, error) {
+ var token string
+ err := db.QueryRow(`SELECT data FROM tokens;`).Scan(&token)
return token, err
}