@mountsqli/sqlite 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/dist/chunk-O5OK22LQ.js +250 -0
- package/dist/driver-BfnsrAUr.d.ts +59 -0
- package/dist/drivers/better-sqlite3/index.d.ts +11 -0
- package/dist/drivers/better-sqlite3/index.js +19 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +28 -0
- package/package.json +39 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// src/sqlite-core/dialect.ts
|
|
2
|
+
import { Dialect, SQL } from "@mountsqli/core";
|
|
3
|
+
var SqliteDialect = class extends Dialect {
|
|
4
|
+
dialect = "sqlite";
|
|
5
|
+
escapeName(name) {
|
|
6
|
+
return `"${name}"`;
|
|
7
|
+
}
|
|
8
|
+
escapeParam(index) {
|
|
9
|
+
return `?`;
|
|
10
|
+
}
|
|
11
|
+
buildSelectQuery(config) {
|
|
12
|
+
const parts = ["SELECT"];
|
|
13
|
+
if (config.distinct) parts.push("DISTINCT");
|
|
14
|
+
if (config.columns.length > 0) {
|
|
15
|
+
const colSqls = config.columns.map((col) => {
|
|
16
|
+
const tableName2 = col._.tableName || config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
17
|
+
if (tableName2) {
|
|
18
|
+
return `${this.escapeName(tableName2)}.${this.escapeName(col.name)}`;
|
|
19
|
+
}
|
|
20
|
+
return this.escapeName(col.name);
|
|
21
|
+
});
|
|
22
|
+
parts.push(colSqls.join(", "));
|
|
23
|
+
} else {
|
|
24
|
+
parts.push("*");
|
|
25
|
+
}
|
|
26
|
+
const tableName = config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
27
|
+
parts.push(`FROM ${this.escapeName(tableName)}`);
|
|
28
|
+
if (config.joins) {
|
|
29
|
+
for (const join of config.joins) {
|
|
30
|
+
const joinTableName = join.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
31
|
+
const joinType = join.type.toUpperCase();
|
|
32
|
+
const onSql = join.on.toQuery(this.getBuildQueryConfig()).sql;
|
|
33
|
+
parts.push(`${joinType} JOIN ${this.escapeName(joinTableName)} ON ${onSql}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (config.where) {
|
|
37
|
+
parts.push(`WHERE ${config.where.toQuery(this.getBuildQueryConfig()).sql}`);
|
|
38
|
+
}
|
|
39
|
+
if (config.groupBy && config.groupBy.length > 0) {
|
|
40
|
+
parts.push(`GROUP BY ${config.groupBy.map((g) => g.toQuery(this.getBuildQueryConfig()).sql).join(", ")}`);
|
|
41
|
+
}
|
|
42
|
+
if (config.having) {
|
|
43
|
+
parts.push(`HAVING ${config.having.toQuery(this.getBuildQueryConfig()).sql}`);
|
|
44
|
+
}
|
|
45
|
+
if (config.orderBy && config.orderBy.length > 0) {
|
|
46
|
+
parts.push(`ORDER BY ${config.orderBy.map((o) => o.toQuery(this.getBuildQueryConfig()).sql).join(", ")}`);
|
|
47
|
+
}
|
|
48
|
+
if (config.limit !== void 0) parts.push(`LIMIT ${config.limit}`);
|
|
49
|
+
if (config.offset !== void 0) parts.push(`OFFSET ${config.offset}`);
|
|
50
|
+
return new SQL([parts.join(" ")]);
|
|
51
|
+
}
|
|
52
|
+
buildInsertQuery(config) {
|
|
53
|
+
const tableName = config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
54
|
+
const columns = Object.keys(config.values[0] ?? {});
|
|
55
|
+
const escapedCols = columns.map((c) => this.escapeName(c));
|
|
56
|
+
const placeholders = columns.map(() => "?");
|
|
57
|
+
let sql = `INSERT INTO ${this.escapeName(tableName)} (${escapedCols.join(", ")}) VALUES (${placeholders.join(", ")})`;
|
|
58
|
+
if (config.onConflict) {
|
|
59
|
+
sql += ` ${config.onConflict.toQuery(this.getBuildQueryConfig()).sql}`;
|
|
60
|
+
}
|
|
61
|
+
if (config.returning && config.returning.length > 0) {
|
|
62
|
+
const retCols = config.returning.map((c) => this.escapeName(c.name)).join(", ");
|
|
63
|
+
sql += ` RETURNING ${retCols}`;
|
|
64
|
+
}
|
|
65
|
+
return new SQL([sql]);
|
|
66
|
+
}
|
|
67
|
+
buildUpdateQuery(config) {
|
|
68
|
+
const tableName = config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
69
|
+
const setClauses = Object.keys(config.set).map((k) => `${this.escapeName(k)} = ?`);
|
|
70
|
+
let sql = `UPDATE ${this.escapeName(tableName)} SET ${setClauses.join(", ")}`;
|
|
71
|
+
if (config.where) {
|
|
72
|
+
sql += ` WHERE ${config.where.toQuery(this.getBuildQueryConfig()).sql}`;
|
|
73
|
+
}
|
|
74
|
+
if (config.returning && config.returning.length > 0) {
|
|
75
|
+
const retCols = config.returning.map((c) => this.escapeName(c.name)).join(", ");
|
|
76
|
+
sql += ` RETURNING ${retCols}`;
|
|
77
|
+
}
|
|
78
|
+
return new SQL([sql]);
|
|
79
|
+
}
|
|
80
|
+
buildDeleteQuery(config) {
|
|
81
|
+
const tableName = config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
82
|
+
let sql = `DELETE FROM ${this.escapeName(tableName)}`;
|
|
83
|
+
if (config.where) {
|
|
84
|
+
sql += ` WHERE ${config.where.toQuery(this.getBuildQueryConfig()).sql}`;
|
|
85
|
+
}
|
|
86
|
+
if (config.returning && config.returning.length > 0) {
|
|
87
|
+
const retCols = config.returning.map((c) => this.escapeName(c.name)).join(", ");
|
|
88
|
+
sql += ` RETURNING ${retCols}`;
|
|
89
|
+
}
|
|
90
|
+
return new SQL([sql]);
|
|
91
|
+
}
|
|
92
|
+
buildCreateTable(config) {
|
|
93
|
+
const tableName = config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
94
|
+
const ifNotExists = config.ifNotExists ? " IF NOT EXISTS" : "";
|
|
95
|
+
const columns = config.table.getSQLColumns();
|
|
96
|
+
const colDefs = Object.values(columns).map(
|
|
97
|
+
(col) => ` ${this.escapeName(col.name)} ${col.sqlType}`
|
|
98
|
+
);
|
|
99
|
+
const pkCols = [];
|
|
100
|
+
for (const [, col] of Object.entries(config.table.columns)) {
|
|
101
|
+
if (col.isPrimaryKey) pkCols.push(this.escapeName(col.name));
|
|
102
|
+
}
|
|
103
|
+
if (pkCols.length > 0) colDefs.push(` PRIMARY KEY (${pkCols.join(", ")})`);
|
|
104
|
+
return new SQL([`CREATE TABLE${ifNotExists} ${this.escapeName(tableName)} (
|
|
105
|
+
${colDefs.join(",\n")}
|
|
106
|
+
)`]);
|
|
107
|
+
}
|
|
108
|
+
buildDropTable(config) {
|
|
109
|
+
const tableName = config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
110
|
+
const ifExists = config.ifExists ? " IF EXISTS" : "";
|
|
111
|
+
return new SQL([`DROP TABLE${ifExists} ${this.escapeName(tableName)}`]);
|
|
112
|
+
}
|
|
113
|
+
buildCreateIndex(config) {
|
|
114
|
+
const tableName = config.table?.[/* @__PURE__ */ Symbol.for("name")];
|
|
115
|
+
const unique = config.unique ? "UNIQUE " : "";
|
|
116
|
+
const colNames = config.columns.map((c) => this.escapeName(c.name)).join(", ");
|
|
117
|
+
return new SQL([`CREATE ${unique}INDEX ${this.escapeName(config.name)} ON ${this.escapeName(tableName)} (${colNames})`]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/sqlite-core/session.ts
|
|
122
|
+
import { Session } from "@mountsqli/core";
|
|
123
|
+
var SqlitePreparedQuery = class {
|
|
124
|
+
_stmt;
|
|
125
|
+
_query;
|
|
126
|
+
constructor(stmt, query) {
|
|
127
|
+
this._stmt = stmt;
|
|
128
|
+
this._query = query;
|
|
129
|
+
}
|
|
130
|
+
async execute() {
|
|
131
|
+
return this._stmt.run(...this._query.params);
|
|
132
|
+
}
|
|
133
|
+
async all() {
|
|
134
|
+
return this._stmt.all(...this._query.params);
|
|
135
|
+
}
|
|
136
|
+
async values() {
|
|
137
|
+
const rows = this._stmt.all(...this._query.params);
|
|
138
|
+
return rows.map((row) => Object.values(row));
|
|
139
|
+
}
|
|
140
|
+
getQuery() {
|
|
141
|
+
return this._query;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var SqliteSession = class extends Session {
|
|
145
|
+
_db;
|
|
146
|
+
constructor(db, logger) {
|
|
147
|
+
super(logger);
|
|
148
|
+
this._db = db;
|
|
149
|
+
}
|
|
150
|
+
async execute(query) {
|
|
151
|
+
const stmt = this._db.prepare(query.sql);
|
|
152
|
+
const result = stmt.all(...query.params);
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
prepare(query) {
|
|
156
|
+
const stmt = this._db.prepare(query.sql);
|
|
157
|
+
return new SqlitePreparedQuery(stmt, query);
|
|
158
|
+
}
|
|
159
|
+
async transaction(fn) {
|
|
160
|
+
return this._db.transaction(() => {
|
|
161
|
+
const tx = new SqliteTransaction(this._db, this.logger);
|
|
162
|
+
return fn(tx);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async dispose() {
|
|
166
|
+
this._db.close();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var SqliteTransaction = class _SqliteTransaction extends Session {
|
|
170
|
+
_db;
|
|
171
|
+
constructor(db, logger) {
|
|
172
|
+
super(logger);
|
|
173
|
+
this._db = db;
|
|
174
|
+
this.inTransaction = true;
|
|
175
|
+
}
|
|
176
|
+
async execute(query) {
|
|
177
|
+
const stmt = this._db.prepare(query.sql);
|
|
178
|
+
return stmt.all(...query.params);
|
|
179
|
+
}
|
|
180
|
+
prepare(query) {
|
|
181
|
+
const stmt = this._db.prepare(query.sql);
|
|
182
|
+
return new SqlitePreparedQuery(stmt, query);
|
|
183
|
+
}
|
|
184
|
+
async transaction(fn) {
|
|
185
|
+
const tx = new _SqliteTransaction(this._db, this.logger);
|
|
186
|
+
this._db.exec(`SAVEPOINT sp_${Date.now()}`);
|
|
187
|
+
try {
|
|
188
|
+
const result = await fn(tx);
|
|
189
|
+
this._db.exec(`RELEASE SAVEPOINT sp_${Date.now()}`);
|
|
190
|
+
return result;
|
|
191
|
+
} catch (err) {
|
|
192
|
+
this._db.exec(`ROLLBACK TO SAVEPOINT sp_${Date.now()}`);
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async rollback() {
|
|
197
|
+
this._db.exec("ROLLBACK");
|
|
198
|
+
throw new Error("Transaction rolled back");
|
|
199
|
+
}
|
|
200
|
+
async commit() {
|
|
201
|
+
this._db.exec("COMMIT");
|
|
202
|
+
}
|
|
203
|
+
async setTransactionIsolation(_level) {
|
|
204
|
+
}
|
|
205
|
+
async dispose() {
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/drivers/better-sqlite3/driver.ts
|
|
210
|
+
import { createLogger } from "@mountsqli/core";
|
|
211
|
+
var BetterSqlite3Driver = class {
|
|
212
|
+
dialect = "sqlite";
|
|
213
|
+
_config;
|
|
214
|
+
_db = null;
|
|
215
|
+
_logger;
|
|
216
|
+
constructor(config) {
|
|
217
|
+
this._config = config;
|
|
218
|
+
this._logger = typeof config.logger === "boolean" ? createLogger({ enabled: config.logger }) : config.logger ?? createLogger({ enabled: false });
|
|
219
|
+
}
|
|
220
|
+
createSession() {
|
|
221
|
+
if (!this._db) throw new Error("Not connected");
|
|
222
|
+
return new SqliteSession(this._db, this._logger);
|
|
223
|
+
}
|
|
224
|
+
async connect() {
|
|
225
|
+
const mod = await import("better-sqlite3");
|
|
226
|
+
const Database = mod.default ?? mod;
|
|
227
|
+
this._db = new Database(this._config.filename);
|
|
228
|
+
}
|
|
229
|
+
async disconnect() {
|
|
230
|
+
if (this._db) {
|
|
231
|
+
this._db.close();
|
|
232
|
+
this._db = null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async ping() {
|
|
236
|
+
try {
|
|
237
|
+
this._db?.prepare("SELECT 1").get();
|
|
238
|
+
return true;
|
|
239
|
+
} catch {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export {
|
|
246
|
+
SqliteDialect,
|
|
247
|
+
SqliteSession,
|
|
248
|
+
SqliteTransaction,
|
|
249
|
+
BetterSqlite3Driver
|
|
250
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Session, Logger, QueryWithTypings, PreparedQuery, Driver } from '@mountsqli/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SQLite session — wraps better-sqlite3.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface SqliteDatabase {
|
|
8
|
+
prepare(sql: string): SqliteStatement;
|
|
9
|
+
exec(sql: string): this;
|
|
10
|
+
close(): void;
|
|
11
|
+
transaction<T>(fn: () => T): T;
|
|
12
|
+
}
|
|
13
|
+
interface SqliteStatement {
|
|
14
|
+
run(...params: any[]): any;
|
|
15
|
+
get(...params: any[]): any;
|
|
16
|
+
all(...params: any[]): any[];
|
|
17
|
+
}
|
|
18
|
+
declare class SqliteSession extends Session {
|
|
19
|
+
private _db;
|
|
20
|
+
constructor(db: SqliteDatabase, logger: Logger);
|
|
21
|
+
execute<T>(query: QueryWithTypings): Promise<T>;
|
|
22
|
+
prepare<T>(query: QueryWithTypings): PreparedQuery<T>;
|
|
23
|
+
transaction<T>(fn: (tx: any) => Promise<T>): Promise<T>;
|
|
24
|
+
dispose(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
declare class SqliteTransaction extends Session {
|
|
27
|
+
private _db;
|
|
28
|
+
constructor(db: SqliteDatabase, logger: Logger);
|
|
29
|
+
execute<T>(query: QueryWithTypings): Promise<T>;
|
|
30
|
+
prepare<T>(query: QueryWithTypings): PreparedQuery<T>;
|
|
31
|
+
transaction<T>(fn: (tx: any) => Promise<T>): Promise<T>;
|
|
32
|
+
rollback(): Promise<never>;
|
|
33
|
+
commit(): Promise<void>;
|
|
34
|
+
setTransactionIsolation(_level: string): Promise<void>;
|
|
35
|
+
dispose(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* better-sqlite3 driver.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
interface BetterSqlite3DriverConfig {
|
|
43
|
+
/** Database file path or ':memory:' */
|
|
44
|
+
filename: string;
|
|
45
|
+
logger?: Logger | boolean;
|
|
46
|
+
}
|
|
47
|
+
declare class BetterSqlite3Driver implements Driver {
|
|
48
|
+
readonly dialect: "sqlite";
|
|
49
|
+
private _config;
|
|
50
|
+
private _db;
|
|
51
|
+
private _logger;
|
|
52
|
+
constructor(config: BetterSqlite3DriverConfig);
|
|
53
|
+
createSession(): SqliteSession;
|
|
54
|
+
connect(): Promise<void>;
|
|
55
|
+
disconnect(): Promise<void>;
|
|
56
|
+
ping(): Promise<boolean>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { type BetterSqlite3DriverConfig as B, SqliteSession as S, BetterSqlite3Driver as a, SqliteTransaction as b };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DatabaseConfig, Database } from '@mountsqli/core';
|
|
2
|
+
import { B as BetterSqlite3DriverConfig } from '../../driver-BfnsrAUr.js';
|
|
3
|
+
export { a as BetterSqlite3Driver } from '../../driver-BfnsrAUr.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* better-sqlite3 driver entry point.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare function mountsqli(connectionOrConfig: string | BetterSqlite3DriverConfig, options?: DatabaseConfig): Database;
|
|
10
|
+
|
|
11
|
+
export { BetterSqlite3DriverConfig, mountsqli };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BetterSqlite3Driver,
|
|
3
|
+
SqliteDialect
|
|
4
|
+
} from "../../chunk-O5OK22LQ.js";
|
|
5
|
+
|
|
6
|
+
// src/drivers/better-sqlite3/index.ts
|
|
7
|
+
import { Database, createLogger } from "@mountsqli/core";
|
|
8
|
+
function mountsqli(connectionOrConfig, options) {
|
|
9
|
+
const logger = typeof options?.logger === "boolean" ? createLogger({ enabled: options.logger }) : options?.logger ?? createLogger({ enabled: false });
|
|
10
|
+
const driverConfig = typeof connectionOrConfig === "string" ? { filename: connectionOrConfig, logger } : { ...connectionOrConfig, logger };
|
|
11
|
+
const driver = new BetterSqlite3Driver(driverConfig);
|
|
12
|
+
const dialect = new SqliteDialect();
|
|
13
|
+
const session = driver.createSession();
|
|
14
|
+
return new Database(session, dialect, { ...options, logger });
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
BetterSqlite3Driver,
|
|
18
|
+
mountsqli
|
|
19
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Table, TableConfig, Column, Dialect, AnyColumn, SQL } from '@mountsqli/core';
|
|
2
|
+
export { a as BetterSqlite3Driver, S as SqliteSession, b as SqliteTransaction } from './driver-BfnsrAUr.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SQLite table factory.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare class SqliteTable extends Table<TableConfig & {
|
|
9
|
+
dialect: 'sqlite';
|
|
10
|
+
}> {
|
|
11
|
+
}
|
|
12
|
+
type SqliteTableColumns = Record<string, Column>;
|
|
13
|
+
declare function sqliteTable<TColumns extends SqliteTableColumns>(name: string, columns: TColumns, config?: {
|
|
14
|
+
schema?: string;
|
|
15
|
+
}): SqliteTable & {
|
|
16
|
+
columns: TColumns;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* SQLite dialect — SQL generation for SQLite.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
declare class SqliteDialect extends Dialect {
|
|
24
|
+
readonly dialect: "sqlite";
|
|
25
|
+
escapeName(name: string): string;
|
|
26
|
+
escapeParam(index: number): string;
|
|
27
|
+
buildSelectQuery(config: {
|
|
28
|
+
table: Table;
|
|
29
|
+
columns: AnyColumn[];
|
|
30
|
+
where?: SQL;
|
|
31
|
+
orderBy?: SQL[];
|
|
32
|
+
groupBy?: SQL[];
|
|
33
|
+
having?: SQL;
|
|
34
|
+
limit?: number;
|
|
35
|
+
offset?: number;
|
|
36
|
+
joins?: Array<{
|
|
37
|
+
table: Table;
|
|
38
|
+
on: SQL;
|
|
39
|
+
type: 'inner' | 'left' | 'right' | 'full';
|
|
40
|
+
}>;
|
|
41
|
+
distinct?: boolean;
|
|
42
|
+
}): SQL;
|
|
43
|
+
buildInsertQuery(config: {
|
|
44
|
+
table: Table;
|
|
45
|
+
values: Record<string, unknown>[];
|
|
46
|
+
onConflict?: SQL;
|
|
47
|
+
returning?: AnyColumn[];
|
|
48
|
+
}): SQL;
|
|
49
|
+
buildUpdateQuery(config: {
|
|
50
|
+
table: Table;
|
|
51
|
+
set: Record<string, unknown>;
|
|
52
|
+
where?: SQL;
|
|
53
|
+
returning?: AnyColumn[];
|
|
54
|
+
}): SQL;
|
|
55
|
+
buildDeleteQuery(config: {
|
|
56
|
+
table: Table;
|
|
57
|
+
where?: SQL;
|
|
58
|
+
returning?: AnyColumn[];
|
|
59
|
+
}): SQL;
|
|
60
|
+
buildCreateTable(config: {
|
|
61
|
+
table: Table;
|
|
62
|
+
ifNotExists?: boolean;
|
|
63
|
+
}): SQL;
|
|
64
|
+
buildDropTable(config: {
|
|
65
|
+
table: Table;
|
|
66
|
+
ifExists?: boolean;
|
|
67
|
+
}): SQL;
|
|
68
|
+
buildCreateIndex(config: {
|
|
69
|
+
name: string;
|
|
70
|
+
table: Table;
|
|
71
|
+
columns: AnyColumn[];
|
|
72
|
+
unique?: boolean;
|
|
73
|
+
concurrently?: boolean;
|
|
74
|
+
}): SQL;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { SqliteDialect, SqliteTable, type SqliteTableColumns, sqliteTable };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BetterSqlite3Driver,
|
|
3
|
+
SqliteDialect,
|
|
4
|
+
SqliteSession,
|
|
5
|
+
SqliteTransaction
|
|
6
|
+
} from "./chunk-O5OK22LQ.js";
|
|
7
|
+
|
|
8
|
+
// src/sqlite-core/table.ts
|
|
9
|
+
import { Table } from "@mountsqli/core";
|
|
10
|
+
var SqliteTable = class extends Table {
|
|
11
|
+
};
|
|
12
|
+
function sqliteTable(name, columns, config) {
|
|
13
|
+
const table = new SqliteTable(name, config?.schema, name);
|
|
14
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
15
|
+
table.columns[key] = col;
|
|
16
|
+
col.tableName = name;
|
|
17
|
+
}
|
|
18
|
+
const result = table;
|
|
19
|
+
result.columns = columns;
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
BetterSqlite3Driver,
|
|
24
|
+
SqliteDialect,
|
|
25
|
+
SqliteSession,
|
|
26
|
+
SqliteTransaction,
|
|
27
|
+
sqliteTable
|
|
28
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mountsqli/sqlite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts"
|
|
9
|
+
},
|
|
10
|
+
"./better-sqlite3": {
|
|
11
|
+
"import": "./dist/drivers/better-sqlite3/index.js",
|
|
12
|
+
"types": "./dist/drivers/better-sqlite3/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": ["dist", "LICENSE", "README.md"],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts src/drivers/better-sqlite3/index.ts --format esm --dts --clean",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"clean": "rm -rf dist"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@mountsqli/core": "workspace:*",
|
|
25
|
+
"@mountsqli/shared": "workspace:*"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"better-sqlite3": "^11.0.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"better-sqlite3": { "optional": true }
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"typescript": "^5.7.0",
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"vitest": "^3.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|