Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RethinkDB Primer
Search
Marcelo Alves
April 09, 2015
Programming
2
140
RethinkDB Primer
A short introduction to RethinkDB
Marcelo Alves
April 09, 2015
Tweet
Share
Other Decks in Programming
See All in Programming
RubyLSPのマルチバイト文字対応
notfounds
0
120
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
C++でシェーダを書く
fadis
6
4.1k
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
130
役立つログに取り組もう
irof
28
9.6k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
受け取る人から提供する人になるということ
little_rubyist
0
230
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
50
7.2k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
4 Signs Your Business is Dying
shpigford
180
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Done Done
chrislema
181
16k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Transcript
RethinkDB a primer
What is RethinkDB? An open-source distributed database built with .
"MongoDB with joins"
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
Getting Started
Installation tyrion@kings-landing:~$ brew update tyrion@kings-landing:~$ brew install rethinkdb
Set Up tyrion@kings-landing:~$ rethinkdb
Web UI
Clustering tyrion@kings-landing:~$ rethinkdb create –d /tmp/db1 tyrion@kings-landing:~$ rethinkdb –j –d
/tmp/db1 --port-offset 1
Clustering
Clustering
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()
Working with RethinkDB
Get All [1] pry(main)> r.table('characters').run
Get Document [1] pry(main)> r.table('characters').get(1).run
Filter [1] pry(main)> r.table('characters').filter({ age: 30 }).run
Update [1] pry(main)> r.table('characters').get(1).update({ age: 50}).run
Delete [1] pry(main)> r.table('characters').get(1).delete.run
ReQL
Principles 1. ReQL embeds into your programming language. 2. All
ReQL queries are chainable. 3. All queries execute on the server.
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
Chainable Queries [1] pry(main)> r.table('characters').run [2] pry(main)> r.table('characters').pluck('last_name').distinct().run [3] pry(main)>
r.table('characters').pluck('last_name').distinct().count().run
Server-Side Execution [1] pry(main)> query = r.table('characters').pluck('last_name').distinct [2] pry(main)> query.run
Examples
Filter + Contains [1] pry(main)> r.table('user').filter{|user| user['emails'].contains('
[email protected]
')}.run
Filter Dates [1] pry(main)> r.table("posts").filter{ |post| [2] pry(main)> post.during(r.time(2012, 1,
1, 'Z'), r.time(2013, 1, 1, 'Z')) [3] pry(main)> }.run
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()
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
Cool Features
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
HTTP [1] pry(main)> r.table('comics').insert(r.http('http://foo.com/comics')).run
Changes [1] pry(main)> r.table('games').changes().run.each{|change| p change}
None