Created
October 26, 2015 03:11
-
-
Save runvnc/45c827c15f44fb778a65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// link.js | |
import r from 'rethinkdb'; | |
let conn = null; | |
async function init() { | |
if (conn) return; | |
conn = await r.connect({db:'links'}); | |
} | |
export async function create(data) { | |
await init(); | |
let inserted = await r.table('links').insert({data}); | |
return inserted.generated_keys[0]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import level from 'level'; | |
const db = level('links'); | |
import {inspect} from 'util'; | |
db.createReadStream() | |
.on('data', data => { | |
console.log(`${data.key}=${inspect(data.value)}`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.js | |
import link from './link'; | |
import shortrest from 'shortrest'; | |
const web = shortrest(8099), user = 'test'; | |
web.post('/link', async (req, res) => { | |
try { | |
const {descr, URL} = req.params; | |
res.json(await link.create({descr, URL, user})); | |
} catch (e) { | |
res.json({error: e}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment