@an5/adapters 0.2.3 → 0.2.5

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 (96) hide show
  1. package/README.md +305 -283
  2. package/{typescript → dist}/browser.d.ts +1 -1
  3. package/{typescript → dist}/browser.js +2 -1
  4. package/{typescript → dist}/index.d.ts +2 -0
  5. package/{typescript → dist}/index.js +6 -1
  6. package/dotnet/An5Adapter.cs +275 -275
  7. package/dotnet/Base/Core.cs +82 -82
  8. package/dotnet/Mssql/MssqlEngine.cs +144 -144
  9. package/dotnet/Postgres/PostgresEngine.cs +121 -121
  10. package/package.json +21 -11
  11. package/python/an5_adapter.py +97 -97
  12. package/python/base/__init__.py +3 -3
  13. package/python/base/dialects.py +8 -8
  14. package/python/base/metadata.py +10 -10
  15. package/python/base/sql.py +121 -121
  16. package/python/mssql/__init__.py +1 -1
  17. package/python/mssql/provider.py +62 -62
  18. package/python/postgres/__init__.py +1 -1
  19. package/python/postgres/provider.py +15 -15
  20. package/python/table_client.py +216 -216
  21. package/typescript/src/an5Adapter.ts +505 -505
  22. package/typescript/src/base/index.ts +3 -3
  23. package/typescript/src/base/metadata.ts +28 -28
  24. package/typescript/src/base/sql.ts +98 -98
  25. package/typescript/src/base/types.ts +24 -24
  26. package/typescript/src/browser.ts +6 -6
  27. package/typescript/src/config.ts +95 -95
  28. package/typescript/src/googlesheets/adapter.ts +259 -259
  29. package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
  30. package/typescript/src/googlesheets/config.ts +47 -47
  31. package/typescript/src/googlesheets/helpers.ts +143 -143
  32. package/typescript/src/googlesheets/index.ts +3 -3
  33. package/typescript/src/googlesheets/parseConnectionString.ts +46 -46
  34. package/typescript/src/googlesheets/retry.ts +126 -126
  35. package/typescript/src/googlesheets/sqlExecutor.ts +301 -301
  36. package/typescript/src/googlesheets/tableClient.ts +455 -455
  37. package/typescript/src/googlesheets/types.ts +6 -6
  38. package/typescript/src/index.ts +28 -19
  39. package/typescript/src/mssql/engine.ts +132 -132
  40. package/typescript/src/mssql/index.ts +1 -1
  41. package/typescript/src/mysql/engine.ts +80 -80
  42. package/typescript/src/mysql/index.ts +1 -1
  43. package/typescript/src/postgres/engine.ts +87 -87
  44. package/typescript/src/postgres/index.ts +1 -1
  45. package/typescript/src/sqlite/engine.ts +55 -55
  46. package/typescript/src/sqlite/index.ts +1 -1
  47. /package/{typescript → dist}/an5Adapter.d.ts +0 -0
  48. /package/{typescript → dist}/an5Adapter.js +0 -0
  49. /package/{typescript → dist}/base/index.d.ts +0 -0
  50. /package/{typescript → dist}/base/index.js +0 -0
  51. /package/{typescript → dist}/base/metadata.d.ts +0 -0
  52. /package/{typescript → dist}/base/metadata.js +0 -0
  53. /package/{typescript → dist}/base/sql.d.ts +0 -0
  54. /package/{typescript → dist}/base/sql.js +0 -0
  55. /package/{typescript → dist}/base/types.d.ts +0 -0
  56. /package/{typescript → dist}/base/types.js +0 -0
  57. /package/{typescript → dist}/base/uuid.d.ts +0 -0
  58. /package/{typescript → dist}/base/uuid.js +0 -0
  59. /package/{typescript → dist}/config.d.ts +0 -0
  60. /package/{typescript → dist}/config.js +0 -0
  61. /package/{typescript → dist}/googlesheets/adapter.d.ts +0 -0
  62. /package/{typescript → dist}/googlesheets/adapter.js +0 -0
  63. /package/{typescript → dist}/googlesheets/an5SheetsAdapter.d.ts +0 -0
  64. /package/{typescript → dist}/googlesheets/an5SheetsAdapter.js +0 -0
  65. /package/{typescript → dist}/googlesheets/config.d.ts +0 -0
  66. /package/{typescript → dist}/googlesheets/config.js +0 -0
  67. /package/{typescript → dist}/googlesheets/helpers.d.ts +0 -0
  68. /package/{typescript → dist}/googlesheets/helpers.js +0 -0
  69. /package/{typescript → dist}/googlesheets/index.d.ts +0 -0
  70. /package/{typescript → dist}/googlesheets/index.js +0 -0
  71. /package/{typescript → dist}/googlesheets/parseConnectionString.d.ts +0 -0
  72. /package/{typescript → dist}/googlesheets/parseConnectionString.js +0 -0
  73. /package/{typescript → dist}/googlesheets/retry.d.ts +0 -0
  74. /package/{typescript → dist}/googlesheets/retry.js +0 -0
  75. /package/{typescript → dist}/googlesheets/sqlExecutor.d.ts +0 -0
  76. /package/{typescript → dist}/googlesheets/sqlExecutor.js +0 -0
  77. /package/{typescript → dist}/googlesheets/tableClient.d.ts +0 -0
  78. /package/{typescript → dist}/googlesheets/tableClient.js +0 -0
  79. /package/{typescript → dist}/googlesheets/types.d.ts +0 -0
  80. /package/{typescript → dist}/googlesheets/types.js +0 -0
  81. /package/{typescript → dist}/mssql/engine.d.ts +0 -0
  82. /package/{typescript → dist}/mssql/engine.js +0 -0
  83. /package/{typescript → dist}/mssql/index.d.ts +0 -0
  84. /package/{typescript → dist}/mssql/index.js +0 -0
  85. /package/{typescript → dist}/mysql/engine.d.ts +0 -0
  86. /package/{typescript → dist}/mysql/engine.js +0 -0
  87. /package/{typescript → dist}/mysql/index.d.ts +0 -0
  88. /package/{typescript → dist}/mysql/index.js +0 -0
  89. /package/{typescript → dist}/postgres/engine.d.ts +0 -0
  90. /package/{typescript → dist}/postgres/engine.js +0 -0
  91. /package/{typescript → dist}/postgres/index.d.ts +0 -0
  92. /package/{typescript → dist}/postgres/index.js +0 -0
  93. /package/{typescript → dist}/sqlite/engine.d.ts +0 -0
  94. /package/{typescript → dist}/sqlite/engine.js +0 -0
  95. /package/{typescript → dist}/sqlite/index.d.ts +0 -0
  96. /package/{typescript → dist}/sqlite/index.js +0 -0
