Sails Js

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

SailsJS Cheat Sheet

by ProLoser via cheatography.com/1600/cs/3124/

Model Valida​tions Model Valida​tions (cont) Model Valida​tions (cont)

after: {Date object} ip: {boolean} text: {boolean}


alpha: {boolean} IPv4 or IPv6 truthy: {boolean}
alphad​ashed: {boolean} ipv4: {boolean} undefined: {boolean}

alphan​umeric: {boolean} ipv6: {boolean} unique: {boolean}


alphan​ume​ric​dashed: {boolean} is: {RegEx} uppercase: {boolean}
array: {boolean} json: {boolean} url: {boolean}
strings formatted as arrays don't pass len: {?} urlish: {boolean}

before: {Date object} is integer > param1 && < param2. /^\s([​^\/​]+.)​+.+​\s*$/g

boolean: {boolean} (Where are params defined?) uuid: {boolean}


strings fail lowercase: {boolean} UUID v3, v4 or v5

contains: {strin​g?R​egEx?} max: {number} uuidv3: {boolean}


credit​card: {boolean} minLength: {int} uuidv4: {boolean}
date: {boolean} not: {RegEx}
Define custom validation using the types
datetime: {boolean} notCon​tains: {strin​g?R​egEx?} property of the model

decimal: {boolean} notEmpty: {boolean}


notIn: {strin​g|a​rray} Websocket PupSub Methods
email: {boolean}
notNull: {boolean} message (recor​d|i​d,m​essage,[request])
empty: {boolean}
notRegex: {boolean?} Message: {id,ve​rb:​'me​ssa​ged​',data}
equals: {mixed}
=== comparison null: {boolean} publis​hCreate(data,[request])

number: {boolean} Message: {id,ve​rb:​'cr​eat​ed'​,data}


falsey: {boolean}
NaN is considered a number publis​hUpdate (id,[data]​,[r​equ​est​],[​opt​ions])
finite: {boolean}
can be coerced to a finite number numeric: {boolean} Message: {id,ve​rb:​'up​dat​ed'​,da​ta:​obj​‐

string contains only numbers ect​,pr​evi​ous​:ob​ject}


float: {boolean}
object: {boolean} publishAdd(id,at​tri​but​es,​idA​dded,[reque​st]​,
hexade​cimal: {boolean}
[o​ptions] )
hexColor: {boolean} regex: {boolean?}
Message: {id,ve​rb:​'ad​ded​To'​,at​tri​but​e,a​‐
in: {array} protected: {boolean}
ddedId}
int: {boolean} remove attribute when toJSON is called
publis​hDe​stroy (id,[reque​st]​,[o​ptions])
on instance
alias for integer
Message: {id,ve​rb:​'de​str​oye​d',​pre​vious}
required: {boolean}
integer: {boolean}
publis​hRemove(id,at​tri​but​e,r​emo​‐
during creation only
vedId,[reque​st]​,[o​ptions])
string: {boolean}
Message: {id,ve​rb:​'re​mov​edF​rom​',a​ttr​‐
ibu​te,​rem​ovedId}

By ProLoser Published 2nd January, 2015. Sponsored by ApolloPad.com


cheatography.com/proloser/ Last updated 12th May, 2016. Everyone has a novel in them. Finish
Page 1 of 3. Yours!
https://apollopad.com
SailsJS Cheat Sheet
by ProLoser via cheatography.com/1600/cs/3124/

Websocket PupSub Methods (cont) Waterline Model Methods Waterline Queries

subscribe(reque​st,​rec​ord(s), [conte​xt(s)]) query(query, callba​ck(err, results)) exec(callback)


Subscribes to record(s) changes. Works Only works with PostgreSQL and Executes a query at the end of a query
for socket requests only. mySQL chain.

unsubs​cribe(reque​st,​rec​ord(s), [conte​xt(s)]) native(callb​ack​(err, collec​tion)) limit (int) {query}


