Skip to main content
Version: 1.11.0

API Reference

Symbol-level documentation for Quark's public API: signatures, parameters, and exact behaviour, grouped the same way the sidebar is.

Use these pages when you know what you want to call and need the details. If you are still working out how to do something, the Guides cover the same ground as walkthroughs.

Core API

  • Client - Creating and configuring the ORM client
  • Query Builder - Fluent type-safe query construction
  • CRUD - Create, Read, Update, Delete operations
  • Querying - Retrieving data: List, Find, aggregates, pagination

Model Definition

  • Modeling - Struct tags, relations, hooks

Schema & Data

Advanced Features

Reference

  • Dialects - Database dialect interface
  • Errors - Error types and handling
  • Routines - Stored procedures and functions

Quick Example

package main

import (
"context"

"github.com/jcsvwinston/quark"
_ "github.com/jcsvwinston/quark/drivers/postgres"
)

type User struct {
ID int64 `db:"id" pk:"true"`
Name string `db:"name"`
Email string `db:"email" quark:"unique"`
}

func main() {
client, _ := quark.New("pgx", "...")
ctx := context.Background()

// Create
user := &User{Name: "Alice", Email: "alice@example.com"}
quark.For[User](ctx, client).Create(user)
// => user.ID is populated with the generated primary key

// Read
u, _ := quark.For[User](ctx, client).Find(user.ID)
// => u is the matching User; err is quark.ErrNotFound if no row exists

// Query
users, _ := quark.For[User](ctx, client).
Where("active", "=", true).
OrderBy("created_at", "DESC").
List()
// => users is a []User of active rows, newest first

// Update
u.Name = "Alice Smith"
quark.For[User](ctx, client).Update(&u)
// => returns (rowsAffected int64, err error)

// Delete
quark.For[User](ctx, client).Delete(&u)
// => returns (rowsAffected int64, err error)
}