ubgo is in early alpha: libraries and APIs may still change.

Skip to content
ubgo Alpha

sqlb

Typed SQL builder with compile-checked columns and joins, Postgres and ClickHouse packages and a driver conformance suite.

go get github.com/ubgo/sqlb
Language
Go
Go version
1.24
Core deps
0 direct
Latest tag
v0.1.1
License
Apache-2.0
Go modules
8

How it fits together

passes sqlbtest

sqlbtest is the shared conformance suite: each one marked green has a test that runs it.

Highlights from the README

  • A column is an Expr[T]. Comparing it with the wrong type, joining it to a mismatched column, or binding it to the wrong pointer is a compile error, not a runtime surprise.
  • A query carries its own scan targets. The column list and the destinations come from one slice, so inserting a column in the middle cannot silently shift a scan.
  • Zero third-party dependencies in the core, enforced by a gate rather than by good intentions. Embedding sqlb adds no driver, no cgo and no version conflict.
  • Engine packages carry what one engine spells differently. JSONB, arrays, ranges, full-text search, DISTINCT ON, ON CONFLICT, MERGE and RETURNING in pg; JSON1, FTS5 and both upsert forms in sqlite; PREWHERE, FINAL and LIMIT BY in ch. The pg surface is the large one — about five hundred constructs to the core’s two hundred and sixty, which is what the universality rule produces: almost nothing is spelled identically by four engines.
  • Extensions are sub-packages over exported guarded constructors, so adding pgvector support, or the next extension nobody has written yet, never edits the engine package.

Code from the README

dist := vector.L2(embedding, vector.ParamVector(query))

_, err := sqlb.NewSelect(sqlb.SQLiteDialect{}).Columns(sqlb.Bind(dist, &d)).From(docs).Build()
// err: sqlb: construct is not supported by this dialect
//      vector.L2 under dialect "sqlite"

From the sqlb README.