Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'waterline' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
app.delete( '/users', function( req, res ) {
app.models.user.destroy( req.body, function( error ) {
if ( error ) return res.json( { error: error });
res.json( { status: 'ok' } );
});
});
// Build Model
var User = waterline.Collection.extend({
adapter: 'waterline-elasticsearch',
tableName: 'users',
schema: true,
identity: 'users',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
type: 'string',
body: 'array'
}
});
new User({ adapters: { 'waterline-elasticsearch': new adapter() }}, function( error, collection ) {
if ( error ) {
console.log( error );
module.exports.initialize = function() {
var waterline = new Waterline();
waterline.loadCollection(Waterline.Collection.extend(account_model));
waterline.loadCollection(Waterline.Collection.extend(keyword_model));
// Start Waterline
waterline.initialize(config, function(err, models) {
if(err) throw err;
global.Account = models.collections['accounts-'+HB.env];
global.Keyword = models.collections['keywords-'+HB.env];
});
};
// Give the models to waterline
var modelDef;
var modelExtended;
for (var i = 0; i < models.length; i++) {
modelDef = models[i];
// If the provided model info is a function, it wants waterline passed to it.
// This is used for lifecycle callbacks to have access to collections, etc.
if (typeof modelDef === 'function') {
modelDef = modelDef(waterline);
}
modelExtended = Waterline.Collection.extend(modelDef);
waterline.loadCollection(modelExtended);
}
// Require the adapters modules if strings are passed instead of objects
var keys = Object.keys(options.adapters);
for (var j = 0; j < keys.length; j++) {
if (typeof options.adapters[keys[j]] === 'string') {
options.adapters[keys[j]] = require(options.adapters[keys[j]]);
}
}
options.defaults = options.defaults || {};
module.exports = function (app, next){
// Create new waterline ORM
var waterline = app.waterline = new Waterline();
// Load All controllers
var modelsDir = path.join(__dirname, '/../models');
var models = app.helpers.loader.load(modelsDir);
// Convert to model object and load into waterline
var collections = {};
for(var k in models){
collections[k] = Waterline.Collection.extend(models[k]);
}
// Config used in this waterline instance
var config = {
adapters: {
'default': require(app.config.adapter)
},
connections: {
default: _.defaults({adapter: 'default'}, app.config.connection),
},
collections,
};
// Initialize waterline app
let config = {
adapters: {
"sails-disk": sailsDisk
},
connections: {
tmp: {
adapter: "sails-disk"
}
},
defaults: {
migrate: "drop"
}
};
let waterlineInstance = new waterline();
models.forEach(model => {
if (!model.connection) {
model.connection = "tmp";
}
waterlineInstance.loadCollection(waterline.Collection.extend(model));
});
function setupAssociations(models) {
_.each(models, function eachInstantiatedModel(thisModel, modelID) {
// Bind context for models
// (this (breaks?)allows usage with tools like `async`)
_.bindAll(thisModel);
// Derive information about this model's associations from its schema
// and attach/expose the metadata as `SomeModel.associations` (an array)
thisModel.associations = _.reduce(
_.each(hook.models, function _loadEachModelDefIntoWaterline(normalizedModelDef, identity) {
// Create a Waterline "Collection" instance for each model, then register it w/ the ORM.
sails.log.silly('Registering model `%s` in Waterline', identity);
orm.registerModel(Waterline.Model.extend(normalizedModelDef));
});
/**
* Dependencies
*/
var Waterline = require('waterline');
module.exports = Waterline.Collection.extend({
identity: 'profileconnection',
connection: 'associations',
schema: false,
attributes: {
profileRef: {
columnName: 'profileRef',
type: 'string',
foreignKey: true,
references: 'profile40',
on: 'id',
onKey: 'id',
via: 'subprofileRef'
},
settings.methods = settings.methods ? settings.methods : injection.methods;
debug('This settings getting passed in to initiate the models %s', settings);
let orm = new Waterline();
let i = Object.keys(injection.models).length - 1;
let keys = _.keysIn(injection.models);
let model;
while (i > -1) {
injection.models[keys[i]].name = keys[i];
let _designModel = yield designModel(injection.models[keys[i]], (injection.methods[keys[i]]) );
debug('Thie model designed %s', _designModel);
if (_designModel) model = Waterline.Collection.extend(_designModel);
if (_designModel) orm.loadCollection(model);
i--;
}
let results = yield ormMaker(settings, orm);
debug('The results of the orm %s', results);
return results;
} catch (err) {
debug('An error occured while trying to create the models in to the ORM');
console.log();
console.error(':: koa-waterline: failed to instiatiate the models ::');
console.error(err.stack);
console.log();
adapter: 'psql',
database: 'postgres',
host: process.env.POSTGRES_PORT_5432_TCP_ADDR,
port: process.env.POSTGRES_PORT_5432_TCP_PORT,
user: 'postgres',
password: config.pg
}
},
defaults: {
migrate: 'alter'
}
}
const User = Waterline.Collection.extend({
identity: 'user',
tableName: 'genamapuser',
connection: 'postgres',
attributes: {
id: {
type: 'text',
primaryKey: true,
unique: true,
defaultsTo: function () {
return guid()
}
},
username: {
type: 'string',
required: false