Skip to content

Instantly share code, notes, and snippets.

@neumino
Created September 5, 2014 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neumino/c7cd56479700fd01f035 to your computer and use it in GitHub Desktop.
Save neumino/c7cd56479700fd01f035 to your computer and use it in GitHub Desktop.
r.db('test').table('foo').update(function(doc) {
return doc.merge({foo: {channel: doc("id").add(doc("name")) }})
})
@cultofmetatron
Copy link

trying to make it so there will be a property on user.specificChannels and user.channels
where the value is name + '_error' and + '_success, inside is a channel property where the channel is computed by adding the user's specific id to the name.

var addGlobalUnique = function(name, type) {
  return r.execute(function() {
    return r.table('users')
    .update(function(user) {

      var channelHash = {};
      channelHash[name + '_error' ] = {
        channel: name + '_error_' + user('id'),
        read: true,
        write: false,
        type: type
      };
      channelHash[name + '_success'] = {
        channel: name + '_success_' + user('id'),
        read: true,
        write: false,
        type: type
      };

      return user.merge({
        specificChannels: channelHash,
        channels: channelHash
      })
    });
  })
};

@cultofmetatron
Copy link

this is what I'm currently getting with name=foobar

"foobar_error": {
"channel":  "foobar_error_var_13("id")" ,
"read": true ,
"type":  "test" ,
"write": false
} 

@neumino
Copy link
Author

neumino commented Sep 5, 2014

@cultofmetatron -- the string concatenation is done on the server, so you must use a ReQL term to perform it.

If you replace

channel: name + '_error_' + user('id'),

with

channel: r.expr(name).add('_error_').add(user('id')),

(and the same for _success), it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment