js-data-cloud-datastore
Cloud Datastore adapter for JSData
Table of contents
Quick Start
npm install --save gcloud js-data@beta js-data-cloud-datastore@beta
Here's a small sample for using js-data-cloud-datastore
:
// Assumes that you have set the following environment variables:
// GCLOUD_PROJECT
// GOOGLE_APPLICATION_CREDENTIALS
import express from 'express'
import store from './store'
const app = express()
app.route('/posts')
.post('/', async function (req, res) {
res.send(await store.create('post', req.body))
})
.get('/:id', async function (req, res) {
res.send(await store.find('post', req.params.id))
})
.put('/:id', async function (req, res) {
res.send(await store.update('post', req.params.id, req.body))
})
.delete('/:id', async function (req, res) {
res.send(await store.destroy('post', req.params.id))
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
// Assumes that you have set the following environment variables:
// GCLOUD_PROJECT
// GOOGLE_APPLICATION_CREDENTIALS
import {CloudDatastoreAdapter} from 'js-data-cloud-datastore'
// Create an instance of CloudDatastoreAdapter
export default const adapter = new CloudDatastoreAdapter()
// Use Container instead of DataStore in Node.js
import {Container} from 'js-data'
import adapter from './adapter'
// Create a store to hold your Mappers
export default const store = new Container()
// Mappers in "store" will use the CloudDatastore adapter by default
store.registerAdapter('datastore', adapter, { default: true })
store.defineMapper('post')
Configuring the adapter
TODO
Links
See an issue with this tutorial?
You can open an issue or better yet, suggest edits right on this page.
Need support?
Have a technical question? Post on the JSData Stack Overflow channel or the Mailing list.
Want to chat with the community? Hop onto the JSData Slack channel.
Updated less than a minute ago