sqlite

package
v0.0.0-...-4ffef1b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const RFC3339NanoZero = "2006-01-02 15:04:05.000000000Z07:00"

Variables

This section is empty.

Functions

func InSQL

func InSQL[T any](args []T) (string, []any)

func LimitOffsetSQL

func LimitOffsetSQL(limit, offset int) string

func Migrate

func Migrate(ctx context.Context, tx *Tx, name string, migrations []string) error

func MigrateFS

func MigrateFS(ctx context.Context, db *DB, name string, fsys fs.FS) error

func NewNullable

func NewNullable[T comparable](value T) (null sql.Null[T])

func NewSorts

func NewSorts(sorts []string, keysToCols map[string]string) []string

func OrderBySQL

func OrderBySQL(sorts []string) string

func PageLimitOffset

func PageLimitOffset(page, size int) (int, int)

func WhereSQL

func WhereSQL(where []string) string

Types

type Conn

type Conn struct {
	*sql.Conn
	// contains filtered or unexported fields
}

func (*Conn) BeginExclusiveTx

func (c *Conn) BeginExclusiveTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginExclusiveTx starts an exclusive transaction with "begin exclusive".

This is a workaround for Go's database/sql package not providing a way to set the transaction type per connection.

References: - https://github.com/golang/go/issues/19981 - https://github.com/mattn/go-sqlite3/issues/400

func (*Conn) BeginImmediateTx

func (c *Conn) BeginImmediateTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginImmediateTx starts an immediate transaction with "begin immediate".

This is a workaround for Go's database/sql package not providing a way to set the transaction type per connection.

References: - https://github.com/golang/go/issues/19981 - https://github.com/mattn/go-sqlite3/issues/400

func (*Conn) BeginTx

func (c *Conn) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

func (*Conn) ExecContext

func (c *Conn) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*Conn) PrepareContext

func (c *Conn) PrepareContext(ctx context.Context, query string) (*Stmt, error)

func (*Conn) QueryContext

func (c *Conn) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)

func (*Conn) QueryRowContext

func (c *Conn) QueryRowContext(ctx context.Context, query string, args ...any) *Row

type DB

type DB struct {
	*sql.DB

	DSN string
	// contains filtered or unexported fields
}

func Open

func Open(ctx context.Context, kind Kind, filename string, metrics *expvar.Map, onConnect OnConnectFunc) (*DB, error)

func OpenInMemoryTestDatabase

func OpenInMemoryTestDatabase(ctx context.Context) *DB

func (*DB) Begin

func (db *DB) Begin() (*Tx, error)

func (*DB) BeginExclusiveTx

func (db *DB) BeginExclusiveTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginExclusiveTx starts an exclusive transaction with "begin exclusive".

This is a workaround for Go's database/sql package not providing a way to set the transaction type per connection.

References: - https://github.com/golang/go/issues/19981 - https://github.com/mattn/go-sqlite3/issues/400

func (*DB) BeginImmediateTx

func (db *DB) BeginImmediateTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginImmediateTx starts an immediate transaction with "begin immediate".

This is a workaround for Go's database/sql package not providing a way to set the transaction type per connection.

References: - https://github.com/golang/go/issues/19981 - https://github.com/mattn/go-sqlite3/issues/400

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

func (*DB) Conn

func (db *DB) Conn(ctx context.Context) (*Conn, error)

func (*DB) Exec

func (db *DB) Exec(query string, args ...any) (sql.Result, error)

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*DB) Prepare

func (db *DB) Prepare(query string) (*Stmt, error)

func (*DB) PrepareContext

func (db *DB) PrepareContext(ctx context.Context, query string) (*Stmt, error)

func (*DB) Query

func (db *DB) Query(query string, args ...any) (*Rows, error)

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...any) *Row

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *Row

type Duration

type Duration time.Duration

func (*Duration) Scan

func (d *Duration) Scan(value any) error

func (Duration) String

func (d Duration) String() string

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

type Kind

type Kind string
const (
	KindFile   Kind = "file"
	KindMemory Kind = "memory"
)

type NullDuration

type NullDuration time.Duration

func (*NullDuration) Scan

func (d *NullDuration) Scan(value any) error

func (NullDuration) String

func (d NullDuration) String() string

func (NullDuration) Value

func (d NullDuration) Value() (driver.Value, error)

type NullTime

type NullTime time.Time

func (*NullTime) Scan

func (t *NullTime) Scan(value any) error

func (NullTime) String

func (t NullTime) String() string

func (NullTime) Value

func (t NullTime) Value() (driver.Value, error)

type OnConnectFunc

type OnConnectFunc func(conn *sqlite3.SQLiteConn) error

type Row

type Row struct {
	*sql.Row
	// contains filtered or unexported fields
}

func (*Row) Err

func (r *Row) Err() error

func (*Row) Scan

func (r *Row) Scan(dst ...any) error

type Rows

type Rows struct {
	*sql.Rows
	// contains filtered or unexported fields
}

func (*Rows) Close

func (rs *Rows) Close() error

func (*Rows) Err

func (rs *Rows) Err() error

func (*Rows) Next

func (rs *Rows) Next() bool

func (*Rows) Scan

func (rs *Rows) Scan(dst ...any) error

type Stmt

type Stmt struct {
	*sql.Stmt
	// contains filtered or unexported fields
}

func (*Stmt) Exec

func (stmt *Stmt) Exec(args ...any) (sql.Result, error)

func (*Stmt) ExecContext

func (stmt *Stmt) ExecContext(ctx context.Context, args ...any) (sql.Result, error)

func (*Stmt) Query

func (stmt *Stmt) Query(args ...any) (*Rows, error)

func (*Stmt) QueryContext

func (stmt *Stmt) QueryContext(ctx context.Context, args ...any) (*Rows, error)

func (*Stmt) QueryRow

func (stmt *Stmt) QueryRow(args ...any) *Row

func (*Stmt) QueryRowContext

func (stmt *Stmt) QueryRowContext(ctx context.Context, args ...any) *Row

type Time

type Time time.Time

func (*Time) Scan

func (t *Time) Scan(value any) error

func (Time) String

func (t Time) String() string

func (Time) Value

func (t Time) Value() (driver.Value, error)

type Tx

type Tx struct {
	*sql.Tx
	Now time.Time
	// contains filtered or unexported fields
}

func NewTx

func NewTx(ctx context.Context, tx *sql.Tx, metrics *expvar.Map) *Tx

func (*Tx) Commit

func (tx *Tx) Commit() error

func (*Tx) Exec

func (tx *Tx) Exec(query string, args ...any) (sql.Result, error)

func (*Tx) ExecContext

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*Tx) Prepare

func (tx *Tx) Prepare(query string) (*Stmt, error)

func (*Tx) PrepareContext

func (tx *Tx) PrepareContext(ctx context.Context, query string) (*Stmt, error)

func (*Tx) Query

func (tx *Tx) Query(query string, args ...any) (*Rows, error)

func (*Tx) QueryContext

func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)

func (*Tx) QueryRow

func (tx *Tx) QueryRow(query string, args ...any) *Row

func (*Tx) QueryRowContext

func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...any) *Row

func (*Tx) Rollback

func (tx *Tx) Rollback() error

func (*Tx) Stmt

func (tx *Tx) Stmt(stmt *Stmt) *Stmt

func (*Tx) StmtContext

func (tx *Tx) StmtContext(ctx context.Context, stmt *Stmt) *Stmt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL