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, Rust, Java, Kotlin, and Swift.
  • 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

Schema-grounded code requests

The @an5/orm/generator export prepareCodeRequest({ request, projectRoot, schemaPath, language: 'auto' }) returns context_ready with schema models and real generated API references for the caller's AI model. It generates reference files in temporary storage and cleans them afterward. detectCodeLanguage reads language manifests in the selected project directory and rejects ambiguous or missing markers. This API does not call an LLM, execute queries, or write application code.

Metadata

Release files for an5-orm 1.3.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.3.0
File Size Uploaded Provenance Actions
an5_orm-1.3.0.tar.gz 4.0 kB Without provenance Details for an5_orm-1.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 7.9 kB

Release files / an5_orm-1.3.0.tar.gz

Download URL an5_orm-1.3.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cc6c44e2744ff3a21524ec13ba85c08d6ea3845c6c4b54fafda2275128bd9682
BLAKE2b-256 checksum
How to use checksums
8ab6640f4ed54de83be22f32857fb5b0a0c4fb858483567099db37bd2fbe2c7a
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.3.0-py3-none-any.whl

Download URL an5_orm-1.3.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e034befd218038926ab254b3eb23ef6f3f5fd24c2e42e7ae51b5a34e62acba73
BLAKE2b-256 checksum
How to use checksums
07f4e1073093a5337118e1133bb099222a54a8a9b07e8f300ac072bd6bdce440
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.3.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