portablesql

Portable SQL toolkit for Go

Write your database code once. Run it on MySQL, PostgreSQL, and SQLite.

Why portablesql?

A modular SQL toolkit designed for real-world Go applications.

Multi-Database

Write queries that work across MySQL, PostgreSQL, and SQLite with zero changes. One API, every database.

Zero Bloat

Only download the driver you need. Import sqlite? You won't pull in pgx or mysql dependencies.

Type-Safe

Struct-based ORM with compile-time safety, generics support, and Go 1.23+ iterators.

Quick Start

Get up and running in minutes with a few lines of Go.

main.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
    }
}

Packages

Install only what you need. Each driver is a separate module.

psql core

Core query builder, ORM, and database abstraction layer.

go get github.com/portablesql/psql
View on GitHub
psql-mysql driver

MySQL and MariaDB driver integration.

go get github.com/portablesql/psql-mysql
View on GitHub
psql-pgsql driver

PostgreSQL driver integration via pgx.

go get github.com/portablesql/psql-pgsql
View on GitHub
psql-sqlite driver

SQLite driver integration for embedded databases.

go get github.com/portablesql/psql-sqlite
View on GitHub