diff --git a/src/index.js b/src/index.js index e45f9eb..4901527 100644 --- a/src/index.js +++ b/src/index.js @@ -16,10 +16,15 @@ class Trilogy { } let obj = this.options = setup(options) - obj.connection.filename = resolve(obj.dir, path) - // ensure the directory exists - makeDirPath(dirname(obj.connection.filename)) + if (path === ':memory:') { + obj.connection.filename = path + } else { + obj.connection.filename = resolve(obj.dir, path) + + // ensure the directory exists + makeDirPath(dirname(obj.connection.filename)) + } this.isNative = obj.client === 'sqlite3' this.verbose = obj.verbose @@ -27,7 +32,10 @@ class Trilogy { let config = { client: 'sqlite3', useNullAsDefault: true } if (this.isNative) { - touchFile(obj.connection.filename) + if (path !== ':memory:') { + touchFile(obj.connection.filename) + } + this.knex = knex({ ...config, connection: obj.connection }) } else { this.knex = knex(config) diff --git a/src/sqljs-handler.js b/src/sqljs-handler.js index 876f676..0a20ba7 100644 --- a/src/sqljs-handler.js +++ b/src/sqljs-handler.js @@ -11,6 +11,10 @@ export function readDatabase (instance) { let client let { filename } = instance.options.connection + if (filename === ':memory:') { + return new SQL.Database() + } + try { makeDirPath(dirname(filename)) let file = readFileSync(filename) @@ -28,9 +32,11 @@ export function readDatabase (instance) { } export function writeDatabase (instance, db) { + let { filename } = instance.options.connection + if (filename === ':memory:') return + let data = db.export() let buffer = Buffer.from(data) - let { filename } = instance.options.connection makeDirPath(dirname(filename)) writeFileSync(filename, buffer, { mode: parseInt('0777', 8) })