Repository navigation
v0.3.0 — Query Builder
🎉 Jone v0.3.0
The query builder is here! Jone now goes beyond migrations with a fluent, fully parameterized query builder for INSERT, SELECT, UPDATE, and DELETE — plus transactions and PostgreSQL RETURNING support.
✨ What's New
Query Builder
jone initnow generates a ready-to-useDBinstance in yourjonefile.go— the connection is lazy and opens automatically on your first query- INSERT accepts a
map[string]any,[]map[string]any, a struct, or a slice of structs (usingdbtags with snake_case fallback) - Multi-row inserts generate a single
INSERT INTO ... VALUES (...), (...)statement - Conflict handling with
OnConflict().Ignore()— no target, column targets, or partial-index expressions (ON CONFLICT DO NOTHINGon PostgreSQL,INSERT IGNOREon MySQL) - SELECT with column selection, ordering, pagination, and
First()for fetching a single row as amap[string]any - UPDATE and DELETE with parameterized SET values and WHERE conditions
ToSQL()on every builder to inspect the generated SQL and args without executing
Parameterized WHERE Clauses
- Conditions with bound values — never string interpolation:
Where("age", ">", 18),Where("email", v) - Full family:
OrWhere,WhereIn/WhereNotIn,WhereNull/WhereNotNull, andWhereRawas the raw-SQL escape hatch (?placeholders are rebound to$non PostgreSQL automatically) - Condition groups: pass a func to
Where/OrWherefor parenthesized groups, nestable to any depth:
db.Select("*").From("users").
Where("active", true).
Where(func(g *jone.WhereGroup) {
g.Where("role", "admin").OrWhere("age", ">", 65)
}).
Exec()
// WHERE "active" = $1 AND ("role" = $2 OR "age" > $3)- Injection-safe
OrderBy("created_at", "desc")— columns are quoted and directions validated;OrderByRawfor expressions
RETURNING Support (PostgreSQL)
ExecReturning("id", ...)on Insert, Update, and Delete returns the affected rows as[]map[string]any- Solves
LastInsertId()being unsupported by the PostgreSQL driver — get your generated IDs back directly - On MySQL, keep using
Exec()withresult.LastInsertId()
Transactions
db.Transaction(func(tx *jone.Schema) error { ... })— automatically commits on nil return, rolls back on errordb.Begin()returns aTxSchemafor manualCommit()/Rollback()control- All query methods work inside transactions
Raw Expressions
jone.Raw("gen_random_uuid()")inlines any SQL expression where a value is expectedjone.Fn.Now()shorthand forCURRENT_TIMESTAMP
⚠️ Breaking Changes
jone.NewSchema()is renamed tojone.New()— update yourjonefile.go(or re-runjone initin a fresh project to see the new template)
📦 Installation
go install github.com/Grandbusta/jone/cmd/jone@v0.3.0