Skip to content

Commit

Permalink
feat: Allow nebra factory to receive database options
Browse files Browse the repository at this point in the history
  • Loading branch information
aerotoad committed Aug 10, 2023
1 parent f55e1a9 commit b417cdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/classes/nebra.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import RegexParser from 'regex-parser';
import { Collection } from './collection';
import Database, { Database as DatabaseConstructor } from 'better-sqlite3';
import { DatabaseOptions } from '../types/database-options';

export class Nebra {

Expand All @@ -12,11 +13,7 @@ export class Nebra {
* If :memory: is used, the database will be stored in memory and will not be persistent
* This path is passed directly to the Knex instance and it uses the better-sqlite3 driver
*/
constructor(path: string, options: {
fileMustExist?: boolean;
timeout?: number;
nativeBinding?: string | undefined;
} = {}) {
constructor(path: string, options: DatabaseOptions = {}) {
this._database = new Database(path, options);
this._database.function('regexp', { deterministic: true }, (regex: unknown, text: unknown) => {
return RegexParser(regex as string).test(text as string) ? 1 : 0;
Expand Down
5 changes: 3 additions & 2 deletions src/functions/nebra.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Nebra } from "../classes/nebra";
import { DatabaseOptions } from "../types/database-options";

export function nebra(path: string) {
return new Nebra(path);
export function nebra(path: string, options: DatabaseOptions) {
return new Nebra(path, options);
}
6 changes: 6 additions & 0 deletions src/types/database-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export interface DatabaseOptions {
fileMustExist?: boolean;
timeout?: number;
nativeBinding?: string | undefined;
}

0 comments on commit b417cdd

Please sign in to comment.