docs/contributing/adapter-specification.md
The adapter interface specification is currently under active development and may change.
e.g.
RestAPIorMySQL
Stability: 3 - Stable
Implementing the basic semantic interface (CRUD) is really a step towards a complete implementation of the Queryable interface, but with some services/datasources, about as far as you'll be able to get using native methods.
By supporting the Semantic interface, you also get the following:
find() function, developers can also use all of its synonyms, including dynamic finders and findOne(). When they're called, they'll automatically be converted into the appropriate criteria object for the basic find() definition in your adapter.where functionality (see Queryable below), Waterline can derive a simplistic version of associations support for you. To optimize the default assumptions with native methods, override the appropriate methods in your adapter.All officially supported Sails.js database adapters implement the
Semanticinterface.
Model.create()Model.find()Model.update()Model.destroy()findOrCreate()createEach()destroyEach()updateEach()findOrCreateEach()findAndUpdateOrCreate()findAndUpdateOrCreateEach()Stability: 3 - Stable
Query building features are common in traditional ORMs, but not at all a guarantee when working with Waterline. Since Waterline adapters can support services as varied as Twitter, SMTP, and Skype, traditional assumptions around structured data don't always apply.
If query modifiers are enabled, the adapter must support Model.find(), as well as the complete query interface, or, where it is impossible to do so, at least provide good error messages. If coverage of the interface is unfinished, it's still not a bad idea to make the adapter available, but it's important to clearly state the unifinished parts, and consequent limitations, up front. This helps prevent the creation of off-topic issues in Sails/Waterline core, protects developers from unexpected consequences, and perhaps most importantly, helps focus contributors on high-value tasks.
All officially supported Sails.js database adapters implement this interface.
Query modifiers include normalized syntax:
wherelimitskipsortselectAnd WHERE supports:
Boolean logic:
andornotIN queries:
Adapters which implement where should recognize a list of values (e.g. name: ['Gandalf', 'Merlin']) as an IN query. In other words, if name is either of those values, a match occured.
Sub-attribute modifiers:
You are also responsible for sub-attribute modifiers, (e.g. { age: { '>=' : 65 } }) with the notable exception of contains, startsWith, and endsWith, since support for those modifiers can be derived programatically by leveraging your definition of like.
like (SQL-style, with % wildcards)'>' (you can also opt to use the more verbose .greaterThan(), etc.)'<' '>=''<='Stability: 1 - Experimental
Adapters which implement the Migratable interface are usually interacting with SQL databases. This interface enables the migrate configuration option on a per-model or adapter-global basis, as well as access to the prototypal/class-level CRUD operations for working with tables.
This is not how it actually works, but how it could work soon:
Adapter.define()Adapter.describe()Adapter.drop()Adapter.alter() (change table name, other table metadata)Adapter.addAttribute() (add column)Adapter.removeAttribute() (remove column)Adapter.alterAttribute() (rename column, add or remove uniquness constraint to column)Adapter.addIndex()Adapter.removeIndex()"safe" (default in production env)
"drop" (default in development env)
"alter"
"create"
Stability: 1 - Experimental
Adapters which implement the SQL interface interact with databases supporting the SQL language. This interface exposes the method .query() allowing the user to run raw SQL queries against the database.
Adapter.query(query,[ data,] cb)