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:
@@ -0,0 +1,27 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as pg from '../packages/postgres/dist/index.js';
|
||||
import * as my from '../packages/mysql/dist/index.js';
|
||||
import * as ms from '../packages/mssql/dist/index.js';
|
||||
import * as lite from '../packages/sqlite/dist/index.js';
|
||||
|
||||
// One install and one import: each database package brings the core with it,
|
||||
// and the server databases open their own connection from a URL.
|
||||
test('every database package exports the core', () => {
|
||||
for (const mod of [pg, my, ms, lite]) {
|
||||
assert.equal(typeof mod.createREST, 'function');
|
||||
assert.equal(typeof mod.nodeListener, 'function');
|
||||
assert.equal(typeof mod.RestError, 'function');
|
||||
}
|
||||
});
|
||||
|
||||
test('postgres and mysql open a pool from a URL without connecting yet', async () => {
|
||||
assert.equal(pg.postgres('postgres://user:secret@127.0.0.1:1/app').name, 'postgres');
|
||||
assert.equal(my.mysql('mysql://user:secret@127.0.0.1:1/app').name, 'mysql');
|
||||
});
|
||||
|
||||
test('postgres serves from a URL', { skip: !process.env.RESTLOOM_PG_URL && 'RESTLOOM_PG_URL is not set' }, async () => {
|
||||
const db = pg.postgres(process.env.RESTLOOM_PG_URL);
|
||||
const rows = await db.transaction((tx) => tx.query('SELECT 1 AS one', []), { timeoutMs: 5000, readOnly: true });
|
||||
assert.deepEqual(rows, [{ one: 1 }]);
|
||||
});
|
||||
@@ -9,9 +9,9 @@ import { sqlite } from '../packages/sqlite/dist/index.js';
|
||||
// The table in docs/dialects.md is what readers compare databases by, on the
|
||||
// site too. It must say what each dialect's capabilities say.
|
||||
const DIALECTS = {
|
||||
'@crudy/restloom-postgres': postgres({}),
|
||||
'@crudy/restloom-mysql': mysql({}),
|
||||
'@crudy/restloom-mssql': mssql({}),
|
||||
'@crudy/restloom-postgres': postgres({ connect() {} }),
|
||||
'@crudy/restloom-mysql': mysql({ getConnection() {} }),
|
||||
'@crudy/restloom-mssql': mssql({ request() {} }),
|
||||
'@crudy/restloom-sqlite': sqlite({ pragma() {} }),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user