sqlite

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 18 Imported by: 0

README

go-sqlite3

Go Reference

Pure Go SQLite3 driver using dynamic linking.

[!WARNING]
This driver is very early in development and should not be used in production environments. Critical features may be missing or unstable.

Features

  • No CGO required, uses dynamic linking via ebitengine/purego
  • Fully compatible with database/sql
  • Works on Linux, macOS, and Windows (untested)
  • Full support for :memory: databases

Planned Features

  • Hrana protocol support - Connect to hosted SQLite/libSQL instances
  • Custom SQL functions - Register Go functions as SQLite UDFs
  • Virtual tables - Create custom virtual table modules in Go

DSN (Data Source Name)

The driver supports various DSN formats:

Basic Format
// File path
db, err := sql.Open("sqlite3", "mydb.db")

// In-memory database
db, err := sql.Open("sqlite3", ":memory:")
DSN Parameters
Parameter Values Description
mode ro, rw, rwc, memory Database access mode (read-only, read-write, read-write-create, in-memory)
cache shared, private Cache mode for database connections
_mutex no, full Threading mode (no mutex, full mutex)
_busy_timeout milliseconds Timeout for busy handler (default: 5000ms)
Examples
// Read-only mode
db, err := sql.Open("sqlite3", "file:mydb.db?mode=ro")

// Read-write with shared cache
db, err := sql.Open("sqlite3", "file:mydb.db?mode=rw&cache=shared")

// Custom busy timeout (10 seconds)
db, err := sql.Open("sqlite3", "file:mydb.db?_busy_timeout=10000")

Requirements

  • Go 1.23 or higher
  • SQLite3 library installed on the system
    • Linux: Usually pre-installed or available via package manager
    • macOS: Pre-installed with the OS
    • Windows: May require SQLite3 DLL in PATH

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	SQLITE_OK         = 0
	SQLITE_ERROR      = 1
	SQLITE_INTERNAL   = 2
	SQLITE_PERM       = 3
	SQLITE_ABORT      = 4
	SQLITE_BUSY       = 5
	SQLITE_LOCKED     = 6
	SQLITE_NOMEM      = 7
	SQLITE_READONLY   = 8
	SQLITE_INTERRUPT  = 9
	SQLITE_IOERR      = 10
	SQLITE_CORRUPT    = 11
	SQLITE_NOTFOUND   = 12
	SQLITE_FULL       = 13
	SQLITE_CANTOPEN   = 14
	SQLITE_PROTOCOL   = 15
	SQLITE_EMPTY      = 16
	SQLITE_SCHEMA     = 17
	SQLITE_TOOBIG     = 18
	SQLITE_CONSTRAINT = 19
	SQLITE_MISMATCH   = 20
	SQLITE_MISUSE     = 21
	SQLITE_NOLFS      = 22
	SQLITE_AUTH       = 23
	SQLITE_FORMAT     = 24
	SQLITE_RANGE      = 25
	SQLITE_NOTADB     = 26
	SQLITE_NOTICE     = 27
	SQLITE_WARNING    = 28
	SQLITE_ROW        = 100
	SQLITE_DONE       = 101

	SQLITE_OPEN_READONLY  = 0x00000001
	SQLITE_OPEN_READWRITE = 0x00000002
	SQLITE_OPEN_CREATE    = 0x00000004
	SQLITE_OPEN_URI       = 0x00000040

	SQLITE_STATIC            = uintptr(0)
	SQLITE_TRANSIENT         = ^uintptr(0)
	SQLITE_OPEN_MEMORY       = 0x00000080
	SQLITE_OPEN_NOMUTEX      = 0x00008000
	SQLITE_OPEN_FULLMUTEX    = 0x00010000
	SQLITE_OPEN_SHAREDCACHE  = 0x00020000
	SQLITE_OPEN_PRIVATECACHE = 0x00040000

	SQLITE_INTEGER = 1
	SQLITE_REAL    = 2
	SQLITE_TEXT    = 3
	SQLITE_BLOB    = 4
	SQLITE_NULL    = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

func (*Conn) Begin

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

func (*Conn) BeginTx

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

func (*Conn) CheckNamedValue

func (c *Conn) CheckNamedValue(nv *driver.NamedValue) error

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) ExecContext

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

func (*Conn) Ping

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

func (*Conn) Prepare

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

func (*Conn) PrepareContext

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

func (*Conn) QueryContext

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

func (*Conn) ResetSession

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

