7e302720200041e3d02095f8758e6f0e029dd9cb
ExprPtrs dereferences []*T values, skips nil entries, and maps survivors through a converter. Co-authored-by: Cursor <cursoragent@cursor.com>
dbx
Database extensions — a small toolkit of reusable database helpers built on Jet and go-toolkit/app.
Install
go get gitea.auvem.com/go-toolkit/dbx
Quick start
import (
"gitea.auvem.com/go-toolkit/app"
"gitea.auvem.com/go-toolkit/dbx"
_ "gitea.auvem.com/go-toolkit/dbx/dbxm" // MySQL debug logging only
)
func main() {
cfg := &dbx.DBConfig{
User: "user",
Password: "pass",
URI: "localhost:3306",
Name: "mydb",
MaxConn: 10,
}
modules := []*app.Module{
dbx.ModuleDB(dbx.DialectMySQL, cfg, false),
}
app.Run(modules...)
db := dbx.SQLO()
_ = db
}
For Postgres, use dbx.DialectPostgres and blank-import dbxp instead of dbxm when DebugLog is enabled.
Helper catalog
| Area | Functions |
|---|---|
| Query | Fetch, MustFetch, FetchOne, MustFetchOne, Query, MustQuery (+ *Context variants) |
| Mutations | Insert, InsertReturning, Update, UpdateAffected, UpdateOne, UpdateReturning, Delete, DeleteAffected (+ *Context variants) |
| Transactions | WithTx, WithTxValue |
| Columns | NormalCols, ContainsCol, ExprValues, ExprPtrs, ExprStringers, StringKSUIDExpr, BinaryKSUIDExpr, QueryCount, BuildQueryCountFn |
| Partial update | ApplyPtr, ApplyComplexPtr, ApplyInterfacePtr, ApplyVal |
| Pointers | Ptr, Val, NowPtr, TrimPtr, TrimPtrToNil, IsZero |
| Types | StringKSUID, BinaryKSUID, JSONB |
| GraphQL | MarshalUint64, UnmarshalUint64 |
KSUID type selection
| Type | SQL column | Storage |
|---|---|---|
StringKSUID |
VARCHAR(27), TEXT |
Base62 string |
BinaryKSUID |
BINARY(20), BYTEA |
Raw 20 bytes |
Both types use identical GraphQL string scalar transit. Pick the type that matches your column encoding — Scan rejects ambiguous payloads.
Dialect notes
- MySQL inserts: use
InsertforLastInsertIdworkflows. - Postgres inserts: use
InsertReturningwith a JetRETURNINGclause. - Debug logging: requires blank-import of
dbxmordbxpmatching your dialect. Without it, module setup returns an error whenDebugLogis true.
Documentation
Package docs are available on pkg.go.dev and via go doc gitea.auvem.com/go-toolkit/dbx.
Description
dbx is a small toolkit of reusable and common database patterns. Provides an app.Subsystem for initialization.
Languages
Go
100%