Documentation
¶
Overview ¶
sqlite driver for Go.
Index ¶
- type Conn
- func (c *Conn) Begin() (driver.Tx, error)deprecated
- func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *Conn) CheckNamedValue(val *driver.NamedValue) error
- func (c *Conn) Close() error
- func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error)deprecated
- func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *Conn) IsValid() bool
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Prepare(query string) (driver.Stmt, error)
- func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error)deprecated
- func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- func (c *Conn) ResetSession(ctx context.Context) error
- func (c *Conn) Validate() error
- type Connector
- type Driver
- type Result
- type Rows
- func (r *Rows) Close() error
- func (r *Rows) ColumnTypeDatabaseTypeName(index int) string
- func (r *Rows) ColumnTypeLength(index int) (length int64, ok bool)
- func (r *Rows) ColumnTypeNullable(index int) (nullable, ok bool)
- func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool)
- func (r *Rows) ColumnTypeScanType(index int) reflect.Type
- func (r *Rows) Columns() []string
- func (r *Rows) HasNextResultSet() bool
- func (r *Rows) Next(dest []driver.Value) error
- func (r *Rows) NextResultSet() error
- type Stmt
- func (s *Stmt) CheckNamedValue(val *driver.NamedValue) error
- func (s *Stmt) Close() error
- func (s *Stmt) ColumnConverter(idx int) driver.ValueConverterdeprecated
- func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)deprecated
- func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *Stmt) NumInput() int
- func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)deprecated
- func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a SQLite database connection.
func (*Conn) CheckNamedValue ¶
func (c *Conn) CheckNamedValue(val *driver.NamedValue) error
CheckNamedValue validates a named value before binding.
This method handles driver.Valuer types by calling Value() to get the underlying value. It also handles time.Time conversion to ISO8601 format.
func (*Conn) ExecContext ¶
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext executes a query that doesn't return rows, with context support.
func (*Conn) PrepareContext ¶
PrepareContext creates a prepared statement with context support.
func (*Conn) QueryContext ¶
func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
QueryContext executes a query that returns rows, with context support.
func (*Conn) ResetSession ¶
ResetSession resets the connection state. Implements the driver.SessionResetter interface.
func (*Conn) Validate ¶
Validate verifies that the connection is still valid and usable. Implements the driver.Validator interface.
This method is called by the database/sql package before returning a connection from the connection pool to ensure it's still usable. It checks that the connection is not closed and that the SQLite database handle is still valid.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector creates new connections for connection pooling. Connector enables connection pooling and allows reusing the same connection configuration across multiple database operations.
type Driver ¶
type Driver struct{}
Driver is the SQLite driver implementation.
func (*Driver) DriverName ¶
DriverName returns the driver name.
func (*Driver) Open ¶
Open creates a new connection to the SQLite database.
Connection string options (comma-separated):
- _foreign_keys=1: Enable foreign key constraints
- _wal=1: Enable WAL mode (default: 1)
- _busy_timeout=N: Set busy timeout in milliseconds (default: 5000)
Examples:
- ":memory:" - In-memory database
- "file.db" - File-based database
- "file.db?_foreign_keys=1&_wal=1" - With options
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result is the result of a query execution that doesn't return rows.
func (*Result) LastInsertId ¶
LastInsertId returns the last inserted row ID.
func (*Result) RowsAffected ¶
RowsAffected returns the number of rows affected by the query.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows is an iterator over the rows returned by a query.
func (*Rows) Close ¶
Close closes the Rows iterator and releases associated resources.
This method implements the driver.Rows interface and is automatically called by the database/sql package when rows are exhausted or explicitly closed. It ensures proper cleanup of SQLite statement handles to prevent resource leaks.
func (*Rows) ColumnTypeDatabaseTypeName ¶
ColumnTypeDatabaseTypeName returns the database system type name for the column.
func (*Rows) ColumnTypeLength ¶
ColumnTypeLength returns the length of the column type.
SQLite does not have fixed-length character types in the same way as other databases. Column declarations like VARCHAR(255) are stored as text, and SQLite does not enforce length constraints. This method returns (0, false) to indicate that the length is unknown.
This is a no-op implementation required by the driver.RowsColumnTypeLength interface.
func (*Rows) ColumnTypeNullable ¶
ColumnTypeNullable reports whether the column type is nullable.
func (*Rows) ColumnTypePrecisionScale ¶
ColumnTypePrecisionScale returns the precision and scale for decimal types.
SQLite does not have native decimal types with precision/scale constraints. Numeric values are stored as flexible types (REAL or INTEGER), and precision/scale are not enforced at the database level. This method returns (0, 0, false) to indicate that precision/scale are unknown.
This is a no-op implementation required by the driver.RowsColumnTypePrecisionScale interface.
func (*Rows) ColumnTypeScanType ¶
ColumnTypeScanType returns the Go type that should be used when scanning.
func (*Rows) HasNextResultSet ¶
HasNextResultSet returns true if there are additional result sets.
SQLite does not support multiple result sets per query, so this method always returns false. This is a no-op implementation required by the driver.RowsNextResultSet interface to ensure compatibility with the database/sql package.
Note: Multiple result sets are not supported by SQLite. Each query returns a single result set, and this method will always return false even after calling NextResultSet.
func (*Rows) NextResultSet ¶
NextResultSet advances to the next result set.
SQLite does not support multiple result sets per query, so this method always returns nil. This is a no-op implementation required by the driver.Rows interface to ensure compatibility with the database/sql package.
Note: Multiple result sets are not supported by SQLite. Each query returns a single result set, and this method will always return nil.
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt represents a prepared statement.
func (*Stmt) CheckNamedValue ¶
func (s *Stmt) CheckNamedValue(val *driver.NamedValue) error
CheckNamedValue validates a named value before binding.
This method handles driver.Valuer types by calling Value() to get the underlying value. It also handles time.Time conversion to ISO8601 format.
This implementation mirrors Conn.CheckNamedValue to ensure consistent type handling whether using prepared statements or direct queries.
func (*Stmt) Close ¶
Close closes the prepared statement and releases associated resources.
This method implements the driver.Stmt interface and is automatically called by the database/sql package when the statement is no longer needed. It ensures proper cleanup of SQLite statement handles to prevent resource leaks.
func (*Stmt) ColumnConverter
deprecated
func (s *Stmt) ColumnConverter(idx int) driver.ValueConverter
ColumnConverter returns a ValueConverter for the column.
Deprecated: Use CheckNamedValue or implement custom conversion logic.
func (*Stmt) ExecContext ¶
ExecContext executes the statement with the given arguments, with context support.
func (*Stmt) QueryContext ¶
QueryContext executes the statement and returns an iterator over the rows, with context support.