Add rethinkdb
This commit is contained in:
parent
54b686fda3
commit
14be2c2433
@ -2,3 +2,8 @@ import path from 'path'
|
||||
|
||||
export const distPath = path.resolve(__dirname, 'dist')
|
||||
export const apiEndpoint = '/graphql'
|
||||
export const rethinkdb = {
|
||||
host: 'localhost',
|
||||
port: 28015,
|
||||
db: 'test'
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
"koa-bodyparser": "^4.2.0",
|
||||
"koa-compress": "^2.0.0",
|
||||
"koa-router": "^7.1.1",
|
||||
"rethinkdbdash": "^2.3.28",
|
||||
"source-map-support": "^0.4.14",
|
||||
"webpack": "^2.3.2",
|
||||
"zoo": "^0.1.9"
|
||||
|
||||
@ -1,3 +1,12 @@
|
||||
import getRethinkDB from './rethinkdb'
|
||||
|
||||
const getNewVal = (result) => {
|
||||
if (result.changes.length === 1) {
|
||||
return result.changes[0].new_val
|
||||
}
|
||||
return result.changes.map((file) => file.new_val)
|
||||
}
|
||||
|
||||
export default {
|
||||
Query: {
|
||||
ignore () {
|
||||
@ -5,13 +14,17 @@ export default {
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
singleUpload (root, {file}) {
|
||||
console.log('Uploaded file:', file)
|
||||
return file
|
||||
async singleUpload (_, {file}) {
|
||||
const db = getRethinkDB()
|
||||
const result = await db.table('uploads')
|
||||
.insert(file, {returnChanges: true})
|
||||
return getNewVal(result)
|
||||
},
|
||||
multiUpload (root, {files}) {
|
||||
console.log('Uploaded files:', files)
|
||||
return files
|
||||
async multiUpload (_, {files}) {
|
||||
const db = getRethinkDB()
|
||||
const result = await db.table('uploads')
|
||||
.insert(files, {returnChanges: true})
|
||||
return getNewVal(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
api/rethinkdb.js
Normal file
10
api/rethinkdb.js
Normal file
@ -0,0 +1,10 @@
|
||||
import rethinkdbdash from 'rethinkdbdash'
|
||||
import {rethinkdb} from './config'
|
||||
|
||||
let driver
|
||||
export default () => {
|
||||
if (!driver) {
|
||||
driver = rethinkdbdash(rethinkdb)
|
||||
}
|
||||
return driver
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user