Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
Working on Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
virkt25 committed Sep 25, 2017
1 parent 698bcb5 commit 0db67f9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/repositories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
juggler,
DataSourceConstructor,
DefaultCrudRepository,
Entity,
} from '@loopback/repository';

const countModel = require('./models/count.model.json');

// I'm unable to do the following ...
export class CountRepository extends DefaultCrudRepository<Entity, string> {
constructor() {
const ds: juggler.DataSource = new DataSourceConstructor({
name: 'db',
connector: 'memory',
file: './data.json',
});

const Count = ds.createModel<typeof juggler.PersistedModel>(
'count',
countModel,
{}
);

super(Count, ds);
}
}

// ***** Works but need to define every function myself :/ *****

// export class CountRepository {
// model: any;

// constructor() {
// // Inject file name via DI? Or maybe the entire config?
// const ds: juggler.DataSource = new DataSourceConstructor({
// name: 'db',
// connector: 'memory',
// file: './data.json',
// });

// this.model = ds.createModel('count', countModel, {});
// }
// };
22 changes: 22 additions & 0 deletions src/repositories/models/count.model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Todo",
"properties": {
"id": {
"type": "string",
"required": true,
"id": true
},
"count": {
"type": "integer",
"required": true
},
"lastAccess": {
"type": "date",
"required": false
},
"avgReqTime": {
"type": "number",
"required": false
}
}
}
1 change: 1 addition & 0 deletions test/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import 'mocha';
import {expect} from '@loopback/testlab';

describe('Smoke test to verify project setup - remove me later', () => {
Expand Down

0 comments on commit 0db67f9

Please sign in to comment.