feat: one install and one import per database; server dialects open their pool from a URL; nodeListener answers a throwing context; 0.5.0

This commit is contained in:
2026-11-03 13:06:04 +01:00
parent 1391c21c1f
commit e7637c3704
24 changed files with 194 additions and 227 deletions
+3 -9
View File
@@ -1,6 +1,6 @@
{
"name": "@crudy/restloom-mysql",
"version": "0.4.0",
"version": "0.5.0",
"type": "module",
"description": "MySQL dialect for restloom",
"keywords": [
@@ -36,17 +36,11 @@
"prepack": "npm run build"
},
"dependencies": {
"@crudy/restloom": "^0.4.0"
},
"peerDependencies": {
"mysql2": "^3.11.0"
},
"peerDependenciesMeta": {
"mysql2": { "optional": true }
"@crudy/restloom": "^0.5.0",
"mysql2": "^3.24.5"
},
"devDependencies": {
"@types/node": "^24.0.0",
"mysql2": "^3.24.5",
"typescript": "^5.9.0"
}
}
+12 -3
View File
@@ -1,8 +1,16 @@
import { RestError, type Dialect, type SqlRenderer } from '@crudy/restloom';
import type { Pool } from 'mysql2/promise';
import { createPool, type Pool, type PoolOptions } from 'mysql2/promise';
import { introspect } from './introspect.js';
import { MysqlRenderer } from './renderer.js';
export * from '@crudy/restloom';
/** A mysql2/promise Pool, or what opens one: a connection URL or pool options. */
export type MysqlConnection = Pool | PoolOptions | string;
const poolOf = (c: MysqlConnection): Pool =>
typeof c === 'string' ? createPool({ uri: c }) : typeof (c as Pool).getConnection === 'function' ? (c as Pool) : createPool(c as PoolOptions);
export { MysqlRenderer } from './renderer.js';
const CODES: Record<number, [number, string]> = {
@@ -31,12 +39,13 @@ export interface MysqlOptions {
}
/**
* The MySQL 8 dialect over a mysql2/promise Pool. Each request is one
* The MySQL 8 dialect over a mysql2/promise Pool, given or opened. Each request is one
* transaction on one connection, in UTC, with MAX_EXECUTION_TIME for reads.
* Text compares with each column's collation, so with a case-insensitive
* collation `eq` ignores case.
*/
export function mysql(pool: Pool, options: MysqlOptions = {}): Dialect {
export function mysql(connection: MysqlConnection, options: MysqlOptions = {}): Dialect {
const pool = poolOf(connection);
return {
name: 'mysql',
capabilities: { returning: false, estimatedCount: false, rowSecurity: false, procedures: true },