sqlite

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	sql2.Base
	// contains filtered or unexported fields
}

DB is the goradd driver for a modernc SQLite database.

Although SQLite has a NUMERIC type, it is not the same as NUMERIC types in other databases, which are variable precision numbers. Instead, SQLite will convert the value internally to an INT, REAL, or TEXT at will, and may lose precision in the process. Therefore, these values are stored as TEXT in SQLite, and no numeric operations can be preformed on these values.

Cyclic foreign keys cannot be created using the modernc driver, because to do this in SQLite requires executing multiple create table statements at one time, and the modernc driver does not support this. Instead, you will need to execute the CREATE TABLE statements outside the ORM.

func NewDB

func NewDB(dbKey string,
	connectionString string) (*DB, error)

NewDB returns a new Sqlite database object based on the modernc driver. See https://sqlite.org/uri.html for the format of the connection string. An empty connection string will create a memory only database that is shared across all commections from within the same process.

func (*DB) FormatArgument

func (m *DB) FormatArgument(n int) string

FormatArgument formats the given argument number for embedding in a SQL statement.

func (*DB) Insert

func (m *DB) Insert(ctx context.Context, table string, fields map[string]interface{}, autoPkKey string) error

Insert inserts the given data as a new record in the database. Table can include a schema name separated with a period.

func (*DB) OperationSql

func (m *DB) OperationSql(op Operator, operands []Node, operandStrings []string) (sql string)

OperationSql provides SQLite specific SQL for certain operators. operandStrings will already be escaped.

func (*DB) QuoteIdentifier

func (m *DB) QuoteIdentifier(v string) string

QuoteIdentifier surrounds the given identifier with quote characters appropriate for Postgres

func (*DB) SupportsForUpdate

func (m *DB) SupportsForUpdate() bool

func (*DB) TableDefinitionSql

func (m *DB) TableDefinitionSql(d *schema2.Database, table *schema2.Table) (tableSql string, extraClauses []string)

TableDefinitionSql will return the sql needed to create the table. This can include clauses separated by semicolons that add additional capabilities to the table.

func (*DB) Update

func (m *DB) Update(ctx context.Context,
	table string,
	primaryKey map[string]any,
	fields map[string]any,
	optLockFieldName string,
	optLockFieldValue int64,
) (err error)

Update sets specific fields of a single record that exists in the database. optLockFieldName is the name of a version field that will implement an optimistic locking check while doing the update. If optLockFieldName is provided:

  • That field will be used to limit the update,
  • That field will be updated with a new version
  • If the record was deleted, or if the record was previously updated, an OptimisticLockError will be returned. You will need to query further to determine if the record still exists.

Otherwise, if optLockFieldName is blank, and the record we are attempting to change does not exist, the database will not be altered, and no error will be returned.

func (*DB) WithConstraintsOff

func (m *DB) WithConstraintsOff(ctx context.Context, f func(ctx context.Context) error) (err error)

WithConstraintsOff makes sure operations in f occur with foreign key constraints turned off. As a byproduct of this, the operations will happen on the same pinned connection, meaning the operations should not be long-running so that the connection pool will not run dry. Nested calls will continue to operate with checks off, and the outermost call will turn them on. For sqlite, this must be done before starting a transaction.

Jump to

Keyboard shortcuts

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