Package: neat

The database layer — ORM, query builder, migrations, and multi-driver connections powering every datastore.

Package: neat

Neat is the Dracory database layer — an ORM and database toolkit aiming for feature parity with Laravel's Eloquent, built from scratch without GORM dependencies. It provides the query builder, migration system, and connection management that every datastore is built on, and replaced the older database, migrate, sb, and uid packages.

Repository: https://github.com/dracory/neat

Installation

go get github.com/dracory/neat

Features

  • Query Builder — fluent WHERE / ORDER BY / GROUP BY / LIMIT with SQL-injection-safe identifier validation.
  • ORM — struct-to-table mapping, associations (BelongsTo, HasMany, HasOne, polymorphic), eager and lazy loading.
  • Migrations — Migrator package with schema builder, rollback support, and automatic tracking.
  • Schema Builder — create/alter tables, indexes, and database views (CreateView, HasView, ...).
  • Seeders & Factories — test-data seeding and factory-pattern generation.
  • Observers — model lifecycle events (creating, created, updating, ...).
  • Soft Deletes — NULL-based or max-date sentinel strategies, WithTrashed, Restore, ForceDelete.
  • Transactions — callback-style transaction support.

Drivers

  • Relational: MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle, Turso (libsql).
  • Cloud: Azure Table Storage / Cosmos DB via aztablessql.
  • File-based: CSVDB (CSV directory or embed.FS), JSONDB, XMLDB.
  • In-memory: GODB (compiled-in Go slices) and array-backed sources via NewArraySourceFrom.

Usage

package main

import (
    "log"
    "github.com/dracory/neat"
)

func main() {
    // Open via DSN
    db, err := neat.NewFromDSN("sqlite:///data/app.db")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    // Query
    var users []User
    err = db.Query().Where("status", "active").OrderBy("id", neat.SortDesc).Get(&users)
}

In the Framework

The app's internal/app/database_open.go opens the configured connection with neat and hands it to every store; store packages run their migrations through the Migrator. neat.GenerateID() produces the IDs for all datastore entities, and neat.SortAsc/neat.SortDesc order store list queries.