Unsubs​cribes from record(s) changes. Only works with MongoDB. For low-level populate(forei​gnKey, [query] ) {query}
Works for socket requests only. usage do requir​e('​mon​godb') popula​teAll( [query] ) {query}
subscr​ibers(recor​d|id, [conte​xt(s)]) {Array​‐ directly.
skip (int) {query}
(So​cket)} count([crit​eria], [callb​ack]) {query} sort(sortS​tring) {query}
watch (request) find (criteria, [callb​ack]) {query} where(criteria) {query}
Subscribe to publis​hCr​eate() . Works for findOne(criteria, [callb​ack]) {query} then(callback) {query}
socket requests only. findOr​Create(criteria, [callb​ack]) {query} Bluebird Promise Method
unwatch(request) create (data, [callb​ack]) {query}
catch(callback) {query}
Unsubs​cribe to publis​hCr​eate() . Works destroy(criteria, [callb​ack]) {query}
Bluebird Promise Method
for socket requests only.
update (criteria, data, [callb​ack]) {query}
Query objects are returned by waterline
http:/​/sa​ils​js.o​rg​/#/​doc​ume​nta​tio​n/r​efe​ren​‐ stream (criteria, [options]) {stream}
methods if a callback was not passed.
ce/​web​soc​ket​s/r​eso​urc​efu​l-p​ubsub
If a callback is not passed, most methods
return chainable query object which ends Model Settings
Model Lifecycle Callbacks
with .exec(​cal​lback)
migrate: {string}
before​Val​idate: {fn(va​lues, next)}
safe: never auto-m​igrate db. alter: auto-
create and update Waterline Record Methods
m​igrate db and attempt to keep existing.
afterV​ali​date: {fn(va​lues, next)} add( {objec​t|id}) drop: drop all data on every lift.
create and update Add a many2many relati​onship schema: {boolean}
before​Create: {fn(va​lues, next)} remove ( {objec​t|id}) only specified attributes are saved
afterC​reate: {fn(ne​wly​Ins​ert​edR​ecord, Remove a many2many relati​onship connec​tion: {string}
next)} toJSON() {clone​dOb​ject} use specified connection config
before​Update: {fn(va​lue​sTo​Update, next)} Contains instance methods identity: {string}
afterU​pdate: {fn(up​dat​edR​ecord, next)}
toObject() {clone​dData} lowercase version of filename
before​Des​troy: {fn(cr​iteria, next)}
Does not contain instance methods globalId {string}
afterD​estroy: {fn(de​str​oye​dRe​cords, next)}
validate(callb​ack​(err)) global variable name if enabled
save(callback) autoPK: {boolean}
persists any changes to the database. autoCr​eat​edAt: {boolean}
Required for add() / remove()
autoUp​dat​edAt: {boolean}

By ProLoser Published 2nd January, 2015. Sponsored by ApolloPad.com


cheatography.com/proloser/ Last updated 12th May, 2016. Everyone has a novel in them. Finish
Page 2 of 3. Yours!
https://apollopad.com
SailsJS Cheat Sheet
by ProLoser via cheatography.com/1600/cs/3124/

Model Settings (cont) Query Language Model Associ​ations

tableName: {string} Where: Has-One:


table or collection to be used Mode.f​ind({ where: conditions }) ​ model: 'model'

attrib​utes: {object} ​ { property: 'value' } Has-Many:

http:/​/sa​ils​js.o​rg​/#/​doc​ume​nta​tio​n/c​onc​ept​‐ ​ { property: { 'comparison': 'value' } } ​ collec​tion: 'model'


s/O​RM/​mod​el-​set​tin​gs.html Complex comparison options. Works for ​ via: 'forei​gnP​rop​ert​yName'
dates: { '>': new Date('​‐ ​ [dominant]: true
Model Attributes 2/4​/2014') } Optionally used if both sides use via
type: {string} ​ ​ { '<' | 'lessThan' : value } property
​ ​string ​ ​ { '<=' | 'lessT​han​OrE​qual' : value } Associ​ations are defined in the attributes
​ text ​ ​ { '>' | 'great​erThan' : value } property of a model
​ ​integer ​ ​ { '>=' | 'great​erT​han​OrE​qual' : value }
​ ​float ​ ​ { '!' | 'not' : value }
​ date ​ ​ { 'like|​con​tai​ns|​sta​rts​Wit​h|e​nds​With': value
​ ​dat​etime }
​ ​boolean like: 'sea%rch' contains: '%search%'
​ ​boolean starts​With: 'search%' endsWith:
'%search'
​ ​binary
​ ​array ​ { property: ['value1', 'value2'] }

​ json Value in array

​ ​email ​ { property: { '!' : ['value1', 'value2'] } }

defaul​tsTo: {mixed} Value not in array

autoIn​cre​ment: {boolean} ​ { or: [ { prop1: 'val1' }, { prop2: val2 } ] }


requires type: 'integer' Limit:

unique: {boolean} Mode.f​ind({ limit: integer })

primar​yKey: {boolean} Skip:


requires autoPK set to false Mode.f​ind({ skip: integer })

enum: {array​[st​ring]} Sort:


size: {integer} Mode.f​ind({ sort: sortString })
column​Name: {string} ​ { sort: 'property' | 'property ASC' }
Each attribute can have an object definition ​ { sort: 'property DESC' }
or just a string specifying containing type ​ { sort: { 'prope​rty1' : 1, 'prope​rty2': 0 } }

By ProLoser Published 2nd January, 2015. Sponsored by ApolloPad.com


cheatography.com/proloser/ Last updated 12th May, 2016. Everyone has a novel in them. Finish
Page 3 of 3. Yours!
https://apollopad.com

You might also like