How to use the @loopback/repository.DataSourceConstructor function in @loopback/repository

To help you get started, we’ve selected a few @loopback/repository examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback4-example-microservices / services / facade / repositories / transaction / index.ts View on Github external
import {DataSourceConstructor} from '@loopback/repository';

// mixin of data source into service is not yet available, swagger.json needs to
// be loaded synchronously (ie. can't instantiate in the class constructor)

let SwaggerClient = require('swagger-client');
const ds = new DataSourceConstructor('TransactionService', {
  connector: 'swagger',
  spec: 'repositories/transaction/swagger.json',
});

export class TransactionRepository {
  model;

  constructor() {
    this.model = ds.createModel('TransactionService', {});
  }

  async find(accountNumber) {
    const response = await this.model.findById({id: accountNumber});
    return (response && response.obj) || [];
  }
}
github strongloop / loopback4-example-microservices / services / facade / src / repositories / customer / swagger.datasource.ts View on Github external
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback4-example-microservices
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {DataSourceConstructor, DataSourceType} from '@loopback/repository';
import {customerDefinition} from './customer.repository.api';

export const dataSource: DataSourceType = new DataSourceConstructor(
  'CustomerService',
  {
    connector: 'loopback-connector-swagger',
    spec: customerDefinition,
  },
);
github strongloop / loopback4-example-microservices / services / customer / src / datasources / memory.datasource.ts View on Github external
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback4-example-microservices
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {DataSourceConstructor, DataSourceType} from '@loopback/repository';
import * as path from 'path';

export const dataSource: DataSourceType = new DataSourceConstructor(
  'local-fs',
  {
    connector: 'memory',
    file: path.resolve(__dirname, './data.json'),
  },
);
github strongloop / loopback4-example-microservices / services / facade / src / repositories / transaction / swagger.datasource.ts View on Github external
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback4-example-microservices
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {DataSourceConstructor, DataSourceType} from '@loopback/repository';
import {transactionDefinition} from './transaction.repository.api';

export const dataSource: DataSourceType = new DataSourceConstructor(
  'TransactionService',
  {
    connector: 'loopback-connector-swagger',
    spec: transactionDefinition,
  },
);
github strongloop / loopback4-example-microservices / services / transaction / src / datasources / memory.datasource.ts View on Github external
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback4-example-microservices
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {DataSourceConstructor, DataSourceType} from '@loopback/repository';
import * as path from 'path';

export const dataSource: DataSourceType = new DataSourceConstructor('memory', {
  connector: 'memory',
  file: path.resolve(__dirname, './data.json'),
});
github strongloop / loopback4-example-microservices / services / facade / src / repositories / account / swagger.datasource.ts View on Github external
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback4-example-microservices
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {DataSourceConstructor, DataSourceType} from '@loopback/repository';
import {accountDefinition} from './account.repository.api';

export const dataSource: DataSourceType = new DataSourceConstructor(
  'AccountService',
  {
    connector: 'loopback-connector-swagger',
    spec: accountDefinition,
  },
);
github strongloop / loopback4-example-microservices / services / todo-legacy / application.ts View on Github external
constructor() {
    super();
    const app = this;
    let ds = datasources['ds'];
    // Controller bindings
    app.controller(TodoController);

    let datasource = new DataSourceConstructor('ds', ds);
    app.bind('datasources.ds').to(datasource);

    // Server protocol bindings
    app.bind('servers.http.enabled').to(true);
    app.bind('servers.https.enabled').to(true);
  }
github strongloop / loopback4-example-microservices / services / account / src / datasources / memory.datasource.ts View on Github external
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: loopback4-example-microservices
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {DataSourceConstructor, DataSourceType} from '@loopback/repository';
import * as path from 'path';

export const dataSource: DataSourceType = new DataSourceConstructor('memory', {
  connector: 'memory',
  file: path.resolve(__dirname, './data.json'),
});
github strongloop / loopback4-example-microservices / services / facade / repositories / customer / index.ts View on Github external
import {DataSourceConstructor} from '@loopback/repository';

// mixin of data source into service is not yet available, swagger.json needs to
// be loaded synchronously (ie. can't instantiate in the class constructor)

let SwaggerClient = require('swagger-client');
const ds = new DataSourceConstructor('CustomerService', {
  connector: 'swagger',
  spec: 'repositories/customer/swagger.json',
});

export class CustomerRepository {
  model;

  constructor() {
    this.model = ds.createModel('CustomerService', {});
  }

  async find(customerNumber) {
    const response = await this.model.findById({id: customerNumber});
    return (response && response.obj) || [];
  }
}
github strongloop / loopback4-example-microservices / services / transaction / repositories / transaction / index.ts View on Github external
constructor() {
    const ds = new DataSourceConstructor('local-fs', {
      connector: 'memory',
      file: './repositories/transaction/datasources/local-fs/data.json',
    });
    this.model = ds.createModel('Transaction', modelDefinition);
  }