database

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnectionString = "file:%s?_journal=WAL"
	FKsOn            = "&_foreign_keys=yes"
	FKsOff           = "&_foreign_keys=no"
)

Variables

View Source
var Settings = &settings.Settings

Functions

func Close

func Close(db *gorm.DB) (err error)

Close the DB.

func Open

func Open(enforceFKs bool) (db *gorm.DB, err error)

Open and automigrate the DB.

Types

type Conn added in v0.6.0

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a DB connection.

func (*Conn) Begin added in v0.6.0

func (c *Conn) Begin() (tx driver.Tx, err error)

Begin a transaction.

func (*Conn) BeginTx added in v0.6.0

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

BeginTx begins a transaction.

func (*Conn) Close added in v0.6.0

func (c *Conn) Close() (err error)

Close the connection.

func (*Conn) ExecContext added in v0.6.0

func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (r driver.Result, err error)

ExecContext executes an SQL/DDL statement with context.

func (*Conn) IsValid added in v0.6.0

func (c *Conn) IsValid() (b bool)

IsValid returns true when the connection is valid. When true, the connection may be reused by the sql package.

func (*Conn) Ping added in v0.6.0

func (c *Conn) Ping(ctx context.Context) (err error)

Ping the DB.

func (*Conn) Prepare added in v0.6.0

func (c *Conn) Prepare(query string) (stmt driver.Stmt, err error)

Prepare a statement.

func (*Conn) PrepareContext added in v0.6.0

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

PrepareContext prepares a statement with context.

func (*Conn) QueryContext added in v0.6.0

func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (r driver.Rows, err error)

QueryContext execute a query with context.

func (*Conn) ResetSession added in v0.6.0

func (c *Conn) ResetSession(ctx context.Context) (err error)

ResetSession reset the connection. - Reset the Tx. - Release the mutex.

type Driver added in v0.6.0

type Driver struct {
	// contains filtered or unexported fields
}

Driver is a wrapper around the SQLite driver. The purpose is to prevent database locked errors using a mutex around write operations.

func (*Driver) Connect added in v0.6.0

func (d *Driver) Connect(context.Context) (conn driver.Conn, err error)

Connect opens a connection.

func (*Driver) Driver added in v0.6.0

func (d *Driver) Driver() driver.Driver

Driver returns the underlying driver.

func (*Driver) Open added in v0.6.0

func (d *Driver) Open(dsn string) (conn driver.Conn, err error)

Open a connection.

func (*Driver) OpenConnector added in v0.6.0

func (d *Driver) OpenConnector(dsn string) (dc driver.Connector, err error)

OpenConnector opens a connection.

type PkSequence added in v0.6.0

type PkSequence struct {
	// contains filtered or unexported fields
}

PkSequence provides a primary key sequence.

var PK PkSequence

PK singleton pk sequence.

func (*PkSequence) Load added in v0.6.0

func (r *PkSequence) Load(db *gorm.DB, models []any) (err error)

Load highest key for all models.

func (*PkSequence) Next added in v0.6.0

func (r *PkSequence) Next(db *gorm.DB) (id uint)

Next returns the next primary key.

type Stmt added in v0.6.0

type Stmt struct {
	// contains filtered or unexported fields
}

Stmt is a SQL/DDL statement.

func (*Stmt) Close added in v0.6.0

func (s *Stmt) Close() (err error)

Close the statement.

func (*Stmt) Exec added in v0.6.0

func (s *Stmt) Exec(args []driver.Value) (r driver.Result, err error)

Exec executes the statement.

func (*Stmt) ExecContext added in v0.6.0

func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (r driver.Result, err error)

ExecContext executes the statement with context.

func (*Stmt) NumInput added in v0.6.0

func (s *Stmt) NumInput() (n int)

NumInput returns the number of (query) input parameters.

func (*Stmt) Query added in v0.6.0

func (s *Stmt) Query(args []driver.Value) (r driver.Rows, err error)

Query executes a query.

func (*Stmt) QueryContext added in v0.6.0

func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (r driver.Rows, err error)

QueryContext executes a query.

type Tx added in v0.6.0

type Tx struct {
	// contains filtered or unexported fields
}

Tx is a transaction.

func (*Tx) Commit added in v0.6.0

func (t *Tx) Commit() (err error)

Commit the transaction. Releases the mutex.

func (*Tx) Rollback added in v0.6.0

func (t *Tx) Rollback() (err error)

Rollback the transaction. Releases the mutex.

Jump to

Keyboard shortcuts

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