type Driver

type Driver struct{}

func (*Driver) Open

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

func (*Driver) OpenConnector

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

type Result

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

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

func (*Result) RowsAffected

func (r *Result) RowsAffected() (int64, error)

type Rows

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

func (*Rows) Close

func (r *Rows) Close() error

func (*Rows) ColumnTypeDatabaseTypeName

func (r *Rows) ColumnTypeDatabaseTypeName(index int) string

func (*Rows) ColumnTypeLength

func (r *Rows) ColumnTypeLength(index int) (int64, bool)

func (*Rows) ColumnTypeNullable

func (r *Rows) ColumnTypeNullable(index int) (bool, bool)

func (*Rows) ColumnTypePrecisionScale

func (r *Rows) ColumnTypePrecisionScale(index int) (int64, int64, bool)

func (*Rows) ColumnTypeScanType

func (r *Rows) ColumnTypeScanType(index int) reflect.Type

func (*Rows) Columns

func (r *Rows) Columns() []string

func (*Rows) HasNextResultSet

func (r *Rows) HasNextResultSet() bool

func (*Rows) Next

func (r *Rows) Next(dest []driver.Value) error

func (*Rows) NextResultSet

func (r *Rows) NextResultSet() error

type Stmt

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

func (*Stmt) CheckNamedValue

func (s *Stmt) CheckNamedValue(nv *driver.NamedValue) error

func (*Stmt) Close

func (s *Stmt) Close() error

func (*Stmt) Exec

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

func (*Stmt) ExecContext

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

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

func (*Stmt) Query

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

func (*Stmt) QueryContext

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

type ThreadSafeMap

type ThreadSafeMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

ThreadSafeMap provides a thread-safe map implementation using generics

func NewThreadSafeMap

func NewThreadSafeMap[K comparable, V any]() *ThreadSafeMap[K, V]

NewThreadSafeMap creates a new thread-safe map

func (*ThreadSafeMap[K, V]) Clear

func (tm *ThreadSafeMap[K, V]) Clear()

Clear removes all entries from the map

func (*ThreadSafeMap[K, V]) CompareAndDelete

func (tm *ThreadSafeMap[K, V]) CompareAndDelete(key K, old V) (deleted bool)

CompareAndDelete deletes the entry for key if its value is equal to old

func (*ThreadSafeMap[K, V]) CompareAndSwap

func (tm *ThreadSafeMap[K, V]) CompareAndSwap(key K, old, new V) bool

CompareAndSwap swaps the old and new values for key if the value stored in the map is equal to old

func (*ThreadSafeMap[K, V]) Delete

func (tm *ThreadSafeMap[K, V]) Delete(key K)

Delete deletes the value for a key

func (*ThreadSafeMap[K, V]) Iter

func (tm *ThreadSafeMap[K, V]) Iter() iter.Seq2[K, V]

Iter returns an iterator over key-value pairs in the map

func (*ThreadSafeMap[K, V]) Keys

func (tm *ThreadSafeMap[K, V]) Keys() iter.Seq[K]

Keys returns an iterator over keys in the map

func (*ThreadSafeMap[K, V]) Len

func (tm *ThreadSafeMap[K, V]) Len() int

Len returns the number of elements in the map Note: This is an O(n) operation as it needs to iterate through all elements

func (*ThreadSafeMap[K, V]) Load

func (tm *ThreadSafeMap[K, V]) Load(key K) (value V, ok bool)

Load returns the value stored in the map for a key, or zero value if no value is present

func (*ThreadSafeMap[K, V]) LoadAndDelete

func (tm *ThreadSafeMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any

func (*ThreadSafeMap[K, V]) LoadOrStore

func (tm *ThreadSafeMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore returns the existing value for the key if present Otherwise, it stores and returns the given value

func (*ThreadSafeMap[K, V]) Store

func (tm *ThreadSafeMap[K, V]) Store(key K, value V)

Store sets the value for a key

func (*ThreadSafeMap[K, V]) Swap

func (tm *ThreadSafeMap[K, V]) Swap(key K, value V) (previous V, loaded bool)

Swap swaps the value for a key and returns the previous value if any

func (*ThreadSafeMap[K, V]) Values

func (tm *ThreadSafeMap[K, V]) Values() iter.Seq[V]

Values returns an iterator over values in the map

type Tx

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

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) Rollback

func (t *Tx) Rollback() error

Jump to

Keyboard shortcuts

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