@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.
- package/README.md +305 -283
- package/{typescript → dist}/browser.d.ts +1 -1
- package/{typescript → dist}/browser.js +2 -1
- package/{typescript → dist}/index.d.ts +2 -0
- package/{typescript → dist}/index.js +6 -1
- 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 +21 -11
- 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/browser.ts +6 -6
- package/typescript/src/config.ts +95 -95
- package/typescript/src/googlesheets/adapter.ts +259 -259
- package/typescript/src/googlesheets/an5SheetsAdapter.ts +3 -3
- package/typescript/src/googlesheets/config.ts +47 -47
- package/typescript/src/googlesheets/helpers.ts +143 -143
- package/typescript/src/googlesheets/index.ts +3 -3
- package/typescript/src/googlesheets/parseConnectionString.ts +46 -46
- package/typescript/src/googlesheets/retry.ts +126 -126
- package/typescript/src/googlesheets/sqlExecutor.ts +301 -301
- package/typescript/src/googlesheets/tableClient.ts +455 -455
- package/typescript/src/googlesheets/types.ts +6 -6
- package/typescript/src/index.ts +28 -19
- 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 → dist}/an5Adapter.d.ts +0 -0
- /package/{typescript → dist}/an5Adapter.js +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}/base/uuid.d.ts +0 -0
- /package/{typescript → dist}/base/uuid.js +0 -0
- /package/{typescript → dist}/config.d.ts +0 -0
- /package/{typescript → dist}/config.js +0 -0
- /package/{typescript → dist}/googlesheets/adapter.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/adapter.js +0 -0
- /package/{typescript → dist}/googlesheets/an5SheetsAdapter.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/an5SheetsAdapter.js +0 -0
- /package/{typescript → dist}/googlesheets/config.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/config.js +0 -0
- /package/{typescript → dist}/googlesheets/helpers.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/helpers.js +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/parseConnectionString.js +0 -0
- /package/{typescript → dist}/googlesheets/retry.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/retry.js +0 -0
- /package/{typescript → dist}/googlesheets/sqlExecutor.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/sqlExecutor.js +0 -0
- /package/{typescript → dist}/googlesheets/tableClient.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/tableClient.js +0 -0
- /package/{typescript → dist}/googlesheets/types.d.ts +0 -0
- /package/{typescript → dist}/googlesheets/types.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
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|