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), 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#), and Golang.
  • 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)

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.0.9

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.0.9
File Size Uploaded Provenance Actions
an5_orm-1.0.9.tar.gz 3.5 kB Without provenance Details for an5_orm-1.0.9.tar.gz

Built distribution (wheel)

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

Total release size: 6.8 kB

Release files / an5_orm-1.0.9.tar.gz

Download URL an5_orm-1.0.9.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
43877603c0c39906ef42cc458c8e629c892c13179ee48e6b60077bc94b33765c
BLAKE2b-256 checksum
How to use checksums
03e870847a2c47355fefe6475759450426ab42b3047253a1d60e86cdb05fbabb
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.0.9-py3-none-any.whl

Download URL an5_orm-1.0.9-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2458859c7dfaf524aad6e61a17eb2422ab5f403566297198d9f44d96b6ac7b3
BLAKE2b-256 checksum
How to use checksums
5dae6bffef17f1269a2eb883a6990970efa52b0885bb3041dc36a2bdddc546ab
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.0.9

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