spooder 4.5.13 → 4.6.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 +9 -9
- package/bun.lock +3 -3
- package/package.json +1 -1
- package/src/api.ts +15 -16
package/README.md
CHANGED
|
@@ -1471,18 +1471,18 @@ const db = await mysql.createConnection({
|
|
|
1471
1471
|
> [!IMPORTANT]
|
|
1472
1472
|
> MySQL requires the optional dependency `mysql2` to be installed - this is not automatically installed with spooder. This will be replaced when bun:sql supports MySQL natively.
|
|
1473
1473
|
|
|
1474
|
-
Database initiation and schema updating can be streamlined with the `
|
|
1474
|
+
Database initiation and schema updating can be streamlined with the `db_init_DRIVER` functions. The following examples are equivalent to the above ones.
|
|
1475
1475
|
|
|
1476
1476
|
```ts
|
|
1477
1477
|
// sqlite example
|
|
1478
|
-
import {
|
|
1479
|
-
const db = await
|
|
1478
|
+
import { db_init_sqlite } from 'spooder';
|
|
1479
|
+
const db = await db_init_sqlite('./database.sqlite', './schema');
|
|
1480
1480
|
```
|
|
1481
1481
|
|
|
1482
1482
|
```ts
|
|
1483
1483
|
// mysql example
|
|
1484
|
-
import {
|
|
1485
|
-
const db = await
|
|
1484
|
+
import { db_init_mysql } from 'spooder';
|
|
1485
|
+
const db = await db_init_mysql({
|
|
1486
1486
|
// connection options
|
|
1487
1487
|
// see https://github.com/mysqljs/mysql#connection-options
|
|
1488
1488
|
}, './schema');
|
|
@@ -1490,14 +1490,14 @@ const db = await db_init_schema_mysql({
|
|
|
1490
1490
|
|
|
1491
1491
|
### Pooling
|
|
1492
1492
|
|
|
1493
|
-
|
|
1493
|
+
Providing `true` to the `pool` parameter of `db_init_mysql` will return a connection pool instead of a single connection.
|
|
1494
1494
|
|
|
1495
1495
|
```ts
|
|
1496
|
-
import {
|
|
1497
|
-
const pool = await
|
|
1496
|
+
import { db_init_mysql } from 'spooder';
|
|
1497
|
+
const pool = await db_init_mysql({
|
|
1498
1498
|
// connection options
|
|
1499
1499
|
connectionLimit: 10
|
|
1500
|
-
});
|
|
1500
|
+
}, './schema', true);
|
|
1501
1501
|
|
|
1502
1502
|
const connection = await pool.getConnection();
|
|
1503
1503
|
```
|
package/bun.lock
CHANGED
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
14
|
"packages": {
|
|
15
|
-
"@types/bun": ["@types/bun@1.2.
|
|
15
|
+
"@types/bun": ["@types/bun@1.2.12", "", { "dependencies": { "bun-types": "1.2.12" } }, "sha512-lY/GQTXDGsolT/TiH72p1tuyUORuRrdV7VwOTOjDOt8uTBJQOJc5zz3ufwwDl0VBaoxotSk4LdP0hhjLJ6ypIQ=="],
|
|
16
16
|
|
|
17
|
-
"@types/node": ["@types/node@22.15.
|
|
17
|
+
"@types/node": ["@types/node@22.15.12", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-K0fpC/ZVeb8G9rm7bH7vI0KAec4XHEhBam616nVJCV51bKzJ6oA3luG4WdKoaztxe70QaNjS/xBmcDLmr4PiGw=="],
|
|
18
18
|
|
|
19
19
|
"aws-ssl-profiles": ["aws-ssl-profiles@1.1.2", "", {}, "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g=="],
|
|
20
20
|
|
|
21
|
-
"bun-types": ["bun-types@1.2.
|
|
21
|
+
"bun-types": ["bun-types@1.2.12", "", { "dependencies": { "@types/node": "*" } }, "sha512-tvWMx5vPqbRXgE8WUZI94iS1xAYs8bkqESR9cxBB1Wi+urvfTrF1uzuDgBHFAdO0+d2lmsbG3HmeKMvUyj6pWA=="],
|
|
22
22
|
|
|
23
23
|
"denque": ["denque@2.1.0", "", {}, "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw=="],
|
|
24
24
|
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -449,15 +449,18 @@ export async function db_update_schema_mysql(db: mysql_types.Connection, schema_
|
|
|
449
449
|
await db.commit();
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
-
export async function
|
|
452
|
+
export async function db_init_sqlite(db_path: string, schema_dir?: string): Promise<Database> {
|
|
453
453
|
const db = new Database(db_path, { create: true });
|
|
454
|
-
|
|
454
|
+
|
|
455
|
+
if (schema_dir !== undefined)
|
|
456
|
+
await db_update_schema_sqlite(db, schema_dir);
|
|
457
|
+
|
|
455
458
|
return db;
|
|
456
459
|
}
|
|
457
460
|
|
|
458
|
-
async function
|
|
461
|
+
export async function db_init_mysql<T extends boolean = false>(db_info: mysql_types.ConnectionOptions, schema_dir?: string, pool: T = false as T): Promise<T extends true ? mysql_types.Pool : mysql_types.Connection> {
|
|
459
462
|
if (mysql === undefined)
|
|
460
|
-
throw new Error('
|
|
463
|
+
throw new Error('db_init_mysql cannot be called without optional dependency {mysql2} installed');
|
|
461
464
|
|
|
462
465
|
// required for parsing multiple statements from schema files
|
|
463
466
|
db_info.multipleStatements = true;
|
|
@@ -466,26 +469,22 @@ async function _db_init_schema_mysql(db_info: mysql_types.ConnectionOptions, sch
|
|
|
466
469
|
const pool = mysql.createPool(db_info);
|
|
467
470
|
const connection = await pool.getConnection();
|
|
468
471
|
|
|
469
|
-
|
|
472
|
+
if (schema_dir !== undefined)
|
|
473
|
+
await db_update_schema_mysql(connection, schema_dir);
|
|
474
|
+
|
|
470
475
|
connection.release();
|
|
471
476
|
|
|
472
|
-
return pool;
|
|
477
|
+
return pool as any;
|
|
473
478
|
} else {
|
|
474
479
|
const connection = await mysql.createConnection(db_info);
|
|
475
|
-
|
|
480
|
+
|
|
481
|
+
if (schema_dir !== undefined)
|
|
482
|
+
await db_update_schema_mysql(connection, schema_dir);
|
|
476
483
|
|
|
477
|
-
return connection;
|
|
484
|
+
return connection as any;
|
|
478
485
|
}
|
|
479
486
|
}
|
|
480
487
|
|
|
481
|
-
export async function db_init_schema_mysql_pool(db_info: mysql_types.ConnectionOptions, schema_dir: string): Promise<mysql_types.Pool> {
|
|
482
|
-
return await _db_init_schema_mysql(db_info, schema_dir, true) as mysql_types.Pool;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
export async function db_init_schema_mysql(db_info: mysql_types.ConnectionOptions, schema_dir: string): Promise<mysql_types.Connection> {
|
|
486
|
-
return await _db_init_schema_mysql(db_info, schema_dir, false) as mysql_types.Connection;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
488
|
export type CookieOptions = {
|
|
490
489
|
same_site?: 'Strict' | 'Lax' | 'None',
|
|
491
490
|
secure?: boolean,
|