Prisma for Go
Type-safe, stdlib-only ORM and query builder for Go.
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
$ go get github.com/malcolmston/prismaQuick start
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 aModelheld by aRegistry - Generic chainable builder —
NewQuery[T]withWhere,OrderBy,Take,Skip,SelectandInclude - Typed operators —
Equals,Not,In,NotIn,Lt/Lte/Gt/Gte,Contains,StartsWith,EndsWith, combined withAnd,OrandNotGroup - Always parameterized — literal values are bound as arguments, never concatenated into the SQL text
*SQLtwins —FindManySQL,CountSQL,CreateSQL,UpdateSQLandDeleteSQLreturn(sql, args)without hitting the database- Terminal operations —
FindMany,FindFirst,FindUnique,Count,Create,CreateMany,UpdateandDelete - Eager loading —
Includepulls a to-one relation via a LEFT JOIN and scans it into the struct - Pluggable dialects —
Question(?) andDollar($1, $2, …) selected withWithDialect - Zero dependencies — pure Go standard library over
database/sql, no cgo, nothing to audit but the toolchain