Portable SQL toolkit for Go
Write your database code once. Run it on MySQL, PostgreSQL, and SQLite.
A modular SQL toolkit designed for real-world Go applications.
Write queries that work across MySQL, PostgreSQL, and SQLite with zero changes. One API, every database.
Only download the driver you need. Import sqlite? You won't pull in pgx or mysql dependencies.
Struct-based ORM with compile-time safety, generics support, and Go 1.23+ iterators.
Get up and running in minutes with a few lines of Go.
package main import ( "context" "github.com/portablesql/psql" _ "github.com/portablesql/psql-sqlite" ) type User struct { ID string `sql:",key=PRIMARY"` Name string `sql:"Name,type=VARCHAR,size=255"` Email string `sql:"Email,type=VARCHAR,size=255"` } func main() { be, _ := psql.New(":memory:") ctx := be.Context(context.Background()) // Insert u := &User{ID: "u1", Name: "Alice", Email: "alice@example.com"} psql.Insert(ctx, u) // Query found, _ := psql.Fetch[User](ctx, map[string]any{"Email": "alice@example.com"}) _ = found // Builder rows := psql.B[User]().Where("Name", psql.Like{Like: "A%"}).Each(ctx) for row, err := range rows { _ = row _ = err } }
Install only what you need. Each driver is a separate module.
Core query builder, ORM, and database abstraction layer.
go get github.com/portablesql/psqlMySQL and MariaDB driver integration.
go get github.com/portablesql/psql-mysqlPostgreSQL driver integration via pgx.
go get github.com/portablesql/psql-pgsqlSQLite driver integration for embedded databases.
go get github.com/portablesql/psql-sqlite