db.go

  1// Code generated by sqlc. DO NOT EDIT.
  2// versions:
  3//   sqlc v1.27.0
  4
  5package db
  6
  7import (
  8	"context"
  9	"database/sql"
 10	"fmt"
 11)
 12
 13type DBTX interface {
 14	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
 15	PrepareContext(context.Context, string) (*sql.Stmt, error)
 16	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
 17	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
 18}
 19
 20func New(db DBTX) *Queries {
 21	return &Queries{db: db}
 22}
 23
 24func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
 25	q := Queries{db: db}
 26	var err error
 27	if q.createSessionStmt, err = db.PrepareContext(ctx, createSession); err != nil {
 28		return nil, fmt.Errorf("error preparing query CreateSession: %w", err)
 29	}
 30	if q.deleteSessionStmt, err = db.PrepareContext(ctx, deleteSession); err != nil {
 31		return nil, fmt.Errorf("error preparing query DeleteSession: %w", err)
 32	}
 33	if q.getSessionByIDStmt, err = db.PrepareContext(ctx, getSessionByID); err != nil {
 34		return nil, fmt.Errorf("error preparing query GetSessionByID: %w", err)
 35	}
 36	if q.listSessionsStmt, err = db.PrepareContext(ctx, listSessions); err != nil {
 37		return nil, fmt.Errorf("error preparing query ListSessions: %w", err)
 38	}
 39	if q.updateSessionStmt, err = db.PrepareContext(ctx, updateSession); err != nil {
 40		return nil, fmt.Errorf("error preparing query UpdateSession: %w", err)
 41	}
 42	return &q, nil
 43}
 44
 45func (q *Queries) Close() error {
 46	var err error
 47	if q.createSessionStmt != nil {
 48		if cerr := q.createSessionStmt.Close(); cerr != nil {
 49			err = fmt.Errorf("error closing createSessionStmt: %w", cerr)
 50		}
 51	}
 52	if q.deleteSessionStmt != nil {
 53		if cerr := q.deleteSessionStmt.Close(); cerr != nil {
 54			err = fmt.Errorf("error closing deleteSessionStmt: %w", cerr)
 55		}
 56	}
 57	if q.getSessionByIDStmt != nil {
 58		if cerr := q.getSessionByIDStmt.Close(); cerr != nil {
 59			err = fmt.Errorf("error closing getSessionByIDStmt: %w", cerr)
 60		}
 61	}
 62	if q.listSessionsStmt != nil {
 63		if cerr := q.listSessionsStmt.Close(); cerr != nil {
 64			err = fmt.Errorf("error closing listSessionsStmt: %w", cerr)
 65		}
 66	}
 67	if q.updateSessionStmt != nil {
 68		if cerr := q.updateSessionStmt.Close(); cerr != nil {
 69			err = fmt.Errorf("error closing updateSessionStmt: %w", cerr)
 70		}
 71	}
 72	return err
 73}
 74
 75func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
 76	switch {
 77	case stmt != nil && q.tx != nil:
 78		return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
 79	case stmt != nil:
 80		return stmt.ExecContext(ctx, args...)
 81	default:
 82		return q.db.ExecContext(ctx, query, args...)
 83	}
 84}
 85
 86func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
 87	switch {
 88	case stmt != nil && q.tx != nil:
 89		return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
 90	case stmt != nil:
 91		return stmt.QueryContext(ctx, args...)
 92	default:
 93		return q.db.QueryContext(ctx, query, args...)
 94	}
 95}
 96
 97func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
 98	switch {
 99	case stmt != nil && q.tx != nil:
100		return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
101	case stmt != nil:
102		return stmt.QueryRowContext(ctx, args...)
103	default:
104		return q.db.QueryRowContext(ctx, query, args...)
105	}
106}
107
108type Queries struct {
109	db                 DBTX
110	tx                 *sql.Tx
111	createSessionStmt  *sql.Stmt
112	deleteSessionStmt  *sql.Stmt
113	getSessionByIDStmt *sql.Stmt
114	listSessionsStmt   *sql.Stmt
115	updateSessionStmt  *sql.Stmt
116}
117
118func (q *Queries) WithTx(tx *sql.Tx) *Queries {
119	return &Queries{
120		db:                 tx,
121		tx:                 tx,
122		createSessionStmt:  q.createSessionStmt,
123		deleteSessionStmt:  q.deleteSessionStmt,
124		getSessionByIDStmt: q.getSessionByIDStmt,
125		listSessionsStmt:   q.listSessionsStmt,
126		updateSessionStmt:  q.updateSessionStmt,
127	}
128}