waterline

Waterline ORM (sails.js) conditions with NOT Equal in query

不想你离开。 提交于 2020-12-29 09:34:26
问题 How can I write a NOT Equal condition in Waterline? This code: Users .count() .where({ id: { '!=': req.params.id}, lastname: req.body.lastname }) Does nothing... (disk adapter in sails.js) 回答1: First thing, it do nothing because looking into database is asynchronous. You have to make the chain longer and add exec or something from Q library like then. User.count().where({ id: { '!=': req.params.id }, lastname: req.body.lastname }).exec(function(err, num){ console.log(num); }); Now it returns

Is there a way to override sails.js waterline endpoint with custom controller, but keep built in pagination, and filtering?

泪湿孤枕 提交于 2020-07-10 06:53:11
问题 I have defined a model, and I like that I get pagination, and filtering out of the box with waterline and blueprint. However, I need to add a where clause to all requests. I don't wasn't the client to add the where. I still want to get all the magical sails.js pagination and filters though that I lose when I create an override controller. Does anyone know how to get my cake and eat it too? 回答1: I initially went the route that arbuthnott suggested, however I was frustrated that it only worked

Compare two fields in Waterline/Sails.js query

安稳与你 提交于 2020-02-06 05:46:06
问题 I want to compare two fields in my Waterline query in Sails.js application, e.g.: SELECT * FROM entity E WHERE E.current < E.max . I've tried the following code, but it's expecting integer value to be passed to it instead of column name: Entity.find({ where: { current: {'<': 'max'} } }); So, how do I compare two columns? 回答1: I have ran some tests and at the same time read the Waterline documentation. There is no indication of anything that could possibly do comparison of two fields/columns

Can we do $all query in sails/waterline js?

亡梦爱人 提交于 2020-02-05 09:22:08
问题 I am using mongodb and sails/waterlinejs One of my documents has a field "participants": ["1" ,"2" ,"3"] I would like to make a mongodb query: Document.find({participants: {$all: ["1", "2"]}}) But I notice that if I do it in waterline , it returns me all the documents that contains EITHER "1" OR "2" . I would like to get BOTH "1" AND "2" Is this something that I have to do in native query? Does waterline have a doc somewhere that lists all the available operators for .find() ? Thanks 回答1: Try

Waterline ORM Foreign Key Error

感情迁移 提交于 2020-01-24 17:53:45
问题 I'm completely new to NodeJS. I'm trying to build my first express app with mysql database. I'm not using Sails, but I read some suggestions to use the Waterline ORM. However, I'm having problems trying to initialize my ORM. Here's my database schema in mysql: CREATE TABLE IF NOT EXISTS `c` ( `c_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `d_id` int(11) UNSIGNED NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`c_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `d`

Sailsjs. Best way to create (and manage) indexes on sails-mongo (mongodb)

隐身守侯 提交于 2020-01-24 15:54:25
问题 I was using sailsjs 0.12. It supported index attributes on models , also i was using npm package Sails-hooks-mongoat to create inverse indexes and so. It wasn't ideal, but it worked. Right now they dropped the index attribute and mongoat is currently unsafe and pending updates to work on Sails.js 1.0. I would like to know the best approach to: Create Indexes on new deployments. Migrate (ensure?) indexes on deployment updates. 回答1: Since you are not allowed to run 'migrate: alter' in

How can I validate a record only without saving in nodejs | sailsjs | waterline

孤者浪人 提交于 2020-01-15 08:41:26
问题 I seek something of this nature //validation rules in model "User" attributes: { age: { required: true, type: 'numeric' } }, //now in controller, i want to be able to do this Recipe.validate({age: 'An invalid age because it is a string. I except a validation error as response'}); Problem is, it doesn't work.. it complains about beforeValidate not being available, e.t.c 回答1: You need to pass a callback into .validate : Recipe.validate({age: 'blah'}, function(err){ if (err && err

Transactional SQL with Sails.js

China☆狼群 提交于 2020-01-12 03:21:11
问题 So I have been playing with NodeJS/Express for a little with now and I would really like to try to rewrite a relatively large side project using a full JavaScript stack just to see how it will work. Sails.js seems to be a pretty good choice for a NodeJS backend for a REST API with support for web sockets which is exactly what I am looking for however is one more issue I am looking to resolve and that is transactional SQL within NodeJS. Most data layer/orms I have seen on the NodeJS side of

Transactional SQL with Sails.js

本秂侑毒 提交于 2020-01-12 03:21:11
问题 So I have been playing with NodeJS/Express for a little with now and I would really like to try to rewrite a relatively large side project using a full JavaScript stack just to see how it will work. Sails.js seems to be a pretty good choice for a NodeJS backend for a REST API with support for web sockets which is exactly what I am looking for however is one more issue I am looking to resolve and that is transactional SQL within NodeJS. Most data layer/orms I have seen on the NodeJS side of

sails/waterline where association not exist

好久不见. 提交于 2020-01-07 03:04:14
问题 I'm using sails for my latest project, and would like to query a model for items that do not have an association. For example title collection... [ { id : 1, name : "ABC123", media : 1 }, { id : 2, name : "DEF456" } ] media collection... [ { id : 1, name : "1234.mpg", title : 1 }, { id : 2, name : "5678.mpg" } ] So, you can see that title 1 is associated (one to one) with media 1, and visa-versa, and that title 2, and media 2 are not associated with anything. My question is, using the