-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(example-todo): use new datasource CLI and booter
- Loading branch information
Showing
4 changed files
with
13 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
examples/todo/config/datasources.json → ...s/todo/src/datasources/db.datasource.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"name": "db", | ||
"connector": "memory", | ||
"localStorage": "", | ||
"file": "./data/db.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,8 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/example-todo | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
import {inject} from '@loopback/core'; | ||
import {juggler, DataSource} from '@loopback/repository'; | ||
|
||
import * as path from 'path'; | ||
// The juggler reference must exist for consuming code to correctly infer | ||
// type info used in the "db" export (contained in juggler.DataSource). | ||
// tslint:disable-next-line:no-unused-variable | ||
import {juggler} from '@loopback/repository'; | ||
|
||
const dsConfigPath = path.resolve( | ||
__dirname, | ||
'../../../config/datasources.json', | ||
); | ||
const config = require(dsConfigPath); | ||
|
||
// TODO(bajtos) Ideally, datasources should be created by @loopback/boot | ||
// and registered with the app for dependency injection. | ||
// However, we need to investigate how to access these datasources from | ||
// integration tests where we don't have access to the full app object. | ||
// For example, @loopback/boot can provide a helper function for | ||
// performing a partial boot that creates datasources only. | ||
export const db = new juggler.DataSource(config); | ||
export class DbDataSource extends juggler.DataSource { | ||
constructor(@inject('datasources.config.db') dsConfig: DataSource) { | ||
super(dsConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// This is an auto-generated file. DO NOT EDIT. | ||
|
||
export * from "./db.datasource"; | ||
|
||
// This is an auto-generated file. DO NOT EDIT. |