Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Created March 14, 2017 13:12
Show Gist options
  • Save stephenplusplus/2f25ad7272d45612a9e8c1d920469be4 to your computer and use it in GitHub Desktop.
Save stephenplusplus/2f25ad7272d45612a9e8c1d920469be4 to your computer and use it in GitHub Desktop.
const _KEY = '__key__'
const DS = require('@google-cloud/datastore')()
const TABLE = 'Members10'
function getAuThoB(hash_) {
return Promise.resolve().then(function () {
const ret = {}
ret.role = true
return ret
})
}
tstSave()
function tstSave() {
const dat = {
id: '57292010259742702'
}
return getAuThoB('aa')
.then(function(autho) {
return save(dat.id, dat, autho)
})
}
function save(id, jDObj) {
const ipro = _save(TABLE, id, jDObj)
return ipro
}
function _makeKey(table_, id) {
const k = DS.key([
table_,
Number(id)
])
return k
}
function _save(table_, id, jDObj) {
const key = _makeKey(table_, id)
const jD = jDObj
jD.id = id
return DS.get(key)
.then(function(data) {
const row = data[0]
return DS.update({
key: key,
data: Object.assign(row, jD)
})
})
.then(function(res) {
return res[0].mutationResults[0]
})
.catch(function(er){
console.log('_save er '+ er)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment