riak-repl

Riak + JavaScript REPL

npm install riak-repl
32 downloads in the last month

Riak REPL

Install

$ npm install -g riak-repl

Use

$ riak-repl
Usage:
riak-repl <host:port> <bucket>
$ riak-repl localhost:8087 users

localhost:8087 (users) > create({email: 'pedro.teixeira@gmail.com'})
{ email: 'pedro.teixeira@gmail.com',
  _meta:
   { content_type: 'application/json',
     vtag: '6UG0ahMKmzjdV7bFP5KJGk',
     vclock: 'a85hYGBgzGDKBVIcypz/fgau2LUmgymRMY+Vweea8mm+LAA=' },
  _id: 'NWFSZCaHYOmUZqlFXS5VumsBHxl' }
localhost:8087 (users) > get('NWFSZCaHYOmUZqlFXS5VumsBHxl')
{ email: 'pedro.teixeira@gmail.com',
  _meta:
   { content_type: 'application/json',
     vtag: '6UG0ahMKmzjdV7bFP5KJGk',
     vclock: 'a85hYGBgzGDKBVIcypz/fgau2LUmgymRMY+Vweea8mm+LAA=' },
  _id: 'NWFSZCaHYOmUZqlFXS5VumsBHxl' }
localhost:8087 (users) > getAll()
[ { email: 'pedro.teixeira@gmail.com',
    _meta:
     { content_type: 'application/json',
       vtag: 'AY0sKVi92ArPwulWPqhRZ',
       vclock: 'a85hYGBgzGDKBVIcypz/fgau2LUmgymRMY+VwXmW8mm+LAA=' },
    _id: 'KoymZQKVsp2SaQtAGwe9XEiKeWT' },
  { email: 'daksjdksajd',
    _meta:
     { content_type: 'application/json',
       vtag: '3Wukh8rsqLuYsjL3kAYXWG',
       vclock: 'a85hYGBgzGDKBVIcypz/fgau2LUmgymRMY+V4fAV5dN8WQA=' },
    _id: 'Xjuu3tJBjWtXqXwW6XJayr97CBv' },
  { email: 'pedro.teixeira@gmail.com',
    _meta:
     { content_type: 'application/json',
       vtag: '40xrxqZ0nSCS4l9afCfMDn',
       vclock: 'a85hYGBgzGDKBVIcypz/fgau2LU2gymRMY+VwXyW8mm+LAA=' },
    _id: 'WmnGCoGJScBo7jKPTm9T1Vafwo4' },
  { a: 1,
    _meta:
     { content_type: 'application/json',
       vtag: '7HHq4ID4y5aXWTB1XMEIbo',
       vclock: 'a85hYGBgzGDKBVIcypz/fgau2LU2gymRMY+VwX6m8mm+LAA=' },
    _id: 'UPjJqTkbcdA79EaPfkKUdh9LcCM' },
  { email: 'pedro.teixeira@gmail.com',
    _meta:
     { content_type: 'application/json',
       vtag: '6UG0ahMKmzjdV7bFP5KJGk',
       vclock: 'a85hYGBgzGDKBVIcypz/fgau2LUmgymRMY+Vweea8mm+LAA=' },
    _id: 'NWFSZCaHYOmUZqlFXS5VumsBHxl' },
  { email: 'pedro.teixeira@gmail.com',
    _meta:
     { content_type: 'application/json',
       vtag: '5mEdqp0qYQq899WWPfNN20',
       vclock: 'a85hYGBgzGDKBVIcypz/fgau2LU2gymRMY+VgX2W8mm+LAA=' },
    _id: '52i8SRNh82H5DFovlkE2hwXYjai' },
  { a: 1,
    _meta:
     { content_type: 'application/json',
       vtag: 'g46TTjqxTJUxwPPGAciTN',
       vclock: 'a85hYGBgzGDKBVIcypz/fgau2LU2gymRMY+V4fkV5dN8WQA=' },
    _id: 'LKDh8bz15QaS0hItOQCNgzyrk9R' } ]
localhost:8087 (users) >

Promises

You can also assign values to variables:

localhost:8087 (users) > var user = get('52i8SRNh82H5DFovlkE2hwXYjai');
localhost:8087 (users) > user
{ email: 'pedro.teixeira@gmail.com',
  _meta:
   { content_type: 'application/json',
     vtag: '5mEdqp0qYQq899WWPfNN20',
     vclock: 'a85hYGBgzGDKBVIcypz/fgau2LU2gymRMY+VgX2W8mm+LAA=' },
  _id: '52i8SRNh82H5DFovlkE2hwXYjai' }

In this case, the user variable will contain a promise, which is a promise for the value.

You can then use some proxy methods:

localhost:8087 (users) > get('52i8SRNh82H5DFovlkE2hwXYjai').get('_id')
52i8SRNh82H5DFovlkE2hwXYjai

You can also use promises as values in Riak command function calls, they get properly resolved:

localhost:8087 (users) > get(getAll().get(0).get('_id'))
{ a: 1,
  _meta:
   { content_type: 'application/json',
     vtag: '4eh9bB6b49L69q1x2xQgxP',
     vclock: 'a85hYGBgzGDKBVIcypz/fgau2LUmgymRMY+VIVNS9TRfFgA=' },
  _id: '45drJcTA48xQKUvcmPp62fyjBly' }

You can even set properties to the promise in plain JavaScript and they will get copied into the resulting value:

localhost:8087 (users) > u = get('Z7LqCcdgHnkgeoDurHAm6Kq3tLq'); u.caneco = 456; save(u);

Commands:

create(doc)

get(id)

getAllKeys()

getAll()

update(doc)

save(doc)

del(id)

del(doc)

destroy(id)

destroy(doc)

Callbacks

You can add a callback to as a last argument to any of these commands.

npm loves you