dorm

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 9 Imported by: 0

README

dorm

dorm is a PostgreSQL-first ORM for Go.

It is designed around explicit schema changes, deterministic migrations, schema drift detection, and context-aware access control.

What This Project Is

  • PostgreSQL-first, not database-agnostic by default
  • Model-driven, with models as the source of truth
  • Migration-based, with no AutoMigrate behavior
  • Context-aware, for company, tenant, and audit injection
  • Observable by design, with an OpenTelemetry-ready API surface

Package Map

  • orm - runtime CRUD, queries, transactions, and session handling
  • migrate - model parsing, diffing, migration generation, and execution
  • schema - schema representation, snapshots, and drift comparison
  • access - context-aware ownership and audit injection
  • dialect - SQL rendering abstractions

Quickstart

1. Define a model
package models

import (
	"time"
)

type User struct {
	ID        string    `orm:"pk"`
	Email     string    `orm:"unique"`
	CompanyID string    `orm:"company"`
	CreatedAt time.Time `orm:"created_at"`
	UpdatedAt time.Time `orm:"updated_at"`
}
2. Build the ORM
db := orm.New(orm.Config{
	Dialect: postgres.New(),
	Schema:   expectedSchema,
	Observability: orm.DefaultObservabilityConfig(),
})
3. Use a context
ctx := access.WithContext(context.Background(), access.Context{
	UserID:    "user-123",
	CompanyID: "company-123",
})
4. Query data
var users []models.User
err := db.WithContext(ctx).Find(&users)
5. Create data
u := models.User{
	Email: "alice@example.com",
}

err := db.WithContext(ctx).Create(&u)

CLI Tutorial

The CLI is part of the workflow for schema changes.

Initialize a project
orm init
Generate a migration
orm migrate generate
Apply migrations
orm migrate run
Check drift
orm schema check
Inspect status
orm migrate status
  1. Edit Go models.
  2. Generate a migration.
  3. Review the generated SQL.
  4. Apply the migration.
  5. Run schema drift checks in CI and at startup.

Tutorial Notes

  • The project does not use AutoMigrate.
  • Schema generation starts from models, not from live database state.
  • Soft delete, company injection, and audit fields are driven by model metadata and request context.
  • Observability is part of the architecture, but full tracing and metrics wiring are added behind the API surface.

Development

go test ./...

Architectural Rules

  • Keep schema changes explicit.
  • Keep PostgreSQL as the primary target.
  • Keep public APIs small and stable.
  • Keep security and correctness ahead of convenience.

Docs

License

This project is licensed under the MIT License.

Documentation

Overview

Package dorm provides the stable public entry points for opening database connections.

Index

Constants

View Source
const (
	// VersionMajor is the major release component for the current public API.
	VersionMajor = 0
	// VersionMinor is the minor release component for the current public API.
	VersionMinor = 1
	// VersionPatch is the patch release component for the current public API.
	VersionPatch = 0
)
View Source
const (
	// MinimumSupportedGoVersion is the minimum Go toolchain version supported by this release line.
	MinimumSupportedGoVersion = "1.26"
)

Variables

View Source
var (
	// SupportedOS lists the platform targets considered supported by the framework.
	SupportedOS = []string{"linux", "darwin", "windows"}
	// SupportedArch lists the CPU architectures considered supported by the framework.
	SupportedArch = []string{"amd64", "arm64"}
	// SupportedPostgresMajorVersions lists the PostgreSQL major versions validated by this release line.
	SupportedPostgresMajorVersions = []int{13, 14, 15, 16, 17}
)

Functions

func RegisterDriver

func RegisterDriver(d driver.Driver)

func RegisteredDriver

func RegisteredDriver() driver.Driver

func Version

func Version() string

Version returns the current module version in semantic version format.

Types

type APIContract

type APIContract struct {
	Name            string
	Lifecycle       APILifecycle
	DeprecatedSince string
	Replacement     string
}

APIContract describes the lifecycle state of a public symbol or package.

func DeprecatedAPI

func DeprecatedAPI(name, since, replacement string) APIContract

DeprecatedAPI creates a deprecated API contract record.

func ExperimentalAPI

func ExperimentalAPI(name string) APIContract

ExperimentalAPI creates an experimental API contract record.

func StableAPI

func StableAPI(name string) APIContract

StableAPI creates a stable API contract record.

func (APIContract) IsDeprecated

func (c APIContract) IsDeprecated() bool

IsDeprecated reports whether the contract is deprecated.

func (APIContract) IsStable

func (c APIContract) IsStable() bool

IsStable reports whether the contract is stable.

type APILifecycle

type APILifecycle string

APILifecycle describes the lifecycle of a public symbol.

const (
	// APILifecycleExperimental marks a symbol that may change without notice.
	APILifecycleExperimental APILifecycle = "experimental"
	// APILifecycleStable marks a supported public symbol.
	APILifecycleStable APILifecycle = "stable"
	// APILifecycleDeprecated marks a public symbol that should not be used for new code.
	APILifecycleDeprecated APILifecycle = "deprecated"
	// APILifecycleRemoved marks a symbol that has been removed from the public API.
	APILifecycleRemoved APILifecycle = "removed"
)

type CompatibilityPolicy

type CompatibilityPolicy struct {
	MinimumGoVersion string
	OperatingSystems []string
	Architectures    []string
	PostgresMajors   []int
}

CompatibilityPolicy describes supported runtime and database environments.

func DefaultCompatibilityPolicy

func DefaultCompatibilityPolicy() CompatibilityPolicy

DefaultCompatibilityPolicy returns the framework compatibility policy for this release line.

func (CompatibilityPolicy) Summary

func (p CompatibilityPolicy) Summary() string

Summary returns a stable human-readable summary of the compatibility policy.

func (CompatibilityPolicy) SupportsPostgreSQLMajor

func (p CompatibilityPolicy) SupportsPostgreSQLMajor(major int) bool

SupportsPostgreSQLMajor reports whether the provided PostgreSQL major version is supported.

func (CompatibilityPolicy) ValidateRuntime

func (p CompatibilityPolicy) ValidateRuntime() error

ValidateRuntime checks whether the current Go runtime and platform are supported.

type DB

type DB = orm.DB

func Open

func Open(ctx context.Context, drivers ...driver.Driver) (*DB, error)

type RoadmapModule

type RoadmapModule struct {
	Name        string
	Description string
	Contract    APIContract
}

RoadmapModule describes a stable core capability or a planned future module.

func ExperimentalRoadmap

func ExperimentalRoadmap() []RoadmapModule

ExperimentalRoadmap returns the planned future modules only.

func Roadmap

func Roadmap() []RoadmapModule

Roadmap returns the stable core and the likely future modules for the framework.

func StableCore

func StableCore() []RoadmapModule

StableCore returns the stable core roadmap items only.

Directories

Path Synopsis
Package access applies context-scoped policies and row-level access controls.
Package access applies context-scoped policies and row-level access controls.
cmd
orm command
Package dialect defines SQL rendering contracts for database-specific implementations.
Package dialect defines SQL rendering contracts for database-specific implementations.
Package driver defines database driver integration for opening connections and exposing dialects.
Package driver defines database driver integration for opening connections and exposing dialects.
Package errkind defines typed error categories used throughout the framework.
Package errkind defines typed error categories used throughout the framework.
Package migrate generates, writes, and applies database migrations.
Package migrate generates, writes, and applies database migrations.
Package orm provides the runtime ORM for querying and mutating application models.
Package orm provides the runtime ORM for querying and mutating application models.
Package schema parses, inspects, and compares database schema definitions.
Package schema parses, inspects, and compares database schema definitions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL