waterline

SELECT and UPDATE multiple records in oriento / orientjs and transaction in waterline

六月ゝ 毕业季﹏ 提交于 2019-12-04 22:11:42
How can I select or update multiple records in oriento? Like in waterline we can offersModel.update({id:items_ids,status:INACTIVE},{status:ACTIVE}) But in waterline transaction is not available. So I want to use : var db = offersModel.getDB(); var trans = db.begin(); trans.update('offers') .set({status:INACTIVE}) .where({id:items_ids,status:ENM.SELLING_STATUS.ACTIVE})//.exec() .then(function(offers){ if (offers.length != items_ids.length) {trans.rollback(); /* send error here*/} else trans.commit(); }) Thanks. Try this db.update(id).set({status:INACTIVE}).scalar() Have you tried following? db

Sails.js Associations many-to-many relation

我的梦境 提交于 2019-12-04 18:42:32
I have a problem with many to many relationship in sails and if somebody can help me it would be great :D I have two models User and Message and the associations is defined as follows api/models/User.js module.exports = { attributes: { messages: { collection: 'message', via: 'owner', dominant: true } } }; api/models/Message.js module.exports = { attributes: { owner: { model: 'user'. via: 'messages' } } }; I checked in the DB (MySQL) the middle table is created and i successfully inserted the data but i cant retrive the data. i start sails console and type User .find() .populate('messages')

Is it possible in Sailsjs to build more complex models

戏子无情 提交于 2019-12-04 18:30:34
问题 I would like to have arrays or collections in my model, is this yet possible with waterline (mongoDB)? are there any alternatives around? example: { name: Bundle, col1 : { name : anOtherModel, subCol: { text: aString, ... } }, col2 : { name : anOtherModel, subCol: { text: aString, ... } } } to: module.exports = { attributes : { name : { type : 'STRING', required : true }, basicModules: { type : 'ARRAY', // or 'COLLECTION' required : false } } }; 回答1: I don't know if this is still an issue,

Sails.js composite unique field

百般思念 提交于 2019-12-04 18:21:49
问题 This model gives me the effect I want at the expense of duplicated data and general uglyness: //Example var Example = { attributes: { foo: { type: 'string', required: true }, bar: { type: 'string', required: true, }, baz: { type: 'integer', required: true, min: 1 }, foobar: { type: 'string', unique: true } }, beforeValidation : function(values,cb) { values.foobar = values.foo+values.bar; cb(); } }; module.exports = Example; Is there a better strategy for creating a composite unique key? 回答1:

How can I select different databases for a model based on request parameters in Sails.js?

為{幸葍}努か 提交于 2019-12-04 17:17:58
I have an application that I am considering porting to Sails.JS. One of the big issues I am having is supporting the per-request database selection that we have right now. Our app creates/uses a different database for each customer that we have and we select the database based on the request. How could I achieve that in Sails.JS? Could I write a Express middleware that would do this on a per request basis? 来源: https://stackoverflow.com/questions/26930432/how-can-i-select-different-databases-for-a-model-based-on-request-parameters-in

Waterline default query condition

断了今生、忘了曾经 提交于 2019-12-04 16:56:49
How can I set the default where/sort condition in my SailsJS waterline model? In Rails I would use default scope . 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.js file, because the blueprint is added for you by default. 来源: https://stackoverflow.com/questions

Sailsjs/waterline specify number of decimal places in model

瘦欲@ 提交于 2019-12-04 14:52:48
How do I tell my sails model that I want some specific number decimal places for a type: 'float' attribute? Like decimalPlaces: 4 or something of that ilk? The problem is that when i post a value to this entry, the value on disk is truncated to the .00 (hundreds) place. Say I want: 3243.2352362 to be stored just as it is. Currently this is transformed into 3243.24 If it matters I'm using the sails-mysql adapter. Martin Malinda types: { decimal2: function(number){ return ((number *100)%1 === 0); } }, attributes: { myNumber: { type: 'float', decimal2: true } } This is for 2 decimal places though

sails.js nested models

淺唱寂寞╮ 提交于 2019-12-04 10:19:39
In sails.js 0.10 I'm trying to do the following // user.js module.exports = { attributes: { uuid: { type: 'string', primaryKey: true, required: true } , profile: { firstname: 'string', lastname: 'string', birthdate: 'date', required: true } } }; I'm getting an error when trying to create a user and sailsJS doesn't recognize the "profile" attribute. I'm not sure if sails supports the nested JSON structure, and if it does I'm not sure how to structure it. error: Sent 500 ("Server Error") response error: Error: Unknown rule: firstname I've tried the following but it failed too // user.js module

Between Dates using Waterline ORM SailsJS

人盡茶涼 提交于 2019-12-04 07:07:50
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('monthStart') + '/' + req.param('dayStart')); end = new Date(req.param('yearEnd') + '/' + req.param('monthEnd

Sails js using models outside web server

家住魔仙堡 提交于 2019-12-04 05:26:27
I want to create a cli to create admin users I have the user model setup in api/models/User.js and in cli on var User, program; program = require("commander"); User = require("../api/models/User"); program.version("0.0.1"); program.command("create_user").description("Create a user into database").action(function() { return console.log(User); }); program.parse(process.argv); User log is: User = { attributes: { username: "string", password: "string", } }; and no waterline methods available to use. You can use sails run <command> . Simply create <appPath>/commands/index.js with this content: