summaryrefslogtreecommitdiffhomepage
path: root/internal/db/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/db.go')
-rw-r--r--internal/db/db.go128
1 files changed, 128 insertions, 0 deletions
diff --git a/internal/db/db.go b/internal/db/db.go
new file mode 100644
index 000000000..b97eb7108
--- /dev/null
+++ b/internal/db/db.go
@@ -0,0 +1,128 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.27.0
+
+package db
+
+import (
+ "context"
+ "database/sql"
+ "fmt"
+)
+
+type DBTX interface {
+ ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
+ PrepareContext(context.Context, string) (*sql.Stmt, error)
+ QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
+ QueryRowContext(context.Context, string, ...interface{}) *sql.Row
+}
+
+func New(db DBTX) *Queries {
+ return &Queries{db: db}
+}
+
+func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
+ q := Queries{db: db}
+ var err error
+ if q.createSessionStmt, err = db.PrepareContext(ctx, createSession); err != nil {
+ return nil, fmt.Errorf("error preparing query CreateSession: %w", err)
+ }
+ if q.deleteSessionStmt, err = db.PrepareContext(ctx, deleteSession); err != nil {
+ return nil, fmt.Errorf("error preparing query DeleteSession: %w", err)
+ }
+ if q.getSessionByIDStmt, err = db.PrepareContext(ctx, getSessionByID); err != nil {
+ return nil, fmt.Errorf("error preparing query GetSessionByID: %w", err)
+ }
+ if q.listSessionsStmt, err = db.PrepareContext(ctx, listSessions); err != nil {
+ return nil, fmt.Errorf("error preparing query ListSessions: %w", err)
+ }
+ if q.updateSessionStmt, err = db.PrepareContext(ctx, updateSession); err != nil {
+ return nil, fmt.Errorf("error preparing query UpdateSession: %w", err)
+ }
+ return &q, nil
+}
+
+func (q *Queries) Close() error {
+ var err error
+ if q.createSessionStmt != nil {
+ if cerr := q.createSessionStmt.Close(); cerr != nil {
+ err = fmt.Errorf("error closing createSessionStmt: %w", cerr)
+ }
+ }
+ if q.deleteSessionStmt != nil {
+ if cerr := q.deleteSessionStmt.Close(); cerr != nil {
+ err = fmt.Errorf("error closing deleteSessionStmt: %w", cerr)
+ }
+ }
+ if q.getSessionByIDStmt != nil {
+ if cerr := q.getSessionByIDStmt.Close(); cerr != nil {
+ err = fmt.Errorf("error closing getSessionByIDStmt: %w", cerr)
+ }
+ }
+ if q.listSessionsStmt != nil {
+ if cerr := q.listSessionsStmt.Close(); cerr != nil {
+ err = fmt.Errorf("error closing listSessionsStmt: %w", cerr)
+ }
+ }
+ if q.updateSessionStmt != nil {
+ if cerr := q.updateSessionStmt.Close(); cerr != nil {
+ err = fmt.Errorf("error closing updateSessionStmt: %w", cerr)
+ }
+ }
+ return err
+}
+
+func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
+ switch {
+ case stmt != nil && q.tx != nil:
+ return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
+ case stmt != nil:
+ return stmt.ExecContext(ctx, args...)
+ default:
+ return q.db.ExecContext(ctx, query, args...)
+ }
+}
+
+func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
+ switch {
+ case stmt != nil && q.tx != nil:
+ return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
+ case stmt != nil:
+ return stmt.QueryContext(ctx, args...)
+ default:
+ return q.db.QueryContext(ctx, query, args...)
+ }
+}
+
+func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
+ switch {
+ case stmt != nil && q.tx != nil:
+ return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
+ case stmt != nil:
+ return stmt.QueryRowContext(ctx, args...)
+ default:
+ return q.db.QueryRowContext(ctx, query, args...)
+ }
+}
+
+type Queries struct {
+ db DBTX
+ tx *sql.Tx
+ createSessionStmt *sql.Stmt
+ deleteSessionStmt *sql.Stmt
+ getSessionByIDStmt *sql.Stmt
+ listSessionsStmt *sql.Stmt
+ updateSessionStmt *sql.Stmt
+}
+
+func (q *Queries) WithTx(tx *sql.Tx) *Queries {
+ return &Queries{
+ db: tx,
+ tx: tx,
+ createSessionStmt: q.createSessionStmt,
+ deleteSessionStmt: q.deleteSessionStmt,
+ getSessionByIDStmt: q.getSessionByIDStmt,
+ listSessionsStmt: q.listSessionsStmt,
+ updateSessionStmt: q.updateSessionStmt,
+ }
+}