Prisma for Go

github.com/malcolmston/prisma

Type-safe, stdlib-only ORM and query builder for Go.

 GitHubports prisma/prisma

A small, type-safe query builder and lightweight ORM over the standard database/sql package, inspired by the ergonomics of Prisma — with no dependencies beyond the Go standard library and no cgo. Models are plain Go structs annotated with prisma:"..." struct tags and compiled into a Model by reflection; a generic, chainable Query[T] builder emits parameterized SQL where literal values are always bound as arguments and never concatenated into the statement. Every terminal operation has a matching *SQL twin that returns the exact (sql, args) without touching the database, and a pluggable Dialect switches placeholder style between ? (MySQL/SQLite) and $1, $2, … (PostgreSQL). The import path is github.com/malcolmston/prisma and the package is named prisma.

Install

shell
$ go get github.com/malcolmston/prisma

Quick start

main.go
import "github.com/malcolmston/prisma"

client := prisma.NewClient(db) // any *sql.DB driver
client.Register(User{})

users, _ := prisma.NewQuery[User](client).
	Where(prisma.StartsWith("email", "ada"), prisma.Gt("id", 0)).
	OrderBy("name", prisma.Asc).
	Take(10).
	FindMany(ctx)

prisma.NewQuery[User](client).
	Create(ctx, User{Name: "Ada", Email: "ada@example.com"})

n, _ := prisma.NewQuery[User](client).Count(ctx)

Features

  • Plain-struct models — annotate fields with prisma:"col=…,pk,auto" tags; reflection compiles them into a Model held by a Registry
  • Generic chainable builder — NewQuery[T] with Where, OrderBy, Take, Skip, Select and Include
  • Typed operators — Equals, Not, In, NotIn, Lt/Lte/Gt/Gte, Contains, StartsWith, EndsWith, combined with And, Or and NotGroup
  • Always parameterized — literal values are bound as arguments, never concatenated into the SQL text
  • *SQL twins — FindManySQL, CountSQL, CreateSQL, UpdateSQL and DeleteSQL return (sql, args) without hitting the database
  • Terminal operations — FindMany, FindFirst, FindUnique, Count, Create, CreateMany, Update and Delete
  • Eager loading — Include pulls a to-one relation via a LEFT JOIN and scans it into the struct
  • Pluggable dialects — Question (?) and Dollar ($1, $2, …) selected with WithDialect
  • Zero dependencies — pure Go standard library over database/sql, no cgo, nothing to audit but the toolchain
Prisma