scheme-runtime-go

module
v0.0.0-...-95dcaac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT

README

Scheme Runtime Go

A type-safe, generics-based Go runtime library for the Scheme ORM framework. Provides a fluent query builder, PostgreSQL SQL compiler, and database execution layer with first-class support for Google API Improvement Proposals (AIPs).

Features

  • Type-Safe Query Builder — Fluent API powered by Go generics (QueryBuilder[Model, Mutator])
  • PostgreSQL Compiler — Generates parameterized SQL with $N bind variables and pgx.Identifier escaping
  • Full CRUD — Get, First, Insert, Update, UpdateMany, Delete, OnConflictUpdate, OnConflictDoNothing with RETURNING variants
  • Bulk Mutations — Efficient multi-row operations using PostgreSQL UNNEST(...) with typed array casts
  • AIP-160 Filtering — Parse Google API filter strings into composable WHERE conditions
  • AIP-132 Ordering — Parse order_by strings into ORDER BY clauses
  • AIP-158 Pagination — Offset-based pagination with page token encoding/decoding
  • Relationship Eager Loading — HasOne, HasMany, BelongsTo, BelongsToMany
  • Rich Column Types — Numeric, String, Array, JSON, Geo, Timestamp, UUID, Duration, Decimal, and nullable variants
  • Composable WHERE Conditions — Basic, Between, Column, Date, Exists, In, JSON, Nested, Null, Raw, Subquery

Installation

go get github.com/uthereal/scheme-runtime-go

Architecture

pkg/contract/    → Interfaces and type definitions
pkg/orm/         → Query builder and fluent API
pkg/grammar/     → SQL compilation engine (PostgreSQL)
pkg/testutil/    → Test infrastructure (ephemeral Postgres via testcontainers)
examples/        → Generated-code examples and integration tests
Quick Example
// Create a query builder (typically from generated code)
qb := orm.NewQueryBuilder[User, UserMutator](
    db, grammar.NewPostgresGrammar(), userTable, hydrateUser, dehydrateUser,
)

// Fluent queries
users, err := qb.
    Where(UserColumns.Status.Eq("active")).
    OrderBy(UserColumns.CreatedAt.Desc()).
    Limit(10).
    Get(ctx)

// AIP-160 filter strings
qb, err := qb.WhereAip160(
    `status = "active" AND age >= 18`,
    globalFields,
    mapColumnToAip160Field,
)

// Bulk insert with RETURNING
users, err := qb.InsertManyReturning(ctx, mutators)

// Eager loading
users, err := qb.With(UserRelations.Posts, UserRelations.Profile).Get(ctx)

Testing

Unit and integration tests use ephemeral PostgreSQL containers via testcontainers-go. Docker must be running.

go test ./...

Dependencies

Dependency Purpose
pgx/v5 PostgreSQL driver
samber/lo Functional utilities
chromium/luci AIP-160/132 parsing
einride/aip AIP-158 pagination
testcontainers-go Ephemeral Postgres for tests

License

MIT

Directories

Path Synopsis
examples
pkg
orm
orm/column
Package column defines the generic, strongly-typed column schemas used by developers to build type-safe query constraints.
Package column defines the generic, strongly-typed column schemas used by developers to build type-safe query constraints.
orm/relation
Package relation defines the concrete, strongly-typed relationship types used to declare relationship structures and compile nested sub-queries.
Package relation defines the concrete, strongly-typed relationship types used to declare relationship structures and compile nested sub-queries.
orm/where
Package where defines the concrete, non-generic WHERE condition structs used by the ORM state machine.
Package where defines the concrete, non-generic WHERE condition structs used by the ORM state machine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL