sqlite

package module
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("database row not found")
	ErrPrepareSQL  = errors.New("database failed to prepare sql")
	ErrExecSQL     = errors.New("database failed to exec sql")
	ErrUnknownType = errors.New("database failed to prepare sql because of unknown type")
)
View Source
var IntegerValue = sqlite.IntegerValue

Functions

func CreateCondSQL

func CreateCondSQL(latitude, longitude, distance float64) string

func CreateDistanceSQL

func CreateDistanceSQL(latitude, longitude float64) string

func GroupPlaceholders

func GroupPlaceholders(numRows, numCols int) string

(?, ?), (?, ?), (?, ?)

func GroupPlaceholdersStringBuilder

func GroupPlaceholdersStringBuilder(numRows, numCols int, sb *strings.Builder)

func LoadBool

func LoadBool(stmt *Stmt, key string) bool

func LoadJsonArray

func LoadJsonArray[T any](stmt *Stmt, col string) ([]T, error)

func LoadJsonMap

func LoadJsonMap[T any](stmt *Stmt, col string) (map[string]T, error)

func LoadJsonStruct added in v0.2.7

func LoadJsonStruct[T any](stmt *Stmt, col string) (*T, error)

func LoadTime

func LoadTime(stmt *Stmt, key string) time.Time

func Migration

func Migration(ctx context.Context, db *Database, fs ReadDirFileFS, dir string) error

migration calls read each sql files in the migration directory and applies it to the database. It will create a table called migrations_sqlite to keep track of the files that have been applied.

Use this function to apply migrations to the database at the start of your application. Make sure each file name is unique and the use either a timestamp or counter to make sure the files are applied in the correct order.

func Placeholders

func Placeholders(count int) string

Placeholders returns a string of ? separated by commas

func RunScript

func RunScript(ctx context.Context, db *Database, sql string) error

func RunScriptFiles

func RunScriptFiles(ctx context.Context, db *Database, path string) error

func ShowSql

func ShowSql(sql string, args ...any) string

func Sql

func Sql(sql string, values ...any) string

Types

type AggregateFunction

type AggregateFunction = sqlite.AggregateFunction

Reason behind this is that I don't want to import two packages that starts with sqlite into my project. I can use the type alias in my project

type Conn

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

func (*Conn) Done added in v0.0.9

func (c *Conn) Done()

Done returns the connection back to the pool

func (*Conn) ExecScript

func (c *Conn) ExecScript(sql string) error

Use this function to execute a script that contains multiple SQL statements

func (*Conn) Prepare

func (c *Conn) Prepare(ctx context.Context, sql string, values ...any) (*Stmt, error)

func (*Conn) Save

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

When your try to use transaction in a nice way, you can use the following at the beginning of your code:

defer conn.Save(&err)

type ConnPrepareFunc added in v0.1.0

type ConnPrepareFunc func(*Conn) error

type Context

type Context = sqlite.Context

Reason behind this is that I don't want to import two packages that starts with sqlite into my project. I can use the type alias in my project

type Database

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

Database struct which holds pool of connection

func New

func New(ctx context.Context, opts ...OptionFunc) (*Database, error)

New creates a sqlite database

func (*Database) Close

func (db *Database) Close() error

Close closes all the connections in the pool and returns error if any connection fails to close NOTE: make sure to call this function at the end of your application

func (*Database) Conn

func (db *Database) Conn(ctx context.Context) (*Conn, error)

Conn returns one connection from connection pool NOTE: make sure to call Done() to put the connection back to the pool usually right after this call, you should call defer conn.Done()

func (*Database) Exec added in v0.2.4

func (db *Database) Exec(ctx context.Context, fn func(ctx context.Context, conn *Conn) error) error

type FunctionImpl

type FunctionImpl = sqlite.FunctionImpl

Reason behind this is that I don't want to import two packages that starts with sqlite into my project. I can use the type alias in my project

type OptionFunc

type OptionFunc func(context.Context, *Database) error

func WithConnPrepareFunc added in v0.1.0

func WithConnPrepareFunc(fn ConnPrepareFunc) OptionFunc

func WithFile

func WithFile(path string) OptionFunc

func WithFunctions

func WithFunctions(fns map[string]*FunctionImpl) OptionFunc

func WithMemory

func WithMemory() OptionFunc

func WithPoolSize

func WithPoolSize(size int) OptionFunc

func WithStringConn

func WithStringConn(stringConn string) OptionFunc

type ReadDirFileFS

type ReadDirFileFS interface {
	fs.ReadDirFS
	fs.ReadFileFS
}

type Stmt

type Stmt = sqlite.Stmt

Reason behind this is that I don't want to import two packages that starts with sqlite into my project. I can use the type alias in my project

type Value

type Value = sqlite.Value

Reason behind this is that I don't want to import two packages that starts with sqlite into my project. I can use the type alias in my project

Jump to

Keyboard shortcuts

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