@wxn0brp/db-storage-accdb 0.120.1 → 0.130.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/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
package/dist/find.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { VQueryT } from "@wxn0brp/db-core/types/query";
2
+ import type { AccDBValthera } from "./index.js";
3
+ export interface Row {
4
+ vid: string;
5
+ doc: any;
6
+ }
7
+ export declare function selectRows(slv: AccDBValthera, collection: string): Promise<Row[]>;
8
+ export declare function selectMatching(slv: AccDBValthera, query: VQueryT.Find | VQueryT.Update | VQueryT.Remove, limit?: number): Promise<Row[]>;
9
+ export declare function find(slv: AccDBValthera, config: VQueryT.Find): Promise<import("@wxn0brp/db-core/types/data").Data[]>;
package/dist/find.js ADDED
@@ -0,0 +1,59 @@
1
+ import { findUtil } from "@wxn0brp/db-core/utils/findUtil";
2
+ import { findObj } from "@wxn0brp/db-core/utils/process";
3
+ import { decodeCell, SPILL, sqlIdent, VID } from "./utils.js";
4
+ function decodeRow(row) {
5
+ const doc = {};
6
+ for (const [column, value] of Object.entries(row)) {
7
+ if (column === VID || column === SPILL)
8
+ continue;
9
+ if (value === null || value === undefined)
10
+ continue;
11
+ doc[column] = decodeCell(value);
12
+ }
13
+ const extra = row[SPILL];
14
+ if (extra !== null && extra !== undefined) {
15
+ const fields = decodeCell(extra);
16
+ if (fields && typeof fields === "object" && !Array.isArray(fields))
17
+ Object.assign(doc, fields);
18
+ }
19
+ return doc;
20
+ }
21
+ export async function selectRows(slv, collection) {
22
+ await slv.init();
23
+ if (!(await slv.issetCollection(collection)))
24
+ return [];
25
+ const result = (await slv.db.query(`SELECT * FROM ${sqlIdent(collection)}`));
26
+ if (!Array.isArray(result))
27
+ return [];
28
+ return result.map(row => ({
29
+ vid: decodeCell(row[VID]),
30
+ doc: decodeRow(row),
31
+ }));
32
+ }
33
+ export async function selectMatching(slv, query, limit) {
34
+ const rows = await selectRows(slv, query.collection);
35
+ const out = [];
36
+ for (const row of rows) {
37
+ if (!findObj({
38
+ collection: query.collection,
39
+ search: query.search,
40
+ }, row.doc))
41
+ continue;
42
+ out.push(row);
43
+ if (limit && out.length >= limit)
44
+ break;
45
+ }
46
+ return out;
47
+ }
48
+ export async function find(slv, config) {
49
+ const rows = await selectRows(slv, config.collection);
50
+ const datas = [];
51
+ for (const row of rows) {
52
+ const doc = findObj(config, row.doc);
53
+ if (doc)
54
+ datas.push(doc);
55
+ }
56
+ return findUtil(config, datas, [
57
+ null,
58
+ ]);
59
+ }
@@ -0,0 +1,37 @@
1
+ import { ValtheraClass } from "@wxn0brp/db-core";
2
+ import { AdapterBase } from "@wxn0brp/db-core/base/adapter";
3
+ import { Data } from "@wxn0brp/db-core/types/data";
4
+ import { VQueryT } from "@wxn0brp/db-core/types/query";
5
+ import { SupportedDB } from "./types.js";
6
+ export declare function createDatabase(file: string): Promise<string>;
7
+ export declare function makeConnect(file: string): Promise<SupportedDB>;
8
+ export declare class AccDBValthera extends AdapterBase {
9
+ db: SupportedDB;
10
+ _inited: boolean;
11
+ primaryKey: Record<string, string>;
12
+ file: string | null;
13
+ private _columns;
14
+ private _ensured;
15
+ constructor(db: SupportedDB, primaryKey?: Record<string, string>);
16
+ init(): Promise<void>;
17
+ close(): Promise<void>;
18
+ getCollections(): Promise<string[]>;
19
+ listTables(): Promise<string[]>;
20
+ issetCollection(collection: string): Promise<boolean>;
21
+ ensureCollection(collection: string): Promise<boolean>;
22
+ removeCollection(collection: string): Promise<boolean>;
23
+ add(config: VQueryT.Add): Promise<Data>;
24
+ find(config: VQueryT.Find): Promise<Data[]>;
25
+ findOne(config: VQueryT.Find): Promise<Data>;
26
+ update(config: VQueryT.Update): Promise<import("@wxn0brp/db-core/types/data").DataInternal[]>;
27
+ updateOne(config: VQueryT.Update): Promise<import("@wxn0brp/db-core/types/data").DataInternal>;
28
+ remove(config: VQueryT.Remove): Promise<import("@wxn0brp/db-core/types/data").DataInternal[]>;
29
+ removeOne(config: VQueryT.Remove): Promise<import("@wxn0brp/db-core/types/data").DataInternal>;
30
+ _ensureColumn(collection: string, field: string): Promise<string | null>;
31
+ private ensureTable;
32
+ private loadColumns;
33
+ }
34
+ export declare function createAccDBValthera(db: SupportedDB, primaryKey?: Record<string, string>): ValtheraClass;
35
+ export declare const DYNAMIC: {
36
+ def(file: string, keys?: Record<string, string>): Promise<ValtheraClass>;
37
+ };
package/dist/index.js ADDED
@@ -0,0 +1,297 @@
1
+ import { genId, ValtheraClass } from "@wxn0brp/db-core";
2
+ import { AdapterBase } from "@wxn0brp/db-core/base/adapter";
3
+ import { AdapterInitError } from "@wxn0brp/db-core/errors";
4
+ import { addId } from "@wxn0brp/db-core/helpers/addId";
5
+ import { execFile } from "node:child_process";
6
+ import fs from "node:fs";
7
+ import { mkdir, stat } from "node:fs/promises";
8
+ import os from "node:os";
9
+ import path from "node:path";
10
+ import { promisify } from "node:util";
11
+ import odbc from "odbc";
12
+ import { find } from "./find.js";
13
+ import { remove } from "./remove.js";
14
+ import { update } from "./update.js";
15
+ import { isSafeIdent, normalizeCreateTable, SPILL, sqlIdent, sqlString, VID, } from "./utils.js";
16
+ const execFileAsync = promisify(execFile);
17
+ const ACCESS_DRIVER = "{Microsoft Access Driver (*.mdb, *.accdb)}";
18
+ let keeperConnection = null;
19
+ async function keepDriverAlive() {
20
+ if (keeperConnection)
21
+ return;
22
+ const file = path.join(os.tmpdir(), `valthera-accdb-keeper-${process.pid}.accdb`);
23
+ if (!fs.existsSync(file))
24
+ await createDatabase(file);
25
+ keeperConnection = await odbc.connect(`Driver=${ACCESS_DRIVER};DBQ=${file}`);
26
+ }
27
+ export async function createDatabase(file) {
28
+ const target = path.resolve(file);
29
+ if (!fs.existsSync(target))
30
+ await mkdir(path.dirname(target), {
31
+ recursive: true,
32
+ });
33
+ const script = `New-Object -ComObject ADOX.Catalog | ForEach-Object { ` +
34
+ `$_.Create('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=${target}') }`;
35
+ try {
36
+ await execFileAsync("powershell", [
37
+ "-NoProfile",
38
+ "-NonInteractive",
39
+ "-Command",
40
+ script,
41
+ ]);
42
+ }
43
+ catch (err) {
44
+ throw new AdapterInitError(`Failed to create Access database "${target}". ` +
45
+ `Microsoft Access Database Engine (ACE) is required.\n${err?.message ?? err}`);
46
+ }
47
+ const size = (await stat(target)).size;
48
+ if (!size)
49
+ throw new AdapterInitError(`Failed to create Access database "${target}"`);
50
+ return target;
51
+ }
52
+ async function createTable(conn, sql) {
53
+ const normalized = normalizeCreateTable(sql);
54
+ if (!normalized || normalized === sql)
55
+ return await conn.query(sql);
56
+ try {
57
+ return await conn.query(normalized);
58
+ }
59
+ catch (err) {
60
+ // keep the original error when the hand written statement is the problem
61
+ try {
62
+ return await conn.query(sql);
63
+ }
64
+ catch {
65
+ throw err;
66
+ }
67
+ }
68
+ }
69
+ function wrapConnection(conn, file) {
70
+ const state = {
71
+ file,
72
+ schemaVersion: 0,
73
+ };
74
+ const proxy = new Proxy(conn, {
75
+ get(target, prop) {
76
+ const value = Reflect.get(target, prop, target);
77
+ if (typeof value !== "function")
78
+ return value;
79
+ return (...args) => {
80
+ if (prop === "query" && typeof args[0] === "string") {
81
+ const sql = args[0];
82
+ if (/^\s*create\s+table\s/i.test(sql))
83
+ return createTable(target, sql);
84
+ if (/^\s*(alter|drop)\s/i.test(sql))
85
+ state.schemaVersion++;
86
+ }
87
+ return value.apply(target, args);
88
+ };
89
+ },
90
+ });
91
+ proxy.__state = state;
92
+ proxy.__file = file;
93
+ return proxy;
94
+ }
95
+ export async function makeConnect(file) {
96
+ const resolved = path.resolve(file);
97
+ const missing = !fs.existsSync(resolved);
98
+ const empty = !missing && (await stat(resolved)).size === 0;
99
+ if (missing || empty)
100
+ await createDatabase(resolved);
101
+ await keepDriverAlive();
102
+ const conn = await odbc.connect(`Driver=${ACCESS_DRIVER};DBQ=${resolved}`);
103
+ return wrapConnection(conn, resolved);
104
+ }
105
+ export class AccDBValthera extends AdapterBase {
106
+ db;
107
+ _inited = false;
108
+ primaryKey;
109
+ file = null;
110
+ _columns = new Map();
111
+ _ensured = new Set();
112
+ constructor(db, primaryKey = {}) {
113
+ super();
114
+ this.db = db;
115
+ this.primaryKey = primaryKey;
116
+ this.file = db?.__file ?? null;
117
+ }
118
+ async init() {
119
+ if (!this.db) {
120
+ if (!this.file)
121
+ throw new AdapterInitError("AccDBValthera: connection is closed and no database file is known");
122
+ this.db = await makeConnect(this.file);
123
+ }
124
+ this._inited = true;
125
+ }
126
+ async close() {
127
+ const db = this.db;
128
+ this.db = null;
129
+ if (db)
130
+ await db.close().catch(() => { });
131
+ this._inited = false;
132
+ this._columns.clear();
133
+ this._ensured.clear();
134
+ }
135
+ async getCollections() {
136
+ const tables = await this.listTables();
137
+ const collections = [];
138
+ for (const name of this._ensured) {
139
+ const table = tables.find(t => t.toLowerCase() === name);
140
+ if (table)
141
+ collections.push(table);
142
+ }
143
+ return collections;
144
+ }
145
+ async listTables() {
146
+ await this.init();
147
+ const result = (await this.db.tables(null, null, null, "TABLE"));
148
+ if (!Array.isArray(result))
149
+ return [];
150
+ const names = [];
151
+ for (const row of result) {
152
+ const name = row.TABLE_NAME ?? row.table_name ?? row.tableName;
153
+ if (!name || String(name).startsWith("MSys"))
154
+ continue;
155
+ names.push(String(name));
156
+ }
157
+ return names;
158
+ }
159
+ async issetCollection(collection) {
160
+ const tables = await this.listTables();
161
+ return tables.some(name => name.toLowerCase() === collection.toLowerCase());
162
+ }
163
+ async ensureCollection(collection) {
164
+ await this.init();
165
+ if (await this.issetCollection(collection)) {
166
+ this._ensured.add(collection.toLowerCase());
167
+ return false;
168
+ }
169
+ await this.db.query(`CREATE TABLE ${sqlIdent(collection)} (${sqlIdent(VID)} MEMO)`);
170
+ this._columns.delete(collection);
171
+ this._ensured.add(collection.toLowerCase());
172
+ return true;
173
+ }
174
+ async removeCollection(collection) {
175
+ await this.init();
176
+ if (!(await this.issetCollection(collection)))
177
+ return false;
178
+ await this.db.query(`DROP TABLE ${sqlIdent(collection)}`);
179
+ this._ensured.delete(collection.toLowerCase());
180
+ this._columns.delete(collection);
181
+ return true;
182
+ }
183
+ async add(config) {
184
+ const { data, collection } = config;
185
+ await addId(config, this);
186
+ const doc = data ?? {};
187
+ const created = await this.ensureTable(collection);
188
+ if (created)
189
+ this._ensured.add(collection.toLowerCase());
190
+ const columns = [
191
+ VID,
192
+ ];
193
+ const values = [
194
+ sqlString(genId()),
195
+ ];
196
+ const spill = {};
197
+ for (const [field, value] of Object.entries(doc)) {
198
+ if (value === undefined)
199
+ continue;
200
+ const column = await this._ensureColumn(collection, field);
201
+ if (column) {
202
+ columns.push(column);
203
+ values.push(sqlString(value));
204
+ }
205
+ else
206
+ spill[field] = value;
207
+ }
208
+ if (Object.keys(spill).length) {
209
+ const column = await this._ensureColumn(collection, SPILL);
210
+ if (column) {
211
+ columns.push(column);
212
+ values.push(sqlString(spill));
213
+ }
214
+ }
215
+ await this.db.query(`INSERT INTO ${sqlIdent(collection)} ` +
216
+ `(${columns.map(sqlIdent).join(", ")}) VALUES (${values.join(", ")})`);
217
+ return doc;
218
+ }
219
+ find(config) {
220
+ return find(this, config);
221
+ }
222
+ async findOne(config) {
223
+ config.dbFindOpts = {
224
+ limit: 1,
225
+ };
226
+ const result = await this.find(config);
227
+ return result.length ? result[0] : null;
228
+ }
229
+ update(config) {
230
+ return update(this, config, false);
231
+ }
232
+ async updateOne(config) {
233
+ const res = await update(this, config, true);
234
+ return res[0] || null;
235
+ }
236
+ remove(config) {
237
+ return remove(this, config, false);
238
+ }
239
+ async removeOne(config) {
240
+ const res = await remove(this, config, true);
241
+ return res[0] || null;
242
+ }
243
+ async _ensureColumn(collection, field) {
244
+ await this.ensureTable(collection);
245
+ const columns = await this.loadColumns(collection);
246
+ const existing = columns.map.get(field.toLowerCase());
247
+ if (existing)
248
+ return existing;
249
+ if (!isSafeIdent(field))
250
+ return null;
251
+ await this.db.query(`ALTER TABLE ${sqlIdent(collection)} ADD ${sqlIdent(field)} MEMO`);
252
+ return field;
253
+ }
254
+ async ensureTable(collection) {
255
+ await this.init();
256
+ if (!(await this.issetCollection(collection))) {
257
+ await this.db.query(`CREATE TABLE ${sqlIdent(collection)} (${sqlIdent(VID)} MEMO)`);
258
+ this._columns.delete(collection);
259
+ return true;
260
+ }
261
+ const columns = await this.loadColumns(collection);
262
+ if (!columns.map.has(VID.toLowerCase()))
263
+ await this.db.query(`ALTER TABLE ${sqlIdent(collection)} ADD ${sqlIdent(VID)} MEMO`);
264
+ return false;
265
+ }
266
+ async loadColumns(collection) {
267
+ const version = this.db?.__state?.schemaVersion ?? 0;
268
+ const cached = this._columns.get(collection);
269
+ if (cached && cached.version === version)
270
+ return cached;
271
+ const result = (await this.db.columns(null, null, collection, null));
272
+ const map = new Map();
273
+ for (const row of Array.isArray(result) ? result : []) {
274
+ const name = row.COLUMN_NAME ?? row.column_name;
275
+ if (!name)
276
+ continue;
277
+ map.set(String(name).toLowerCase(), String(name));
278
+ }
279
+ const entry = {
280
+ version,
281
+ map,
282
+ };
283
+ this._columns.set(collection, entry);
284
+ return entry;
285
+ }
286
+ }
287
+ export function createAccDBValthera(db, primaryKey = {}) {
288
+ const adapter = new AccDBValthera(db, primaryKey);
289
+ return new ValtheraClass({
290
+ adapter,
291
+ });
292
+ }
293
+ export const DYNAMIC = {
294
+ async def(file, keys = {}) {
295
+ return createAccDBValthera(await makeConnect(file), keys);
296
+ },
297
+ };
@@ -0,0 +1,4 @@
1
+ import { DataInternal } from "@wxn0brp/db-core/types/data";
2
+ import { VQueryT } from "@wxn0brp/db-core/types/query";
3
+ import type { AccDBValthera } from "./index.js";
4
+ export declare function remove(slv: AccDBValthera, query: VQueryT.Remove, one: boolean): Promise<DataInternal[]>;
package/dist/remove.js ADDED
@@ -0,0 +1,9 @@
1
+ import { selectMatching } from "./find.js";
2
+ import { VID, sqlIdent, sqlString } from "./utils.js";
3
+ export async function remove(slv, query, one) {
4
+ const { collection } = query;
5
+ const rows = await selectMatching(slv, query, one ? 1 : undefined);
6
+ for (const row of rows)
7
+ await slv.db.query(`DELETE FROM ${sqlIdent(collection)} WHERE ${sqlIdent(VID)} = ${sqlString(row.vid)}`);
8
+ return rows.map(row => row.doc);
9
+ }
@@ -0,0 +1,2 @@
1
+ import type odbc from "odbc";
2
+ export type SupportedDB = odbc.Connection;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { DataInternal } from "@wxn0brp/db-core/types/data";
2
+ import { VQueryT } from "@wxn0brp/db-core/types/query";
3
+ import type { AccDBValthera } from "./index.js";
4
+ export declare function update(slv: AccDBValthera, query: VQueryT.Update, one: boolean): Promise<DataInternal[]>;
package/dist/update.js ADDED
@@ -0,0 +1,63 @@
1
+ import { QueryValidationError } from "@wxn0brp/db-core/errors";
2
+ import { updateObjectAdvanced } from "@wxn0brp/db-core/utils/updateOperators";
3
+ import { selectMatching } from "./find.js";
4
+ import { VID, sqlIdent, sqlString, SPILL } from "./utils.js";
5
+ function applyUpdater(target, updater) {
6
+ const doc = {
7
+ ...target,
8
+ };
9
+ if (updater && typeof updater === "object") {
10
+ updateObjectAdvanced(doc, updater);
11
+ return doc;
12
+ }
13
+ if (updater !== undefined && updater !== null)
14
+ throw new QueryValidationError("Invalid updater value", {
15
+ op: "update",
16
+ updater,
17
+ });
18
+ return doc;
19
+ }
20
+ async function writeRow(slv, collection, row, doc) {
21
+ const columns = [];
22
+ const values = [];
23
+ const spill = {};
24
+ const fields = new Set([
25
+ ...Object.keys(row.doc),
26
+ ...Object.keys(doc),
27
+ ]);
28
+ for (const field of fields) {
29
+ const has = Object.hasOwn(doc, field) && doc[field] !== undefined;
30
+ const column = await slv._ensureColumn(collection, field);
31
+ if (!column) {
32
+ if (has)
33
+ spill[field] = doc[field];
34
+ continue;
35
+ }
36
+ columns.push(column);
37
+ values.push(has ? sqlString(doc[field]) : "NULL");
38
+ }
39
+ if (Object.keys(spill).length) {
40
+ const column = await slv._ensureColumn(collection, SPILL);
41
+ if (column) {
42
+ columns.push(column);
43
+ values.push(sqlString(spill));
44
+ }
45
+ }
46
+ if (!columns.length)
47
+ return;
48
+ const sets = columns
49
+ .map((column, i) => `${sqlIdent(column)} = ${values[i]}`)
50
+ .join(", ");
51
+ await slv.db.query(`UPDATE ${sqlIdent(collection)} SET ${sets} WHERE ${sqlIdent(VID)} = ${sqlString(row.vid)}`);
52
+ }
53
+ export async function update(slv, query, one) {
54
+ const { collection, updater } = query;
55
+ const rows = await selectMatching(slv, query, one ? 1 : undefined);
56
+ const results = [];
57
+ for (const row of rows) {
58
+ const doc = applyUpdater(row.doc, updater);
59
+ await writeRow(slv, collection, row, doc);
60
+ results.push(doc);
61
+ }
62
+ return results;
63
+ }
@@ -0,0 +1,9 @@
1
+ export declare const VID = "__vid";
2
+ export declare const SPILL = "__vfields";
3
+ export declare function escapeValue(val: any): string;
4
+ export declare function sqlString(value: unknown): string;
5
+ export declare function sqlIdent(name: string): string;
6
+ export declare function isSafeIdent(name: string): boolean;
7
+ export declare function decodeCell(value: unknown): any;
8
+ export declare function normalizeCreateTable(sql: string): string;
9
+ export declare function createTableName(sql: string): string;
package/dist/utils.js ADDED
@@ -0,0 +1,123 @@
1
+ export const VID = "__vid";
2
+ export const SPILL = "__vfields";
3
+ export function escapeValue(val) {
4
+ if (val === null || val === undefined)
5
+ return "NULL";
6
+ if (typeof val === "number")
7
+ return val.toString();
8
+ if (typeof val === "boolean")
9
+ return val ? "TRUE" : "FALSE";
10
+ if (typeof val === "string")
11
+ return `'${val.replace(/'/g, "''")}'`;
12
+ if (typeof val === "object")
13
+ return `'${JSON.stringify(val).replace(/'/g, "''")}'`;
14
+ return `'${String(val).replace(/'/g, "''")}'`;
15
+ }
16
+ export function sqlString(value) {
17
+ return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
18
+ }
19
+ export function sqlIdent(name) {
20
+ return `[${name.replace(/\]/g, "]]")}]`;
21
+ }
22
+ export function isSafeIdent(name) {
23
+ return /^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(name);
24
+ }
25
+ export function decodeCell(value) {
26
+ if (typeof value !== "string")
27
+ return value;
28
+ try {
29
+ return JSON.parse(value);
30
+ }
31
+ catch {
32
+ return value;
33
+ }
34
+ }
35
+ function splitTop(input, sep) {
36
+ const out = [];
37
+ let depth = 0;
38
+ let current = "";
39
+ let quote = null;
40
+ for (const ch of input) {
41
+ if (quote) {
42
+ current += ch;
43
+ if (ch === quote)
44
+ quote = null;
45
+ continue;
46
+ }
47
+ if (ch === "'" || ch === '"' || ch === "`") {
48
+ quote = ch;
49
+ current += ch;
50
+ continue;
51
+ }
52
+ if (ch === "[" || ch === "(")
53
+ depth++;
54
+ else if (ch === "]" || ch === ")")
55
+ depth--;
56
+ if (ch === sep && depth === 0) {
57
+ out.push(current);
58
+ current = "";
59
+ continue;
60
+ }
61
+ current += ch;
62
+ }
63
+ if (current.trim())
64
+ out.push(current);
65
+ return out;
66
+ }
67
+ function readIdentifier(input) {
68
+ const trimmed = input.trimStart();
69
+ if (trimmed.startsWith("[")) {
70
+ const end = trimmed.indexOf("]");
71
+ if (end === -1)
72
+ return null;
73
+ return {
74
+ value: trimmed.slice(1, end),
75
+ raw: trimmed.slice(0, end + 1),
76
+ };
77
+ }
78
+ const match = /^[^\s(]+/.exec(trimmed);
79
+ if (!match)
80
+ return null;
81
+ return {
82
+ value: match[0],
83
+ raw: match[0],
84
+ };
85
+ }
86
+ export function normalizeCreateTable(sql) {
87
+ const source = sql.trim().replace(/;\s*$/, "");
88
+ const match = /^create\s+table\s+(.+?)\s*\(([\s\S]*)\)$/i.exec(source);
89
+ if (!match)
90
+ return null;
91
+ const tableName = readIdentifier(match[1].trim());
92
+ if (!tableName)
93
+ return null;
94
+ const seen = new Set();
95
+ const columns = [];
96
+ for (const def of splitTop(match[2], ",")) {
97
+ const identifier = readIdentifier(def);
98
+ if (!identifier)
99
+ continue;
100
+ const rest = def.trimStart().slice(identifier.raw.length).trim();
101
+ if (!rest)
102
+ continue;
103
+ const key = identifier.value.toLowerCase();
104
+ if (seen.has(key))
105
+ continue;
106
+ seen.add(key);
107
+ columns.push(`${sqlIdent(identifier.value)} MEMO`);
108
+ }
109
+ if (!columns.length)
110
+ return null;
111
+ if (!seen.has(VID.toLowerCase()))
112
+ columns.push(`${sqlIdent(VID)} MEMO`);
113
+ return `CREATE TABLE ${sqlIdent(tableName.value)} (${columns.join(", ")})`;
114
+ }
115
+ export function createTableName(sql) {
116
+ const match = /^\s*create\s+table\s+(.+?)\s*\(/i.exec(sql.trim());
117
+ if (!match)
118
+ return null;
119
+ const identifier = readIdentifier(match[1].trim());
120
+ if (!identifier)
121
+ return null;
122
+ return identifier.value;
123
+ }
package/package.json CHANGED
@@ -1,49 +1,46 @@
1
1
  {
2
- "name": "@wxn0brp/db-storage-accdb",
3
- "version": "0.120.1",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "description": "A pure ACCDB storage adapter for the ValtheraDB database library",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/wxn0brP/ValtheraDB-storage-accdb.git"
10
- },
11
- "homepage": "https://github.com/wxn0brP/ValtheraDB-storage-accdb",
12
- "author": "wxn0brP",
13
- "license": "MIT",
14
- "type": "module",
15
- "keywords": [
16
- "valthera",
17
- "valtheradb",
18
- "vdb-adapter",
19
- "accdb"
20
- ],
21
- "scripts": {
22
- "build": "tsc && tsc-alias"
23
- },
24
- "devDependencies": {
25
- "@types/bun": "*",
26
- "@wxn0brp/biome": "*",
27
- "tsc-alias": "^1",
28
- "typescript": "^7"
29
- },
30
- "dependencies": {
31
- "@wxn0brp/db-core": "^0.13.0-alpha.0",
32
- "odbc": "^2.6.0"
33
- },
34
- "files": [
35
- "dist"
36
- ],
37
- "exports": {
38
- ".": {
39
- "types": "./dist/index.d.ts",
40
- "import": "./dist/index.js",
41
- "default": "./dist/index.js"
42
- },
43
- "./*": {
44
- "types": "./dist/*.d.ts",
45
- "import": "./dist/*.js",
46
- "default": "./dist/*.js"
47
- }
48
- }
49
- }
2
+ "name": "@wxn0brp/db-storage-accdb",
3
+ "version": "0.130.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "description": "A pure ACCDB storage adapter for the ValtheraDB database library",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/wxn0brP/ValtheraDB-storage-accdb.git"
10
+ },
11
+ "homepage": "https://github.com/wxn0brP/ValtheraDB-storage-accdb",
12
+ "author": "wxn0brP",
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "keywords": [
16
+ "valthera",
17
+ "valtheradb",
18
+ "vdb-adapter",
19
+ "accdb"
20
+ ],
21
+ "devDependencies": {
22
+ "@types/bun": "*",
23
+ "@wxn0brp/biome": "*",
24
+ "tsc-alias": "^1",
25
+ "typescript": "^7"
26
+ },
27
+ "dependencies": {
28
+ "@wxn0brp/db-core": "^0.13.0-alpha.0",
29
+ "odbc": "^2.6.0"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./*": {
41
+ "types": "./dist/*.d.ts",
42
+ "import": "./dist/*.js",
43
+ "default": "./dist/*.js"
44
+ }
45
+ }
46
+ }