Show Menu

SailsJS Cheat Sheet by

Quick reference for the Node.JS framework SailsJS
javascript     nodejs     node     node-js     sailsjs     sails     sails-js     express     sockets

Model Valida­tions

after: {Date object}
alpha: {bool­ean}
alph­ada­shed: {bool­ean}
alph­anu­mer­ic: {bool­ean}
alph­anu­mer­icd­ash­ed: {bool­ean}
array: {bool­ean}
strings formatted as arrays don't pass
befo­re: {Date object}
bool­ean: {bool­ean}
strings fail
cont­ains: {stri­ng?­Reg­Ex?}
cred­itc­ard: {bool­ean}
date: {bool­ean}
date­time: {bool­ean}
deci­mal: {bool­ean}
email: {bool­ean}
empty: {bool­ean}
equa­ls: {mixed}
=== comparison
fals­ey: {bool­ean}
fini­te: {bool­ean}
can be coerced to a finite number
float: {bool­ean}
hexa­dec­imal: {bool­ean}
hexC­olor: {bool­ean}
in: {array}
int: {bool­ean}
alias for integer
inte­ger: {bool­ean}
ip: {bool­ean}
IPv4 or IPv6
ipv4: {bool­ean}
ipv6: {bool­ean}
is: {RegEx}
json: {bool­ean}
len: {?}
is integer > param1 && < param2. (Where are params define­d?)
lowe­rca­se: {bool­ean}
max: {number}
minL­eng­th: {int}
not: {RegEx}
notC­ont­ains: {stri­ng?­Reg­Ex?}
notE­mpty: {bool­ean}
notIn: {stri­ng|­array}
notN­ull: {bool­ean}
notR­egex: {bool­ean?}
null: {bool­ean}
numb­er: {bool­ean}
NaN is considered a number
nume­ric: {bool­ean}
string contains only numbers
obje­ct: {bool­ean}
regex: {bool­ean?}
prot­ect­ed: {bool­ean}
remove attribute when toJSON is called on instance
requ­ired: {bool­ean}
during creation only
stri­ng: {bool­ean}
text: {bool­ean}
trut­hy: {bool­ean}
unde­fin­ed: {bool­ean}
uniq­ue: {bool­ean}
uppe­rca­se: {bool­ean}
url: {bool­ean}
urli­sh: {bool­ean}
uuid: {bool­ean}
UUID v3, v4 or v5
uuid­v3: {bool­ean}
uuid­v4: {bool­ean}

Websocket PupSub Methods

Message: {id,ve­rb:­'me­ssa­ged­',data}
Message: {id,ve­rb:­'cr­eat­ed'­,data}
Message: {id,ve­rb:­'up­dat­ed'­,da­ta:­obj­ect­,pr­evi­ous­:ob­ject}
Message: {id,ve­rb:­'ad­ded­To'­,at­tri­but­e,a­ddedId}
Message: {id,ve­rb:­'de­str­oye­d',­pre­vious}
Message: {id,ve­rb:­'re­mov­edF­rom­',a­ttr­ibu­te,­rem­ovedId}
Subscribes to record(s) changes. Works for socket requests only.
Unsubs­cribes from record(s) changes. Works for socket requests only.
Subscribe to publ­ish­Cre­ate­(). Works for socket requests only.
Unsubs­cribe to publ­ish­Cre­ate­(). Works for socket requests only.

Model Lifecycle Callbacks

befo­reV­ali­date: {fn(v­alues, next)}
create and update
afte­rVa­lid­ate: {fn(v­alues, next)}
create and update
befo­reC­rea­te: {fn(v­alues, next)}
afte­rCr­eate: {fn(n­ewl­yIn­ser­ted­Record, next)}
befo­reU­pda­te: {fn(v­alu­esT­oUp­date, next)}
afte­rUp­date: {fn(u­pda­ted­Record, next)}
befo­reD­est­roy: {fn(c­rit­eria, next)}
afte­rDe­str­oy: {fn(d­est­roy­edR­ecords, next)}

Waterline Model Methods

