Skip to content

Commit ad67011

Browse files
committed
Removed redundant dynamic import for the sqlite3 client that was messing up with the bundle
1 parent b7d6a98 commit ad67011

File tree

11 files changed

+367
-360
lines changed

11 files changed

+367
-360
lines changed

.github/workflows/build_and_test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
- name: Install dependencies
4242
run: npm ci
4343

44+
- name: Rebuild sqlite3
45+
run: npm rebuild sqlite3
46+
4447
- name: Build TS
4548
run: npm run build:ts
4649

samples/simple-ts/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
dts: true, // generate dts files
77
format: ['cjs', 'esm'], // generate cjs and esm files
88
minify: true, //env === 'production',
9-
bundle: true, //env === 'production',
9+
bundle: false, //env === 'production',
1010
skipNodeModulesBundle: true,
1111
target: 'esnext',
1212
outDir: 'dist', //env === 'production' ? 'dist' : 'lib',

src/package-lock.json

Lines changed: 286 additions & 286 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getDatabaseDriverName, type DatabaseDriverType } from '../../..';
2-
import type { SQLiteClientFactory } from './connections';
1+
import { type DatabaseDriverType } from '../../..';
32

43
export * from './connections';
54
export * from './execute';
@@ -15,21 +14,3 @@ export type SQLiteDriverType<DriverName extends string = string> =
1514
DatabaseDriverType<SQLiteDatabaseName, DriverName>;
1615

1716
export type SQLiteDatabaseType = 'SQLite';
18-
19-
export const sqliteClientProvider = async <
20-
DriverType extends SQLiteDriverType = SQLiteDriverType,
21-
>(
22-
driverType: DriverType,
23-
): Promise<SQLiteClientFactory> => {
24-
const driverName = getDatabaseDriverName(driverType);
25-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
26-
const driverModule = await import(`../${driverName.toLowerCase()}`);
27-
28-
if (!('sqliteClient' in driverModule))
29-
throw new Error(
30-
`The driver type module "${driverType}" does not export a sqliteClient`,
31-
);
32-
33-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
34-
return driverModule.sqliteClient as SQLiteClientFactory;
35-
};

