Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Mongo on Demand
Max Mulatz
February 04, 2016
Programming
0
33
Mongo on Demand
Talk at vienna.rb #30
NoSQL in PostgreSQL without giving up your beloved relational database.
Max Mulatz
February 04, 2016
Tweet
Share
More Decks by Max Mulatz
See All by Max Mulatz
My Message on Commit Messages
klappradla
0
210
Thanx vienna.rb
klappradla
0
29
Reactive Ruby - building web apps with JRuby and Ratpack
klappradla
1
180
jRuby and Ratpack
klappradla
1
130
MINASWAN 4 EVERYONE
klappradla
0
96
Other Decks in Programming
See All in Programming
Jetpack Composeでの画面遷移
iwata_n
0
200
Jetpack Compose best practices 動画紹介 @GoogleI/O LT会
takakitojo
0
410
CSE360 Tutorial 07
javiergs
PRO
0
110
OSS貢献を気軽にしたい Let's Go Talk #1
yuyaabo
1
130
短納期でローンチした新サービスをJavaで開発した話/launched new service using Java
eichisanden
6
2k
オブジェクト指向で挫折する初学者へ
deepoil
0
200
エンジニアによる事業指標計測のススメ
doyaaaaaken
1
190
BASE BANKチームの技術選定と歴史 / how to decide technology selection for startup
budougumi0617
0
1.6k
How we run a Realtime Puzzle Fighting Game on AWS Serverless
falken
0
260
Cybozu GoogleI/O 2022 LT会 - Input for all screens
jaewgwon
0
400
Gitlab CIでMRを自動生成する
forcia_dev_pr
0
120
UI Testing of Jetpack Compose Apps, AppDevCon
alexzhukovich
0
170
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
62
7.2k
How to Ace a Technical Interview
jacobian
265
21k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
5
520
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
15
950
Art, The Web, and Tiny UX
lynnandtonic
280
17k
No one is an island. Learnings from fostering a developers community.
thoeni
9
1.3k
Debugging Ruby Performance
tmm1
65
10k
Producing Creativity
orderedlist
PRO
334
37k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
100
5.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
15
36k
WebSockets: Embracing the real-time Web
robhawkes
57
5.4k
Building a Scalable Design System with Sketch
lauravandoore
448
30k
Transcript
MONGO ON DEMAND NOSQL IN POSTGRESQL
max klappradla
NoSQL "...data which is modeled in means other than the
tabular relations.." wikipedia
WHY?
None
{ "meta": { "disclaimer": "openFDA is a beta research project
and not for clinical use. While we make every effort to ensure that data is accurate, you should assume all results are unvalidated.", "license": "http://open.fda.gov/license", "last_updated": "2016-01-28", "results": { "skip": 0, "limit": 1, "total": 4160934 } }, "results": [ { "receivedate": "20040319", "patient": { "patientonsetage": "56", "reaction": [ { "reactionmeddrapt": "ARTHRALGIA" }, { "reactionmeddrapt": "OEDEMA PERIPHERAL" }, { "reactionmeddrapt": "PURPURA" } ], "patientonsetageunit": "801", "patientsex": "1", "drug": [ { "drugcharacterization": "2", "medicinalproduct": "PYOSTACINE (PRISTINAMYCIN)" }, { "drugcharacterization": "2", "openfda": { "product_ndc": [ "0004-1963", "0004-1964" ], "nui": [ "N0000011161", "N0000175488" ], "generic_name": [ "CEFTRIAXONE SODIUM" ], "spl_set_id": [ "9467f6c9-3e59-45c6-a1be-77200f2d4554" ], "pharm_class_cs": [ "Cephalosporins [Chemical/Ingredient]" ], "brand_name": [ "ROCEPHIN" ], "manufacturer_name": [ "Genentech, Inc." ], "unii": [ "75J73V1629" ], "rxcui": [ "204871", "105212" ], "spl_id": [ "86e3103c-9d8b-4693-b5db-3fd62330c754" ], "substance_name": [ "CEFTRIAXONE SODIUM" ], "product_type": [ "HUMAN PRESCRIPTION DRUG" ] }, "medicinalproduct": "ROCEPHIN" }, { "drugcharacterization": "2", "openfda": { "product_ndc": [ "55111-160", "55111-161", "55111-162", "0093-7181" ], "nui": [ "N0000175937", "N0000007606" ], "package_ndc": [ "16571-130-50", "55111-161-50", "61314-012-05", "17478-713-11", "17478-713-10", ], "generic_name": [ "OFLOXACIN", "OFLOXAXIN" ], "spl_set_id": [ "8db221b1-32f3-f6ca-e404-71f56a860d08", "1d19a6db-6da5-e7de-f929-2d18bdfa2cf5", "95b9fc17-9c94-4762-910c-df0bb0b2aa85", "7aab4449-3dda-4e2c-8e40-b3244a548bf5" ], "pharm_class_cs": [ "Quinolones [Chemical/Ingredient]" ], "unii": [ "A4P49JAZ9H" ], "rxcui": [ "207202", "312075", "198048", "198049", "198050", "242446" ], "route": [ "AURICULAR (OTIC)", "ORAL", "OPHTHALMIC" ], "application_number": [ "ANDA076407", "ANDA076182", "NDA019921", "ANDA091656", "ANDA076128", "ANDA078222", "ANDA090395", "ANDA076527", "ANDA076622", "ANDA076513", "ANDA076616", "ANDA202692", "ANDA078559",
{ "id": "100000000000000", "email": "vienna@rb.com", "first_name": "Vienna", "gender": "other", "last_name":
"Rb", "link": "https://www.facebook.com/vienna.rb", "locale": "de_AT", "name": "Vienna Rb", "timezone": "2", "updated_time": "2014-03-31T08:26:19+0000", "username": "viennarb", "verified": "false" } { "username":"vienna-rb", "bio":"", "website":"", "profile_picture":"http://instagram.com/123.jpg", "full_name":"", "counts":{"media":1,"followed_by":0,"follows":0}, "id":"1000000001" }
{ "preferences":{ "newsletter":false, "web_notifications":[ "Notifications::CommentOnUsersPost", "Notifications::AlsoCommentedPost", "Notifications::NewWallComment" ], "immediate_mail_notifications":[ "Notifications::AlsoCommentedPost",
"Notifications::LocationApproved", "Notifications::MeetingUpdated", "Notifications::NewWallComment" ], "daily_mail_notifications":[ "Notifications::NewUserPost", "Notifications::NewLocationPost", "Notifications::NewMeeting" ] } }
MONGO POSTGRES in
# Serialize a preferences attribute. class User < ActiveRecord::Base serialize
:preferences end # Serialize preferences using JSON as coder. class User < ActiveRecord::Base serialize :preferences, JSON end # Serialize preferences as Hash using YAML coder. class User < ActiveRecord::Base serialize :preferences, Hash end
None
JSON JSONB INDEXES, FUNCTIONS DOUBLICATED KEYS, PRESERVE ORDERING
CREATE TABLE users ( id serial not null, settings json
not null default '{}', preferences jsonb not null default '{}' ); CREATE
INSERT INTO users (settings) VALUES (1, '{ "newsletter":true, "interests":[ "biking",
"programming" ] }' ); INSERT
SELECT count(*) FROM users WHERE preferences ->> 'newsletter' = 'true';
SELECT count(*) FROM users WHERE preferences -> 'interests' ? 'biking'; SELECT count(*) FROM users WHERE preferences @> '{"newsletter":true}'; QUERY
CREATE INDEX idxpreferences_interests_exp ON users ((preferences->'interests')); CREATE INDEX idxpreferences_news_exp ON
users ((preferences->>'newsletter')); CREATE INDEX idxpreferences_gin ON users USING GIN (preferences); INDEX
DEMO
RAILS?
CREATE class CreateUsers < ActiveRecord::Migration def change create_table :users do
|t| t.string :name, null: false t.jsonb :preferences, null: false, default: '{}' end add_index :users, :preferences, using: :gin end end
USE class User < ActiveRecord::Base scope :programmers, -> { where('preferences
@> ?', {interests: ['programming']}.to_json ) } end user.preferences['newsletter'] = true user.save #=> updates whole preferences document
ACCESS class User < ActiveRecord::Base store_accessor :preferences, :newsletter, :interests end
user = User.new(newsletter: false, interests: ['runninng']) user.preferences #=> {"newsletter" ... user.newsletter #=> false user.preferences[:newsletter] #=> false
DEMO