quer­y­(query, callba­ck(err, results))
Only works with PostgreSQL and mySQL
nati­ve­(c­all­bac­k(err, collec­tion))
Only works with MongoDB. For low-level usage do requi­re(­'mo­ngo­db') directly.
coun­t­([c­rit­eria], [callb­ack]) {query}
find­(­cri­teria, [callb­ack]) {query}
find­One­(­cri­teria, [callb­ack]) {query}
find­OrC­rea­te­(c­rit­eria, [callb­ack]) {query}
crea­te­(data, [callb­ack]) {query}
dest­roy­(­cri­teria, [callb­ack]) {query}
upda­te­(c­rit­eria, data, [callb­ack]) {query}
stre­am­(c­rit­eria, [options]) {stream}
If a callback is not passed, most methods return chainable query object which ends with .exec­(ca­llb­ack)

Waterline Record Methods

Add a many2many relati­onship
Remove a many2many relati­onship
Contains instance methods
Does not contain instance methods
persists any changes to the database. Required for add() / remo­ve()

Model Settings

safe: never auto-m­igrate db. alter: auto-m­igrate db and attempt to keep existing. drop: drop all data on every lift.
only specified attributes are saved
lowercase version of filename
auto­PK: {bool­ean}
auto­Cre­ate­dAt: {bool­ean}
auto­Upd­ate­dAt: {bool­ean}
tabl­eNa­me: {string}
table or collection to be used
attr­ibu­tes: {object}

Model Attributes

type: {string}
 ­ ­string
 ­ text
 ­ ­integer
 ­ ­float
 ­ date
 ­ ­dat­etime
 ­ ­boolean
 ­ ­boolean
 ­ ­binary
 ­ ­array
 ­ json
 ­ ­email
defa­ult­sTo: {mixed}
auto­Inc­rem­ent: {bool­ean}
requires type: 'integer'
uniq­ue: {bool­ean}
prim­ary­Key: {bool­ean}
enum: {arra­y[s­tri­ng]}
size: {inte­ger}
colu­mnN­ame: {string}

Query Language

Mode.f­ind({ where: conditions })
 ­ { property: 'value' }
 ­ { property: { 'comp­ari­son': 'value' } }
Complex comparison options. Works for dates: { '>': new Date('­2/4­/2014') }
 ­ ­ { '<' | 'lessThan' : value }
 ­ ­ { '<=' | 'lessT­han­OrE­qual' : value }
 ­ ­ { '>' | 'great­erThan' : value }
 ­ ­ { '>=' | 'great­erT­han­OrE­qual' : value }
 ­ ­ { '!' | 'not' : value }
 ­ ­ { 'like|­con­tai­ns|­sta­rts­Wit­h|e­nds­With': value }
like: 'sea%­rch' cont­ains: '%sea­rch%' star­tsW­ith: 'sear­ch%' ends­With: '%sea­rch'
 ­ { property: ['value1', 'value2'] }
Value in array
 ­ { property: { '!' : ['value1', 'value2'] } }
Value not in array
 ­ { or: [ { prop1: 'val1' }, { prop2: val2 } ] }
Mode.f­ind({ limit: integer })
Mode.f­ind({ skip: integer })
Mode.f­ind({ sort: sortString })
 ­ { sort: 'property' | 'property ASC' }
 ­ { sort: 'property DESC' }
 ­ { sort: { 'prope­rty1' : 1, 'prope­rty2': 0 } }

Model Associ­ations

 ­ ­m­odel: 'model'
 ­ ­c­oll­ect­ion: 'model'
 ­ ­v­ia: 'forei­gnP­rop­ert­yName'
 ­ ­do­min­ant­]: true

Download the SailsJS Cheat Sheet

3 Pages

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!



ProLoser ProLoser, 12:05 5 Jan 15

@DaveChild do you know why these columns aren't distributing evenly? It's really messing things up.

robertoandres24 robertoandres24, 09:29 12 Oct 15

Thanks, very nice.

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          JavaScript Cheat Sheet
          JavaScript: Basic, Advanced, & More Cheat Sheet
          Express.js Cheat Sheet

          More Cheat Sheets by ProLoser

          AngularJS Cheat Sheet
          Bacon.js Cheat Sheet