src/packages/dumbo/src/storage/sqlite/core/pool/pool.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
InMemorySQLiteDatabase,
3-
sqliteClientProvider,
43
sqliteConnection,
54
SQLiteConnectionString,
65
type SQLiteClient,
76
type SQLiteClientConnection,
7+
type SQLiteClientFactory,
88
type SQLiteDriverType,
99
type SQLitePoolClientConnection,
1010
} from '..';
@@ -55,22 +55,22 @@ export const sqliteSingletonClientPool = <
5555
driverType: DriverType;
5656
database?: string | undefined;
5757
allowNestedTransactions?: boolean;
58-
} & SQLiteFileNameOrConnectionString,
58+
} & SQLiteFileNameOrConnectionString &
59+
SQLitePoolConfig,
5960
): SQLiteAmbientClientPool<DriverType> => {
60-
const { driverType } = options;
61+
const { driverType, sqliteClient } = options;
6162
let connection: SQLiteClientConnection | undefined = undefined;
6263

6364
const getConnection = () => {
6465
if (connection) return connection;
6566

66-
const connect = () =>
67-
sqliteClientProvider(driverType).then(async (sqliteClient) => {
68-
const client = sqliteClient(options);
67+
const connect = async () => {
68+
const client = sqliteClient(options);
6969

70-
await client.connect();
70+
await client.connect();
7171

72-
return client;
73-
});
72+
return client;
73+
};
7474

7575
return (connection = sqliteConnection({
7676
driverType,
@@ -101,21 +101,21 @@ export const sqliteAlwaysNewClientPool = <
101101
driverType: DriverType;
102102
database?: string | undefined;
103103
allowNestedTransactions?: boolean;
104-
} & SQLiteFileNameOrConnectionString,
104+
} & SQLiteFileNameOrConnectionString &
105+
SQLitePoolConfig,
105106
): SQLiteAmbientClientPool<DriverType> => {
106-
const { driverType, allowNestedTransactions } = options;
107+
const { driverType, allowNestedTransactions, sqliteClient } = options;
107108

108109
return createConnectionPool({
109110
driverType,
110111
getConnection: () => {
111-
const connect = () =>
112-
sqliteClientProvider(driverType).then(async (sqliteClient) => {
113-
const client = sqliteClient(options);
112+
const connect = async () => {
113+
const client = sqliteClient(options);
114114

115-
await client.connect();
115+
await client.connect();
116116

117-
return client;
118-
});
117+
return client;
118+
};
119119

120120
return sqliteConnection({
121121
driverType,
@@ -218,17 +218,20 @@ export type SQLiteDumboConnectionOptions<
218218
serializer?: JSONSerializer;
219219
} & SQLiteFileNameOrConnectionString;
220220

221+
export type SQLitePoolConfig = { sqliteClient: SQLiteClientFactory };
222+
221223
export function sqlitePool<
222224
DriverType extends SQLiteDriverType = SQLiteDriverType,
223225
>(
224226
options: SQLitePoolNotPooledOptions<DriverType> &
225-
SQLiteFileNameOrConnectionString,
227+
SQLiteFileNameOrConnectionString &
228+
SQLitePoolConfig,
226229
): SQLiteAmbientClientPool<DriverType>;
227230

228231
export function sqlitePool<
229232
DriverType extends SQLiteDriverType = SQLiteDriverType,
230233
>(
231-
options: SQLiteDumboConnectionOptions<DriverType>,
234+
options: SQLiteDumboConnectionOptions<DriverType> & SQLitePoolConfig,
232235
):
233236
| SQLiteAmbientClientPool<DriverType>
234237
| SQLiteAmbientConnectionPool<DriverType> {

src/packages/dumbo/src/storage/sqlite/sqlite3/connections/connection.int.spec.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { afterEach, describe, it } from 'node:test';
44
import path from 'path';
55
import { fileURLToPath } from 'url';
66
import { SQL } from '../../../../core';
7-
import { InMemorySQLiteDatabase, sqlitePool } from '../../core';
7+
import { sqlite3Pool } from '../../../../sqlite3';
8+
import { InMemorySQLiteDatabase } from '../../core';
89
import { sqlite3Client } from './connection';
910

1011
void describe('Node SQLite pool', () => {
@@ -35,7 +36,7 @@ void describe('Node SQLite pool', () => {
3536

3637
void describe(`in-memory database`, () => {
3738
void it('returns the singleton connection', async () => {
38-
const pool = sqlitePool({
39+
const pool = sqlite3Pool({
3940
driverType: 'SQLite:sqlite3',
4041
fileName: inMemoryfileName,
4142
});
@@ -58,7 +59,10 @@ void describe('Node SQLite pool', () => {
5859

5960
void describe(`file-based database`, () => {
6061
void it('returns the new connection each time', async () => {
61-
const pool = sqlitePool({ driverType: 'SQLite:sqlite3', fileName });
62+
const pool = sqlite3Pool({
63+
driverType: 'SQLite:sqlite3',
64+
fileName,
65+
});
6266
const connection = await pool.connection();
6367
const otherConnection = await pool.connection();
6468

@@ -76,7 +80,7 @@ void describe('Node SQLite pool', () => {
7680
});
7781

7882
void it('for singleton setting returns the singleton connection', async () => {
79-
const pool = sqlitePool({
83+
const pool = sqlite3Pool({
8084
driverType: 'SQLite:sqlite3',
8185
fileName,
8286
singleton: true,
@@ -99,9 +103,12 @@ void describe('Node SQLite pool', () => {
99103
});
100104

101105
for (const { testName, fileName } of testCases) {
102-
void describe(`sqlitePool with ${testName} database`, () => {
106+
void describe(`sqlite3Pool with ${testName} database`, () => {
103107
void it('connects using default pool', async () => {
104-
const pool = sqlitePool({ driverType: 'SQLite:sqlite3', fileName });
108+
const pool = sqlite3Pool({
109+
driverType: 'SQLite:sqlite3',
110+
fileName,
111+
});
105112
const connection = await pool.connection();
106113

107114
try {
@@ -116,7 +123,7 @@ void describe('Node SQLite pool', () => {
116123
});
117124

118125
void it('connects using client', async () => {
119-
const pool = sqlitePool({
126+
const pool = sqlite3Pool({
120127
driverType: 'SQLite:sqlite3',
121128
fileName,
122129
pooled: false,
@@ -135,7 +142,7 @@ void describe('Node SQLite pool', () => {
135142
const existingClient = sqlite3Client({ fileName });
136143
await existingClient.connect();
137144

138-
const pool = sqlitePool({
145+
const pool = sqlite3Pool({
139146
driverType: 'SQLite:sqlite3',
140147
fileName,
141148
client: existingClient,
@@ -152,14 +159,14 @@ void describe('Node SQLite pool', () => {
152159
});
153160

154161
void it('connects using connected ambient connected connection', async () => {
155-
const ambientPool = sqlitePool({
162+
const ambientPool = sqlite3Pool({
156163
driverType: 'SQLite:sqlite3',
157164
fileName,
158165
});
159166
const ambientConnection = await ambientPool.connection();
160167
await ambientConnection.open();
161168

162-
const pool = sqlitePool({
169+
const pool = sqlite3Pool({
163170
driverType: 'SQLite:sqlite3',
164171
fileName,
165172
connection: ambientConnection,
@@ -175,13 +182,13 @@ void describe('Node SQLite pool', () => {
175182
});
176183

177184
void it('connects using connected ambient not-connected connection', async () => {
178-
const ambientPool = sqlitePool({
185+
const ambientPool = sqlite3Pool({
179186
driverType: 'SQLite:sqlite3',
180187
fileName,
181188
});
182189
const ambientConnection = await ambientPool.connection();
183190

184-
const pool = sqlitePool({
191+
const pool = sqlite3Pool({
185192
driverType: 'SQLite:sqlite3',
186193
fileName,
187194
connection: ambientConnection,
@@ -197,7 +204,7 @@ void describe('Node SQLite pool', () => {
197204
});
198205

199206
void it('connects using ambient connected connection with transaction', async () => {
200-
const ambientPool = sqlitePool({
207+
const ambientPool = sqlite3Pool({
201208
driverType: 'SQLite:sqlite3',
202209
fileName,
203210
});
@@ -206,7 +213,7 @@ void describe('Node SQLite pool', () => {
206213

207214
try {
208215
await ambientConnection.withTransaction<void>(async () => {
209-
const pool = sqlitePool({
216+
const pool = sqlite3Pool({
210217
driverType: 'SQLite:sqlite3',
211218
fileName,
212219
connection: ambientConnection,
@@ -226,15 +233,15 @@ void describe('Node SQLite pool', () => {
226233
});
227234

228235
void it('connects using ambient not-connected connection with transaction', async () => {
229-
const ambientPool = sqlitePool({
236+
const ambientPool = sqlite3Pool({
230237
driverType: 'SQLite:sqlite3',
231238
fileName,
232239
});
233240
const ambientConnection = await ambientPool.connection();
234241

235242
try {
236243
await ambientConnection.withTransaction<void>(async () => {
237-
const pool = sqlitePool({
244+
const pool = sqlite3Pool({
238245
driverType: 'SQLite:sqlite3',
239246
fileName,
240247
connection: ambientConnection,
@@ -254,13 +261,13 @@ void describe('Node SQLite pool', () => {
254261
});
255262

256263
void it('connects using ambient connection in withConnection scope', async () => {
257-
const ambientPool = sqlitePool({
264+
const ambientPool = sqlite3Pool({
258265
driverType: 'SQLite:sqlite3',
259266
fileName,
260267
});
261268
try {
262269
await ambientPool.withConnection(async (ambientConnection) => {
263-
const pool = sqlitePool({
270+
const pool = sqlite3Pool({
264271
driverType: 'SQLite:sqlite3',
265272
fileName,
266273
connection: ambientConnection,
@@ -279,14 +286,14 @@ void describe('Node SQLite pool', () => {
279286
});
280287

281288
void it('connects using ambient connection in withConnection and withTransaction scope', async () => {
282-
const ambientPool = sqlitePool({
289+
const ambientPool = sqlite3Pool({
283290
driverType: 'SQLite:sqlite3',
284291
fileName,
285292
});
286293
try {
287294
await ambientPool.withConnection((ambientConnection) =>
288295
ambientConnection.withTransaction<void>(async () => {
289-
const pool = sqlitePool({
296+
const pool = sqlite3Pool({
290297
driverType: 'SQLite:sqlite3',
291298
fileName,
292299
connection: ambientConnection,

src/packages/dumbo/src/storage/sqlite/sqlite3/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ import {
1212
sqlitePool,
1313
type SQLiteConnection,
1414
type SQLiteDumboConnectionOptions,
15+
type SQLitePoolConfig,
1516
} from '../core';
16-
import {
17-
SQLite3DriverType,
18-
sqlite3Client as sqliteClient,
19-
} from './connections';
17+
import { sqlite3Client, SQLite3DriverType } from './connections';
18+
19+
export const sqlite3Pool = (
20+
options: SQLiteDumboConnectionOptions<SQLite3DriverType>,
21+
) =>
22+
sqlitePool({
23+
...options,
24+
sqliteClient: sqlite3Client,
25+
} as SQLiteDumboConnectionOptions<SQLite3DriverType> & SQLitePoolConfig);
2026

2127
export const sqlite3DatabaseDriver = {
2228
driverType: 'SQLite:sqlite3' as const,
2329
createPool: (options) =>
24-
sqlitePool(options as SQLiteDumboConnectionOptions<SQLite3DriverType>),
30+
sqlite3Pool(options as SQLiteDumboConnectionOptions<SQLite3DriverType>),
2531
sqlFormatter: sqliteFormatter,
2632
defaultMigratorOptions: DefaultSQLiteMigratorOptions,
2733
getDatabaseNameOrDefault: () => InMemorySQLiteDatabase,
@@ -52,6 +58,9 @@ export type SQLite3DumboConnectionOptions = DumboConnectionOptions<
5258

5359
useSqlite3DatabaseDriver();
5460

55-
export { sqlite3DatabaseDriver as databaseDriver, sqliteClient };
61+
export {
62+
sqlite3DatabaseDriver as databaseDriver,
63+
sqlite3Client as sqliteClient,
64+
};
5665

5766
export const connectionPool = sqlitePool;

0 commit comments

Comments
 (0)