本文整理汇总了TypeScript中rethinkdb.table函数的典型用法代码示例。如果您正苦于以下问题:TypeScript table函数的具体用法?TypeScript table怎么用?TypeScript table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了table函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateCanvas
/**
* Update canvas details.
* @param canvas Updated canvas details. Must contain canvas ID.
*/
updateCanvas(canvas: DrawGaiden.Canvas) {
if (!canvas.id) {
return Promise.reject('Cannot update canvas with missing ID.');
}
return r.table('canvases')
.get(canvas.id)
.update(canvas)
.run(this.conn);
}
示例2: function
(async function() {
var conn = await r.connect(config.database);
try {
await r.dbCreate(config.database.db).run(conn);
await r.tableCreate("messages").run(conn);
await r.table("messages").indexCreate("time").run(conn);
}
catch (err) {
if (err.message.indexOf("already exists") < 0)
console.log(err.message);
}
(await r.table("messages").changes().run(conn)).each((err, item) => {
if (item && item.new_val)
io.sockets.emit("message", item.new_val);
});
})();
示例3: function
routerUnauthenticated.get("/tracks/:barId", async function () {
var conn = await r.connect(AppConfig.dbConfig);
this.body = await r.table("tracks")
.filter({ location: this.params.barId })
//.orderBy({ index: r.desc("begin") })
.limit(50)
.run(conn);
conn.close();
});
示例4: catch
db.connect(async () => {
console.log('rethink', settings.rethinkdb)
let conn = await rethink.connect(settings.rethinkdb)
var dbs = await rethink.dbList().run(conn)
console.log(dbs)
let fails = 0
conn.use('icecondor')
try {
const cursor = await rethink.table('fences').run(conn)
const fences = await cursor.toArray() // all at once
for (const fence of fences) {
try {
console.log(JSON.stringify(fence))
const eu = await db.fence_add(fence)
if (eu.inserted != 1) {
console.log('fence2lmdb fence_add error')
fails += 1
}
} catch (e) {
console.log('fence2lmdb fence_add', fence.id, 'CATCH', e)
process.exit(1)
}
}
console.log('*** done', fences.length, 'rethink fences', fails, 'save fails')
await db.schema_dump()
const cursor2 = await rethink.table('rules').run(conn)
const rules = await cursor2.toArray() // all at once
for (const rule of rules) {
try {
console.log(rule)
const add = await db.rule_add(rule)
} catch (e) {
console.log('rule2lmdb', rule, 'CATCH', e)
process.exit(1)
}
}
console.log('*** done', rules.length, 'rethink rules', fails, 'save fails')
await db.schema_dump()
} catch (e) {
console.log(e)
}
}).catch(e => { console.log(e); process.exit(1) })
示例5: function
r.connect({ host: "localhost", port: 28015 }, function(err: Error, conn: r.Connection) {
console.log("HI", err, conn);
conn.server((err, server) => {});
const testDb = r.db("test");
r.table("players").hasFields("games_won").run(conn, errorAndCursorCallback);
r.table("players").hasFields({ "games_won": { "championships": true } }).run(conn, errorAndCursorCallback);
r.table("players").filter(r.row.hasFields("games_won").not()).run(conn, errorAndCursorCallback);
r.table("players").filter(r.row.hasFields({ "games_won": { "championships": true } }).not()).run(conn, errorAndCursorCallback);
r.table("players").filter(
r.row.hasFields("games_won").not()
.or(r.row("games_won").not().eq(true))
.and(true)
)
.run(conn, errorAndCursorCallback);
const center = r.point(123, 456);
r.table("geo")
.getIntersecting(r.circle(center, 1000, { unit: "m" }), { index: "location" })
.orderBy(r.row("location").distance(center, { unit: "m" }))
.eqJoin("external", testDb.table("other"), { index: "external" })
.getField("right")
.run(conn, errorAndCursorCallback);
testDb.tableCreate("users").run(conn, function(err, stuff) {
const users = testDb.table("users");
users.wait({waitFor: 'ready_for_reads'});
users.insert({ name: "bob" }).run(conn, function() {
});
users.hasFields("foo_bar").run(conn, () => {});
users.filter(function(doc?) {
return doc("henry").eq("bob");
})
.filter(r.row("updatedAt").default(0).lt(r.now().sub(1000)))
.between("james", "beth")
.limit(4)
.run(conn, function(err, cursor) {
cursor.toArray<string>((err, strings) => {
console.log(strings);
});
});
});
testDb.table("users").indexCreate("name_index", [r.row("name")]);
r.js("'str1' + 'str2'").run(conn, function (err, value) {});
r.uuid().run(conn, function (err, uuid) {});
r.uuid("input value").run(conn, function (err, uuid) {});
r.table("games").changes().run(conn, function(err, cursor) {
cursor.each(console.log);
});
});
示例6: gm
gm(req.file.path).compress("JPEG").toBuffer((err, buf) => {
r.table("files").insert({ file: buf }).run(req.conn)
.then((result) => {
return r.table("users").get(req.params['id']).update({ avatar: result.generated_keys[0] }).run(req.conn)
})
.then((result) => {
res.end("Upload successful")
})
.error((err) => {
res.status(500).end('Failed to change profile photo')
})
})
示例7:
router.get('/avatar/:id', userMW.verify, (req, res) => {
if (req.params["id"]) {
r.table("files").get(req.params['id']).pluck("file").run(req.conn)
.then((file) => {
res.json(file);
})
.error((err) => {
console.log(err)
res.end()
})
}
});
示例8: createCanvas
/**
* Create a new canvas.
* @param name Unique name of the canvas (used as the ID).
*/
createCanvas(name: string) {
let canvas: DrawGaiden.Canvas = {
id: name,
width: config.defaultCanvas.width,
height: config.defaultCanvas.height,
layers: config.defaultCanvas.layers,
backgroundColor: config.defaultCanvas.backgroundColor
};
return r.table('canvases')
.insert([canvas])
.run(this.conn);
}