Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RethinkDB Primer

RethinkDB Primer

A short introduction to RethinkDB

Avatar for Marcelo Alves

Marcelo Alves

April 09, 2015
Tweet

Other Decks in Programming

Transcript

  1. Features JSON data model Distributed joins, subqueries, aggregation and atomic

    updates Hadoop-style map/reduce Friendly web and command-line administration tools Multi-datacenter replication and failover Sharding and replication Queries are automatically parallelized and distributed
  2. Gem tyrion@kings-landing:~$ gem install rethinkdb [1] pry(main)> require "rethinkdb" [2]

    pry(main)> include RethinkDB::Shortcuts [3] pry(main)> r.connect(host: 'localhost', database: 'marvel').repl()
  3. Principles 1. ReQL embeds into your programming language. 2. All

    ReQL queries are chainable. 3. All queries execute on the server.
  4. Embeds into your Language [1] pry(main)> require "rethinkdb" [2] pry(main)>

    include RethinkDB::Shortcuts [3] pry(main)> r.connect(host: 'localhost', database: 'marvel').repl() [1] pry(main)> r.table('characters').get(1).delete.run
  5. Filter + Pluck + Order + Limit [1] pry(main)> r.table('snippets').

    [1] pry(main)* filter({lang: 'ruby'}). [1] pry(main)* pluck('id', 'title', 'created_at'). [1] pry(main)* order_by(r.desc('created_at')). [1] pry(main)* limit(10). [1] pry(main)* run()
  6. Group + Merge [1] pry(main)> r.table('invoices').group( [1] pry(main)* [r.row['date'].year(), r.row['date'].month()]

    [1] pry(main)* ).ungroup().merge( [1] pry(main)* {invoices: r.row['reduction'], month: r.row['group']} [1] pry(main)* ).without('reduction', 'group').order_by('month').run
  7. Geospatial [1] pry(main)> point1 = r.point(-122.423246,37.779388) [2] pry(main)> point2 =

    r.point(-117.220406,32.719464) [3] pry(main)> r.distance(point1, point2, {:unit => 'm'}).run [4] pry(main)> r.circle(point1, 2000).includes(point2).run