forked from rmp135/sql-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterFactory.ts
More file actions
29 lines (27 loc) · 929 Bytes
/
Copy pathAdapterFactory.ts
File metadata and controls
29 lines (27 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { AdapterInterface } from './Adapters/AdapterInterface.js'
import { resolveAdapterName } from './SharedTasks.js'
import mysql from './Adapters/mysql.js'
import mssql from './Adapters/mssql.js'
import postgres from './Adapters/postgres.js'
import sqlite from './Adapters/sqlite.js'
const adapters: Record<string, AdapterInterface> = {
'mysql': mysql,
'mssql': mssql,
'postgres': postgres,
'sqlite': sqlite
}
/**
* Returns an AdapterInterface that matches the dialect.
*
* @export
* @param {string} adapterName The name of SQL adapter that should be returned.
* @returns {AdapterInterface} The adapter for connecting to a SQL database.
*/
export function buildAdapter(adapterName: string): AdapterInterface {
const dialect = resolveAdapterName(adapterName)
const adapter = adapters[dialect]
if (!adapter) {
throw new Error(`Unable to find adapter for dialect '${dialect}'.`)
}
return adapter
}