@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
.an5syntax 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.an5models. - Direct Schema Push (
db:push): Synchronize.an5schema 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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| an5_orm-1.3.1.tar.gz | 4.0 kB | Without provenance | Details for an5_orm-1.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| an5_orm-1.3.1-py3-none-any.whl | Python 3 | none | any | Details for an5_orm-1.3.1-py3-none-any.whl |
Total release size: 7.9 kB
Release files / an5_orm-1.3.1.tar.gz
| Download URL | an5_orm-1.3.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
671362d641bd30f29a01bef7046f8573cb229dd8e7ddbca9ac9517152e9c1d61
|
|
BLAKE2b-256 checksum How to use checksums |
748e3644ff58d02909a283beba1aeffc9cdd01e747e3c43dec838c8c559c7ed7
|
| 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.1-py3-none-any.whl
| Download URL | an5_orm-1.3.1-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
051ee3f39378d47fc63265f6eae06b9cf98c7051ee9db1fc28673b17696f5446
|
|
BLAKE2b-256 checksum How to use checksums |
5fa5e843cb188f9a58f3f4ce6359d259c2374fc9a5a465653fcc894d21b77aa5
|
| 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.1
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.