diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a0881..ce6c559 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.1.0 - 12-30-2019 + +- Allow knex instance to be referenced by `this.knex` in addition to `this.db` + ## v1.0.2 - 10-07-2019 - Fix issue with repeated constructor calls diff --git a/README.md b/README.md index fdb9572..37866ae 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This package combines the power of [Knex] with the ease of use of [Apollo DataSo In v1.0.0 this lib has a new fluid interface that plays nicely with Knex and stays more true to the spirit of Apollo DataSources. ```js -const query = this.db.select("*").from("fruit").where({ id: 1 }).cache(); +const query = this.knex.select("*").from("fruit").where({ id: 1 }).cache(); query.then(data => /* ... */ ); ``` @@ -33,7 +33,7 @@ const MINUTE = 60; class MyDatabase extends SQLDataSource { getFruits() { - return this.db + return this.knex .select("*") .from("fruit") .where({ id: 1 }) @@ -95,9 +95,9 @@ If no cache is provided in your Apollo server configuration, SQLDataSource falls The context from your Apollo server is available as `this.context`. -### db +### knex -The instance of knex you reference in the constructor is made available as `this.db`. +The knex instance is made available as `this.knex` or `this.db`. ## Debug mode diff --git a/index.js b/index.js index ec6314f..9f0ac74 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ class SQLDataSource extends DataSource { this.context; this.cache; this.db = Knex(knexConfig); + this.knex = this.db; const _this = this; if (!this.db.cache) { diff --git a/package-lock.json b/package-lock.json index 1574b4b..fa0c167 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "datasource-sql", - "version": "1.0.2", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9a0bce6..cd72616 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasource-sql", - "version": "1.0.2", + "version": "1.1.0", "description": "SQL DataSource for Apollo GraphQL projects", "main": "index.js", "scripts": {