Documentation
¶
Overview ¶
Package sqlitekit provides SQLite connection management and migration support using pure-Go SQLite.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate applies pending SQL migrations from the given filesystem. The migrationsFS should contain a "migrations" directory with .sql files that are sorted lexicographically by filename (e.g., 001_init.sql, 002_add_users.sql). Each migration runs inside its own transaction and is tracked in a schema_migrations table to ensure idempotency.
func Open ¶
Open opens a SQLite database at the given path with WAL mode and recommended pragmas. The database is configured for concurrent reads/writes (WAL mode), a 5-second busy timeout, and foreign key enforcement. Returns a ready-to-use *sql.DB.
The pragmas are carried in the connection DSN rather than executed once via db.Exec. database/sql maintains a connection pool and opens connections lazily; a PRAGMA run once only affects the single connection it executed on, and busy_timeout and foreign_keys are per-connection settings that otherwise reset to SQLite defaults (timeout 0, foreign keys OFF) on every other pooled connection. Putting them in the DSN guarantees they apply to every connection.
Example ¶
ExampleOpen demonstrates opening a SQLite database and performing basic CRUD operations through the standard database/sql interface.
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/danieljustus/symaira-corekit/sqlitekit"
_ "modernc.org/sqlite"
)
func main() {
// Open creates the database directory if needed and configures WAL mode,
// busy_timeout, and foreign_keys on every pooled connection.
dir, _ := os.MkdirTemp("", "sqlitekit-example")
defer os.RemoveAll(dir)
db, err := sqlitekit.Open(filepath.Join(dir, "test.db"))
if err != nil {
fmt.Printf("open error: %v\n", err)
return
}
defer db.Close()
_, _ = db.Exec("CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT)")
_, _ = db.Exec("INSERT INTO items (name) VALUES (?)", "hello")
var name string
_ = db.QueryRow("SELECT name FROM items WHERE id = 1").Scan(&name)
fmt.Println(name)
}
Output: hello
Types ¶
This section is empty.