Skip to content

Instantly share code, notes, and snippets.

@bajtos
Created March 19, 2021 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bajtos/9445c8230991ec860b6e923ffe5eed38 to your computer and use it in GitHub Desktop.
Save bajtos/9445c8230991ec860b6e923ffe5eed38 to your computer and use it in GitHub Desktop.
LoopBack datasource test
'use strict';
// Make sure to `npm install loopback-datasource-juggler`
const juggler = require('loopback-datasource-juggler');
const ds = new juggler.DataSource({
connector: 'memory', // replace with 'oracle'
// additional connector config - hostname, database, credentials, etc.
});
// A GitHub like Repository object keyed by org+name,
// e.g. "strongloop" + // "loopback"
const Repo = ds.createModel('Repo', {
org: {
type: 'string',
id: 1,
},
name: {
type: 'string',
id: 2,
},
description: {
type: 'string',
required: true,
},
});
main().catch(err => {
console.error(err);
process.exit(1);
});
async function main() {
const lb3 = await Repo.create({
org: 'strongloop',
name: 'loopback',
description: 'Legacy LoopBack 3 repo',
});
const lb4 = await Repo.create({
org: 'strongloop',
name: 'loopback-next',
description: 'The new monorepo for LoopBack 4',
});
// this doesn't work for the Memory connector
const all = await Repo.find();
console.log('All entries:', all);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment