Skip to content

Commit b57e2f6

Browse files
Support specifying a knex instance instead of config object (#52)
* Support specifying a knex instance instead of config object * bump version and update changelog * npm audit fix Co-authored-by: Charles Burgess <[email protected]>
1 parent 54426cc commit b57e2f6

File tree

5 files changed

+124
-159
lines changed

5 files changed

+124
-159
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v1.2.0 - 04-07-2020
4+
5+
- Support specifying a knex instance instead of config object ( Thanks @theogravity! )
6+
37
## v1.1.1 - 01-23-2020
48

59
- Knex update for security

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const knexConfig = {
5858
}
5959
};
6060

61+
// you can also pass a knex instance instead of a configuration object
6162
const db = new MyDatabase(knexConfig);
6263

6364
const server = new ApolloServer({

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ class SQLDataSource extends DataSource {
1414

1515
this.context;
1616
this.cache;
17-
this.db = Knex(knexConfig);
17+
18+
if (typeof knexConfig === "function") {
19+
this.db = knexConfig;
20+
} else {
21+
this.db = Knex(knexConfig);
22+
}
23+
1824
this.knex = this.db;
1925

2026
const _this = this;

0 commit comments

Comments
 (0)