Skip to content

Commit

Permalink
43: Support both this.db and this.knex (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorensr authored and cvburgess committed Dec 31, 2019
1 parent 8198c19 commit fd88f6e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 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.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
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 => /* ... */ );
```
Expand All @@ -33,7 +33,7 @@ const MINUTE = 60;

class MyDatabase extends SQLDataSource {
getFruits() {
return this.db
return this.knex
.select("*")
.from("fruit")
.where({ id: 1 })
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit fd88f6e

Please # to comment.