-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathSQLOpenFactory.ts
55 lines (49 loc) · 1.31 KB
/
SQLOpenFactory.ts
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { DBAdapter } from '../db/DBAdapter.js';
export interface SQLOpenOptions {
/**
* Filename for the database.
*/
dbFilename: string;
/**
* Directory where the database file is located.
*
* When set, the directory must exist when the database is opened, it will
* not be created automatically.
*/
dbLocation?: string;
/**
* Enable debugMode to log queries to the performance timeline.
*
* Defaults to false.
*
* To enable in development builds, use:
*
* debugMode: process.env.NODE_ENV !== 'production'
*/
debugMode?: boolean;
}
export interface SQLOpenFactory {
/**
* Opens a connection adapter to a SQLite DB
*/
openDB(): DBAdapter;
}
/**
* Tests if the input is a {@link SQLOpenOptions}
*/
export const isSQLOpenOptions = (test: any): test is SQLOpenOptions => {
// typeof null is `object`, but you cannot use the `in` operator on `null.
return test && typeof test == 'object' && 'dbFilename' in test;
};
/**
* Tests if input is a {@link SQLOpenFactory}
*/
export const isSQLOpenFactory = (test: any): test is SQLOpenFactory => {
return typeof test?.openDB == 'function';
};
/**
* Tests if input is a {@link DBAdapter}
*/
export const isDBAdapter = (test: any): test is DBAdapter => {
return typeof test?.writeTransaction == 'function';
};