Skip to main content

@an5/orm

The Schema, Code Generator, and Migration Toolkit for the AN5 ecosystem.

Overview

@an5/orm provides core schema parsing, multi-language code generation (TypeScript, Python, .NET C#, Golang, Rust), database introspection (pull), schema deployment (push), and automated database migrations.

Runtime database connections, query building, transactions, and multi-database drivers (MSSQL, PostgreSQL, MySQL, SQLite, Google Sheets) are powered by @an5/adapters.

Features

  • Schema Definition: Define models and relationships using concise .an5 syntax with native database types.
  • Multi-Language Generator: Generate typed clients and entity models for TypeScript, Python, .NET (C#), Golang, and Rust.
  • Database Introspection (db:pull): Inspect an existing database schema and generate matching .an5 models.
  • Direct Schema Push (db:push): Synchronize .an5 schema definitions directly to the database.
  • Automated Migrations (db:migrate): Diff schema against database, generate up/down migration SQL scripts, apply, rollback, and check migration status.
  • Seeding & Cleanup: Generic runner for project seed scripts (seed.ts/seed.js) and database cleanup.
  • Seamless Adapter Integration: Built-in connection support via @an5/adapters.

Quick Start

Installation

npm install @an5/orm @an5/adapters

Configuration

Create an5Orm.config.js in your project root:

module.exports = {
  // Schema directory (default: 'an5Schema')
  schemaDir: 'an5Schema',

  // Generated client outputs
  outputs: {
    typescript: {
      outputDir: 'an5Client/typescript',
      metadataFile: 'an5Client/typescript/an5Metadata.ts',
    },
    python: {
      outputDir: 'an5Client/python',
      metadataFile: 'an5Client/python/an5_metadata.py',
    },
    dotnet: {
      outputDir: 'an5Client/dotnet',
    },
    golang: {
      outputDir: 'an5Client/golang',
    },
  },

  // Database pull options
  pull: {
    exclude: ['^__', '^sys\\.', '^migrations'],
    preserveRelations: true,
  },
};

Configure your environment variables in .env:

DATABASE_URL=sqlserver://localhost:1433;database=mydb;user=sa;password=Secret123!;encrypt=false

CLI Commands

# Generate client code from .an5 schemas
npm run generate

# Push schema directly to database
npm run db:push

# Pull database schema into .an5 files
npm run db:pull

# Check schema diff
npm run db:migrate diff

# Generate new migration script
npm run db:migrate:generate

# Apply pending migrations
npm run db:migrate:apply

# Rollback last migration
npm run db:migrate:rollback

# View migration status
npm run db:migrate:status

# Run database seed script
npm run db:seed

# Clean up database tables
npm run db:cleanup

Runtime Database Usage (via @an5/adapters)

To connect to your database and perform queries, use @an5/adapters:

import { createAn5Adapter } from '@an5/adapters';

const db = createAn5Adapter({
  connectionString: process.env.DATABASE_URL!,
});

// Connect to database
await db.$connect();

// Model operations
const users = await db.user.findMany({
  where: { email: { contains: '@example.com' } },
  orderBy: { createdAt: 'desc' },
  take: 10,
});

// Create record
const newUser = await db.user.create({
  data: {
    email: 'alex@example.com',
    name: 'Alex',
  },
});

// Transactions
await db.$transaction(async (tx) => {
  await tx.exec('UPDATE Users SET active = 1 WHERE id = @p_0', { p_0: 'u1' });
});

// Disconnect
await db.$disconnect();

Schema Definition (.an5)

Field types are validated against the database you are generating for. The provider comes from the connection string (DATABASE_URL first, then connectionString in an5Orm.config.js): sqlserver:// (and the fallback) is SQL Server, postgres:// PostgreSQL, mysql:// MySQL, sqlite:// SQLite, googlesheets:// Google Sheets. A type the provider does not have stops generation with every offending field listed at once — see PROVIDER_FIELD_TYPES in generator/src/field-types.ts.

model User {
  id        NVARCHAR(1000) @id @default(uuid())
  email     NVARCHAR(255)  @unique
  name      NVARCHAR(255)?
  createdAt DATETIME2      @default(now())
  orders    Order[]

  @@map("users")
}

model Order {
  id        NVARCHAR(1000) @id @default(uuid())
  userId    NVARCHAR(1000)
  total     INT            @default(0)
  user      User           @relation(fields: [userId], references: [id])

  @@map("orders")
}

License

MIT

Metadata

Release files for an5-orm 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for an5-orm 1.1.0
File Size Uploaded Provenance Actions
an5_orm-1.1.0.tar.gz 3.7 kB Without provenance Details for an5_orm-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for an5-orm 1.1.0
File Interpreter ABI Platform Actions
an5_orm-1.1.0-py3-none-any.whl Python 3 none any Details for an5_orm-1.1.0-py3-none-any.whl

Total release size: 7.3 kB

Release files / an5_orm-1.1.0.tar.gz

Download URL an5_orm-1.1.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c31e5b5a322179247fea3a885bf1556f890355c4d780315d83f467c128108b75
BLAKE2b-256 checksum
How to use checksums
d27432a85737f064a252680692f0e00a2dbb3900b6e1d5d5438056291e3e7f8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / an5_orm-1.1.0-py3-none-any.whl

Download URL an5_orm-1.1.0-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d68ff5101868c87a22488766b9cc5e4e87ac2121943049b91254e1afafd7820
BLAKE2b-256 checksum
How to use checksums
d206de2db96a1914571e4f899bce997addfc068590e3b9ac16c070807fb63ddb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for an5-orm 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page