@an5/adapters 0.2.4 → 0.2.6
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 +189 -304
- package/dist/an5Adapter.d.ts +85 -7
- package/dist/an5Adapter.js +736 -64
- package/dist/base/metadata.d.ts +10 -0
- package/dist/base/metadata.js +107 -0
- package/dist/base/sql.d.ts +19 -1
- package/dist/base/sql.js +152 -24
- package/dist/base/types.d.ts +4 -1
- package/dist/browser.d.ts +5 -2
- package/dist/browser.js +10 -2
- package/dist/googlesheets/adapter.d.ts +1 -0
- package/dist/googlesheets/adapter.js +9 -2
- package/dist/googlesheets/config.d.ts +4 -4
- package/dist/googlesheets/helpers.js +2 -0
- package/dist/googlesheets/parseConnectionString.js +5 -2
- package/dist/googlesheets/sqlExecutor.js +29 -24
- package/dist/googlesheets/tableClient.js +14 -5
- package/dist/index.d.ts +5 -1
- package/dist/index.js +12 -1
- package/dist/mssql/engine.js +8 -4
- package/dist/mysql/engine.js +1 -1
- package/dist/postgres/engine.js +1 -1
- package/dist/sqlite/browserEngine.d.ts +27 -0
- package/dist/sqlite/browserEngine.js +161 -0
- package/dist/sqlite/engine.js +15 -3
- package/dist/sqlite/index.d.ts +1 -0
- package/dist/sqlite/index.js +1 -0
- package/dist/typed.d.ts +5 -0
- package/dist/typed.js +2 -0
- package/dotnet/An5Adapter.cs +1089 -275
- package/dotnet/Base/Core.cs +340 -82
- package/dotnet/Mssql/MssqlEngine.cs +145 -144
- package/dotnet/Postgres/PostgresEngine.cs +121 -121
- package/golang/an5_adapter.go +314 -0
- package/golang/base/base.go +100 -0
- package/golang/base/metadata.go +116 -0
- package/golang/base/where.go +311 -0
- package/golang/go.mod +3 -0
- package/golang/mssql/mssql.go +32 -0
- package/golang/postgres/postgres.go +37 -0
- package/golang/sqlite/sqlite.go +14 -0
- package/golang/sqlite_test.go +42 -0
- package/golang/table_client.go +1329 -0
- package/package.json +18 -8
- package/python/an5_adapter.py +119 -97
- package/python/base/__init__.py +3 -3
- package/python/base/dialects.py +11 -8
- package/python/base/metadata.py +35 -10
- package/python/base/sql.py +172 -121
- package/python/mssql/__init__.py +1 -1
- package/python/mssql/provider.py +62 -62
- package/python/postgres/__init__.py +1 -1
- package/python/postgres/provider.py +15 -15
- package/python/table_client.py +619 -216
- package/typescript/src/an5Adapter.ts +1220 -505
- package/typescript/src/base/index.ts +3 -3
- package/typescript/src/base/metadata.ts +148 -28
- package/typescript/src/base/sql.ts +264 -98
- package/typescript/src/base/types.ts +27 -24
- package/typescript/src/browser.ts +10 -6
- package/typescript/src/config.ts +95 -95
- package/typescript/src/googlesheets/adapter.ts +269 -259
- package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
- package/typescript/src/googlesheets/config.ts +47 -47
- package/typescript/src/googlesheets/helpers.ts +144 -143
- package/typescript/src/googlesheets/index.ts +3 -3
- package/typescript/src/googlesheets/parseConnectionString.ts +48 -46
- package/typescript/src/googlesheets/retry.ts +126 -126
- package/typescript/src/googlesheets/sqlExecutor.ts +304 -301
- package/typescript/src/googlesheets/tableClient.ts +461 -455
- package/typescript/src/googlesheets/types.ts +6 -6
- package/typescript/src/index.ts +32 -19
- package/typescript/src/mssql/engine.ts +134 -132
- package/typescript/src/mssql/index.ts +1 -1
- package/typescript/src/mysql/engine.ts +80 -80
- package/typescript/src/mysql/index.ts +1 -1
- package/typescript/src/postgres/engine.ts +87 -87
- package/typescript/src/postgres/index.ts +1 -1
- package/typescript/src/sqlite/browserEngine.ts +192 -0
- package/typescript/src/sqlite/engine.ts +66 -55
- package/typescript/src/sqlite/index.ts +3 -1
- package/typescript/src/typed.ts +52 -0
package/README.md
CHANGED
|
@@ -1,304 +1,189 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
Standalone runtime
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
apiKey: 'AIzaSy...',
|
|
191
|
-
});
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Integrated factory (auto-detect adapter)
|
|
195
|
-
|
|
196
|
-
```typescript
|
|
197
|
-
import { createAn5Adapter, An5Adapter } from '@an5/adapters';
|
|
198
|
-
|
|
199
|
-
// Auto-detects from connection string
|
|
200
|
-
const sqlDb = createAn5Adapter({ connectionString: 'sqlserver://localhost:1433;database=mydb;user=sa;password=pass' });
|
|
201
|
-
|
|
202
|
-
const sheetsDb = createAn5Adapter({
|
|
203
|
-
connectionString: 'googlesheets://spreadsheetId;clientEmail=sa@project.iam.gserviceaccount.com;privateKey=...',
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// Or use the Sheets config object directly (also auto-detected)
|
|
207
|
-
const sheetsDb2 = createAn5Adapter({
|
|
208
|
-
spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms',
|
|
209
|
-
clientEmail: 'sa@project.iam.gserviceaccount.com',
|
|
210
|
-
privateKey: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----',
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// Constructor form also delegates googlesheets:// to the Sheets adapter
|
|
214
|
-
const sheetsDb3 = new An5Adapter({
|
|
215
|
-
connectionString: 'googlesheets://spreadsheetId;clientEmail=sa@project.iam.gserviceaccount.com;privateKey=...',
|
|
216
|
-
});
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
**Notes:**
|
|
220
|
-
- Each model/table maps to a **sheet tab** (first row = headers)
|
|
221
|
-
- Sheets without header rows get auto-created on first `create()`
|
|
222
|
-
- Type coercion can use optional adapter metadata (`setAdapterMetadata`) for field types and model-to-table mapping
|
|
223
|
-
- Numeric strings (without leading zeros) are auto-coerced; `"00123"` stays string
|
|
224
|
-
- Boolean strings `"true"` / `"false"` are auto-coerced
|
|
225
|
-
- Sheet names with spaces are automatically escaped (A1 notation)
|
|
226
|
-
- Supports service account JSON or individual `clientEmail`+`privateKey`
|
|
227
|
-
- Automatic retry with exponential backoff for rate limits (429/500/503)
|
|
228
|
-
|
|
229
|
-
### Provider Imports
|
|
230
|
-
|
|
231
|
-
Use the package root for normal SQL applications:
|
|
232
|
-
|
|
233
|
-
```typescript
|
|
234
|
-
import { createAn5Adapter, An5Adapter } from '@an5/adapters';
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
The Sheets adapter is exposed through its own subpath:
|
|
238
|
-
|
|
239
|
-
```typescript
|
|
240
|
-
import { createAn5SheetsAdapter, An5SheetsAdapter } from '@an5/adapters/googlesheets';
|
|
241
|
-
import { parseSheetsConnectionString } from '@an5/adapters/googlesheets';
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
Browser builds (no Node.js modules) use `@an5/adapters/browser`. The public SQL factory `createAn5Adapter` lives in `typescript/src/an5Adapter.ts` and auto-detects `googlesheets://` connection strings.
|
|
245
|
-
|
|
246
|
-
## API Reference
|
|
247
|
-
|
|
248
|
-
### An5Adapter / An5SheetsAdapter
|
|
249
|
-
|
|
250
|
-
| Method | Description |
|
|
251
|
-
|--------|-------------|
|
|
252
|
-
| `exec(query, params)` | Execute query, return rows (SQL only) |
|
|
253
|
-
| `table<T>(name)` | Get typed table client |
|
|
254
|
-
| `$transaction(fn)` | Execute in transaction |
|
|
255
|
-
| `$connect()` | Open connection / authenticate |
|
|
256
|
-
| `$disconnect()` | Close connection / clear auth |
|
|
257
|
-
| `readRange(range)` | Read raw sheet range (Sheets only) |
|
|
258
|
-
| `writeRange(range, values)` | Write raw sheet range (Sheets only) |
|
|
259
|
-
| `appendRange(range, values)` | Append rows to sheet (Sheets only) |
|
|
260
|
-
| `listSheets()` | List all sheet tab names (Sheets only) |
|
|
261
|
-
| `deleteSheet(name)` | Delete a sheet tab (Sheets only) |
|
|
262
|
-
|
|
263
|
-
### AdapterTableClient / SheetsTableClient
|
|
264
|
-
|
|
265
|
-
| Method | Description |
|
|
266
|
-
|--------|-------------|
|
|
267
|
-
| `findMany(args)` | Query multiple rows |
|
|
268
|
-
| `findFirst(args)` | Query single row |
|
|
269
|
-
| `findUnique(where)` | Find by unique key |
|
|
270
|
-
| `count(where)` | Count rows |
|
|
271
|
-
| `create(data)` | Insert row |
|
|
272
|
-
| `createMany(data)` | Bulk insert |
|
|
273
|
-
| `update(where, data)` | Update row |
|
|
274
|
-
| `updateMany(where, data)` | Update multiple rows |
|
|
275
|
-
| `delete(where)` | Delete row |
|
|
276
|
-
| `deleteMany(where)` | Delete multiple rows |
|
|
277
|
-
| `upsert(where, create, update)` | Insert or update |
|
|
278
|
-
| `aggregate(args)` | SUM, AVG, MIN, MAX, COUNT |
|
|
279
|
-
| `groupBy(args)` | Group by fields |
|
|
280
|
-
| `vectorSearch(args)` | Semantic similarity search |
|
|
281
|
-
| `clear()` | Clear all data rows, keep headers (Sheets only) |
|
|
282
|
-
| `deleteAll()` | Delete all data rows including headers (Sheets only) |
|
|
283
|
-
|
|
284
|
-
## Provider Layout
|
|
285
|
-
|
|
286
|
-
- TypeScript source providers live under `typescript/src/{base,mssql,postgres,mysql,sqlite,googlesheets}`; `npm run build` compiles them into `dist/` (also exposed via `@an5/adapters/base`, `@an5/adapters/mssql`, … subpaths).
|
|
287
|
-
- Python providers live under `python/{base,mssql,postgres}`, with `python/an5_adapter.py` kept as the public facade. `npm run build:python` (or `python -m build --outdir dist-py`) builds the package into `dist-py/`.
|
|
288
|
-
- .NET providers live under `dotnet/{Base,Mssql,Postgres}`, with `dotnet/an5Adapter.cs` kept as the public facade.
|
|
289
|
-
- Adapters do not depend on generated `an5-client` artifacts; generated clients may pass metadata in explicitly when they need model/table mapping.
|
|
290
|
-
|
|
291
|
-
## Testing
|
|
292
|
-
|
|
293
|
-
```bash
|
|
294
|
-
# TypeScript/Node
|
|
295
|
-
node test/unit.test.js
|
|
296
|
-
|
|
297
|
-
# Python
|
|
298
|
-
python -m compileall python
|
|
299
|
-
python test/smoke.py
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
## License
|
|
303
|
-
|
|
304
|
-
MIT
|
|
1
|
+
# @an5/adapters
|
|
2
|
+
|
|
3
|
+
Standalone runtime database adapter and query engine for AN5 ORM. Provides connection pooling, SQL dialect query building (`parseWhere`, `buildOrderBy`, `quote`), dynamic model proxy access, eager loading (`include`), nested writes, vector search, transactions, and typed table clients across TypeScript, Python, .NET (C#), Golang, and Google Sheets.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Dynamic Model Access** — Access models directly via `db.user.findMany()` or `db.User.create()` (proxy resolves casing/plurals via metadata); `db.table('User')` is the escape hatch for runtime-known model names
|
|
8
|
+
- **Typed Model Access** — Bind generated delegates for full type-safety: `createAn5Adapter<{ user: UserTableClient }>({...})`, plus the `TypedAn5Adapter` / `AdapterAPI` helper types
|
|
9
|
+
- **Relations & Eager Loading** — Query nested relations with `include`, relation-level `select`, `where`, `orderBy`, pagination, and `_count`
|
|
10
|
+
- **Nested Writes** — Create and update records with nested relation writes (`create`, `update`, `disconnect`)
|
|
11
|
+
- **Query Builder & Dialects** — Dialect-aware SQL formatting for MSSQL, PostgreSQL, MySQL, and SQLite
|
|
12
|
+
- **Aggregations & GroupBy** — Standard ORM aggregates (`_count`, `_sum`, `_avg`, `_min`, `_max`) and `groupBy`
|
|
13
|
+
- **Field Math Operators** — Atomic updates with `increment`, `decrement`, `multiply`, `divide`, `set`
|
|
14
|
+
- **Vector Search** — Similarity search using pgvector (PostgreSQL), `VECTOR_DISTANCE` (MSSQL), or in-memory cosine/euclidean/dot similarity
|
|
15
|
+
- **Real Transactions** — Interactive and callback transactions (`$transaction(async tx => ...)` and `$begin()/$commit()/$rollback()`)
|
|
16
|
+
- **Cross-Language** — Unified API in TypeScript, Python, .NET (C#), and Golang
|
|
17
|
+
- **Google Sheets Database** — Use spreadsheets as a live database with full CRUD and SQL syntax support
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
### TypeScript
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @an5/adapters
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Python
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install an5-adapters
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### .NET
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
dotnet add package An5Adapters
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Go
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Included in the npm package under golang/ or via go module
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### TypeScript
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createAn5Adapter } from '@an5/adapters';
|
|
55
|
+
|
|
56
|
+
const db = createAn5Adapter({
|
|
57
|
+
connectionString: process.env.DATABASE_URL!,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Dynamic model access
|
|
61
|
+
const users = await db.user.findMany({
|
|
62
|
+
where: { active: true },
|
|
63
|
+
include: {
|
|
64
|
+
orders: {
|
|
65
|
+
where: { status: 'paid' },
|
|
66
|
+
orderBy: { total: 'desc' },
|
|
67
|
+
take: 5,
|
|
68
|
+
},
|
|
69
|
+
_count: true,
|
|
70
|
+
},
|
|
71
|
+
take: 10,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Nested writes
|
|
75
|
+
const created = await db.user.create({
|
|
76
|
+
data: {
|
|
77
|
+
email: 'alpha@example.com',
|
|
78
|
+
name: 'Alpha',
|
|
79
|
+
orders: {
|
|
80
|
+
create: [
|
|
81
|
+
{ total: 100, status: 'open' },
|
|
82
|
+
{ total: 250, status: 'paid' },
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
include: { orders: true, _count: true },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Atomic updates
|
|
90
|
+
await db.user.update({
|
|
91
|
+
where: { id: created.id },
|
|
92
|
+
data: {
|
|
93
|
+
score: { increment: 10 },
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Aggregations
|
|
98
|
+
const stats = await db.order.aggregate({
|
|
99
|
+
_count: true,
|
|
100
|
+
_sum: { total: true },
|
|
101
|
+
_avg: { total: true },
|
|
102
|
+
});
|
|
103
|
+
console.log(stats._count._all, stats._sum.total, stats._avg.total);
|
|
104
|
+
|
|
105
|
+
// Transactions
|
|
106
|
+
await db.$transaction(async (tx) => {
|
|
107
|
+
await tx.user.update({
|
|
108
|
+
where: { id: created.id },
|
|
109
|
+
data: { score: { increment: 5 } },
|
|
110
|
+
});
|
|
111
|
+
await tx.order.create({
|
|
112
|
+
data: { userId: created.id, total: 50, status: 'paid' },
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Raw query
|
|
117
|
+
const rawRows = await db.$queryRawUnsafe('SELECT * FROM users WHERE active = @p_0', 1);
|
|
118
|
+
|
|
119
|
+
// Disconnect
|
|
120
|
+
await db.$disconnect();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Python
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from an5_adapter import create_an5_adapter
|
|
127
|
+
|
|
128
|
+
db = create_an5_adapter("sqlserver://localhost:1433;database=mydb;user=sa;password=pass")
|
|
129
|
+
|
|
130
|
+
# Dynamic model access
|
|
131
|
+
users = db.user.find_many(where={"active": True}, take=10)
|
|
132
|
+
|
|
133
|
+
# Nested create
|
|
134
|
+
created = db.user.create({
|
|
135
|
+
"data": {
|
|
136
|
+
"email": "alpha@example.com",
|
|
137
|
+
"name": "Alpha",
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
# Transactions
|
|
142
|
+
def perform_transfer(tx):
|
|
143
|
+
tx.user.update({"where": {"id": "u1"}, "data": {"score": {"increment": 10}}})
|
|
144
|
+
|
|
145
|
+
db.transaction(perform_transfer)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## API Reference
|
|
151
|
+
|
|
152
|
+
### `An5Adapter`
|
|
153
|
+
|
|
154
|
+
| Method / Property | Description |
|
|
155
|
+
|-------------------|-------------|
|
|
156
|
+
| `db[modelName]` | Dynamic proxy returning `AdapterTableClient` for the model |
|
|
157
|
+
| `table<T>(name)` | Explicitly returns `AdapterTableClient<T>` |
|
|
158
|
+
| `exec(query, params)` | Execute raw parameterized query returning rows |
|
|
159
|
+
| `$queryRawUnsafe(sql, ...args)` | Positional raw query |
|
|
160
|
+
| `$executeRaw(sql, ...args)` | Raw DML execution returning affected count |
|
|
161
|
+
| `$transaction(fn)` | Callback transaction with automatic commit/rollback |
|
|
162
|
+
| `$begin()` | Interactive transaction returning `An5AdapterTx` |
|
|
163
|
+
| `$connect()` | Open connection / pool |
|
|
164
|
+
| `$disconnect()` | Close connections |
|
|
165
|
+
|
|
166
|
+
### `AdapterTableClient`
|
|
167
|
+
|
|
168
|
+
| Method | Description |
|
|
169
|
+
|--------|-------------|
|
|
170
|
+
| `findMany(args)` | Query multiple records with `where`, `orderBy`, `skip`, `take`, `select`, `include` |
|
|
171
|
+
| `findFirst(args)` | Query first matching record |
|
|
172
|
+
| `findUnique(args)` | Query unique record by unique filter |
|
|
173
|
+
| `create(args)` | Insert a record with support for nested relation writes |
|
|
174
|
+
| `createMany(args)` | Bulk insert records |
|
|
175
|
+
| `update(args)` | Update record with field math operations & nested relation writes |
|
|
176
|
+
| `updateMany(args)` | Update multiple records |
|
|
177
|
+
| `delete(args)` | Delete a single record |
|
|
178
|
+
| `deleteMany(args)` | Delete multiple records |
|
|
179
|
+
| `upsert(args)` | Insert or update a record |
|
|
180
|
+
| `count(args)` | Count matching records |
|
|
181
|
+
| `aggregate(args)` | Compute `_count`, `_sum`, `_avg`, `_min`, `_max` |
|
|
182
|
+
| `groupBy(args)` | Group by fields with aggregations and pagination |
|
|
183
|
+
| `vectorSearch(args)` | Semantic vector similarity search |
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT
|
package/dist/an5Adapter.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { An5SheetsAdapter, An5SheetsAdapterConfig, SheetsTableClient } from './googlesheets';
|
|
2
2
|
import type { An5AdapterConfig, Dialect, TransactionHandle } from './base/types';
|
|
3
3
|
export type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from './base/types';
|
|
4
|
-
export { setAdapterMetadata, type AdapterMetadata } from './base/metadata';
|
|
4
|
+
export { setAdapterMetadata, createAdapterProxy, type AdapterMetadata } from './base/metadata';
|
|
5
|
+
export type { TypedAn5Adapter, AdapterAPI } from './typed';
|
|
5
6
|
export type AnyAdapter = An5Adapter | An5SheetsAdapter;
|
|
6
7
|
export type AnyAdapterConfig = An5AdapterConfig | An5SheetsAdapterConfig | {
|
|
7
8
|
connectionString: string;
|
|
8
9
|
};
|
|
9
10
|
export declare class An5Adapter {
|
|
11
|
+
[key: string]: any;
|
|
10
12
|
private _engine;
|
|
11
13
|
private _engineType;
|
|
12
14
|
private _engineConfig;
|
|
@@ -29,28 +31,92 @@ export declare class An5Adapter {
|
|
|
29
31
|
timeout?: number;
|
|
30
32
|
}): Promise<R>;
|
|
31
33
|
$transaction<R>(list: Promise<R>[]): Promise<R[]>;
|
|
34
|
+
$begin(): Promise<An5AdapterTx>;
|
|
32
35
|
table<T = any>(modelName: string): AdapterTableClient<T> | SheetsTableClient<T>;
|
|
36
|
+
private _listeners;
|
|
37
|
+
private _middlewares;
|
|
38
|
+
$on(event: 'query' | 'error' | 'warn' | 'info' | string, callback: (...args: any[]) => void): this;
|
|
39
|
+
$off(event: string, callback: (...args: any[]) => void): this;
|
|
40
|
+
$emit(event: string, ...args: any[]): void;
|
|
41
|
+
$use(middleware: (params: {
|
|
42
|
+
model?: string;
|
|
43
|
+
action: string;
|
|
44
|
+
args: any;
|
|
45
|
+
run: (args: any) => Promise<any>;
|
|
46
|
+
}) => Promise<any>): this;
|
|
47
|
+
view<T = any>(viewName: string): ViewClient<T>;
|
|
48
|
+
$queryProc<T = any>(procName: string, params?: Record<string, any> | any[]): Promise<T[]>;
|
|
49
|
+
$executeProc(procName: string, params?: Record<string, any> | any[]): Promise<number>;
|
|
33
50
|
readRange<T = any>(range: string): Promise<T[][]>;
|
|
34
51
|
writeRange(range: string, values: any[][]): Promise<void>;
|
|
35
52
|
appendRange(range: string, values: any[][]): Promise<void>;
|
|
36
53
|
listSheets(): Promise<string[]>;
|
|
37
54
|
deleteSheet(name: string): Promise<void>;
|
|
38
55
|
}
|
|
56
|
+
export declare class ViewClient<T = any> {
|
|
57
|
+
readonly adapter: An5Adapter | An5AdapterTx;
|
|
58
|
+
readonly viewName: string;
|
|
59
|
+
private readonly tableClient;
|
|
60
|
+
constructor(adapter: An5Adapter | An5AdapterTx, viewName: string);
|
|
61
|
+
get dialect(): Dialect;
|
|
62
|
+
get tableName(): string;
|
|
63
|
+
findMany(args?: {
|
|
64
|
+
where?: any;
|
|
65
|
+
orderBy?: any;
|
|
66
|
+
skip?: number;
|
|
67
|
+
take?: number;
|
|
68
|
+
select?: any;
|
|
69
|
+
include?: any;
|
|
70
|
+
}): Promise<T[]>;
|
|
71
|
+
findFirst(args?: {
|
|
72
|
+
where?: any;
|
|
73
|
+
orderBy?: any;
|
|
74
|
+
select?: any;
|
|
75
|
+
include?: any;
|
|
76
|
+
}): Promise<T | null>;
|
|
77
|
+
findUnique(args: {
|
|
78
|
+
where: any;
|
|
79
|
+
select?: any;
|
|
80
|
+
include?: any;
|
|
81
|
+
}): Promise<T | null>;
|
|
82
|
+
count(args?: {
|
|
83
|
+
where?: any;
|
|
84
|
+
}): Promise<number>;
|
|
85
|
+
aggregate(args: any): Promise<any>;
|
|
86
|
+
groupBy(args: any): Promise<any[]>;
|
|
87
|
+
vectorSearch(args: any): Promise<(T & {
|
|
88
|
+
distance: number;
|
|
89
|
+
})[]>;
|
|
90
|
+
create(): Promise<never>;
|
|
91
|
+
createMany(): Promise<never>;
|
|
92
|
+
update(): Promise<never>;
|
|
93
|
+
updateMany(): Promise<never>;
|
|
94
|
+
delete(): Promise<never>;
|
|
95
|
+
deleteMany(): Promise<never>;
|
|
96
|
+
upsert(): Promise<never>;
|
|
97
|
+
}
|
|
39
98
|
export declare class An5AdapterTx {
|
|
40
99
|
private readonly handle;
|
|
41
100
|
readonly dialect: Dialect;
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
private closed;
|
|
42
103
|
constructor(handle: TransactionHandle, dialect: Dialect);
|
|
43
104
|
exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]>;
|
|
44
105
|
_executeRaw(query: string, params?: Record<string, any>): Promise<number>;
|
|
106
|
+
$commit(): Promise<void>;
|
|
107
|
+
$rollback(): Promise<void>;
|
|
45
108
|
table<T = any>(modelName: string): AdapterTableClient<T>;
|
|
109
|
+
private ensureOpen;
|
|
46
110
|
}
|
|
47
111
|
export declare class AdapterTableClient<T = any> {
|
|
48
|
-
|
|
49
|
-
|
|
112
|
+
readonly adapter: An5Adapter | An5AdapterTx;
|
|
113
|
+
readonly modelName: string;
|
|
50
114
|
constructor(adapter: An5Adapter | An5AdapterTx, modelName: string);
|
|
51
|
-
|
|
52
|
-
|
|
115
|
+
get dialect(): Dialect;
|
|
116
|
+
get tableName(): string;
|
|
53
117
|
private get nolock();
|
|
118
|
+
/** Build the shared context used by parseWhere to resolve relations and self references. */
|
|
119
|
+
private whereContext;
|
|
54
120
|
private doExec;
|
|
55
121
|
private doExecuteRaw;
|
|
56
122
|
findMany(args?: {
|
|
@@ -59,20 +125,26 @@ export declare class AdapterTableClient<T = any> {
|
|
|
59
125
|
skip?: number;
|
|
60
126
|
take?: number;
|
|
61
127
|
select?: any;
|
|
128
|
+
include?: any;
|
|
62
129
|
}): Promise<T[]>;
|
|
63
130
|
findFirst(args?: {
|
|
64
131
|
where?: any;
|
|
65
132
|
orderBy?: any;
|
|
66
133
|
select?: any;
|
|
134
|
+
include?: any;
|
|
67
135
|
}): Promise<T | null>;
|
|
68
136
|
findUnique(args: {
|
|
69
137
|
where: any;
|
|
138
|
+
select?: any;
|
|
139
|
+
include?: any;
|
|
70
140
|
}): Promise<T | null>;
|
|
71
141
|
count(args?: {
|
|
72
142
|
where?: any;
|
|
73
143
|
}): Promise<number>;
|
|
74
144
|
create(args: {
|
|
75
|
-
data: Partial<T
|
|
145
|
+
data: Partial<T> | any;
|
|
146
|
+
include?: any;
|
|
147
|
+
select?: any;
|
|
76
148
|
}): Promise<T>;
|
|
77
149
|
createMany(args: {
|
|
78
150
|
data: Partial<T>[];
|
|
@@ -82,7 +154,9 @@ export declare class AdapterTableClient<T = any> {
|
|
|
82
154
|
}>;
|
|
83
155
|
update(args: {
|
|
84
156
|
where: any;
|
|
85
|
-
data: Partial<T
|
|
157
|
+
data: Partial<T> | any;
|
|
158
|
+
include?: any;
|
|
159
|
+
select?: any;
|
|
86
160
|
}): Promise<T>;
|
|
87
161
|
updateMany(args: {
|
|
88
162
|
where?: any;
|
|
@@ -111,9 +185,13 @@ export declare class AdapterTableClient<T = any> {
|
|
|
111
185
|
where?: any;
|
|
112
186
|
vectorField?: string;
|
|
113
187
|
distanceMetric?: 'cosine' | 'euclidean' | 'dot';
|
|
188
|
+
vectorElementType?: 'float32' | 'float16' | 'uint8';
|
|
114
189
|
}): Promise<(T & {
|
|
115
190
|
distance: number;
|
|
116
191
|
})[]>;
|
|
117
192
|
}
|
|
118
193
|
export declare function createAn5Adapter(config: AnyAdapterConfig): AnyAdapter;
|
|
194
|
+
export declare function createAn5Adapter<TModels extends object>(config: AnyAdapterConfig): import('./typed').TypedAn5Adapter<TModels>;
|
|
119
195
|
export declare const createAdapter: typeof createAn5Adapter;
|
|
196
|
+
export declare function createBrowserSqliteAdapter(config: any): An5Adapter;
|
|
197
|
+
export declare function executorFromAdapter(adapterLike: any): any;
|