Skip to main content

@an5/orm

SQL Server ORM. Proxy client. CRUD. Vector search. Middleware. Raw queries. Transactions.

Features

  • Proxy Client. Flexible model access (db.User, db.user, db.Users, db.users).
  • CRUD. findMany, findFirst, findUnique, count, create, createMany, update, updateMany, delete, deleteMany, upsert.
  • Advanced Queries. OR/AND, nested relations, aggregates, groupBy.
  • Vector Search. Native SQL Server VECTOR_DISTANCE. In-memory fallback.
  • Middleware. Hook ORM operations: logging, auth, validation.
  • Raw Queries. $queryRaw, $executeRaw. Auto NOLOCK.
  • Transactions. $transaction. Rollback support.
  • Schema Generator. Parse .an5 files. Generate TypeScript, Python, .NET (C#), and Golang code.

Quick Start

Installation

TypeScript / Node.js

npm install @an5/orm

Python

pip install an5-orm

Configuration

cp .env.example .env
# Edit .env. Set DATABASE_URL.

Development Commands

Run from the an5Orm/ repository directory (no separate CLI binary is shipped):

# Generate client code from schema
npm run generate

# Push schema to database
npm run db:push

# Pull schema from database
npm run db:pull

# Seed database
npm run db:seed

# Compare schema with database
npm run db:migrate diff

# Generate migration SQL / show status
npm run db:migrate:generate
npm run db:migrate:status

# Run tests
npm test

Usage

import { An5ORM } from '@an5/orm';

const db = new An5ORM();

The default executor reads the DATABASE_URL environment variable. Schema metadata (model→table mapping, relations, field types) is auto-loaded from the ORM's own generated metadata file an5Metadata.ts (created by npm run generate, configured via outputs.typescript.ormMetadataFile). The ORM owns this metadata locally — it never imports from the generated client package (the client is generated from the ORM).

To provide metadata explicitly instead:

import { An5ORM } from '@an5/orm';
import { modelToTable, relationMap, modelFields } from './an5Metadata';

const db = new An5ORM(undefined, { modelToTable, relationMap, modelFields });

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

const user = await db.user.create({ data: { email: 'john@example.com', name: 'John' }, });

// Relations const orders = await db.user.findMany({ include: { orders: true }, });

// Vector Search const similar = await db.document.vectorSearch({ vector: [0.1, 0.2, 0.3], take: 5, distanceMetric: 'cosine', });

// Transactions await db.$transaction(async (tx) => { const user = await tx.user.create({ data: { email: 'jane@example.com' } }); await tx.order.create({ data: { userId: user.id, total: 100 } }); });

const tx = await db.$begin(); try { await tx.user.update({ where: { id }, data: { active: true } }); await tx.$commit(); } catch (error) { await tx.$rollback(); throw error; }

// Raw Queries const results = await db.$queryRawSELECT * FROM users WHERE id = ${id};


## Schema Definition

Schema files: `.an5`. Path: `an5Schema/`. SQL Server types.

```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")
}

Supported SQL Server Types

Type mapping: .an5 to TypeScript.

Schema Type TypeScript
NVARCHAR(n), VARCHAR(n), CHAR(n), TEXT string
INT, SMALLINT, TINYINT, FLOAT, REAL, DECIMAL, NUMERIC number
BIGINT number | bigint
BIT boolean
DATETIME, DATETIME2, DATE, TIME Date
UNIQUEIDENTIFIER string
VARBINARY, BINARY, IMAGE Buffer

Testing

# Unit tests
node test/unit.test.js

# Generator tests
node test/generator.test.js

# Smoke test
npm test

License

MIT

Metadata

Release files for an5-orm 1.0.8

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.8
File Size Uploaded Provenance Actions
an5_orm-1.0.8.tar.gz 3.6 kB Without provenance Details for an5_orm-1.0.8.tar.gz

Built distribution (wheel)

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

Total release size: 7.2 kB

Release files / an5_orm-1.0.8.tar.gz

Download URL an5_orm-1.0.8.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1de26ea5f4219e0822c92bdfa062696f407c340b6074c29d4cb2e766a962d9b4
BLAKE2b-256 checksum
How to use checksums
07e1ca576a55f789f002f1a9aa47bb3ea51494e93daf87a2d2c2ff2b10034142
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.8-py3-none-any.whl

Download URL an5_orm-1.0.8-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0538f2852d2ace9514e509136f10f9b38e1f6973ff3c4ad78710c86702aa6399
BLAKE2b-256 checksum
How to use checksums
8a26788ec26c7cf819f052a766d873a333e21daefa00595d09134e0fc2f33f4b
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.8

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