Documentation
¶
Index ¶
- Variables
- func CreateCondSQL(latitude, longitude, distance float64) string
- func CreateDistanceSQL(latitude, longitude float64) string
- func GroupPlaceholders(numRows, numCols int) string
- func GroupPlaceholdersStringBuilder(numRows, numCols int, sb *strings.Builder)
- func LoadBool(stmt *Stmt, key string) bool
- func LoadJsonArray[T any](stmt *Stmt, col string) ([]T, error)
- func LoadJsonMap[T any](stmt *Stmt, col string) (map[string]T, error)
- func LoadJsonStruct[T any](stmt *Stmt, col string) (*T, error)
- func LoadTime(stmt *Stmt, key string) time.Time
- func Migration(ctx context.Context, db *Database, fs ReadDirFileFS, dir string) error
- func Placeholders(count int) string
- func RunScript(ctx context.Context, db *Database, sql string) error
- func RunScriptFiles(ctx context.Context, db *Database, path string) error
- func ShowSql(sql string, args ...any) string
- func Sql(sql string, values ...any) string
- type AggregateFunction
- type Conn
- type ConnPrepareFunc
- type Context
- type Database
- type FunctionImpl
- type OptionFunc
- type ReadDirFileFS
- type Stmt
- type Value
Constants ¶
This section is empty.
Variables ¶
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") )
var IntegerValue = sqlite.IntegerValue
Functions ¶
func CreateCondSQL ¶
func CreateDistanceSQL ¶
func LoadJsonStruct ¶ added in v0.2.7
func Migration ¶
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 ¶
Placeholders returns a string of ? separated by commas
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 ¶
Use this function to execute a script that contains multiple SQL statements
type ConnPrepareFunc ¶ added in v0.1.0
type 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 ¶
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
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 ¶
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 }