Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Created November 21, 2012 08:51
Show Gist options
  • Select an option

  • Save mikermcneil/4123873 to your computer and use it in GitHub Desktop.

Select an option

Save mikermcneil/4123873 to your computer and use it in GitHub Desktop.
An example of what the new Sails adapter specification looks like
// An example sails adapter
module.exports = {
////////////////////////////////////////////////////////////////////////////////
//
// Sails uses migrate() to synchronize the underlying data model with your app's schema.
// If any changes are detected in your models, migrate() is called when starting the server.
//
// Handle associations/references logic here (i.e. belongsTo,has, hasMany)
//
// Some possible approaches:
// * drop and create ( migrate === "create" )
// * alter the schema ( migrate === "update" )
// * do something custom ( migrate === someFunction() )
// * or do nothing ( migrate === null )
//
////////////////////////////////////////////////////////////////////////////////
//
migrate: function (cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Fetch the definition for a collection, @name
//
////////////////////////////////////////////////////////////////////////////////
//
// @name
// * the name of the collection to create
//
describe: function (name, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Define a new collection, @name
//
////////////////////////////////////////////////////////////////////////////////
//
// @name
// * the name of the collection to create
//
// @definition
// * a definition for the new collection
//
define: function (name, definition, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Drop a collection, @name
//
////////////////////////////////////////////////////////////////////////////////
//
// @name
// * the name of the collection to drop
//
drop: function (name, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Update one or more attributes in a collection called @name
//
////////////////////////////////////////////////////////////////////////////////
//
// @name
// * the name of the collection to alter
//
// @definition
// * a partial or complete definition to update the collection with
// (should override existing attributes, but leave unspecified values untouched)
//
alter: function (name,definition, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Create one or more new models in the data store.
//
////////////////////////////////////////////////////////////////////////////////
//
// @values
// * the attribute object to use to instantiate the new model
// (for unspecified attrs, should use the "default" property, or null)
//
create: function (values, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Find one or more models from the data store.
//
////////////////////////////////////////////////////////////////////////////////
//
// @criteria
// * required: the criteria object or id to lookup the model(s) with
//
find: function (criteria, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Update one or more models in the data store.
//
////////////////////////////////////////////////////////////////////////////////
//
// @criteria
// * required: the criteria object or id to lookup the model(s) with
//
// @values
// * the object to update the model(s) with
// (should leave unspecified values untouched)
//
update: function (criteria, values, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Delete one or more models from the data store.
//
////////////////////////////////////////////////////////////////////////////////
//
// @criteria
// * required: the criteria object or id to lookup the model(s) with
//
destroy: function (criteria, cb) {
},
////////////////////////////////////////////////////////////////////////////////
//
// Join this.model with @otherModel.
// By default, an inner join, but right and left outer joins are also supported.
//
////////////////////////////////////////////////////////////////////////////////
//
// @otherModel
// * required: the other model to join with
//
// @foreignKey
// * the attribute(s) in the other model to use for the join
// (defaults to FooId, where Foo is the name of this.model)
//
// @key
// * the attribute(s) in this.model to use for the join
// (defaults to the primary key of this.model, or id)
//
// @left
// * whether to include results which don't exist in @otherModel
// (defaults to true)
//
// @right
// * whether to include results which don't exist in this.model
// (defaults to true)
//
join: function (otherModel, foreignKey, key, left, right, cb) {
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment