@aigne/afs-sqlite 1.1.0 → 1.11.0-beta
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 +51 -36
- package/dist/index.cjs +1324 -0
- package/dist/index.d.cts +758 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +758 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1299 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -44
- package/CHANGELOG.md +0 -73
- package/lib/cjs/actions/built-in.d.ts +0 -5
- package/lib/cjs/actions/built-in.js +0 -165
- package/lib/cjs/actions/registry.d.ts +0 -49
- package/lib/cjs/actions/registry.js +0 -102
- package/lib/cjs/actions/types.d.ts +0 -51
- package/lib/cjs/actions/types.js +0 -2
- package/lib/cjs/config.d.ts +0 -89
- package/lib/cjs/config.js +0 -33
- package/lib/cjs/index.d.ts +0 -13
- package/lib/cjs/index.js +0 -47
- package/lib/cjs/node/builder.d.ts +0 -43
- package/lib/cjs/node/builder.js +0 -187
- package/lib/cjs/operations/crud.d.ts +0 -64
- package/lib/cjs/operations/crud.js +0 -225
- package/lib/cjs/operations/query-builder.d.ts +0 -37
- package/lib/cjs/operations/query-builder.js +0 -102
- package/lib/cjs/operations/search.d.ts +0 -75
- package/lib/cjs/operations/search.js +0 -172
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/router/path-router.d.ts +0 -38
- package/lib/cjs/router/path-router.js +0 -90
- package/lib/cjs/router/types.d.ts +0 -30
- package/lib/cjs/router/types.js +0 -2
- package/lib/cjs/schema/introspector.d.ts +0 -48
- package/lib/cjs/schema/introspector.js +0 -186
- package/lib/cjs/schema/types.d.ts +0 -104
- package/lib/cjs/schema/types.js +0 -13
- package/lib/cjs/sqlite-afs.d.ts +0 -144
- package/lib/cjs/sqlite-afs.js +0 -337
- package/lib/dts/actions/built-in.d.ts +0 -5
- package/lib/dts/actions/registry.d.ts +0 -49
- package/lib/dts/actions/types.d.ts +0 -51
- package/lib/dts/config.d.ts +0 -89
- package/lib/dts/index.d.ts +0 -13
- package/lib/dts/node/builder.d.ts +0 -43
- package/lib/dts/operations/crud.d.ts +0 -64
- package/lib/dts/operations/query-builder.d.ts +0 -37
- package/lib/dts/operations/search.d.ts +0 -75
- package/lib/dts/router/path-router.d.ts +0 -38
- package/lib/dts/router/types.d.ts +0 -30
- package/lib/dts/schema/introspector.d.ts +0 -48
- package/lib/dts/schema/types.d.ts +0 -104
- package/lib/dts/sqlite-afs.d.ts +0 -144
- package/lib/esm/actions/built-in.d.ts +0 -5
- package/lib/esm/actions/built-in.js +0 -162
- package/lib/esm/actions/registry.d.ts +0 -49
- package/lib/esm/actions/registry.js +0 -98
- package/lib/esm/actions/types.d.ts +0 -51
- package/lib/esm/actions/types.js +0 -1
- package/lib/esm/config.d.ts +0 -89
- package/lib/esm/config.js +0 -30
- package/lib/esm/index.d.ts +0 -13
- package/lib/esm/index.js +0 -17
- package/lib/esm/node/builder.d.ts +0 -43
- package/lib/esm/node/builder.js +0 -177
- package/lib/esm/operations/crud.d.ts +0 -64
- package/lib/esm/operations/crud.js +0 -221
- package/lib/esm/operations/query-builder.d.ts +0 -37
- package/lib/esm/operations/query-builder.js +0 -92
- package/lib/esm/operations/search.d.ts +0 -75
- package/lib/esm/operations/search.js +0 -167
- package/lib/esm/package.json +0 -3
- package/lib/esm/router/path-router.d.ts +0 -38
- package/lib/esm/router/path-router.js +0 -83
- package/lib/esm/router/types.d.ts +0 -30
- package/lib/esm/router/types.js +0 -1
- package/lib/esm/schema/introspector.d.ts +0 -48
- package/lib/esm/schema/introspector.js +0 -182
- package/lib/esm/schema/types.d.ts +0 -104
- package/lib/esm/schema/types.js +0 -10
- package/lib/esm/sqlite-afs.d.ts +0 -144
- package/lib/esm/sqlite-afs.js +0 -333
package/README.md
CHANGED
|
@@ -36,10 +36,12 @@ import { SQLiteAFS } from "@aigne/afs-sqlite";
|
|
|
36
36
|
const afs = new AFS();
|
|
37
37
|
|
|
38
38
|
// Mount SQLite module
|
|
39
|
-
afs.mount(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
afs.mount(
|
|
40
|
+
new SQLiteAFS({
|
|
41
|
+
url: "file:./database.sqlite3",
|
|
42
|
+
accessMode: "readwrite",
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
43
45
|
|
|
44
46
|
// List all tables
|
|
45
47
|
const tables = await afs.list("/modules/sqlite-afs");
|
|
@@ -52,12 +54,12 @@ const user = await afs.read("/modules/sqlite-afs/users/1");
|
|
|
52
54
|
|
|
53
55
|
// Create a new row
|
|
54
56
|
await afs.write("/modules/sqlite-afs/users", {
|
|
55
|
-
content: { name: "John", email: "john@example.com" }
|
|
57
|
+
content: { name: "John", email: "john@example.com" },
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
// Update an existing row
|
|
59
61
|
await afs.write("/modules/sqlite-afs/users/1", {
|
|
60
|
-
content: { name: "John Doe" }
|
|
62
|
+
content: { name: "John Doe" },
|
|
61
63
|
});
|
|
62
64
|
|
|
63
65
|
// Delete a row
|
|
@@ -104,17 +106,17 @@ interface SQLiteAFSOptions {
|
|
|
104
106
|
|
|
105
107
|
The module exposes the following path patterns:
|
|
106
108
|
|
|
107
|
-
| Path
|
|
108
|
-
|
|
109
|
-
| `/`
|
|
110
|
-
| `/:table`
|
|
111
|
-
| `/:table/@schema`
|
|
112
|
-
| `/:table/:pk`
|
|
113
|
-
| `/:table/:pk/@attr`
|
|
114
|
-
| `/:table/:pk/@attr/:column`
|
|
115
|
-
| `/:table/:pk/@meta`
|
|
116
|
-
| `/:table/:pk/@actions`
|
|
117
|
-
| `/:table/:pk/@actions/:action` | Execute an action
|
|
109
|
+
| Path | Description |
|
|
110
|
+
| ------------------------------ | ------------------------------------ |
|
|
111
|
+
| `/` | List all tables |
|
|
112
|
+
| `/:table` | List rows in table or create new row |
|
|
113
|
+
| `/:table/@schema` | Get table schema |
|
|
114
|
+
| `/:table/:pk` | Read/update/delete specific row |
|
|
115
|
+
| `/:table/:pk/@attr` | List row attributes (columns) |
|
|
116
|
+
| `/:table/:pk/@attr/:column` | Get specific column value |
|
|
117
|
+
| `/:table/:pk/@meta` | Get row metadata |
|
|
118
|
+
| `/:table/:pk/@actions` | List available actions |
|
|
119
|
+
| `/:table/:pk/@actions/:action` | Execute an action |
|
|
118
120
|
|
|
119
121
|
## Built-in Actions
|
|
120
122
|
|
|
@@ -131,14 +133,20 @@ The module exposes the following path patterns:
|
|
|
131
133
|
|
|
132
134
|
```typescript
|
|
133
135
|
// Validate a row
|
|
134
|
-
const result = await afs.write(
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
const result = await afs.write(
|
|
137
|
+
"/modules/sqlite-afs/users/1/@actions/validate",
|
|
138
|
+
{
|
|
139
|
+
content: {},
|
|
140
|
+
},
|
|
141
|
+
);
|
|
137
142
|
|
|
138
143
|
// Duplicate a row
|
|
139
|
-
const result = await afs.write(
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
const result = await afs.write(
|
|
145
|
+
"/modules/sqlite-afs/users/1/@actions/duplicate",
|
|
146
|
+
{
|
|
147
|
+
content: {},
|
|
148
|
+
},
|
|
149
|
+
);
|
|
142
150
|
|
|
143
151
|
// Export table data
|
|
144
152
|
const jsonData = await sqliteAfs.exportTable("users", "json");
|
|
@@ -156,14 +164,16 @@ sqliteAfs.registerAction(
|
|
|
156
164
|
"archive",
|
|
157
165
|
async (ctx, params) => {
|
|
158
166
|
// ctx contains: db, schemas, table, pk, row, module
|
|
159
|
-
await ctx.db.run(
|
|
167
|
+
await ctx.db.run(
|
|
168
|
+
sql.raw(`UPDATE "${ctx.table}" SET archived = 1 WHERE id = '${ctx.pk}'`),
|
|
169
|
+
);
|
|
160
170
|
return { archived: true };
|
|
161
171
|
},
|
|
162
172
|
{
|
|
163
173
|
description: "Archive the row",
|
|
164
174
|
rowLevel: true,
|
|
165
|
-
tableLevel: false
|
|
166
|
-
}
|
|
175
|
+
tableLevel: false,
|
|
176
|
+
},
|
|
167
177
|
);
|
|
168
178
|
```
|
|
169
179
|
|
|
@@ -178,16 +188,19 @@ const sqliteAfs = new SQLiteAFS({
|
|
|
178
188
|
enabled: true,
|
|
179
189
|
tables: {
|
|
180
190
|
posts: ["title", "content"],
|
|
181
|
-
users: ["name", "bio"]
|
|
182
|
-
}
|
|
183
|
-
}
|
|
191
|
+
users: ["name", "bio"],
|
|
192
|
+
},
|
|
193
|
+
},
|
|
184
194
|
});
|
|
185
195
|
|
|
186
196
|
// Search across all FTS-enabled tables
|
|
187
197
|
const results = await afs.search("/modules/sqlite-afs", "search query");
|
|
188
198
|
|
|
189
199
|
// Search within a specific table
|
|
190
|
-
const postResults = await afs.search(
|
|
200
|
+
const postResults = await afs.search(
|
|
201
|
+
"/modules/sqlite-afs/posts",
|
|
202
|
+
"search query",
|
|
203
|
+
);
|
|
191
204
|
```
|
|
192
205
|
|
|
193
206
|
## Advanced Usage
|
|
@@ -223,19 +236,21 @@ import { AFS } from "@aigne/afs";
|
|
|
223
236
|
import { SQLiteAFS } from "@aigne/afs-sqlite";
|
|
224
237
|
|
|
225
238
|
const afs = new AFS();
|
|
226
|
-
afs.mount(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
239
|
+
afs.mount(
|
|
240
|
+
new SQLiteAFS({
|
|
241
|
+
url: "file:./database.sqlite3",
|
|
242
|
+
accessMode: "readwrite",
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
230
245
|
|
|
231
246
|
const agent = AIAgent.from({
|
|
232
247
|
name: "database-assistant",
|
|
233
|
-
afs: afs
|
|
248
|
+
afs: afs,
|
|
234
249
|
});
|
|
235
250
|
|
|
236
251
|
const context = aigne.newContext();
|
|
237
252
|
const result = await context.invoke(agent, {
|
|
238
|
-
message: "Show me all users in the database"
|
|
253
|
+
message: "Show me all users in the database",
|
|
239
254
|
});
|
|
240
255
|
```
|
|
241
256
|
|