@an5/adapters 0.2.5 → 0.2.9

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.
Files changed (99) hide show
  1. package/README.md +283 -305
  2. package/dist/an5Adapter.d.ts +142 -7
  3. package/dist/an5Adapter.js +998 -68
  4. package/dist/base/metadata.d.ts +10 -0
  5. package/dist/base/metadata.js +107 -0
  6. package/dist/base/sql.d.ts +19 -1
  7. package/dist/base/sql.js +152 -24
  8. package/dist/base/types.d.ts +10 -1
  9. package/dist/browser.d.ts +4 -1
  10. package/dist/browser.js +9 -2
  11. package/dist/googlesheets/adapter.d.ts +1 -0
  12. package/dist/googlesheets/adapter.js +9 -2
  13. package/dist/googlesheets/config.d.ts +4 -4
  14. package/dist/googlesheets/helpers.js +2 -0
  15. package/dist/googlesheets/parseConnectionString.js +5 -2
  16. package/dist/googlesheets/sqlExecutor.js +29 -24
  17. package/dist/googlesheets/tableClient.js +14 -5
  18. package/dist/index.d.ts +5 -1
  19. package/dist/index.js +15 -1
  20. package/dist/mssql/engine.js +8 -4
  21. package/dist/mysql/engine.js +1 -1
  22. package/dist/nbase/client.d.ts +92 -0
  23. package/dist/nbase/client.js +147 -0
  24. package/dist/nbase/index.d.ts +47 -0
  25. package/dist/nbase/index.js +80 -0
  26. package/dist/postgres/engine.js +1 -1
  27. package/dist/sqlite/browserEngine.d.ts +27 -0
  28. package/dist/sqlite/browserEngine.js +161 -0
  29. package/dist/sqlite/engine.js +15 -3
  30. package/dist/sqlite/index.d.ts +1 -0
  31. package/dist/sqlite/index.js +1 -0
  32. package/dist/typed.d.ts +5 -0
  33. package/dist/typed.js +2 -0
  34. package/dotnet/An5Adapter.cs +1112 -275
  35. package/dotnet/Base/Core.cs +380 -82
  36. package/dotnet/Mssql/MssqlEngine.cs +145 -144
  37. package/dotnet/Postgres/PostgresEngine.cs +149 -121
  38. package/dotnet/Sqlite/SqliteEngine.cs +214 -0
  39. package/golang/an5_adapter.go +314 -0
  40. package/golang/base/base.go +100 -0
  41. package/golang/base/metadata.go +116 -0
  42. package/golang/base/where.go +311 -0
  43. package/golang/go.mod +3 -0
  44. package/golang/mssql/mssql.go +32 -0
  45. package/golang/postgres/postgres.go +37 -0
  46. package/golang/sqlite/sqlite.go +14 -0
  47. package/golang/sqlite_test.go +42 -0
  48. package/golang/table_client.go +1329 -0
  49. package/package.json +26 -9
  50. package/python/an5_adapter.py +184 -97
  51. package/python/base/__init__.py +3 -3
  52. package/python/base/dialects.py +11 -8
  53. package/python/base/metadata.py +59 -10
  54. package/python/base/sql.py +202 -121
  55. package/python/mssql/__init__.py +1 -1
  56. package/python/mssql/provider.py +62 -62
  57. package/python/postgres/__init__.py +1 -1
  58. package/python/postgres/provider.py +15 -15
  59. package/python/sqlite/__init__.py +3 -0
  60. package/python/sqlite/provider.py +83 -0
  61. package/python/table_client.py +636 -216
  62. package/rust/Cargo.toml +31 -0
  63. package/rust/README.md +71 -0
  64. package/rust/src/adapter.rs +1312 -0
  65. package/rust/src/base/dialect.rs +172 -0
  66. package/rust/src/base/metadata.rs +134 -0
  67. package/rust/src/base/mod.rs +17 -0
  68. package/rust/src/base/where_builder.rs +405 -0
  69. package/rust/src/lib.rs +75 -0
  70. package/typescript/src/an5Adapter.ts +1515 -505
  71. package/typescript/src/base/index.ts +3 -3
  72. package/typescript/src/base/metadata.ts +148 -28
  73. package/typescript/src/base/sql.ts +264 -98
  74. package/typescript/src/base/types.ts +33 -24
  75. package/typescript/src/browser.ts +10 -6
  76. package/typescript/src/config.ts +95 -95
  77. package/typescript/src/googlesheets/adapter.ts +269 -259
  78. package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
  79. package/typescript/src/googlesheets/config.ts +47 -47
  80. package/typescript/src/googlesheets/helpers.ts +144 -143
  81. package/typescript/src/googlesheets/index.ts +3 -3
  82. package/typescript/src/googlesheets/parseConnectionString.ts +48 -46
  83. package/typescript/src/googlesheets/retry.ts +126 -126
  84. package/typescript/src/googlesheets/sqlExecutor.ts +304 -301
  85. package/typescript/src/googlesheets/tableClient.ts +461 -455
  86. package/typescript/src/googlesheets/types.ts +6 -6
  87. package/typescript/src/index.ts +48 -27
  88. package/typescript/src/mssql/engine.ts +134 -132
  89. package/typescript/src/mssql/index.ts +1 -1
  90. package/typescript/src/mysql/engine.ts +80 -80
  91. package/typescript/src/mysql/index.ts +1 -1
  92. package/typescript/src/nbase/client.ts +214 -0
  93. package/typescript/src/nbase/index.ts +104 -0
  94. package/typescript/src/postgres/engine.ts +87 -87
  95. package/typescript/src/postgres/index.ts +1 -1
  96. package/typescript/src/sqlite/browserEngine.ts +192 -0
  97. package/typescript/src/sqlite/engine.ts +66 -55
  98. package/typescript/src/sqlite/index.ts +3 -1
  99. package/typescript/src/typed.ts +52 -0
