Type-Safe SQL Query Builder for Go. Schema Once, Query Forever.

Extract schema from struct tags, validate fields at init, and build queries with zero reflection on the hot path. Returns *T, not interface{}.

Get Started
import "github.com/zoobz-io/soy"

type User struct {
    ID    int64  `db:"id"    type:"bigserial primary key"`
    Email string `db:"email" type:"text unique not null"`
    Name  string `db:"name"  type:"text"`
    Age   int    `db:"age"   type:"int"`
}

// Schema extracted and validated here — once
users, _ := soy.New[User](db, "users", postgres.New())

// Every query after: type-safe, zero reflection, validated fields
user, _ := users.Select().
    Where("email", "=", "email_param").
    Exec(ctx, map[string]any{"email_param": "alice@example.com"})
// Returns *User, not interface{}

active, _ := users.Query().
    Where("age", ">=", "min_age").
    OrderBy("name", "asc").
    Limit(10).
    Exec(ctx, map[string]any{"min_age": 18})
// Returns []*User

updated, _ := users.Modify().
    Set("age", "new_age").
    Where("id", "=", "user_id").
    Exec(ctx, map[string]any{"new_age": 31, "user_id": 42})
// UPDATE requires WHERE — prevents accidents
58%Test Coverage
A+Go Report
MITLicense
1.24.0+Go Version
v1.0.8Latest Release

Why Soy?

All reflection at init. All validation at init. Everything after that is fast, safe, and typed.

Zero Reflection on Hot Path

Schema extracted once at New(). Query building uses O(1) map lookups. No reflection during execution.

True Generic Returns

Select returns *T, Query returns []*T. The compiler enforces correct types. No runtime casting.

Schema Validation at Init

Field name typos caught immediately at New(), not when the query executes at 3am in production.

Safety by Default

DELETE and UPDATE require explicit WHERE clauses. No accidental full-table operations.

Multi-Database Parity

PostgreSQL, MariaDB, SQLite, SQL Server via pluggable ASTQL providers. Same API, different dialects.

JSON-Serializable Specs

Build queries from config files, LLM output, or API request bodies. Validated against the same schema.

Capabilities

Six fluent builders covering the full SQL surface — all schema-validated, all type-safe.

FeatureDescriptionLink
Select & QuerySingle and multi-record retrieval with WHERE, ORDER BY, DISTINCT, GROUP BY, and row locking.Queries
Create & ModifyINSERT with conflict handling and UPDATE with required WHERE. Returns the affected record.Mutations
AggregatesCOUNT, SUM, AVG, MIN, MAX with GROUP BY, HAVING, FILTER, and window functions.Aggregates
Compound QueriesUNION, INTERSECT, EXCEPT for set operations across multiple query builders.Compound
Lifecycle CallbacksOnScan and OnRecord hooks for post-processing, computed fields, and audit logging.Lifecycle
Vector Searchpgvector semantic search with distance operators, embedding columns, and metadata filtering.pgvector

Articles

Browse the full soy documentation.

OverviewType-safe SQL query builder for Go with multi-database support

Learn

QuickstartGet started with soy in minutes
Core ConceptsQueries, conditions, builders, and specs - the building blocks of soy
ArchitectureSystem design and internal structure of soy

Guides

QueriesSELECT queries with filtering, ordering, grouping, and distinct
MutationsINSERT, UPDATE, and DELETE operations with safety features
AggregatesCOUNT, SUM, AVG, MIN, MAX with GROUP BY and HAVING
SpecsJSON-serializable query specifications for external construction
Compound QueriesUNION, INTERSECT, and EXCEPT for combining result sets
Lifecycle CallbacksIntercept records on scan and before write with OnScan and OnRecord

Cookbook

PaginationOffset-based and cursor-based pagination patterns
pgvectorSemantic search and similarity queries with pgvector

Reference

API ReferenceComplete API reference for the soy package