25 lines
488 B
Go
25 lines
488 B
Go
|
|
package tenant
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"database/sql"
|
||
|
|
)
|
||
|
|
|
||
|
|
type DB interface {
|
||
|
|
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
|
||
|
|
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
|
||
|
|
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
|
||
|
|
}
|
||
|
|
|
||
|
|
type Queries struct {
|
||
|
|
db DB
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewQueries(db *sql.DB) *Queries {
|
||
|
|
return &Queries{db: db}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||
|
|
return &Queries{db: tx}
|
||
|
|
}
|