本文整理匯總了TypeScript中rethinkdb.db函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript db函數的具體用法?TypeScript db怎麽用?TypeScript db使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了db函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: doc
r.connect({ host: "localhost", port: 28015 }).then(function(conn: r.Connection) {
console.log("HI", conn);
const testDb = r.db("test");
r.table("players").hasFields("games_won").run(conn).then(cursorCallback);
r.table("players").hasFields({ "games_won": { "championships": true } }).run(conn).then(cursorCallback);
r.table("players").filter(r.row.hasFields("games_won").not()).run(conn).then(cursorCallback);
r.table("players").filter(r.row.hasFields({ "games_won": { "championships": true } }).not()).run(conn).then(cursorCallback);
testDb.tableCreate("users").run(conn).then(function() {
const users = testDb.table("users");
users.insert({ name: "bob" }).run(conn, function() {
});
users.filter(function(doc?) {
return doc("henry").eq("bob");
})
.between("james", "beth")
.limit(4)
.run(conn)
.then((cursor: r.Cursor) => {
cursor.toArray().then((rows: any[]) => {
console.log(rows);
});
});
});
});
示例2: function
r.dbCreate('howmidoin').run(conn, function(err, res) {
if(err) {}
console.log('second')
r.db('howmidoin').tableCreate('data').run(conn, function(err, res) {
if(err) {}
console.log('third')
});
});
示例3: 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);
});
});
示例4: PrepareTablesEvent
r.connect({host: 'localhost', port: 28015}, (err, conn) => {
if (err) throw err;
dbConnection = conn;
r.dbCreate('lingua').run(conn, (er, rtr) => {
//console.log(er);
});
db = r.db('lingua');
new PrepareTablesEvent().dispatch();
});
示例5: obtenerPosts
async function obtenerPosts(ctx) {
try {
let con = await r.connect(config);
let query = await r.db('blog').table('posts').orderBy(r.desc('fecha')).run(con);
let posts = await query.toArray();
ctx.body = posts;
} catch (e) {
ctx.status = 500;
ctx.body = {
status: ctx.status,
error: e.message
}
}
}
示例6: function
r.connect({ host: "localhost", port: 28015 }, function(err: Error, conn: r.Connection) {
console.log("HI", err, conn);
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);
testDb.tableCreate("users").run(conn, function(err, stuff) {
const users = testDb.table("users");
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);
});
});
});
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);
});
});
示例7: moment
router.post('/', (req: any, res) => {
if (req.body && req.body.email && req.body.password) {
r.db(config.DB_NAME).table('users').filter({ email: req.body.email }).run(req.conn)
.then((cursor) => {
cursor.next((err, row) => {
if (err && err.message.indexOf('No more rows ') > -1) {
const salt = bcrypt.genSaltSync(saltRounds);
if (!salt) res.status(500).end('User registration failed try again later.');
const hash = bcrypt.hashSync(req.body.password, salt);
if (!hash) res.status(500).end('User registration failed try again later.');
const refresh_token = crypto.randomBytes(20).toString('hex');
if (!refresh_token) res.status(500).end('User registration failed try again later.');
r.table("users").insert({ isAdmin: false, email: req.body.email, password: hash, refresh_token: refresh_token }).run(req.conn)
.then((result) => {
const exp = moment().add(3, "months").valueOf();
const user = { userId: result.generated_keys[0], email: req.body.email, expires: exp, refresh_token: refresh_token, access_token: jwtoken.sign({ isAdmin: false }, config.SECRET, { issuer: result.generated_keys[0], expiresIn: exp }) };
res.set('Content-Type', 'application/json');
res.json(user);
}, (err) => {
console.log(err)
res.status(500).end('Internal server error');
})
} else if (row) {
res.end('An account already exists for this email address.');
}
})
},
(err) => {
console.log(err)
res.status(500).end('Internal server error');
})
} else if (req.body && !req.body.email) {
res.status(500).end('Email cannot be empty');
} else if (req.body && !req.body.password) {
res.status(500).end('Password cannot be empty');
}
});
示例8: crearPost
async function crearPost(ctx) {
try {
let { titulo, texto } = ctx.request.body;
let con = await r.connect(config);
let post = await r.db('blog').table('posts').insert({
titulo: titulo,
fecha: r.now(),
texto: texto
}).run(con);
ctx.body = {
post_id: post.generated_keys[0]
}
} catch (e) {
ctx.status = 500;
ctx.body = {
status: ctx.status,
error: e.message
}
}
}