@an5/adapters 0.2.2 → 0.2.4
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 +304 -263
- package/{typescript → dist}/an5Adapter.js +2 -2
- package/dist/base/uuid.d.ts +5 -0
- package/dist/base/uuid.js +17 -0
- package/{typescript → dist}/googlesheets/adapter.d.ts +1 -1
- package/{typescript → dist}/googlesheets/adapter.js +19 -8
- package/{typescript → dist}/googlesheets/config.d.ts +5 -1
- package/{typescript → dist}/googlesheets/config.js +2 -1
- package/{typescript → dist}/googlesheets/helpers.js +28 -9
- package/{typescript → dist}/googlesheets/parseConnectionString.js +4 -0
- package/dist/googlesheets/retry.d.ts +25 -0
- package/dist/googlesheets/retry.js +115 -0
- package/{typescript → dist}/googlesheets/tableClient.d.ts +1 -0
- package/{typescript → dist}/googlesheets/tableClient.js +59 -42
- package/dotnet/An5Adapter.cs +275 -275
- package/dotnet/Base/Core.cs +82 -82
- package/dotnet/Mssql/MssqlEngine.cs +144 -144
- package/dotnet/Postgres/PostgresEngine.cs +121 -121
- package/package.json +22 -10
- package/python/an5_adapter.py +97 -97
- package/python/base/__init__.py +3 -3
- package/python/base/dialects.py +8 -8
- package/python/base/metadata.py +10 -10
- package/python/base/sql.py +121 -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 +216 -216
- package/typescript/src/an5Adapter.ts +505 -505
- package/typescript/src/base/index.ts +3 -3
- package/typescript/src/base/metadata.ts +28 -28
- package/typescript/src/base/sql.ts +98 -98
- package/typescript/src/base/types.ts +24 -24
- package/typescript/src/base/uuid.ts +14 -0
- package/typescript/src/browser.ts +6 -6
- package/typescript/src/config.ts +95 -95
- package/typescript/src/googlesheets/adapter.ts +259 -242
- package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
- package/typescript/src/googlesheets/config.ts +47 -44
- package/typescript/src/googlesheets/helpers.ts +143 -124
- package/typescript/src/googlesheets/index.ts +3 -3
- package/typescript/src/googlesheets/parseConnectionString.ts +46 -44
- package/typescript/src/googlesheets/retry.ts +126 -32
- package/typescript/src/googlesheets/sqlExecutor.ts +301 -301
- package/typescript/src/googlesheets/tableClient.ts +455 -435
- package/typescript/src/googlesheets/types.ts +6 -6
- package/typescript/src/index.ts +18 -18
- package/typescript/src/mssql/engine.ts +132 -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/engine.ts +55 -55
- package/typescript/src/sqlite/index.ts +1 -1
- package/typescript/googlesheets/retry.d.ts +0 -3
- package/typescript/googlesheets/retry.js +0 -39
- /package/{typescript → dist}/an5Adapter.d.ts +0 -0
- /package/{typescript → dist}/base/index.d.ts +0 -0
- /package/{typescript → dist}/base/index.js +0 -0
- /package/{typescript → dist}/base/metadata.d.ts +0 -0
- /package/{typescript → dist}/base/metadata.js +0 -0
- /package/{typescript → dist}/base/sql.d.ts +0 -0
- /package/{typescript → dist}/base/sql.js +0 -0
- /package/{typescript → dist}/base/types.d.ts +0 -0
- /package/{typescript → dist}/base/types.js +0 -0
- /package/{typescript → dist}/browser.d.ts +0 -0
- /package/{typescript → dist}/browser.js +0 -0
- /package/{typescript → dist}/config.d.ts +0 -0
- /package/{typescript → dist}/config.js +0 -0
- /package/{typescript → dist}/googlesheets/an5SheetsAdapter.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/an5SheetsAdapter.js +0 -0
- /package/{typescript → dist}/googlesheets/helpers.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/index.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/index.js +0 -0
- /package/{typescript → dist}/googlesheets/parseConnectionString.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/sqlExecutor.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/sqlExecutor.js +0 -0
- /package/{typescript → dist}/googlesheets/types.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/types.js +0 -0
- /package/{typescript → dist}/index.d.ts +0 -0
- /package/{typescript → dist}/index.js +0 -0
- /package/{typescript → dist}/mssql/engine.d.ts +0 -0
- /package/{typescript → dist}/mssql/engine.js +0 -0
- /package/{typescript → dist}/mssql/index.d.ts +0 -0
- /package/{typescript → dist}/mssql/index.js +0 -0
- /package/{typescript → dist}/mysql/engine.d.ts +0 -0
- /package/{typescript → dist}/mysql/engine.js +0 -0
- /package/{typescript → dist}/mysql/index.d.ts +0 -0
- /package/{typescript → dist}/mysql/index.js +0 -0
- /package/{typescript → dist}/postgres/engine.d.ts +0 -0
- /package/{typescript → dist}/postgres/engine.js +0 -0
- /package/{typescript → dist}/postgres/index.d.ts +0 -0
- /package/{typescript → dist}/postgres/index.js +0 -0
- /package/{typescript → dist}/sqlite/engine.d.ts +0 -0
- /package/{typescript → dist}/sqlite/engine.js +0 -0
- /package/{typescript → dist}/sqlite/index.d.ts +0 -0
- /package/{typescript → dist}/sqlite/index.js +0 -0
package/README.md
CHANGED
|
@@ -1,263 +1,304 @@
|
|
|
1
|
-
# an5Adapters
|
|
2
|
-
|
|
3
|
-
Standalone runtime adapters for AN5 ORM. Provides connection pooling, query execution, typed table clients in TypeScript, Python, .NET, and Google Sheets API.
|
|
4
|
-
|
|
5
|
-
Adapters are runtime packages only. They do not import generated `an5Client` artifacts; generated clients or applications can pass model metadata explicitly when table-name mapping or field type coercion is needed.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- **Connection pooling** — Managed connection pools with configurable limits
|
|
10
|
-
- **Type-safe table clients** — Generic CRUD operations with type inference
|
|
11
|
-
- **Full query support** — WHERE, ORDER BY, pagination, aggregates
|
|
12
|
-
- **Vector search** — Cosine, euclidean, and dot product similarity
|
|
13
|
-
- **Transactions** — Begin/commit/rollback with automatic cleanup
|
|
14
|
-
- **Cross-language** — Same API in TypeScript, Python, and .NET
|
|
15
|
-
- **Google Sheets** — Use spreadsheets as a database with the same CRUD API
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
### TypeScript
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm install an5
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Python
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
pip install an5-adapters
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### .NET
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
dotnet add package An5Adapters
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
### TypeScript
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { createAn5Adapter, setAdapterMetadata } from 'an5
|
|
43
|
-
|
|
44
|
-
setAdapterMetadata({
|
|
45
|
-
modelToTable: { User: 'dbo.users' },
|
|
46
|
-
modelFields: {
|
|
47
|
-
User: {
|
|
48
|
-
id: { ts: 'string', sql: 'uniqueidentifier', isId: true },
|
|
49
|
-
active: { ts: 'boolean', sql: 'bit' },
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const db = createAn5Adapter({
|
|
55
|
-
connectionString: 'sqlserver://localhost:1433;database=mydb;user=sa;password=pass',
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Table client
|
|
59
|
-
const users = db.table<User>('users');
|
|
60
|
-
await users.findMany({ where: { active: true }, take: 10 });
|
|
61
|
-
|
|
62
|
-
// Raw queries
|
|
63
|
-
const rows = await db.exec('SELECT * FROM users WHERE id = @id', { id: '123' });
|
|
64
|
-
|
|
65
|
-
// Transactions
|
|
66
|
-
await db.$transaction(async (tx) => {
|
|
67
|
-
await tx.table('users').create({ data: { name: 'John' } });
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Python
|
|
72
|
-
|
|
73
|
-
```python
|
|
74
|
-
from an5_adapter import create_an5_adapter
|
|
75
|
-
from base.metadata import set_adapter_metadata
|
|
76
|
-
|
|
77
|
-
set_adapter_metadata({
|
|
78
|
-
"modelToTable": {"User": "dbo.users"},
|
|
79
|
-
"modelFields": {
|
|
80
|
-
"User": {
|
|
81
|
-
"id": {"py": "str", "sql": "uniqueidentifier", "isId": True},
|
|
82
|
-
"active": {"py": "bool", "sql": "bit"},
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
db = create_an5_adapter("sqlserver://localhost:1433;database=mydb;user=sa;password=pass")
|
|
88
|
-
|
|
89
|
-
# Table client
|
|
90
|
-
users = db.table("User")
|
|
91
|
-
users.find_many(where={"active": True}, take=10)
|
|
92
|
-
|
|
93
|
-
# Raw queries
|
|
94
|
-
rows = db.exec("SELECT * FROM users WHERE id = ?", params=["123"])
|
|
95
|
-
|
|
96
|
-
# Transactions
|
|
97
|
-
db.transaction(lambda tx: tx.table("User").create({"name": "John"}))
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### .NET
|
|
101
|
-
|
|
102
|
-
```csharp
|
|
103
|
-
using
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
db.
|
|
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
|
-
await
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
//
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
1
|
+
# an5Adapters
|
|
2
|
+
|
|
3
|
+
Standalone runtime adapters for AN5 ORM. Provides connection pooling, query execution, typed table clients in TypeScript, Python, .NET, and Google Sheets API.
|
|
4
|
+
|
|
5
|
+
Adapters are runtime packages only. They do not import generated `an5Client` artifacts; generated clients or applications can pass model metadata explicitly when table-name mapping or field type coercion is needed.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Connection pooling** — Managed connection pools with configurable limits
|
|
10
|
+
- **Type-safe table clients** — Generic CRUD operations with type inference
|
|
11
|
+
- **Full query support** — WHERE, ORDER BY, pagination, aggregates
|
|
12
|
+
- **Vector search** — Cosine, euclidean, and dot product similarity
|
|
13
|
+
- **Transactions** — Begin/commit/rollback with automatic cleanup
|
|
14
|
+
- **Cross-language** — Same API in TypeScript, Python, and .NET
|
|
15
|
+
- **Google Sheets** — Use spreadsheets as a database with the same CRUD API
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### TypeScript
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @an5/adapters
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Python
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install an5-adapters
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### .NET
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
dotnet add package An5Adapters
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### TypeScript
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { createAn5Adapter, setAdapterMetadata } from '@an5/adapters';
|
|
43
|
+
|
|
44
|
+
setAdapterMetadata({
|
|
45
|
+
modelToTable: { User: 'dbo.users' },
|
|
46
|
+
modelFields: {
|
|
47
|
+
User: {
|
|
48
|
+
id: { ts: 'string', sql: 'uniqueidentifier', isId: true },
|
|
49
|
+
active: { ts: 'boolean', sql: 'bit' },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const db = createAn5Adapter({
|
|
55
|
+
connectionString: 'sqlserver://localhost:1433;database=mydb;user=sa;password=pass',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Table client
|
|
59
|
+
const users = db.table<User>('users');
|
|
60
|
+
await users.findMany({ where: { active: true }, take: 10 });
|
|
61
|
+
|
|
62
|
+
// Raw queries
|
|
63
|
+
const rows = await db.exec('SELECT * FROM users WHERE id = @id', { id: '123' });
|
|
64
|
+
|
|
65
|
+
// Transactions
|
|
66
|
+
await db.$transaction(async (tx) => {
|
|
67
|
+
await tx.table('users').create({ data: { name: 'John' } });
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Python
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from an5_adapter import create_an5_adapter
|
|
75
|
+
from base.metadata import set_adapter_metadata
|
|
76
|
+
|
|
77
|
+
set_adapter_metadata({
|
|
78
|
+
"modelToTable": {"User": "dbo.users"},
|
|
79
|
+
"modelFields": {
|
|
80
|
+
"User": {
|
|
81
|
+
"id": {"py": "str", "sql": "uniqueidentifier", "isId": True},
|
|
82
|
+
"active": {"py": "bool", "sql": "bit"},
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
db = create_an5_adapter("sqlserver://localhost:1433;database=mydb;user=sa;password=pass")
|
|
88
|
+
|
|
89
|
+
# Table client
|
|
90
|
+
users = db.table("User")
|
|
91
|
+
users.find_many(where={"active": True}, take=10)
|
|
92
|
+
|
|
93
|
+
# Raw queries
|
|
94
|
+
rows = db.exec("SELECT * FROM users WHERE id = ?", params=["123"])
|
|
95
|
+
|
|
96
|
+
# Transactions
|
|
97
|
+
db.transaction(lambda tx: tx.table("User").create({"name": "John"}))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### .NET
|
|
101
|
+
|
|
102
|
+
```csharp
|
|
103
|
+
using System.Collections.Generic;
|
|
104
|
+
using An5Orm;
|
|
105
|
+
|
|
106
|
+
var db = new An5Adapter("sqlserver://localhost:1433;database=mydb;user=sa;password=pass");
|
|
107
|
+
|
|
108
|
+
// Table client
|
|
109
|
+
var users = db.Table<User>("dbo.users");
|
|
110
|
+
var activeUsers = users.FindMany(
|
|
111
|
+
"IsActive = @p",
|
|
112
|
+
new Dictionary<string, object> { ["p"] = true });
|
|
113
|
+
|
|
114
|
+
// Raw queries
|
|
115
|
+
var rows = db.QueryRaw("SELECT * FROM users WHERE Id = @id",
|
|
116
|
+
new Dictionary<string, object> { ["id"] = "123" });
|
|
117
|
+
|
|
118
|
+
// Create / Update / Delete
|
|
119
|
+
users.Create(new User { Name = "John", IsActive = true });
|
|
120
|
+
users.Update(existingUser); // uses the Id property as the key
|
|
121
|
+
users.Delete("123");
|
|
122
|
+
|
|
123
|
+
// Transactions (must return a value; use db.Transaction<int> for void-style)
|
|
124
|
+
db.Transaction(tx =>
|
|
125
|
+
{
|
|
126
|
+
tx.Table<User>("dbo.users").Create(new User { Name = "John" });
|
|
127
|
+
return 0;
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Note: `QueryRaw`/`FindMany` take parameters as a `Dictionary<string, object>`,
|
|
132
|
+
not anonymous objects. See `dotnet/An5Adapter.cs` for the full API.
|
|
133
|
+
|
|
134
|
+
### Google Sheets
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { createAn5SheetsAdapter } from '@an5/adapters/googlesheets';
|
|
138
|
+
|
|
139
|
+
const db = createAn5SheetsAdapter({
|
|
140
|
+
spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms',
|
|
141
|
+
// Option 1: client email + private key
|
|
142
|
+
clientEmail: 'sa@project.iam.gserviceaccount.com',
|
|
143
|
+
privateKey: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----',
|
|
144
|
+
// Option 2: full service account JSON
|
|
145
|
+
// credentials: { client_email: '...', private_key: '...' },
|
|
146
|
+
// Optional: map model names to sheet names
|
|
147
|
+
sheetMapping: { users: 'UsersData', orders: 'OrdersData' },
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Table client (same API as SQL adapters)
|
|
151
|
+
const users = db.table<User>('users');
|
|
152
|
+
await users.findMany({ where: { active: true }, take: 10 });
|
|
153
|
+
await users.create({ data: { name: 'John', email: 'john@example.com' } });
|
|
154
|
+
await users.update({ where: { email: 'john@example.com' }, data: { name: 'Johnny' } });
|
|
155
|
+
await users.delete({ where: { email: 'john@example.com' } });
|
|
156
|
+
|
|
157
|
+
// Raw range access (Google Sheets specific)
|
|
158
|
+
const rawData = await db.readRange('Sheet1!A1:C10');
|
|
159
|
+
await db.writeRange('Sheet1!A1:B2', [['Name', 'Age'], ['Alice', '30']]);
|
|
160
|
+
await db.appendRange('Sheet1!A:A', [['Bob', '25']]);
|
|
161
|
+
|
|
162
|
+
// Auto-creates sheet + header row on first create()
|
|
163
|
+
await db.table('orders').create({ data: { id: '1', total: 100 } });
|
|
164
|
+
|
|
165
|
+
// List, delete sheets
|
|
166
|
+
const sheets = await db.listSheets();
|
|
167
|
+
await db.deleteSheet('OldSheet');
|
|
168
|
+
|
|
169
|
+
// Clear data (keeps headers) or delete all rows
|
|
170
|
+
await db.table('users').clear();
|
|
171
|
+
await db.table('users').deleteAll();
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Browser Mode (Google Sheets)
|
|
175
|
+
|
|
176
|
+
For browser environments (React, Vue, Svelte, Next.js client components), import from `@an5/adapters/browser` and configure `accessToken` or `apiKey`. In browser mode, the adapter uses native `fetch()` without importing Node.js modules (`googleapis`, `crypto`, `fs`).
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { createAn5SheetsAdapter } from '@an5/adapters/browser';
|
|
180
|
+
|
|
181
|
+
// Option 1: OAuth2 Access Token (e.g. from Firebase Auth or Google Sign-In)
|
|
182
|
+
const db = createAn5SheetsAdapter({
|
|
183
|
+
spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms',
|
|
184
|
+
accessToken: userOAuthAccessToken,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Option 2: Google API Key
|
|
188
|
+
const db2 = createAn5SheetsAdapter({
|
|
189
|
+
spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms',
|
|
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
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAdapter = exports.AdapterTableClient = exports.An5AdapterTx = exports.An5Adapter = exports.setAdapterMetadata = void 0;
|
|
4
4
|
exports.createAn5Adapter = createAn5Adapter;
|
|
5
|
-
const
|
|
5
|
+
const uuid_1 = require("./base/uuid");
|
|
6
6
|
const googlesheets_1 = require("./googlesheets");
|
|
7
7
|
const parseConnectionString_1 = require("./googlesheets/parseConnectionString");
|
|
8
8
|
const sql_1 = require("./base/sql");
|
|
@@ -304,7 +304,7 @@ class AdapterTableClient {
|
|
|
304
304
|
const normalizedType = String(rawType).toLowerCase();
|
|
305
305
|
const isStringType = ['string', 'uuid', 'uniqueidentifier', 'nvarchar', 'varchar', 'text'].includes(normalizedType);
|
|
306
306
|
if (isStringType && !data[idFieldName])
|
|
307
|
-
data[idFieldName] = (0,
|
|
307
|
+
data[idFieldName] = (0, uuid_1.generateUUID)();
|
|
308
308
|
}
|
|
309
309
|
const cols = Object.keys(data).filter(k => data[k] !== undefined);
|
|
310
310
|
const params = {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUUID = generateUUID;
|
|
4
|
+
/**
|
|
5
|
+
* Cross-platform UUID generator safe for both Browser and Node.js environments.
|
|
6
|
+
* Uses crypto.randomUUID() when available, with a standard RFC4122 v4 fallback.
|
|
7
|
+
*/
|
|
8
|
+
function generateUUID() {
|
|
9
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
10
|
+
return crypto.randomUUID();
|
|
11
|
+
}
|
|
12
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
13
|
+
const r = (Math.random() * 16) | 0;
|
|
14
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
15
|
+
return v.toString(16);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -7,7 +7,7 @@ export declare class An5SheetsAdapter {
|
|
|
7
7
|
config: ReturnType<typeof resolveConfig>;
|
|
8
8
|
private sheetsCache;
|
|
9
9
|
constructor(config: An5SheetsAdapterConfig);
|
|
10
|
-
private get
|
|
10
|
+
private get isFetchMode();
|
|
11
11
|
getSheets(): Promise<any>;
|
|
12
12
|
private getApi;
|
|
13
13
|
invalidateCache(): void;
|