New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for better-sqlite3
Driver
#4871
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d3d2855
chore: starting to work through adding our own driver to knex for bet…
benjdlambert fce7063
chore: fixing of duplicate loading of test suites
benjdlambert 823f22a
chore: more work towards getting better to work nicely and play great
benjdlambert 322cfb9
chore: migrating some more of the tests to work with bettersqlite3. M…
benjdlambert 254674f
chore: fixing some smaller tests
benjdlambert 508ef72
Merge branch 'master' into master
benjdlambert b03e918
chore: removing some console logs
benjdlambert 43a440e
chore: date binding should be number I think
benjdlambert f957eac
chore: removing some more debugging logs
benjdlambert 0bcb646
chore: fixing up some more tests only 3 left, and fixing the sqlite t…
benjdlambert c244ba2
chore: fixing some code review comments
benjdlambert 1942f97
chore: finishing off the remaining test failures
benjdlambert 6b9c5ed
Merge branch 'master' into master
kibertoad File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// better-sqlite3 Client | ||
// ------- | ||
const Client_SQLite3 = require('../sqlite3'); | ||
|
||
class Client_BetterSQLite3 extends Client_SQLite3 { | ||
_driver() { | ||
return require('better-sqlite3'); | ||
} | ||
|
||
// Get a raw connection from the database, returning a promise with the connection object. | ||
async acquireRawConnection() { | ||
return new this.driver(this.connectionSettings.filename); | ||
} | ||
|
||
// Used to explicitly close a connection, called internally by the pool when | ||
// a connection times out or the pool is shutdown. | ||
async destroyRawConnection(connection) { | ||
return connection.close(); | ||
} | ||
|
||
// Runs the query on the specified connection, providing the bindings and any | ||
// other necessary prep work. | ||
async _query(connection, obj) { | ||
if (!obj.sql) throw new Error('The query is empty'); | ||
|
||
if (!connection) { | ||
throw new Error('No connection provided'); | ||
} | ||
|
||
const statement = connection.prepare(obj.sql); | ||
const bindings = this._formatBindings(obj.bindings); | ||
|
||
if (statement.reader) { | ||
const response = await statement.all(bindings); | ||
obj.response = response; | ||
return obj; | ||
} | ||
|
||
const response = await statement.run(bindings); | ||
obj.response = response; | ||
obj.context = { | ||
lastID: response.lastInsertRowid, | ||
changes: response.changes, | ||
}; | ||
|
||
return obj; | ||
} | ||
|
||
_formatBindings(bindings) { | ||
if (!bindings) { | ||
return []; | ||
} | ||
return bindings.map((binding) => { | ||
if (binding instanceof Date) { | ||
return binding.valueOf(); | ||
} | ||
|
||
if (binding instanceof Boolean) { | ||
return String(binding); | ||
} | ||
|
||
return binding; | ||
}); | ||
} | ||
} | ||
|
||
Object.assign(Client_BetterSQLite3.prototype, { | ||
// The "dialect", for reference . | ||
driverName: 'better-sqlite3', | ||
}); | ||
|
||
module.exports = Client_BetterSQLite3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nop. 😂