@@ -1,87 +1,87 @@
1
- import type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from '../base/types';
2
-
3
- // ─── PostgreSQL Engine ─────────────────────────────────────────────────────────────
4
-
5
- let PgPool: any = null;
6
- try { PgPool = require('pg').Pool; } catch { }
7
-
8
- export class PostgresEngine implements QueryEngine {
9
- dialect: Dialect = 'postgres';
10
- private pool: any = null;
11
-
12
- constructor(adapterConfig: An5AdapterConfig) {
13
- if (!PgPool) throw new Error('pg package is required for PostgreSQL support. Run: npm install pg');
14
- this.pool = new PgPool({
15
- connectionString: adapterConfig.connectionString,
16
- max: adapterConfig.poolMax ?? 10,
17
- });
18
- }
19
-
20
- /** Convert @name → $N; identical names reuse the same $N */
21
- private transform(query: string, params?: Record<string, any>): { text: string; values: any[] } {
22
- if (!params || Object.keys(params).length === 0) return { text: query, values: [] };
23
- const values: any[] = [];
24
- const seen: Record<string, number> = {};
25
- const text = query.replace(/@(\w+)/g, (_, name: string) => {
26
- if (seen[name] !== undefined) return `$${seen[name]}`;
27
- const idx = values.length + 1;
28
- seen[name] = idx;
29
- values.push(params[name] ?? null);
30
- return `$${idx}`;
31
- });
32
- return { text, values };
33
- }
34
-
35
- async exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]> {
36
- const { text, values } = this.transform(query, params);
37
- const result = await this.pool.query(text, values);
38
- return result.rows as T[];
39
- }
40
-
41
- async executeRaw(query: string, params?: Record<string, any>): Promise<number> {
42
- const { text, values } = this.transform(query, params);
43
- const result = await this.pool.query(text, values);
44
- return result.rowCount ?? 0;
45
- }
46
-
47
- async connect(): Promise<void> {
48
- const client = await this.pool.connect();
49
- client.release();
50
- }
51
-
52
- async disconnect(): Promise<void> { await this.pool.end(); }
53
-
54
- async beginTransaction(): Promise<TransactionHandle> {
55
- const client = await this.pool.connect();
56
- await client.query('BEGIN');
57
-
58
- const transform = (query: string, params?: Record<string, any>) => {
59
- if (!params || Object.keys(params).length === 0) return { text: query, values: [] };
60
- const values: any[] = [];
61
- const seen: Record<string, number> = {};
62
- const text = query.replace(/@(\w+)/g, (_, name: string) => {
63
- if (seen[name] !== undefined) return `$${seen[name]}`;
64
- const idx = values.length + 1;
65
- seen[name] = idx;
66
- values.push(params[name] ?? null);
67
- return `$${idx}`;
68
- });
69
- return { text, values };
70
- };
71
-
72
- return {
73
- exec: async <T>(q: string, p?: Record<string, any>) => {
74
- const { text, values } = transform(q, p);
75
- const r = await client.query(text, values);
76
- return (r.rows || []) as T[];
77
- },
78
- executeRaw: async (q: string, p?: Record<string, any>) => {
79
- const { text, values } = transform(q, p);
80
- const r = await client.query(text, values);
81
- return r.rowCount ?? 0;
82
- },
83
- commit: async () => { await client.query('COMMIT'); client.release(); },
84
- rollback: async () => { await client.query('ROLLBACK'); client.release(); },
85
- };
86
- }
87
- }
1
+ import type { An5AdapterConfig, Dialect, QueryEngine, TransactionHandle } from '../base/types';
2
+
3
+ // ─── PostgreSQL Engine ─────────────────────────────────────────────────────────────
4
+
5
+ let PgPool: any = null;
6
+ try { PgPool = require('pg').Pool; } catch { }
7
+
8
+ export class PostgresEngine implements QueryEngine {
9
+ dialect: Dialect = 'postgres';
10
+ private pool: any = null;
11
+
12
+ constructor(adapterConfig: An5AdapterConfig) {
13
+ if (!PgPool) throw new Error('pg package is required for PostgreSQL support. Run: npm install pg');
14
+ this.pool = new PgPool({
15
+ connectionString: adapterConfig.connectionString,
16
+ max: adapterConfig.poolMax ?? 10,
17
+ });
18
+ }
19
+
20
+ /** Convert @name → $N; identical names reuse the same $N */
21
+ private transform(query: string, params?: Record<string, any>): { text: string; values: any[] } {
22
+ if (!params || Object.keys(params).length === 0) return { text: query, values: [] };
23
+ const values: any[] = [];
24
+ const seen: Record<string, number> = {};
25
+ const text = query.replace(/@(\w+)/g, (_, name: string) => {
26
+ if (seen[name] !== undefined) return `$${seen[name]}`;
27
+ const idx = values.length + 1;
28
+ seen[name] = idx;
29
+ values.push(params[name] ?? null);
30
+ return `$${idx}`;
31
+ });
32
+ return { text, values };
33
+ }
34
+
35
+ async exec<T = any>(query: string, params?: Record<string, any>): Promise<T[]> {
36
+ const { text, values } = this.transform(query, params);
37
+ const result = await this.pool.query(text, values);
38
+ return result.rows as T[];
39
+ }
40
+
41
+ async executeRaw(query: string, params?: Record<string, any>): Promise<number> {
42
+ const { text, values } = this.transform(query, params);
43
+ const result = await this.pool.query(text, values);
44
+ return result.rowCount ?? 0;
45
+ }
46
+
47
+ async connect(): Promise<void> {
48
+ const client = await this.pool.connect();
49
+ client.release();
50
+ }
51
+
52
+ async disconnect(): Promise<void> { await this.pool.end(); }
53
+
54
+ async beginTransaction(): Promise<TransactionHandle> {
55
+ const client = await this.pool.connect();
56
+ await client.query('BEGIN');
57
+
58
+ const transform = (query: string, params?: Record<string, any>) => {
59
+ if (!params || Object.keys(params).length === 0) return { text: query, values: [] };
60
+ const values: any[] = [];
61
+ const seen: Record<string, number> = {};
62
+ const text = query.replace(/@(\w+)/g, (_, name: string) => {
63
+ if (seen[name] !== undefined) return `$${seen[name]}`;
64
+ const idx = values.length + 1;
65
+ seen[name] = idx;
66
+ values.push(params[name] ?? null);
67
+ return `$${idx}`;
68
+ });
69
+ return { text, values };
70
+ };
71
+
72
+ return {
73
+ exec: async <T>(q: string, p?: Record<string, any>) => {
74
+ const { text, values } = transform(q, p);
75
+ const r = await client.query(text, values);
76
+ return (r.rows || []) as T[];
77
+ },
78
+ executeRaw: async (q: string, p?: Record<string, any>) => {
79
+ const { text, values } = transform(q, p);
80
+ const r = await client.query(text, values);
81
+ return r.rowCount ?? 0;
82
+ },
83
+ commit: async () => { await client.query('COMMIT'); client.release(); },
84
+ rollback: async () => { await client.query('ROLLBACK'); client.release(); },
85
+ };
86
+ }
87
+ }
@@ -1 +1 @@
1
- export * from './engine';
1
+ export * from './engine';
@@ -1,55 +1,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
- 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
+ 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 +1 @@
1
- export * from './engine';
1
+ export * from './engine';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes