How to use the loopback-datasource-juggler.DataSource function in loopback-datasource-juggler

To help you get started, we’ve selected a few loopback-datasource-juggler 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 SciCatProject / catamel / common / models / job.js View on Github external
module.exports = function (Job) {

    // Attach job submission to Kafka
    if ('queue' in config && config.queue === 'kafka') {
        // var options = {
        //     connectionString: 'localhost:2181/'
        // };
        var dataSource = new DataSource('kafka', options);
        Job.attachTo(dataSource);
    }

    Job.observe('before save', (ctx, next) => {
        // email job initiator should always be the person running the job request
        // therefore override this field both for users and functional accounts
        if (ctx.instance) {
            ctx.instance.emailJobInitiator = ctx.options.currentUserEmail;
            if (ctx.isNewInstance) {
                ctx.instance.jobStatusMessage = "jobSubmitted"
            }
        }
        next()
    });

    Job.observe('after save', (ctx, next) => {
github strongloop / loopback-connector-couchdb2 / test / init.js View on Github external
global.getDataSource = global.getSchema = function(customConfig) {
  var db = new DataSource(require('../'), customConfig || config);
  db.log = function(a) {
    console.log(a);
  };

  var originalConnector = _.clone(db.connector);
  var overrideConnector = {};

  overrideConnector.save = function(model, data, options, cb) {
    if (!global.IMPORTED_TEST) {
      return originalConnector.save(model, data, options, cb);
    } else {
      var self = this;
      var idName = self.idName(model);
      var id = data[idName];
      var mo = self.selectModel(model);
      data[idName] = id.toString();
github dyaa / loopback-connector-firestore / test / init.js View on Github external
global.getDataSource = global.getSchema = customConfig => {
	const db = new DataSource(lib, customConfig || config);

	db.log = a => {
		console.log(a);
	};

	return db;
};
github dyaa / loopback-connector-firestore / test / init.js View on Github external
global.getDataSource = global.getSchema = function(customConfig) {
	const db = new DataSource(require('../'), customConfig || config);
	db.log = function(a) {
		console.log(a);
	};

	return db;
};
github strongloop / loopback-next / packages / repository / src / __tests__ / acceptance / repository.acceptance.ts View on Github external
function givenProductRepository() {
    const db = new DataSource({
      connector: 'memory',
    });
    repo = new ProductRepository(db);
  }
});
github strongloop / loopback-connector-mssql / test / connection.js View on Github external
const getDS = function(myconfig) {
    const db = new DataSource(mssqlConnector, myconfig);
    return db;
  };
github strongloop / loopback-next / packages / repository / src / __tests__ / acceptance / repository.acceptance.ts View on Github external
})
      id: number;

      @property({type: 'string'})
      name: string;

      @property.array(Role)
      roles: Role[];

      @property()
      address: Address;
    }

    const userRepo = new DefaultCrudRepository(
      User,
      new DataSource({connector: 'memory'}),
    );

    const user = {
      id: 1,
      name: 'foo',
      roles: [{name: 'admin'}, {name: 'user'}],
      address: {street: 'backstreet'},
    };
    const created = await userRepo.create(user);

    const stored = await userRepo.findById(created.id);
    expect(stored).to.containDeep(user);
  });
github strongloop / loopback-next / packages / repository / src / decorators / relation.repository.decorator.ts View on Github external
DefaultCrudRepository
    >(injection.bindingKey);

    /**
     * discussion point: use a fake DataSource instance so that we can get back
     * the source model possible alternatives we considered:
     *  - use context to resolve an instance of the source repository and thus a
     *    source model (results in circular dependency between related
     *    repositories)
     *  - change UX so that users pass in the source model manually
     *    (inconvenient)
     *  - enforce binding of models to application context, so that it can be
     *    retrieved
     */

    const fakeDs = new DataSource();
    const sourceModel = new injection.metadata!.sourceRepo(fakeDs).entityClass;
    return getConstrainedRepositoryFunction(sourceModel, tRepo);
  }
}