@@ -1,55 +1,66 @@
1
- import type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from '../base/types';
2
-
3
- // ─── SQLite Engine ─────────────────────────────────────────────────────────────────
4
-
5
- let BetterSqlite3: any = null;
6
- try { BetterSqlite3 = require('better-sqlite3'); } catch { }
7
-
8
- export class SqliteEngine implements QueryEngine {
9
- dialect: Dialect = 'sqlite';
10
- private db: any = null;
11
- private readonly filePath: string;
12
-
13
- constructor(adapterConfig: An5AdapterConfig) {
14
- if (!BetterSqlite3) throw new Error('better-sqlite3 package is required for SQLite support. Run: npm install better-sqlite3');
15
- this.filePath = adapterConfig.connectionString
16
- .replace(/^sqlite:\/\/\//i, '/')
17
- .replace(/^sqlite:\/\//i, '');
18
- }
19
-
20
- private getDb(): any {
21
- if (!this.db) this.db = new BetterSqlite3(this.filePath);
22
- return this.db;
23
- }
24
-
25
- // better-sqlite3 natively supports @name parameters
26
- async exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]> {
27
- return this.getDb().prepare(query).all(params ?? {}) as T[];
28
- }
29
-
30
- async executeRaw(query: string, params?: Record<string, any>): Promise<number> {
31
- const info = this.getDb().prepare(query).run(params ?? {});
32
- return info.changes ?? 0;
33
- }
34
-
35
- async connect(): Promise<void> { this.getDb(); }
36
-
37
- async disconnect(): Promise<void> {
38
- if (this.db) { this.db.close(); this.db = null; }
39
- }
40
-
41
- async beginTransaction(): Promise<TransactionHandle> {
42
- const db = this.getDb();
43
- db.prepare('BEGIN').run();
44
- let done = false;
45
-
46
- return {
47
- exec: async <T>(q: string, p?: Record<string, any>) =>
48
- db.prepare(q).all(p ?? {}) as T[],
49
- executeRaw: async (q: string, p?: Record<string, any>) =>
50
- (db.prepare(q).run(p ?? {}).changes ?? 0),
51
- commit: async () => { if (!done) { db.prepare('COMMIT').run(); done = true; } },
52
- rollback: async () => { if (!done) { db.prepare('ROLLBACK').run(); done = true; } },
53
- };
54
- }
55
- }
1
+ import type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from '../base/types';
2
+
3
+ // ─── SQLite Engine ─────────────────────────────────────────────────────────────────
4
+
5
+ let BetterSqlite3: any = null;
6
+ try { BetterSqlite3 = require('better-sqlite3'); } catch { }
7
+
8
+ export class SqliteEngine implements QueryEngine {
9
+ dialect: Dialect = 'sqlite';
10
+ private db: any = null;
11
+ private readonly filePath: string;
12
+
13
+ constructor(adapterConfig: An5AdapterConfig) {
14
+ if (!BetterSqlite3) throw new Error('better-sqlite3 package is required for SQLite support. Run: npm install better-sqlite3');
15
+ this.filePath = (adapterConfig.connectionString ?? '')
16
+ .replace(/^sqlite:\/\/\//i, '/')
17
+ .replace(/^sqlite:\/\//i, '');
18
+ }
19
+
20
+ private getDb(): any {
21
+ if (!this.db) this.db = new BetterSqlite3(this.filePath);
22
+ return this.db;
23
+ }
24
+
25
+ // better-sqlite3 natively supports @name parameters
26
+ async exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]> {
27
+ const stmt = this.getDb().prepare(query);
28
+ if (stmt.reader) {
29
+ return stmt.all(params ?? {}) as T[];
30
+ }
31
+ stmt.run(params ?? {});
32
+ return [] as T[];
33
+ }
34
+
35
+ async executeRaw(query: string, params?: Record<string, any>): Promise<number> {
36
+ const info = this.getDb().prepare(query).run(params ?? {});
37
+ return info.changes ?? 0;
38
+ }
39
+
40
+ async connect(): Promise<void> { this.getDb(); }
41
+
42
+ async disconnect(): Promise<void> {
43
+ if (this.db) { this.db.close(); this.db = null; }
44
+ }
45
+
46
+ async beginTransaction(): Promise<TransactionHandle> {
47
+ const db = this.getDb();
48
+ db.prepare('BEGIN').run();
49
+ let done = false;
50
+
51
+ return {
52
+ exec: async <T>(q: string, p?: Record<string, any>) => {
53
+ const stmt = db.prepare(q);
54
+ if (stmt.reader) {
55
+ return stmt.all(p ?? {}) as T[];
56
+ }
57
+ stmt.run(p ?? {});
58
+ return [] as T[];
59
+ },
60
+ executeRaw: async (q: string, p?: Record<string, any>) =>
61
+ (db.prepare(q).run(p ?? {}).changes ?? 0),
62
+ commit: async () => { if (!done) { db.prepare('COMMIT').run(); done = true; } },
63
+ rollback: async () => { if (!done) { db.prepare('ROLLBACK').run(); done = true; } },
64
+ };
65
+ }
66
+ }
@@ -1 +1,3 @@
1
- export * from './engine';
1
+ export * from './engine';
2
+ export * from './browserEngine';
3
+
@@ -0,0 +1,52 @@
1
+ import type { AdapterTableClient, An5Adapter } from './an5Adapter';
2
+
3
+ // ─── Typed model access ──────────────────────────────────────────────────────
4
+ // The runtime adapter resolves `db.user` / `db.User` dynamically through a
5
+ // Proxy, which TypeScript normally types as `any` (An5Adapter declares
6
+ // `[key: string]: any`). These helpers let app code bind generated model
7
+ // delegate types (e.g. `UserTableClient` emitted by the schema generator) so
8
+ // `db.user` gets full autocomplete and compile-time argument checking — the
9
+ // standard ORM experience — without changing any runtime behavior.
10
+ //
11
+ // Usage:
12
+ // import { createAn5Adapter } from '@an5/adapters';
13
+ // import type { UserTableClient } from './generated/typescript/User';
14
+ // import type { OrderTableClient } from './generated/typescript/Order';
15
+ // const db = createAn5Adapter<{
16
+ // user: UserTableClient;
17
+ // order: OrderTableClient;
18
+ // }>({ connectionString: process.env.DATABASE_URL! });
19
+ // await db.user.findMany({ where: { email: { contains: '@example.com' } } });
20
+
21
+ // Public adapter surface (methods/getters) without the open-ended index
22
+ // signature, so explicit model props in TModels take effect instead of `any`.
23
+ type AdapterMethodKeys =
24
+ | 'dialect'
25
+ | 'exec'
26
+ | '$queryRawUnsafe'
27
+ | '$executeRaw'
28
+ | '$executeRawUnsafe'
29
+ | '$connect'
30
+ | '$disconnect'
31
+ | '$transaction'
32
+ | '$begin'
33
+ | 'table'
34
+ | '$on'
35
+ | '$off'
36
+ | '$emit'
37
+ | '$use'
38
+ | 'view'
39
+ | '$queryProc'
40
+ | '$executeProc'
41
+ | 'readRange'
42
+ | 'writeRange'
43
+ | 'appendRange'
44
+ | 'listSheets'
45
+ | 'deleteSheet';
46
+
47
+ export type AdapterAPI = Pick<An5Adapter, AdapterMethodKeys>;
48
+
49
+ // An5Adapter with dynamically-resolved model delegates typed as TModels.
50
+ // NOTE: keep AdapterMethodKeys in sync when adding public An5Adapter methods.
51
+ export type TypedAn5Adapter<TModels extends object = Record<string, AdapterTableClient<any>>> =
52
+ AdapterAPI & TModels;