Show Menu
Cheatography

Quick reference for the Node.JS framework SailsJS

Model Valida­tions

after: {Date object}
alpha: {boolean}
alphad­ashed: {boolean}
alphan­umeric: {boolean}
alphan­ume­ric­dashed: {boolean}
array: {boolean}
strings formatted as arrays don't pass
before: {Date object}
boolean: {boolean}
strings fail
contains: {strin­g?R­egEx?}
credit­card: {boolean}
date: {boolean}
datetime: {boolean}
decimal: {boolean}
email: {boolean}
empty: {boolean}
equals: {mixed}
=== comparison
falsey: {boolean}
finite: {boolean}
can be coerced to a finite number
float: {boolean}
hexade­cimal: {boolean}
hexColor: {boolean}
in: {array}
int: {boolean}
alias for integer
integer: {boolean}
ip: {boolean}
IPv4 or IPv6
ipv4: {boolean}
ipv6: {boolean}
is: {RegEx}
json: {boolean}
len: {?}
is integer > param1 && < param2. (Where are params defined?)
lowercase: {boolean}
max: {number}
minLength: {int}
not: {RegEx}
notCon­tains: {strin­g?R­egEx?}
notEmpty: {boolean}
notIn: {strin­g|a­rray}
notNull: {boolean}
notRegex: {boolean?}
null: {boolean}
number: {boolean}
NaN is considered a number
numeric: {boolean}
string contains only numbers
object: {boolean}
regex: {boolean?}
protected: {boolean}
remove attribute when toJSON is called on instance
required: {boolean}
during creation only
string: {boolean}
text: {boolean}
truthy: {boolean}
undefined: {boolean}
unique: {boolean}
uppercase: {boolean}
url: {boolean}
urlish: {boolean}
/^\s([­^\/­]+.)­+.+­\s*$/g
uuid: {boolean}
UUID v3, v4 or v5
uuidv3: {boolean}
uuidv4: {boolean}
 

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 publis­hCr­eate(). Works for socket requests only.
Unsubs­cribe to publis­hCr­eate(). Works for socket requests only.

Model Lifecycle Callbacks

before­Val­idate: {fn(va­lues, next)}
create
and
update
afterV­ali­date: {fn(va­lues, next)}
create
and
update
before­Create: {fn(va­lues, next)}
afterC­reate: {fn(ne­wly­Ins­ert­edR­ecord, next)}
before­Update: {fn(va­lue­sTo­Update, next)}
afterU­pdate: {fn(up­dat­edR­ecord, next)}
before­Des­troy: {fn(cr­iteria, next)}
afterD­estroy: {fn(de­str­oye­dRe­cords, next)}

Waterline Model Methods

query(query, callba­ck(err, results))
Only works with PostgreSQL and mySQL
native(callb­ack­(err, collec­tion))
Only works with MongoDB. For low-level usage do
requir­e('­mon­godb')
directly.
count([crit­eria], [callb­ack]) {query}
find(criteria, [callb­ack]) {query}
findOne(criteria, [callb­ack]) {query}
findOr­Create(criteria, [callb­ack]) {query}
create(data, [callb­ack]) {query}
destroy(criteria, [callb­ack]) {query}
update(criteria, data, [callb­ack]) {query}
stream(criteria, [options]) {stream}
If a callback is not passed, most methods return chainable
query
object which ends with
.exec(­cal­lback)

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() / remove()

Waterline Queries

 

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
autoPK: {boolean}
autoCr­eat­edAt: {boolean}
autoUp­dat­edAt: {boolean}
tableName: {string}
table or collection to be used
attrib­utes: {object}

Model Attributes

type: {string}
 ­ ­string
 ­ text
 ­ ­integer
 ­ ­float
 ­ date
 ­ ­dat­etime
 ­ ­boolean
 ­ ­boolean
 ­ ­binary
 ­ ­array
 ­ json
 ­ ­email
defaul­tsTo: {mixed}
autoIn­cre­ment: {boolean}
requires
type: 'integer'
unique: {boolean}
primar­yKey: {boolean}
enum: {array­[st­ring]}
size: {integer}
column­Name: {string}

Query Language

Where:
Mode.f­ind({ where: conditions })
 ­ { property: 'value' }
 ­ { property: { 'comparison': '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'
contains:
'%search%'
starts­With:
'search%'
endsWith:
'%search'
 ­ { property: ['value1', 'value2'] }
Value in array
 ­ { property: { '!' : ['value1', 'value2'] } }
Value not in array
 ­ { or: [ { prop1: 'val1' }, { prop2: val2 } ] }
Limit:
Mode.f­ind({ limit: integer })
Skip:
Mode.f­ind({ skip: integer })
Sort:
Mode.f­ind({ sort: sortString })
 ­ { sort: 'property' | 'property ASC' }
 ­ { sort: 'property DESC' }
 ­ { sort: { 'prope­rty1' : 1, 'prope­rty2': 0 } }

Model Associ­ations

 ­ model: 'model'
 ­ collec­tion: 'model'
 ­ via: 'forei­gnP­rop­ert­yName'
 ­ [dominant]: true
                               
 

Comments

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

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
          Express.js Cheat Sheet
          JavaScript: Basic, Advanced, & More Cheat Sheet

          More Cheat Sheets by ProLoser

          AngularJS Cheat Sheet
          Bacon.js Cheat Sheet