How to use the loopback.Model function in loopback

To help you get started, we’ve selected a few loopback 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 / loopback-component-explorer / example / hidden.js View on Github external
// Copyright IBM Corp. 2014,2019. All Rights Reserved.
// Node module: loopback-component-explorer
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

'use strict';

const g = require('strong-globalize')();

const loopback = require('loopback');
const app = loopback();
const explorer = require('../');
const port = 3000;

const User = loopback.Model.extend('user', {
  username: 'string',
  email: 'string',
  sensitiveInternalProperty: 'string',
}, {hidden: ['sensitiveInternalProperty']});

User.attachTo(loopback.memory());
app.model(User);

const apiPath = '/api';
explorer(app, {basePath: apiPath});
app.use(apiPath, loopback.rest());
g.log('{{Explorer}} mounted at {{localhost:%s/explorer}}', port);

app.listen(port);
github strongloop / loopback-sdk-angular / apidocs / describe-builtin-models.js View on Github external
process.exit();
  }
  throw err;
}

console.log('Generating API docs for LoopBack built-in models.');

var app = loopback();

app.dataSource('db', { connector: 'memory' });

var modelNames = [];
for (var key in loopback) {
  var model = loopback[key];
  if (!model) continue;
  if (model === loopback.Model) continue;
  if (model.prototype instanceof loopback.Model)
    modelNames.push(key);
}

modelNames.sort(function(l, r) {
  if (l === r) return 0;
  if (l === 'PersistedModel') return -1;
  if (r === 'PersistedModel') return 1;
  return l < r ? -1 : 1;
});

modelNames.forEach(function(key) {
  var model = loopback[key];
  if (model.prototype instanceof loopback.PersistedModel) {
    app.model(model, { dataSource: 'db' });
    console.log('  added persisted model %s', key);
github strongloop / loopback-sdk-angular / apidocs / describe-builtin-models.js View on Github external
modelNames.forEach(function(key) {
  var model = loopback[key];
  if (model.prototype instanceof loopback.PersistedModel) {
    app.model(model, { dataSource: 'db' });
    console.log('  added persisted model %s', key);
  } else if (model.prototype instanceof loopback.Model) {
    app.model(model);
    console.log('  added model %s', key);
  }
});
github strongloop / loopback-sdk-angular / apidocs / describe-builtin-models.js View on Github external
}
  throw err;
}

console.log('Generating API docs for LoopBack built-in models.');

var app = loopback();

app.dataSource('db', { connector: 'memory' });

var modelNames = [];
for (var key in loopback) {
  var model = loopback[key];
  if (!model) continue;
  if (model === loopback.Model) continue;
  if (model.prototype instanceof loopback.Model)
    modelNames.push(key);
}

modelNames.sort(function(l, r) {
  if (l === r) return 0;
  if (l === 'PersistedModel') return -1;
  if (r === 'PersistedModel') return 1;
  return l < r ? -1 : 1;
});

modelNames.forEach(function(key) {
  var model = loopback[key];
  if (model.prototype instanceof loopback.PersistedModel) {
    app.model(model, { dataSource: 'db' });
    console.log('  added persisted model %s', key);
  } else if (model.prototype instanceof loopback.Model) {
github backstage / loopback-jsonschema / lib / models / json-schema.js View on Github external
var debug = require('debug')('json-schema');

var loopback = require('loopback');
var loopbackExplorer = require('loopback-explorer');
var Model = require('loopback').Model;

var logger = require('../support/logger')

var JsonSchemaLinks = require('./json-schema-links');
var LJSRequest = require('./ljs-request');
var modelPropertiesSanitizer = require('./model-properties-sanitizer');

var JsonSchema = module.exports = Model.extend('json-schema');


JsonSchema.findByCollectionName = function(collectionName, next, callback) {
    JsonSchema.findOne({ where: { collectionName: collectionName }}, function(err, jsonSchema) {
        if (err) {
            logger.error("Error fetching JSON Schema for collectionName:", collectionName, "Error:", err);
        } else if (jsonSchema === null) {
            logger.warn("JSON Schema for collectionName", collectionName, "not found.");
github backstage / loopback-jsonschema / lib / models / item-schema.js View on Github external
var debug = require('debug')('json-schema');

var loopback = require('loopback');
var loopbackExplorer = require('loopback-explorer');
var Model = require('loopback').Model;

var logger = require('../support/logger')

var JsonSchemaLinks = require('./json-schema-links');
var LJSRequest = require('./ljs-request');
var modelPropertiesSanitizer = require('./model-properties-sanitizer');

var ItemSchema = module.exports = Model.extend('item-schema');


ItemSchema.findByCollectionName = function(collectionName, next, callback) {
    ItemSchema.findOne({ where: { collectionName: collectionName }}, function(err, jsonSchema) {
        if (err) {
            logger.error("Error fetching JSON Schema for collectionName:", collectionName, "Error:", err);
        } else if (jsonSchema === null) {
            logger.warn("JSON Schema for collectionName", collectionName, "not found.");