@an5/orm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/dist/an5Orm.d.ts +29 -0
- package/dist/an5Orm.js +1348 -0
- package/dist/cleanup.d.ts +2 -0
- package/dist/cleanup.js +117 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/migrate.d.ts +11 -0
- package/dist/migrate.js +298 -0
- package/dist/pull.d.ts +2 -0
- package/dist/pull.js +336 -0
- package/dist/push.d.ts +2 -0
- package/dist/push.js +258 -0
- package/dist/scripts/release-cli.d.ts +3 -0
- package/dist/scripts/release-cli.js +116 -0
- package/dist/seed.d.ts +2 -0
- package/dist/seed.js +401 -0
- package/generator/src/code-generator.ts +234 -0
- package/generator/src/dotnet-generator.ts +544 -0
- package/generator/src/index.ts +92 -0
- package/generator/src/metadata-generator.ts +79 -0
- package/generator/src/parser.ts +202 -0
- package/generator/src/python-generator.ts +90 -0
- package/generator/src/types.ts +29 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# an5Orm
|
|
2
|
+
|
|
3
|
+
SQL Server ORM. Proxy client. CRUD. Vector search. Middleware. Raw queries. Transactions.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Proxy Client.** Model access. `db.modelName` syntax.
|
|
8
|
+
- **CRUD.** `findMany`, `findFirst`, `findUnique`, `create`, `update`, `delete`, `upsert`.
|
|
9
|
+
- **Advanced Queries.** OR/AND, nested relations, aggregates, `groupBy`.
|
|
10
|
+
- **Vector Search.** Native SQL Server `VECTOR_DISTANCE`. In-memory fallback.
|
|
11
|
+
- **Middleware.** Hook ORM operations: logging, auth, validation.
|
|
12
|
+
- **Raw Queries.** `$queryRaw`, `$executeRaw`. Auto `NOLOCK`.
|
|
13
|
+
- **Transactions.** `$transaction`. Rollback support.
|
|
14
|
+
- **Schema Generator.** Parse `.an5` files. Generate TypeScript/Python/.NET code.
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### Configuration
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
cp .env.example .env
|
|
22
|
+
# Edit .env. Set DATABASE_URL.
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Development Commands
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Generate code from schema
|
|
29
|
+
npm run generate
|
|
30
|
+
|
|
31
|
+
# Push schema to database
|
|
32
|
+
npm run db:push
|
|
33
|
+
|
|
34
|
+
# Pull schema from database
|
|
35
|
+
npm run db:pull
|
|
36
|
+
|
|
37
|
+
# Seed database
|
|
38
|
+
npm run db:seed
|
|
39
|
+
|
|
40
|
+
# Run tests
|
|
41
|
+
npm test
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { An5ORM } from './an5Orm';
|
|
48
|
+
|
|
49
|
+
const db = new An5ORM();
|
|
50
|
+
|
|
51
|
+
// CRUD Operations
|
|
52
|
+
const users = await db.user.findMany({
|
|
53
|
+
where: { email: { contains: '@example.com' } },
|
|
54
|
+
orderBy: { createdAt: 'desc' },
|
|
55
|
+
take: 10,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const user = await db.user.create({
|
|
59
|
+
data: { email: 'john@example.com', name: 'John' },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Relations
|
|
63
|
+
const orders = await db.user.findMany({
|
|
64
|
+
include: { orders: true },
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Vector Search
|
|
68
|
+
const similar = await db.document.vectorSearch({
|
|
69
|
+
vector: [0.1, 0.2, 0.3],
|
|
70
|
+
take: 5,
|
|
71
|
+
distanceMetric: 'cosine',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Transactions
|
|
75
|
+
await db.$transaction(async (tx) => {
|
|
76
|
+
const user = await tx.user.create({ data: { email: 'jane@example.com' } });
|
|
77
|
+
await tx.order.create({ data: { userId: user.id, total: 100 } });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Raw Queries
|
|
81
|
+
const results = await db.$queryRaw`SELECT * FROM users WHERE id = ${id}`;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Schema Definition
|
|
85
|
+
|
|
86
|
+
Schema files: `.an5`. Path: `an5Schema/`. SQL Server types.
|
|
87
|
+
|
|
88
|
+
```an5
|
|
89
|
+
model User {
|
|
90
|
+
id NVARCHAR(1000) @id @default(uuid())
|
|
91
|
+
email NVARCHAR(255) @unique
|
|
92
|
+
name NVARCHAR(255)?
|
|
93
|
+
createdAt DATETIME2 @default(now())
|
|
94
|
+
orders Order[]
|
|
95
|
+
|
|
96
|
+
@@map("users")
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
model Order {
|
|
100
|
+
id NVARCHAR(1000) @id @default(uuid())
|
|
101
|
+
userId NVARCHAR(1000)
|
|
102
|
+
total INT @default(0)
|
|
103
|
+
user User @relation(fields: [userId], references: [id])
|
|
104
|
+
|
|
105
|
+
@@map("orders")
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Supported SQL Server Types
|
|
110
|
+
|
|
111
|
+
Type mapping: `.an5` to TypeScript.
|
|
112
|
+
|
|
113
|
+
| Schema Type | TypeScript |
|
|
114
|
+
|-------------|------------|
|
|
115
|
+
| `NVARCHAR(n)`, `VARCHAR(n)`, `CHAR(n)`, `TEXT` | `string` |
|
|
116
|
+
| `INT`, `SMALLINT`, `TINYINT`, `FLOAT`, `REAL`, `DECIMAL`, `NUMERIC` | `number` |
|
|
117
|
+
| `BIGINT` | `number \| bigint` |
|
|
118
|
+
| `BIT` | `boolean` |
|
|
119
|
+
| `DATETIME`, `DATETIME2`, `DATE`, `TIME` | `Date` |
|
|
120
|
+
| `UNIQUEIDENTIFIER` | `string` |
|
|
121
|
+
| `VARBINARY`, `BINARY`, `IMAGE` | `Buffer` |
|
|
122
|
+
|
|
123
|
+
## Testing
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Unit tests
|
|
127
|
+
node test/unit.test.js
|
|
128
|
+
|
|
129
|
+
# Generator tests
|
|
130
|
+
node test/generator.test.js
|
|
131
|
+
|
|
132
|
+
# Smoke test
|
|
133
|
+
npm test
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
package/dist/an5Orm.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type ExecutorFn = (queryText: string, params?: Record<string, any>) => Promise<any[]>;
|
|
2
|
+
export interface MiddlewareParams {
|
|
3
|
+
model?: string;
|
|
4
|
+
action: string;
|
|
5
|
+
args: any;
|
|
6
|
+
runInTransaction?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type MiddlewareNext = (params: MiddlewareParams) => Promise<any>;
|
|
9
|
+
export type Middleware = (params: MiddlewareParams, next: MiddlewareNext) => Promise<any>;
|
|
10
|
+
export declare class An5ORM {
|
|
11
|
+
private customExecutor?;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
private middlewares;
|
|
14
|
+
constructor(customExecutor?: ExecutorFn | undefined);
|
|
15
|
+
$use(middleware: Middleware): void;
|
|
16
|
+
_executeMiddleware(params: MiddlewareParams, finalAction: (params: MiddlewareParams) => Promise<any>): Promise<any>;
|
|
17
|
+
$connect(): Promise<void>;
|
|
18
|
+
$disconnect(): Promise<void>;
|
|
19
|
+
$queryRaw(queryParts: any, ...values: any[]): Promise<any[]>;
|
|
20
|
+
$queryRawUnsafe<R = any>(queryText: string, ...values: any[]): Promise<R>;
|
|
21
|
+
$executeRaw(queryParts: any, ...values: any[]): Promise<number>;
|
|
22
|
+
$executeRawUnsafe(queryText: string, ...values: any[]): Promise<number>;
|
|
23
|
+
$transaction<R>(fn: ((tx: any) => Promise<R>) | Promise<any>[], options?: {
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}): Promise<any>;
|
|
26
|
+
}
|
|
27
|
+
export declare const an5Orm: An5ORM;
|
|
28
|
+
export default an5Orm;
|
|
29
|
+
//# sourceMappingURL=an5Orm.d.ts.map
|