Skip to content

Commit fd88f6e

Browse files
lorensrcvburgess
authored andcommitted
43: Support both this.db and this.knex (#44)
1 parent 8198c19 commit fd88f6e

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
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.1.0 - 12-30-2019
4+
5+
- Allow knex instance to be referenced by `this.knex` in addition to `this.db`
6+
37
## v1.0.2 - 10-07-2019
48

59
- Fix issue with repeated constructor calls

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This package combines the power of [Knex] with the ease of use of [Apollo DataSo
77
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.
88

99
```js
10-
const query = this.db.select("*").from("fruit").where({ id: 1 }).cache();
10+
const query = this.knex.select("*").from("fruit").where({ id: 1 }).cache();
1111

1212
query.then(data => /* ... */ );
1313
```
@@ -33,7 +33,7 @@ const MINUTE = 60;
3333

3434
class MyDatabase extends SQLDataSource {
3535
getFruits() {
36-
return this.db
36+
return this.knex
3737
.select("*")
3838
.from("fruit")
3939
.where({ id: 1 })
@@ -95,9 +95,9 @@ If no cache is provided in your Apollo server configuration, SQLDataSource falls
9595

9696
The context from your Apollo server is available as `this.context`.
9797

98-
### db
98+
### knex
9999

100-
The instance of knex you reference in the constructor is made available as `this.db`.
100+
The knex instance is made available as `this.knex` or `this.db`.
101101

102102
## Debug mode
103103

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class SQLDataSource extends DataSource {
1515
this.context;
1616
this.cache;
1717
this.db = Knex(knexConfig);
18+
this.knex = this.db;
1819

1920
const _this = this;
2021
if (!this.db.cache) {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datasource-sql",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "SQL DataSource for Apollo GraphQL projects",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)