waterline

Waterline default query condition

允我心安 提交于 2019-12-12 09:13:36
问题 How can I set the default where/sort condition in my SailsJS waterline model? In Rails I would use default scope. 回答1: Sails doesn't support default criteria on a per-model basis, but if you're using blueprint routes you can set default criteria for the route by overriding in your config/routes.js file, for example: "GET /user": { controller: 'user', action: 'find', where: {'deleted': false}, sort: 'age DESC' } This will work even if you don't have a find action defined in your UserController

Between Dates using Waterline ORM SailsJS

我只是一个虾纸丫 提交于 2019-12-12 08:54:48
问题 Goal: Return a list of items that were created between two dates. According to this issue https://github.com/balderdashy/waterline/issues/110 there is no between function just yet. However the work around is the following: User.find({ date: { '>': new Date('2/4/2014'), '<': new Date('2/7/2014') } }).exec(/* ... */); To be more exact, we don't want the hard coded dates above so we read in the input from a form submission like so: start = new Date(req.param('yearStart') + '/' + req.param(

How to show queries in console log using sails?

血红的双手。 提交于 2019-12-12 08:21:56
问题 I am starting a project with sails and mysql, and I do'nt know how configurate it to show the queries executed in the console. 回答1: Unfortunately this isn't possible with Sails at this time, although the feature has been requested. Your best bet is to inspect the log file provided by your database: Postgres: How to log PostgreSQL queries? MySQL: Log all queries in mysql MongoDB: MongoDB logging all queries 回答2: The mysql adapter has a debug variable LOG_QUERIES to send all queries to the

How to create a normal sails model without being in the models folder

蹲街弑〆低调 提交于 2019-12-12 07:44:11
问题 So, I'm in the middle of implementing a plugin api for my application, and the plugins can have their own models, imagine this. SimplePlugin = { pluginName: 'simple', pluginConfig: {}, SimpleModel: { attributes: { name: 'string' } } } So I need to be able to create the "one-time" model with a function whenever it's needed, it needs to have exactly the same functionality as other models so you automatically get the urls like /simplePlugin/:id for find ..etc Thanks 回答1: What are you trying to

How to return two Objects in a Promise using Sails?

[亡魂溺海] 提交于 2019-12-12 02:59:31
问题 I'm using SailsJs v0.11.3 and I want to use Promises to avoid using nested callback but I don't know how to return two objects from one stage ( .then() ) to another one. My code looks like this but I got undefined when trying to print start param on the third .then statement. User.findOneById(userId) .then(function (result) { // #1 return result; }).then( function (result_a) { // #2 console.log('---------------- ' + result_a ); var result_b = User.findOneById(ownerId) .then(function (result)

How to implement many to many association using through in Sails?

戏子无情 提交于 2019-12-12 02:43:29
问题 I'm using Sails v0.11.2 and MongoDB 3.2 on Mac OS X El Capitan and I'm trying to implement Many-To-Many association using Through option which isn't supported yet. However, googling I found this Waterline Github Issue and elennaro , a github user, gave me a couple of links with some examples: First one Second one I have tried to adapt them to my own Sails app but I can't make it works. I got no errors on the console but the record or document on the intermediary table is not created only the

Sails.js & MongoDB: duplicate key error index

谁说我不能喝 提交于 2019-12-12 02:33:55
问题 I'm using Sails.js (0.9.8) and MongoDB (via the sails-mongo adaptor) to create a collection of pages that can be positioned in a tree-view. I would like to store the path of a page in an array of UUIDs My model: module.exports = { schema: true, attributes: { uuid: { type: 'string', unique: true, required: true, uuidv4: true }, name: { type: 'string', required: true, empty: false }, path: { type: 'array', required: true, array: true } } } It works well when I save a 'root' page (the 'path'

Transaction in orientdb and waterline

无人久伴 提交于 2019-12-12 01:48:54
问题 I am trying to to create transaction in waterline but I am getting this error from OrientDB: com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.BEGIN Here is my code: try { itemsModel.query("BEGIN", function(err) { if (err) {throw new Error(err);} itemsModel.update({id:items_ids,status:ACTIVE},{status:INACTIVE}) .exec(function(err, INA_items){ if (err) {throw new Error(err);} if (INA_items.length != items

sails-mongo auth error in sails 0.10

南笙酒味 提交于 2019-12-11 14:35:45
问题 Using "sails-mongo": "^0.10.0-rc2", "sails": "~0.10.0-rc4" I'm getting the following error on sails lift . verbose: Loading adapter ( sails-mongo ) for algorithm from `node_modules` directory... Failed to load c++ bson extension, using pure JS version verbose: Starting ORM... error: A hook (`orm`) failed to load! error: MongoError: auth fails at Object.toError (/home/default/Projects/machine_learning_data_sets/machine-learning- engine/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb

Sails js - waterline orm - mysql. Tables autogeneration

夙愿已清 提交于 2019-12-11 12:33:13
问题 When I create my model in sails - waterline the db is autogenerated. The problem is that my primary keys are unsigned int(10) and the external keys are int(11) (with sign). In fact the relationship is only in my models and not in db. A code example is the following: // A user may only have a single pet var User = Waterline.Collection.extend({ identity: 'user', connection: 'local-postgresql', attributes: { firstName: 'string', lastName: 'string', // Add a reference to Pet pet: { model: 'pet' }