From afd94efbad7c17aa7e522cd703b06dd793866edf Mon Sep 17 00:00:00 2001 From: citycide Date: Sat, 1 Jun 2019 18:10:32 -0500 Subject: [PATCH] fix(sql.js): use the same code path as native to create db file sql.js 1.x no longer loads synchronously, so it's better to now create the db file the same way as the native driver. --- src/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index c980f3a..fff7f28 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import * as knex from 'knex' import Model from './model' import { runQuery } from './helpers' import { toKnexSchema, createTimestampTrigger } from './schema-helpers' -import { pureConnect, readDatabase } from './sqljs-handler' +import { pureConnect } from './sqljs-handler' import { defaultTo, invariant, makeDirPath } from './util' import { Pool } from 'generic-pool' @@ -52,16 +52,15 @@ export class Trilogy { const config = { client: 'sqlite3', useNullAsDefault: true } - if (this.isNative) { - if (path !== ':memory:') { - ensureExists(obj.connection!.filename) - } + if (path !== ':memory:') { + ensureExists(obj.connection!.filename) + } + if (this.isNative) { this.knex = knex(({ ...config, connection: obj.connection } as knex.Config)) } else { this.knex = knex(config) this.pool = pureConnect(this) - readDatabase(this) } this._definitions = new Map()