Skip to content

Instantly share code, notes, and snippets.

View neumino's full-sized avatar

Michel neumino

View GitHub Profile
@neumino
neumino / gist:0916562008c620ba81c7
Last active August 29, 2015 14:14
Pipe the changfeed of a table in the same table.
// Require the current branch [next] of rethinkdbdash (probably 1.16.5)
var r = require('rethinkdbdash')();
// Set up the infinite domino effect
r.table('test').changes()('new_val').without('id').toStream()
.on('error', handleError)
.pipe(r.table('test').toWritableStream())
.on('error', handleError);
// Start the domino effect
@neumino
neumino / gist:d125dee5258494af6818
Last active August 29, 2015 14:14
One new thing with rethinkdbdash 1.16
var r = require('rethinkdbdash')();
var bluebird = require('bluebird');
var assert = require('assert');
bluebird.coroutine(function*() {
try {
var result = yield r.table('users').get("[email protected]").update(function(user) {
return { age: user("age").add(1) }
});
assert.equal(result.replaced, 1);
    {
        "name": "John",
        "mark": 70,
        "id": 1,
        "course": "Mathematics"
    },
    {
        "name": "John",
        "mark": 90,
// Suppose that there are 10 digits somewhere in the string
// Extract the 10 digits, and concatenate them
r.add(r.args(
r.expr('(123) 456-7890').match('^[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*([\\d]{1})[^\\d]*$')("groups")("str")
))

Here's a proposal:

join takes 2 arguments:

  • left_key that can be a string or a function (it's the same thing as what eqJoin require for the first argument
  • other_table: the second sequence is a table.

The command has the following options:

  • index - <string>: The name of the index used on other_table to perform the join, default to the primary key.
  • group - <string>: If this option is undefined, the join command would operate as it does now. If it's set to a string, it would group the right values into an array and inject in the field (or just inject the document is unique is set to true (the value for group). The default is undefined.
  • outer_join - whether the join should behave like an outer join or not. By default true. The value is always false when group is false.
var r = require('rethinkdbdash')();
setInterval(function() {
r.table("logs").insert({
date: r.now()
}).run({noreply: true})
, 1000)
r.table("logs").changes().run().then(function(feed) {
var config = require(__dirname+'/config.js');
var thinky = require(__dirname+'/lib/thinky.js')(config);
var r = thinky.r;
var Errors = thinky.Errors;
var util = require(__dirname+'/test/util.js');
var assert = require('assert');
thinky.r.dbCreate("foo").run().then(function(result) {
from pytz import timezone
import pickle
timezone = timezone('US/Pacific')
print timezone
f = open('test.txt', 'w')
pickle.dump(timezone, f)
f.close()
r.db('test').table('foo').update(function(doc) {
return doc.merge({foo: {channel: doc("id").add(doc("name")) }})
})
r.table('story').indexCreate('storyAndId', [r.row("storyAuthor"), r.row("id")] )
var authorId = '1';
r.table('comment').orderBy({index: r.desc('created')})
.eqJoin(function(comment) {
return [authorId, comment("parentId")]
}, r.table('story'), {index: "storyAndId"})
.limit(20)