Documentation ¶
Overview ¶
Package sqlite3 provides a high level interface for sqlite3, including pooled connections object serialization and transactions
Index ¶
- Constants
- func NewProfileArray(cap, samples int, age time.Duration) *profilearray
- func NewSampleArray(cap int) *samplearray
- func Version() string
- type Conn
- func (conn *Conn) Attach(schema, path string) error
- func (conn *Conn) Close() error
- func (c *Conn) ColumnsForIndex(schema, index string) []string
- func (c *Conn) ColumnsForTable(schema, table string) []SQColumn
- func (c *Conn) Count(schema, table string) int64
- func (c *Conn) Counter() int64
- func (conn *Conn) Detach(schema string) error
- func (conn *Conn) Do(ctx context.Context, flag SQFlag, fn func(SQTransaction) error) error
- func (conn *Conn) Exec(st SQStatement, fn SQExecFunc) error
- func (c *Conn) Filename(schema string) string
- func (c *Conn) Flags() SQFlag
- func (this *Conn) ForeignKeyConstraints() (bool, error)
- func (c *Conn) IndexesForTable(schema, table string) []SQIndexView
- func (c *Conn) Modules(prefix ...string) []string
- func (conn *Conn) Query(st SQStatement, v ...interface{}) (SQResults, error)
- func (c *Conn) Schemas() []string
- func (this *Conn) SetForeignKeyConstraints(enable bool) error
- func (c *Conn) SetTraceHook(fn TraceFunc)
- func (conn *Conn) String() string
- func (c *Conn) Tables(schema string) []string
- func (c *Conn) Views(schema string) []string
- type ConnCache
- type ExecFunc
- type Pool
- type PoolConfig
- type Results
- func (r *Results) Close() error
- func (r *Results) ColumnSource(i int) (string, string, string)
- func (r *Results) Columns() []SQColumn
- func (r *Results) ExpandedSQL() string
- func (r *Results) LastInsertId() int64
- func (r *Results) Next(t ...reflect.Type) []interface{}
- func (r *Results) NextQuery(v ...interface{}) error
- func (r *Results) RowsAffected() int
- func (r *Results) String() string
- type TraceFunc
- type Txn
- type TxnFunc
Constants ¶
const ( // DefaultFlags are the default flags for a new database connection DefaultFlags = SQFlag(sqlite3.SQLITE_OPEN_CREATE | sqlite3.SQLITE_OPEN_READWRITE) DefaultSchema = sqlite3.DefaultSchema )
Variables ¶
This section is empty.
Functions ¶
func NewProfileArray ¶
NewProfileArray returns a new set of profiles, up to "capacity" profiles, removing the oldest profiles based on age
func NewSampleArray ¶
func NewSampleArray(cap int) *samplearray
NewSampleArray returns a new set of samples, up to "capacity" samples.
Types ¶
type Conn ¶
func New ¶
New creates an in-memory database. Pass any flags to set open options. If no flags are provided, the default is to create a read/write database.
func (*Conn) Attach ¶ added in v1.0.51
Attach database as schema. If path is empty then a new in-memory database is attached. If the path does not exist then it is created if the SQLITE_OPEN_CREATE flag is set.
func (*Conn) ColumnsForIndex ¶
ColumnsForIndex returns the indexes associated with a table
func (*Conn) ColumnsForTable ¶
ColumnsForTable returns the columns in a table
func (*Conn) Exec ¶
Execute SQL statement without preparing, and invoke a callback for each row of results which may return true to abort
func (*Conn) ForeignKeyConstraints ¶
func (*Conn) IndexesForTable ¶
IndexesForTable returns the indexes associated with a table
func (*Conn) Modules ¶
Modules returns a list of modules in a schema. If an argument is provided, then only modules with those name prefixes are returned.
func (*Conn) SetForeignKeyConstraints ¶
func (*Conn) SetTraceHook ¶
SetTraceHook sets a function to receive executed SQL statements, with the time it took to execute them. The callback is provided with the SQL statement. If the second argument is less than zero, the callback is preparing a statement for execution. If the second argument is non-zero, the callback is invoked when the statement is completed.
type ConnCache ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a connection pool object
func NewPool ¶
NewPool returns a new default pool with a shared cache and maxiumum pool size of 5 connections. If filename is not empty, this database is opened or else memory is used. Pass a channel to receive errors, or nil to ignore
func OpenPool ¶
func OpenPool(config PoolConfig, errs chan<- error) (*Pool, error)
OpenPool returns a new pool with the specified configuration
type PoolConfig ¶
type PoolConfig struct { Max int32 `yaml:"max"` // The maximum number of connections in the pool Schemas map[string]string `yaml:"databases"` // Schema names mapped onto path for database file Create bool `yaml:"create"` // When false, do not allow creation of new file-based databases Auth SQAuth // Authentication and Authorization interface Trace TraceFunc // Trace function Flags SQFlag // Flags for opening connections }
PoolConfig is the starting configuration for a pool
func (PoolConfig) WithAuth ¶
func (cfg PoolConfig) WithAuth(auth SQAuth) PoolConfig
Enable authentication and authorization
func (PoolConfig) WithCreate ¶ added in v1.0.37
func (cfg PoolConfig) WithCreate(create bool) PoolConfig
Enable or disable creation of database files
func (PoolConfig) WithMaxConnections ¶
func (cfg PoolConfig) WithMaxConnections(n int) PoolConfig
Set maxmimum concurrent connections
func (PoolConfig) WithSchema ¶
func (cfg PoolConfig) WithSchema(name, path string) PoolConfig
Add schema to the pool
func (PoolConfig) WithTrace ¶
func (cfg PoolConfig) WithTrace(fn TraceFunc) PoolConfig
Enable trace of statement execution
type Results ¶
type Results struct {
// contains filtered or unexported fields
}
PoolConfig is the starting configuration for a pool
func NewResults ¶
func NewResults(st *sqlite3.StatementEx) *Results
func (*Results) Columns ¶
func (r *Results) Columns() []SQColumn
Return the columns for the current results
func (*Results) ExpandedSQL ¶
func (*Results) LastInsertId ¶
Return LastInsertId by last execute or -1 if no valid results
func (*Results) Next ¶
Return a row from the results, or return io.EOF if all results have been consumed
func (*Results) NextQuery ¶
NextQuery will execute the next query in the statement, return io.EOF if there are no more statements. In order to read the rows, repeatedly read the rows using the Next function.
func (*Results) RowsAffected ¶
Return RowsAffected by last execute or -1 if no valid results