Skip to content

Instantly share code, notes, and snippets.

@antonkatz
Created December 30, 2019 18:03
Show Gist options
  • Save antonkatz/b74b1a6cbcf5702faaa9463b0991bfa2 to your computer and use it in GitHub Desktop.
Save antonkatz/b74b1a6cbcf5702faaa9463b0991bfa2 to your computer and use it in GitHub Desktop.
import {OpR} from "./types"
import {PlayId} from "@honest-news/data-types/gameplay"
import {logDescriptor} from "./logTable"
import {nSQL} from "@nano-sql/core"
const TABLE_NAME = 'descriptor'
export const TABLE_DESCRIPTOR = {
name: TABLE_NAME,
model: {
'id:uuid': {pk: true},
'playId:string': {notNull: true},
'descriptor:string': {notNull: true},
'timestamp:int': {notNull: true}
},
indexes: {
'playId:string': {}
}
}
// @ts-ignore
export function insertDescriptor(playId: PlayId, descriptor: string): OpR<any> {
// noinspection JSIgnoredPromiseFromCall
logDescriptor(playId, descriptor)
return nSQL(TABLE_NAME).query('upsert', {playId, descriptor, timestamp: Date.now()}).exec()
}
export function getPlayDescriptors(playId: PlayId): OpR<string[]> {
console.log(playId)
return nSQL(TABLE_NAME).query('select')
.where(['playId', '=', playId])
.exec().then(res => {
console.log(res)
return res.map(d => d.descriptor)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment