_ __ __ _
_________ (_)___ ____ _/ / _________ _________/ / (_)____
/ ___/ __ \/ / __ \/ __ `/ /_____/ ___/ __ \/ ___/ __ / / / ___/
(__ ) /_/ / / / / / /_/ / /_____/ /__/ /_/ / / / /_/ / / (__ )
/____/ .___/_/_/ /_/\__,_/_/ \___/\____/_/ \__,_(_)_/ /____/
/_/ /___/
This project is inspired by backbone.js's data layer, i.e Collections and Models. It allows users to manipulate data objects with classical backbone.js style syntax, on both frontend and backend.
On the spinal-cord roadmap. We plan to support different backends as data store. Including:
- Restful API (Server Side & Client Side)
- IndexDB (In the browser)
- LocalStorage (KVDB in Browser)
- Redis (KVDB on Server)
'use strict'
const RestfulModel = require('spinal-cord').RestfulModel
// Using Restful Backend
class User extends RestfulModel {
get resource_name() {
return 'user'
}
get host() {
return 'http://your-nice-server.com'
}
}
var user0 = new User({ "email": "[email protected]" })
var user1 = new User({ "mobile": "13394058373" })
var user2 = new User({ "email": "[email protected]" })
user0.get()
.then((res)=>{ return user0.delete() }) // Delete user0
.then((res)=>{ return user1.get() }) // Fetch user1 from Server
.then((res)=>{ return user1.delete() }) // Delete user1
.then((res)=>{ return user2.get() }) // Fetch user2 from Server
.then((res)=>{ return user2.delete() }) // Delete user2
let user = new User({ "email": "[email protected]" })
user.get() // Get user
.then(res =>{ return user.save({ "email": "[email protected]" }) })
// Modify user
.then((res)=>{
// do your stuff here
})
Please Refer to https://github.com/cyanideio/spinal-cord/releases