Quarry Docs
GitHub
Reference

Codex and Recipes

Store raw SQL templates, bind parameters safely, or register typed recipes for repeated Quarry builders.

Quarry logo

Raw stored queries

cx := codex.New()

if err := cx.AddRawNamed("users.by_id", `
    SELECT id, email
    FROM users
    WHERE id = :id
`); err != nil {
    panic(err)
}
q := cx.MustRaw("users.by_id").With(qq).BindMap(map[string]any{
    "id": 10,
})

sql, args, err := q.ToSQL()
Behavior Named raw SQL still follows the active dialect. PostgreSQL gets $1, MySQL and SQLite get ?.

Recipes

type UserSearchParams struct {
    Search string
    Status *string
}

recipe := codex.NewRecipe(func(qq *quarry.Quarry, p UserSearchParams) quarry.SQLer {
    return qq.Select("id", "email").
        From("users").
        Where(
            quarry.OptionalILike("email", p.Search),
            quarry.OptionalEq("status", p.Status),
        )
})
q, err := recipe.Build(qq, UserSearchParams{
    Search: "%bob%",
})
if err != nil {
    panic(err)
}
Truthful contract Recipe builds return (quarry.SQLer, error). The API prefers errors over panic in normal use.

Registry helpers

Validation

Query names are validated, duplicates are rejected, and the store stays deterministic.

Strict mode

Named queries can reject unused parameters when you want tighter review discipline.

Bindings

Bind by map, struct, or typed recipe parameter depending on the use case.