Skip to content

Commit

Permalink
Switch to better-sqlite3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Mar 5, 2020
1 parent f502b5c commit 7d5ec58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cli/prisma2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
"@prisma/studio-transports": "0.202.0",
"@prisma/studio-types": "0.202.0",
"@sentry/node": "5.12.4",
"@types/better-sqlite3": "^5.4.0",
"@types/debug": "^4.1.5",
"@types/mocha": "^5.2.7",
"@types/mysql": "^2.15.9",
"@types/sqlite3": "^3.1.6",
"@zeit/ncc": "0.21.0",
"better-sqlite3": "^6.0.1",
"checkpoint-client": "^1.0.7",
"dotenv": "^8.2.0",
"jest": "^25.1.0",
Expand All @@ -67,7 +68,6 @@
"rimraf": "^3.0.0",
"serialize-error": "^5.0.0",
"snap-shot-it": "^7.9.2",
"sqlite3": "^4.1.1",
"strip-ansi": "^6.0.0",
"strip-indent": "3.0.0",
"terminal-link": "^2.0.0",
Expand Down
33 changes: 11 additions & 22 deletions cli/prisma2/src/__tests__/integrate.sqlite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import rimraf from 'rimraf'
import fs from 'fs'
import path from 'path'
import snapshot from 'snap-shot-it'
import sqlite3 from 'sqlite3'
import Database from 'better-sqlite3'

process.env.SKIP_GENERATE = 'true'

Expand All @@ -28,17 +28,6 @@ after(async () => {
engine.stop()
})

function getDb(): Promise<sqlite3.Database> {
return new Promise((resolve, reject) => {
const db = new sqlite3.Database(sqlitePath, err => {
if (err) {
return reject(err)
}
resolve(db)
})
})
}

const nameCache = {}

const prettyName = (fn: any): string => {
Expand Down Expand Up @@ -79,19 +68,19 @@ tests().map((t: Test) => {
} catch (err) {
throw err
} finally {
const db = await getDb()
await db.exec(t.down)
await db.close()
const db = new Database(sqlitePath)
db.exec(t.down)
db.close()
}
}).timeout(15000)
})

async function runTest(name: string, t: Test) {
console.log(t)
let db = await getDb()
await db.exec(t.down)
await db.exec(t.up)
await db.close()
let db = new Database(sqlitePath)
db.exec(t.down)
db.exec(t.up)
db.close()

const schema = `
generator client {
Expand All @@ -117,16 +106,16 @@ datasource sqlite {
const { PrismaClient } = await import(prismaClientPath)
const prisma = new PrismaClient()
await prisma.connect()
db = await getDb()
db = new Database(sqlitePath)
try {
const result = await t.do(prisma)
await db.exec(t.down)
db.exec(t.down)
assert.deepEqual(result, t.expect)
} catch (err) {
throw err
} finally {
await prisma.disconnect()
await db.close()
db.close()
}
}

Expand Down

0 comments on commit 7d5ec58

Please sign in to comment.