This document provides a cheat sheet for SailsJS that outlines model validations, model lifecycle callbacks, Waterline model and query methods, and Websocket PubSub methods. It includes descriptions and examples of validations, callbacks, methods for CRUD operations, relationships and subscriptions.
This document provides a cheat sheet for SailsJS that outlines model validations, model lifecycle callbacks, Waterline model and query methods, and Websocket PubSub methods. It includes descriptions and examples of validations, callbacks, methods for CRUD operations, relationships and subscriptions.
creditcard: {boolean} minLength: {int} uuidv4: {boolean} date: {boolean} not: {RegEx} Define custom validation using the types datetime: {boolean} notContains: {string?RegEx?} property of the model
falsey: {boolean} NaN is considered a number publishUpdate (id,[data],[request],[options]) finite: {boolean} can be coerced to a finite number numeric: {boolean} Message: {id,verb:'updated',data:obj‐
string contains only numbers ect,previous:object}
float: {boolean} object: {boolean} publishAdd(id,attributes,idAdded,[request], hexadecimal: {boolean} [options] ) hexColor: {boolean} regex: {boolean?} Message: {id,verb:'addedTo',attribute,a‐ in: {array} protected: {boolean} ddedId} int: {boolean} remove attribute when toJSON is called publishDestroy (id,[request],[options]) on instance alias for integer Message: {id,verb:'destroyed',previous} required: {boolean} integer: {boolean} publishRemove(id,attribute,remo‐ during creation only vedId,[request],[options]) string: {boolean} Message: {id,verb:'removedFrom',attr‐ ibute,removedId}
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
Unsubscribes from record(s) changes. Only works with MongoDB. For low-level populate(foreignKey, [query] ) {query} Works for socket requests only. usage do require('mongodb') populateAll( [query] ) {query} subscribers(record|id, [context(s)]) {Array‐ directly. skip (int) {query} (Socket)} count([criteria], [callback]) {query} sort(sortString) {query} watch (request) find (criteria, [callback]) {query} where(criteria) {query} Subscribe to publishCreate() . Works for findOne(criteria, [callback]) {query} then(callback) {query} socket requests only. findOrCreate(criteria, [callback]) {query} Bluebird Promise Method unwatch(request) create (data, [callback]) {query} catch(callback) {query} Unsubscribe to publishCreate() . Works destroy(criteria, [callback]) {query} Bluebird Promise Method for socket requests only. update (criteria, data, [callback]) {query} Query objects are returned by waterline http://sailsjs.org/#/documentation/referen‐ stream (criteria, [options]) {stream} methods if a callback was not passed. ce/websockets/resourceful-pubsub If a callback is not passed, most methods return chainable query object which ends Model Settings Model Lifecycle Callbacks with .exec(callback) migrate: {string} beforeValidate: {fn(values, next)} safe: never auto-migrate db. alter: auto- create and update Waterline Record Methods migrate db and attempt to keep existing. afterValidate: {fn(values, next)} add( {object|id}) drop: drop all data on every lift. create and update Add a many2many relationship schema: {boolean} beforeCreate: {fn(values, next)} remove ( {object|id}) only specified attributes are saved afterCreate: {fn(newlyInsertedRecord, Remove a many2many relationship connection: {string} next)} toJSON() {clonedObject} use specified connection config beforeUpdate: {fn(valuesToUpdate, next)} Contains instance methods identity: {string} afterUpdate: {fn(updatedRecord, next)} toObject() {clonedData} lowercase version of filename beforeDestroy: {fn(criteria, next)} Does not contain instance methods globalId {string} afterDestroy: {fn(destroyedRecords, next)} validate(callback(err)) global variable name if enabled save(callback) autoPK: {boolean} persists any changes to the database. autoCreatedAt: {boolean} Required for add() / remove() autoUpdatedAt: {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 Associations
tableName: {string} Where: Has-One:
table or collection to be used Mode.find({ where: conditions }) model: 'model'
requires autoPK set to false Mode.find({ skip: integer })
enum: {array[string]} Sort:
size: {integer} Mode.find({ sort: sortString }) columnName: {string} { sort: 'property' | 'property ASC' } Each attribute can have an object definition { sort: 'property DESC' } or just a string specifying containing type { sort: { 'property1' : 1, 'property2': 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