Skip to content

Commit

Permalink
Merge pull request #165 from mediachain/yn-fix-db-timeout
Browse files Browse the repository at this point in the history
Use temp file for statement db to avoid connection timeout issues
  • Loading branch information
yusefnapora committed Jan 18, 2017
2 parents 113a6bd + 2d17201 commit d8cf31d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"pull-stream": "3.5.0",
"pull-window": "^2.1.4",
"sqlite3": "^3.1.8",
"temp": "^0.8.3",
"thenify": "https://registry.npmjs.org/thenify/-/thenify-3.2.1.tgz",
"thenify-all": "^1.6.0",
"tunnel-ssh": "^4.1.1",
Expand Down
10 changes: 5 additions & 5 deletions src/peer/db/statement-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const path = require('path')
const Knex = require('knex')
const locks = require('locks')
const temp = require('temp').track()
const pb = require('../../protobuf')

import type { StatementMsg, SimpleStatementMsg, EnvelopeStatementMsg, CompoundStatementMsg } from '../../protobuf/types'
Expand All @@ -11,11 +12,11 @@ import type { Mutex } from 'locks'
const MIGRATIONS_DIR = path.join(__dirname, 'migrations')

type StatementDBOptions = {
filename: string,
filename: ?string,
}

const DefaultOptions: StatementDBOptions = {
filename: ':memory:'
filename: null
}

class StatementDB {
Expand All @@ -25,12 +26,11 @@ class StatementDB {

constructor (options: ?StatementDBOptions = DefaultOptions) {
if (options == null) options = DefaultOptions
const filename = options.filename || temp.path({prefix: 'aleph-', suffix: '.db'})

this._db = Knex({
client: 'sqlite3',
connection: {
filename: options.filename
},
connection: { filename },
useNullAsDefault: true
})
this._migrated = false
Expand Down

0 comments on commit d8cf31d

Please sign in to comment.