You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Combined conditions: WHERE + OR + JOIN + GROUP BY + HAVINGvarresults []Result_, err:=db.Read.Table("orders").
Select("user_id", "SUM(amount) AS total").
Join("users", "users.id = orders.user_id").
WhereGe("created_at", "2026-01-01").
OrWhereEq("status", "vip").
GroupBy("user_id").
HavingGt("total", 1000).
OrderBy("total", core.Desc).
Limit(10).
Bind(&results).
Get()
iferr!=nil {
log.Fatal(err)
}
// First / LastvarlatestUser_, err=db.Read.Table("users").
OrderBy("id", core.Desc).
Bind(&latest).
First()
// Countcount, err:=db.Read.Table("users").
WhereNotNull("email").
Count()
// Paginated query with Totalvarpage []User_, err=db.Read.Table("users").
Total().
Limit(20).
Offset(40).
Bind(&page).
Get()
Write Operations
// Batch insertaffected, err:=db.Write.Table("users").InsertBatch([]map[string]any{
{"name": "Bob", "email": "bob@example.com", "age": 25},
{"name": "Charlie", "email": "charlie@example.com", "age": 28},
})
// Conflict handling (Upsert)id, err:=db.Write.Table("users").
Conflict(core.Replace).
Insert(
map[string]any{"name": "Alice", "email": "alice@example.com", "age": 31},
map[string]any{"age": 31}, // ON CONFLICT DO UPDATE SET
)
// Updateaffected, err=db.Write.Table("users").
WhereEq("id", 1).
Update(map[string]any{"age": 32})
// Increase / Decrease / Toggleaffected, err=db.Write.Table("users").
WhereEq("id", 1).
Increase("age", 1).
Update()
affected, err=db.Write.Table("posts").
WhereEq("id", 5).
Toggle("is_published").
Update()
// Delete (requires explicit WHERE or force)affected, err=db.Write.Table("users").
WhereEq("id", 1).
Delete()
// Context supportctx, cancel:=context.WithTimeout(context.Background(), 5*time.Second)
defercancel()
_, err=db.Read.Table("users").
Context(ctx).
WhereEq("id", 1).
Bind(&user).
Get()
// Raw SQLrows, err:=db.Read.Raw().Query("SELECT * FROM users WHERE age > ?", 18)
result, err:=db.Write.Raw().Exec("DELETE FROM sessions WHERE expired_at < ?", time.Now())
API Reference
goSqlite.New
funcNew(c core.Config) (*core.Connector, error)
Create a read-write separated SQLite connection. The write side uses a single connection with WAL mode; the read side uses a configurable connection pool.
core.Config
Field
Type
Required
Description
Path
string
Yes
SQLite database file path
Lifetime
int
No
Max read connection lifetime in seconds (default 120)