Skip to content

Commit

Permalink
Support specifying a knex instance instead of config object (#52)
Browse files Browse the repository at this point in the history
* Support specifying a knex instance instead of config object

* bump version and update changelog

* npm audit fix

Co-authored-by: Charles Burgess <consulting@cvburgess.com>
  • Loading branch information
theogravity and cvburgess authored Apr 7, 2020
1 parent 54426cc commit b57e2f6
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 159 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.2.0 - 04-07-2020

- Support specifying a knex instance instead of config object ( Thanks @theogravity! )

## v1.1.1 - 01-23-2020

- Knex update for security
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const knexConfig = {
}
};

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

const server = new ApolloServer({
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ class SQLDataSource extends DataSource {

this.context;
this.cache;
this.db = Knex(knexConfig);

if (typeof knexConfig === "function") {
this.db = knexConfig;
} else {
this.db = Knex(knexConfig);
}

this.knex = this.db;

const _this = this;
Expand Down
Loading

0 comments on commit b57e2f6

Please # to comment.