an5-orm 1.3.2__tar.gz → 1.3.6__tar.gz

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.
@@ -1,191 +1,254 @@
1
- Metadata-Version: 2.4
2
- Name: an5-orm
3
- Version: 1.3.2
4
- Summary: Lightweight ORM for SQL Server with Python support.
5
- Author: an5ORM
6
- License: MIT
7
- Keywords: an5,orm,sqlserver
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Requires-Python: >=3.8
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: an5-adapters>=0.2.0
13
-
14
- # @an5/orm
15
-
16
- The Schema, Code Generator, and Migration Toolkit for the AN5 ecosystem.
17
-
18
- ## Overview
19
-
20
- `@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.
21
-
22
- Runtime database connections, query building, transactions, and multi-database drivers (MSSQL, PostgreSQL, MySQL, SQLite, Google Sheets) are powered by **[@an5/adapters](https://github.com/an5ORM/an5Adapters)**.
23
-
24
- ## Features
25
-
26
- - **Schema Definition:** Define models and relationships using concise `.an5` syntax with native database types.
27
- - **Multi-Language Generator:** Generate typed clients and entity models for TypeScript, Python, .NET (C#), Golang, Rust, Java, Kotlin, and Swift.
28
- - **Database Introspection (`db:pull`):** Inspect an existing database schema and generate matching `.an5` models.
29
- - **Direct Schema Push (`db:push`):** Synchronize `.an5` schema definitions directly to the database.
30
- - **Automated Migrations (`db:migrate`):** Diff schema against database, generate up/down migration SQL scripts, apply, rollback, and check migration status.
31
- - **Seeding & Cleanup:** Generic runner for project seed scripts (`seed.ts`/`seed.js`) and database cleanup.
32
- - **Seamless Adapter Integration:** Built-in connection support via `@an5/adapters`.
33
-
34
- ## Quick Start
35
-
36
- ### Installation
37
-
38
- ```bash
39
- npm install @an5/orm @an5/adapters
40
- ```
41
-
42
- ### Configuration
43
-
44
- Create `an5Orm.config.js` in your project root:
45
-
46
- ```javascript
47
- module.exports = {
48
- // Schema directory (default: 'an5Schema')
49
- schemaDir: 'an5Schema',
50
-
51
- // Generated client outputs
52
- outputs: {
53
- typescript: {
54
- outputDir: 'an5Client/typescript',
55
- metadataFile: 'an5Client/typescript/an5Metadata.ts',
56
- },
57
- python: {
58
- outputDir: 'an5Client/python',
59
- metadataFile: 'an5Client/python/an5_metadata.py',
60
- },
61
- dotnet: {
62
- outputDir: 'an5Client/dotnet',
63
- },
64
- golang: {
65
- outputDir: 'an5Client/golang',
66
- },
67
- },
68
-
69
- // Database pull options
70
- pull: {
71
- exclude: ['^__', '^sys\\.', '^migrations'],
72
- preserveRelations: true,
73
- },
74
- };
75
- ```
76
-
77
- Configure your environment variables in `.env`:
78
-
79
- ```env
80
- DATABASE_URL=sqlserver://localhost:1433;database=mydb;user=sa;password=Secret123!;encrypt=false
81
- ```
82
-
83
- ### CLI Commands
84
-
85
- ```bash
86
- # Generate client code from .an5 schemas
87
- npm run generate
88
-
89
- # Push schema directly to database
90
- npm run db:push
91
-
92
- # Pull database schema into .an5 files
93
- npm run db:pull
94
-
95
- # Check schema diff
96
- npm run db:migrate diff
97
-
98
- # Generate new migration script
99
- npm run db:migrate:generate
100
-
101
- # Apply pending migrations
102
- npm run db:migrate:apply
103
-
104
- # Rollback last migration
105
- npm run db:migrate:rollback
106
-
107
- # View migration status
108
- npm run db:migrate:status
109
-
110
- # Run database seed script
111
- npm run db:seed
112
-
113
- # Clean up database tables
114
- npm run db:cleanup
115
- ```
116
-
117
- ## Runtime Database Usage (via `@an5/adapters`)
118
-
119
- To connect to your database and perform queries, use `@an5/adapters`:
120
-
121
- ```typescript
122
- import { createAn5Adapter } from '@an5/adapters';
123
-
124
- const db = createAn5Adapter({
125
- connectionString: process.env.DATABASE_URL!,
126
- });
127
-
128
- // Connect to database
129
- await db.$connect();
130
-
131
- // Model operations
132
- const users = await db.user.findMany({
133
- where: { email: { contains: '@example.com' } },
134
- orderBy: { createdAt: 'desc' },
135
- take: 10,
136
- });
137
-
138
- // Create record
139
- const newUser = await db.user.create({
140
- data: {
141
- email: 'alex@example.com',
142
- name: 'Alex',
143
- },
144
- });
145
-
146
- // Transactions
147
- await db.$transaction(async (tx) => {
148
- await tx.exec('UPDATE Users SET active = 1 WHERE id = @p_0', { p_0: 'u1' });
149
- });
150
-
151
- // Disconnect
152
- await db.$disconnect();
153
- ```
154
-
155
- ## Schema Definition (`.an5`)
156
-
157
- Field types are validated against the database you are generating for. The provider
158
- comes from the connection string (`DATABASE_URL` first, then `connectionString` in
159
- `an5Orm.config.js`): `sqlserver://` (and the fallback) is SQL Server, `postgres://`
160
- PostgreSQL, `mysql://` MySQL, `sqlite://` SQLite, `googlesheets://` Google Sheets.
161
- A type the provider does not have stops generation with every offending field
162
- listed at once — see `PROVIDER_FIELD_TYPES` in `generator/src/field-types.ts`.
163
-
164
- ```an5
165
- model User {
166
- id NVARCHAR(1000) @id @default(uuid())
167
- email NVARCHAR(255) @unique
168
- name NVARCHAR(255)?
169
- createdAt DATETIME2 @default(now())
170
- orders Order[]
171
-
172
- @@map("users")
173
- }
174
-
175
- model Order {
176
- id NVARCHAR(1000) @id @default(uuid())
177
- userId NVARCHAR(1000)
178
- total INT @default(0)
179
- user User @relation(fields: [userId], references: [id])
180
-
181
- @@map("orders")
182
- }
183
- ```
184
-
185
- ## License
186
-
187
- MIT
188
-
189
- ## Schema-grounded code requests
190
-
191
- 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.
1
+ Metadata-Version: 2.4
2
+ Name: an5-orm
3
+ Version: 1.3.6
4
+ Summary: Lightweight ORM for SQL Server with Python support.
5
+ Author: an5ORM
6
+ License: MIT
7
+ Keywords: an5,orm,sqlserver
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: an5-adapters>=0.2.0
13
+
14
+ # @an5/orm
15
+
16
+ The Schema, Code Generator, and Migration Toolkit for the AN5 ecosystem.
17
+
18
+ ## Overview
19
+
20
+ `@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.
21
+
22
+ Runtime database connections, query building, transactions, and multi-database drivers (MSSQL, PostgreSQL, MySQL, SQLite, Google Sheets) are powered by **[@an5/adapters](https://github.com/an5ORM/an5Adapters)**.
23
+
24
+ ## Features
25
+
26
+ - **Schema Definition:** Define models and relationships using concise `.an5` syntax with native database types.
27
+ - **Multi-Language Generator:** Generate typed clients and entity models for TypeScript, Python, .NET (C#), Golang, Rust, Java, Kotlin, and Swift.
28
+ - **Database Introspection (`db:pull`):** Inspect an existing database schema and generate matching `.an5` models.
29
+ - **Direct Schema Push (`db:push`):** Synchronize `.an5` schema definitions directly to the database.
30
+ - **Automated Migrations (`db:migrate`):** Diff schema against database, generate up/down migration SQL scripts, apply, rollback, and check migration status.
31
+ - **Seeding & Cleanup:** Generic runner for project seed scripts (`seed.ts`/`seed.js`) and database cleanup.
32
+ - **Seamless Adapter Integration:** Built-in connection support via `@an5/adapters`.
33
+
34
+ ## Quick Start
35
+
36
+ ### Installation
37
+
38
+ ```bash
39
+ npm install @an5/orm @an5/adapters
40
+ ```
41
+
42
+ ### Configuration
43
+
44
+ Create `an5Orm.config.js` in your project root:
45
+
46
+ ```javascript
47
+ module.exports = {
48
+ // Schema directory (default: 'an5Schema')
49
+ schemaDir: 'an5Schema',
50
+
51
+ // Generated client outputs
52
+ outputs: {
53
+ typescript: {
54
+ outputDir: 'an5Client/typescript',
55
+ metadataFile: 'an5Client/typescript/an5Metadata.ts',
56
+ },
57
+ python: {
58
+ outputDir: 'an5Client/python',
59
+ metadataFile: 'an5Client/python/an5_metadata.py',
60
+ },
61
+ dotnet: {
62
+ outputDir: 'an5Client/dotnet',
63
+ },
64
+ golang: {
65
+ outputDir: 'an5Client/golang',
66
+ },
67
+ },
68
+
69
+ // Database pull options
70
+ pull: {
71
+ exclude: ['^__', '^sys\\.', '^migrations'],
72
+ preserveRelations: true,
73
+ },
74
+ };
75
+ ```
76
+
77
+ Configure your environment variables in `.env`:
78
+
79
+ ```env
80
+ DATABASE_URL=sqlserver://localhost:1433;database=mydb;user=sa;password=Secret123!;encrypt=false
81
+ ```
82
+
83
+ ### CLI Commands
84
+
85
+ You can run AN5 commands directly using `npx @an5/orm` (or `npx an5`):
86
+
87
+ ```bash
88
+ # Generate client code from .an5 schemas
89
+ npx @an5/orm generate
90
+ # or: npx an5 generate
91
+
92
+ # Push schema directly to database
93
+ npx @an5/orm db:push
94
+
95
+ # Pull database schema into .an5 files
96
+ npx @an5/orm db:pull
97
+
98
+ # Check schema diff
99
+ npx @an5/orm db:migrate diff
100
+
101
+ # Generate new migration script
102
+ npx @an5/orm db:migrate generate
103
+
104
+ # Apply pending migrations
105
+ npx @an5/orm db:migrate apply
106
+
107
+ # Rollback last migration
108
+ npx @an5/orm db:migrate rollback
109
+
110
+ # View migration status
111
+ npx @an5/orm db:migrate status
112
+
113
+ # Run database seed script
114
+ npx @an5/orm db:seed
115
+
116
+ # Clean up extra tables and views
117
+ npx @an5/orm db:cleanup
118
+ ```
119
+
120
+ You can also add these commands to your project's `package.json` scripts:
121
+
122
+ ```json
123
+ {
124
+ "scripts": {
125
+ "generate": "an5 generate",
126
+ "db:push": "an5 db:push",
127
+ "db:pull": "an5 db:pull",
128
+ "db:migrate": "an5 db:migrate",
129
+ "db:seed": "an5 db:seed",
130
+ "db:cleanup": "an5 db:cleanup"
131
+ }
132
+ }
133
+ ```
134
+
135
+ Then run them with `npm run generate`, `npm run db:push`, etc.
136
+
137
+ ## Runtime Database Usage (via `@an5/adapters`)
138
+
139
+ To connect to your database and perform queries, use `@an5/adapters`:
140
+
141
+ ```typescript
142
+ import { createAn5Adapter } from '@an5/adapters';
143
+
144
+ const db = createAn5Adapter({
145
+ connectionString: process.env.DATABASE_URL!,
146
+ });
147
+
148
+ // Connect to database
149
+ await db.$connect();
150
+
151
+ // Model operations
152
+ const users = await db.user.findMany({
153
+ where: { email: { contains: '@example.com' } },
154
+ orderBy: { createdAt: 'desc' },
155
+ take: 10,
156
+ });
157
+
158
+ // Create record
159
+ const newUser = await db.user.create({
160
+ data: {
161
+ email: 'alex@example.com',
162
+ name: 'Alex',
163
+ },
164
+ });
165
+
166
+ // Transactions
167
+ await db.$transaction(async (tx) => {
168
+ await tx.exec('UPDATE Users SET active = 1 WHERE id = @p_0', { p_0: 'u1' });
169
+ });
170
+
171
+ // Disconnect
172
+ await db.$disconnect();
173
+ ```
174
+
175
+ ## Schema Definition (`.an5`)
176
+
177
+ Field types are validated against the database you are generating for. The provider
178
+ comes from the connection string (`DATABASE_URL` first, then `connectionString` in
179
+ `an5Orm.config.js`): `sqlserver://` (and the fallback) is SQL Server, `postgres://`
180
+ PostgreSQL, `mysql://` MySQL, `sqlite://` SQLite, `googlesheets://` Google Sheets.
181
+ A type the provider does not have stops generation with every offending field
182
+ listed at once — see `PROVIDER_FIELD_TYPES` in `generator/src/field-types.ts`.
183
+
184
+ ```an5
185
+ model User {
186
+ id NVARCHAR(1000) @id @default(uuid())
187
+ email NVARCHAR(255) @unique
188
+ name NVARCHAR(255)?
189
+ createdAt DATETIME2 @default(now())
190
+ orders Order[]
191
+
192
+ @@map("users")
193
+ }
194
+
195
+ model Order {
196
+ id NVARCHAR(1000) @id @default(uuid())
197
+ userId NVARCHAR(1000)
198
+ total INT @default(0)
199
+ user User @relation(fields: [userId], references: [id])
200
+
201
+ @@map("orders")
202
+ }
203
+ ```
204
+
205
+ Views are declared with the same field syntax, so generated clients can type their
206
+ rows, plus the `SELECT` that defines them. A view is read-only: writes are not
207
+ generated, and `db:push`/`db:migrate` create the view after the tables it reads —
208
+ and after any view it reads. `db:pull` writes a database view back as a `view`
209
+ block, with its columns and the SQL body from the catalog. `db:cleanup` drops
210
+ views that are no longer in the schema, before the tables they might read.
211
+
212
+ `@@sql` holds the `SELECT` body; a full `CREATE VIEW ... AS ...` statement pasted
213
+ from a catalog is reduced to that body, so its header and object name are not
214
+ repeated in the generated DDL.
215
+
216
+ Generated clients expose a view through a read-only client — `ViewClient` in
217
+ TypeScript, Python, .NET, Java and Kotlin, `ViewModelClient` in Swift, and
218
+ `ViewClient[T]` in Go and Rust. Those types have the read methods only, so a write
219
+ to a view is rejected at compile time rather than by the database.
220
+
221
+ ```an5
222
+ view ActiveUser {
223
+ id NVARCHAR(1000)
224
+ email NVARCHAR(255)
225
+
226
+ @@map("active_users")
227
+ @@sql("SELECT id, email FROM users WHERE active = 1")
228
+ }
229
+ ```
230
+
231
+ A longer query can be written over several lines with triple quotes; the indentation
232
+ shared by the SQL lines is removed before it reaches the database:
233
+
234
+ ```an5
235
+ view ActiveUser {
236
+ id NVARCHAR(1000)
237
+ email NVARCHAR(255)
238
+
239
+ @@map("active_users")
240
+ @@sql("""
241
+ SELECT id, email
242
+ FROM users
243
+ WHERE active = 1
244
+ """)
245
+ }
246
+ ```
247
+
248
+ ## License
249
+
250
+ MIT
251
+
252
+ ## Schema-grounded code requests
253
+
254
+ 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.