Skip to content

Commit

Permalink
fix(sql.js): use the same code path as native to create db file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haltcase committed Jun 1, 2019
1 parent 2680842 commit afd94ef
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit afd94ef

Please sign in to comment.