<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.firebase.com/js/client/2.1.2/firebase.js"></script>
<script src="https://cdn.rawgit.com/js-data/js-data/master/dist/js-data.js"></script>
<script src="https://cdn.rawgit.com/js-data/js-data-firebase/master/dist/js-data-firebase.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Open up your console to see the output</h1>
</body>
</html>
var store = new JSData.DS();
var fbAdapter = new DSFirebaseAdapter({
basePath: 'https://js-data-firebase.firebaseio.com'
});
store.registerAdapter('fb', fbAdapter, { default: true });
var Document = store.defineResource('document');
console.log('Document.create({ author: \'John Anderson\' })');
Document.create({
author: 'John Anderson'
}).then(function (document) {
console.log(document);
console.log('Document.get(document.id)');
console.log(Document.get(document.id));
return Document.destroy(document.id);
}).then(function () {
var document2 = Document.createInstance({ title: 'foo.txt' });
console.log('Document.createInstance({ title: \'foo.txt\' })');
console.log(document2);
console.log('document2.DSCreate()');
return document2.DSCreate();
}).then(function (document) {
console.log(document);
return Document.destroy(document.id);
}).then(function () {
var document3 = { title: 'bar.txt' };
console.log('var document3 = { title: \'bar.txt\' }');
console.log(document3);
console.log('store.create(\'document\', document3)');
return store.create('document', document3);
}).then(function (document) {
console.log(document);
return Document.destroy(document.id);
});
## DS#create(resourceName, attrs[, options])
The "C" in "CRUD". Delegate to the `create` method of whichever adapter is being used and inject the result into the data store.
Returns a promise.
###### Arguments
| name | type | description |
| ---- | ---- | ----------- |
| resourceName | string | The name of the resource to use. Unnecessary if using the resource directly. |
| attrs | object | The attributes with which to create the item. |
| options | object | Configuration options. Also passed through to the adapter and (conditionally) to `DS#inject`. |
| options.adapter | string | Override the default adapter. |
| options.cacheResponse | boolean | Inject the result into the store. Default: `true`. |
| options.upsert | boolean | If `attrs` already contains a primary key, then attempt to call `DS.update` instead. Default: `true`. |
###### Examples
```js
var Document = store.defineResource('document');
// See Method Variants section below for different ways to call DS#create
Document.create({
author: 'John Anderson'
}).then(function (document) {
document; // { id: 5, author: 'John Anderson' }
// The new document is already in the data store
Document.get(document.id); // { id: 5, author: 'John Anderson' }
});
```