@an5/adapters 0.1.0
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 +263 -0
- package/dotnet/An5Adapter.cs +275 -0
- package/dotnet/Base/Core.cs +82 -0
- package/dotnet/Mssql/MssqlEngine.cs +144 -0
- package/dotnet/Postgres/PostgresEngine.cs +121 -0
- package/package.json +46 -0
- package/python/an5_adapter.py +97 -0
- package/python/base/__init__.py +3 -0
- package/python/base/dialects.py +8 -0
- package/python/base/metadata.py +9 -0
- package/python/base/sql.py +121 -0
- package/python/mssql/__init__.py +1 -0
- package/python/mssql/provider.py +62 -0
- package/python/postgres/__init__.py +1 -0
- package/python/postgres/provider.py +15 -0
- package/python/table_client.py +209 -0
- package/typescript/an5Adapter.d.ts +117 -0
- package/typescript/an5Adapter.js +447 -0
- package/typescript/an5Adapter.ts +474 -0
- package/typescript/base/index.d.ts +3 -0
- package/typescript/base/index.js +19 -0
- package/typescript/base/index.ts +3 -0
- package/typescript/base/metadata.d.ts +14 -0
- package/typescript/base/metadata.js +17 -0
- package/typescript/base/metadata.ts +28 -0
- package/typescript/base/sql.d.ts +4 -0
- package/typescript/base/sql.js +143 -0
- package/typescript/base/sql.ts +98 -0
- package/typescript/base/types.d.ts +21 -0
- package/typescript/base/types.js +2 -0
- package/typescript/base/types.ts +24 -0
- package/typescript/config.d.ts +17 -0
- package/typescript/config.js +92 -0
- package/typescript/config.ts +95 -0
- package/typescript/googlesheets/adapter.d.ts +31 -0
- package/typescript/googlesheets/adapter.js +138 -0
- package/typescript/googlesheets/adapter.ts +167 -0
- package/typescript/googlesheets/an5SheetsAdapter.d.ts +3 -0
- package/typescript/googlesheets/an5SheetsAdapter.js +8 -0
- package/typescript/googlesheets/an5SheetsAdapter.ts +3 -0
- package/typescript/googlesheets/config.d.ts +17 -0
- package/typescript/googlesheets/config.js +29 -0
- package/typescript/googlesheets/config.ts +33 -0
- package/typescript/googlesheets/helpers.d.ts +9 -0
- package/typescript/googlesheets/helpers.js +155 -0
- package/typescript/googlesheets/helpers.ts +124 -0
- package/typescript/googlesheets/index.d.ts +2 -0
- package/typescript/googlesheets/index.js +9 -0
- package/typescript/googlesheets/index.ts +2 -0
- package/typescript/googlesheets/parseConnectionString.d.ts +11 -0
- package/typescript/googlesheets/parseConnectionString.js +44 -0
- package/typescript/googlesheets/parseConnectionString.ts +44 -0
- package/typescript/googlesheets/retry.d.ts +3 -0
- package/typescript/googlesheets/retry.js +26 -0
- package/typescript/googlesheets/retry.ts +23 -0
- package/typescript/googlesheets/sqlExecutor.d.ts +12 -0
- package/typescript/googlesheets/sqlExecutor.js +306 -0
- package/typescript/googlesheets/sqlExecutor.ts +301 -0
- package/typescript/googlesheets/tableClient.d.ts +78 -0
- package/typescript/googlesheets/tableClient.js +394 -0
- package/typescript/googlesheets/tableClient.ts +434 -0
- package/typescript/googlesheets/types.d.ts +4 -0
- package/typescript/googlesheets/types.js +3 -0
- package/typescript/googlesheets/types.ts +6 -0
- package/typescript/index.d.ts +2 -0
- package/typescript/index.js +14 -0
- package/typescript/index.ts +15 -0
- package/typescript/mssql/engine.d.ts +16 -0
- package/typescript/mssql/engine.js +138 -0
- package/typescript/mssql/engine.ts +132 -0
- package/typescript/mssql/index.d.ts +1 -0
- package/typescript/mssql/index.js +17 -0
- package/typescript/mssql/index.ts +1 -0
- package/typescript/mysql/engine.d.ts +13 -0
- package/typescript/mysql/engine.js +77 -0
- package/typescript/mysql/engine.ts +80 -0
- package/typescript/mysql/index.d.ts +1 -0
- package/typescript/mysql/index.js +17 -0
- package/typescript/mysql/index.ts +1 -0
- package/typescript/postgres/engine.d.ts +13 -0
- package/typescript/postgres/engine.js +86 -0
- package/typescript/postgres/engine.ts +87 -0
- package/typescript/postgres/index.d.ts +1 -0
- package/typescript/postgres/index.js +17 -0
- package/typescript/postgres/index.ts +1 -0
- package/typescript/sqlite/engine.d.ts +13 -0
- package/typescript/sqlite/engine.js +58 -0
- package/typescript/sqlite/engine.ts +55 -0
- package/typescript/sqlite/index.d.ts +1 -0
- package/typescript/sqlite/index.js +17 -0
- package/typescript/sqlite/index.ts +1 -0
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './engine';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./engine"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './engine';
|