An Ember Data adapter for Sails.js v0.10.
Note: If you like to use this adapter with Sails.js v0.9 please use the 1.x line.
This package contains 2 Adapters, DS.SailsSocketAdapter
and DS.SailsRESTAdapter
.
bower install ember-data-sails-adapter
<script type="text/javascript" src="/bower_components/ember-data-sails-adapter/ember-data-sails-adapter.js"></script>
The SailsSocketAdapter
uses Sails's websocket support to find, create and delete records. This has the benifit of automatically subscribing to the Sails' update
, create
and delete
events for for the model. To enable these events with Blueprint controllers in Sails v0.10 you will need to set the autosubscribe
property on your Model. The adapter will add or update records in the store when a Sails emits an updated
, created
or destroyed
event.
App.ApplicationAdapter = DS.SailsSocketAdapter.extend({
namespace: '/api/v1',
});
The SailsRESTAdapter
works similarly to the Ember RESTAdapter. The main differences are this adapter automatically attempts to use the JSONSerializer
instead of the RESTSerializer
because it more closely matches the JSON response from Sails. Additionally it will re-format the error messages returned by Sails to match the format that Ember Data expects. With the SailsRESTAdapter
you will not get the live updateing that comes with the SailsSocketAdapter
. However, because websockets do not support compression using the SailsRESTAdapter
may be benificial when you are expecting a large response from the Sails api.
App.ApplicationAdapter = DS.SailsRESTAdapter.extend({
namespace: '/api/v1'
});
Unlike, the Serializer from v1.x, in version 2 of ember-data-sails-adapter
the the SailsSocketAdapter
and SailsRESTAdapter
both work best using the RESTSerializer
.
App.ApplicationSerializer = DS.RESTSerializer.extend({});
The options below are for the SailsSocketAdapter. To see a list of options for the SailsRESTAdapter
see the RESTAdapter docs.
Type: String
Default value: ''
The prefix to add to the request uris.
Type: Boolean
Default value: false
Set to true if you would like to see a log of all requests in the command line.
Type: Boolean
Default value: false
Used to map lowercase model names that sails uses to model names that ember can understand.
An Ember Data adapter for Sails.js v0.9.
This package contains 2 Adapters, DS.SailsSocketAdapter
and DS.SailsRESTAdapter
.
bower install ember-data-sails-adapter#1.0.1
<script type="text/javascript" src="/bower_components/ember-data-sails-adapter/ember-data-sails-adapter.js"></script>
The SailsSocketAdapter
uses Sails's websocket support to find, create and delete records. This has the benifit of automatically subscribing to the Sails' update
, create
and delete
events for for the model. The adapter will add or update records in the store when a Sails emits an update
, create
and delete
event.
App.ApplicationAdapter = DS.SailsSocketAdapter.extend({
namespace: '/api/v1',
log: false,
modelNameMap: {
userprofile: 'UserProfile'
}
});
The SailsRESTAdapter
works similarly to the Ember RESTAdapter. The main differences are this adapter automatically attempts to use the JSONSerializer
instead of the RESTSerializer
because it more closely matches the JSON response from Sails. Additionally it will re-format the error messages returned by Sails to match the format that Ember Data expects. With the SailsRESTAdapter
you will not get the live updateing that comes with the SailsSocketAdapter
. However, because websockets do not support compression using the SailsRESTAdapter
may be benificial when you are expecting a large response from the Sails api.
App.ApplicationAdapter = DS.SailsRESTAdapter.extend({
namespace: '/api/v1'
});
In Sails v0.9, the SailsSocketAdapter
and SailsRESTAdapter
both work best using the JSONSerializer
. As a result of a bug in the stock JSONSerializer
it is recommend that you create an ApplicationSerializer
by extending the JSONSerializer
like in the example below.
App.ApplicationSerializer = DS.JSONSerializer.extend({
// Fix broken extractArray see:
// https://github.com/emberjs/data/pull/1479
extractArray: function(store, type, arrayPayload) {
var serializer = this;
return Ember.ArrayPolyfills.map.call(arrayPayload, function(singlePayload) {
return serializer.extractSingle(store, type, singlePayload);
});
},
// Allow JSONSerializer to work with RESTAdapter
// https://github.com/emberjs/data/blob/7e83ed158034cf7fedf2a7113a82de5d5ce67e76/packages/ember-data/lib/adapters/rest_adapter.js#L379
serializeIntoHash: function(hash, type, record, options) {
Ember.merge(hash, this.serialize(record, options));
}
});
The options below are for the SailsSocketAdapter. To see a list of options for the SailsRESTAdapter
see the RESTAdapter docs.
Type: String
Default value: ''
The prefix to add to the request uris.
Type: Boolean
Default value: false
Set to true if you would like to see a log of all requests in the command line.
Type: Object
Default value: {}
Used to map lowercase model names that sails uses to model names that ember can understand.