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

Postgres & Rails 4: NoSQL in your SQL Database

Postgres & Rails 4: NoSQL in your SQL Database

Postgres 9.2 brings the best of NoSQL to SQL, with features like hstore, PLV8, and the JSON datatype. Come learn how Rails 4 takes advantage of these and other advanced Postgres features, and how you can make your application more flexible and performant. This workshop is great for anyone new to either PostgreSQL or Rails 4.

Mattt Thompson

April 13, 2013
Tweet

More Decks by Mattt Thompson

Other Decks in Programming

Transcript

  1. \l – List all Databases \d – List all Tables

    \x – Turn on/off Expanded Mode \? – List all of the Slash Commands 13೥4݄20೔౔༵೔
  2. make your application performant by putting as much of your

    application logic in your database as possible 13೥4݄20೔౔༵೔
  3. • hstore • plv8 • JSON Data Type • Full

    Text Indexing 13೥4݄20೔౔༵೔
  4. • hstore • plv8 • JSON Data Type • Full

    Text Indexing • soundex 13೥4݄20೔౔༵೔
  5. • hstore • plv8 • JSON Data Type • Full

    Text Indexing • soundex • PostGIS 13೥4݄20೔౔༵೔
  6. hstore UPDATE tab SET h = h || ('c' =>

    '3'); 13೥4݄20೔౔༵೔
  7. hstore UPDATE tab SET h = h || ('c' =>

    '3'); UPDATE tab SET h = delete(h, 'k1'); 13೥4݄20೔౔༵೔
  8. • Parse Documents / Fields into Tokens • Stem Tokens

    • Strip Stop Words 13೥4݄20೔౔༵೔
  9. • Parse Documents / Fields into Tokens • Stem Tokens

    • Strip Stop Words • Normalize Synonyms, Alternate Spellings, & Common Misspellings 13೥4݄20೔౔༵೔
  10. • Parse Documents / Fields into Tokens • Stem Tokens

    • Strip Stop Words • Normalize Synonyms, Alternate Spellings, & Common Misspellings • Create Indexes using GIN 13೥4݄20೔౔༵೔
  11. • Parse Documents / Fields into Tokens • Stem Tokens

    • Strip Stop Words • Normalize Synonyms, Alternate Spellings, & Common Misspellings • Create Indexes using GIN • Search for Full & Partial Results w/ Location in Document 13೥4݄20೔౔༵೔
  12. • Geometry types: points, linestrings, polygons, multipoints, multilinestrings, multipolygons, &

    geometrycollections. • Spatial operators: area, distance, length, & perimeter. 13೥4݄20೔౔༵೔
  13. • Geometry types: points, linestrings, polygons, multipoints, multilinestrings, multipolygons, &

    geometrycollections. • Spatial operators: area, distance, length, & perimeter. • Spatial operators: union, difference, symmetric difference, & buffers 13೥4݄20೔౔༵೔
  14. • Geometry types: points, linestrings, polygons, multipoints, multilinestrings, multipolygons, &

    geometrycollections. • Spatial operators: area, distance, length, & perimeter. • Spatial operators: union, difference, symmetric difference, & buffers • R-Tree over GIST Indexes 13೥4݄20೔౔༵೔
  15. • Geometry types: points, linestrings, polygons, multipoints, multilinestrings, multipolygons, &

    geometrycollections. • Spatial operators: area, distance, length, & perimeter. • Spatial operators: union, difference, symmetric difference, & buffers • R-Tree over GIST Indexes • Index selectivity support, for mixed spatial/ non-spatial queries. 13೥4݄20೔౔༵೔
  16. • Cache Digests / "Russian Doll" • Turbo Links •

    Live Streaming 13೥4݄20೔౔༵೔
  17. • Cache Digests / "Russian Doll" • Turbo Links •

    Live Streaming • Mass Assignment Protection 13೥4݄20೔౔༵೔
  18. • Cache Digests / "Russian Doll" • Turbo Links •

    Live Streaming • Mass Assignment Protection • Encrypted Cookies 13೥4݄20೔౔༵೔
  19. class CreateArticles < ActiveRecord::Migration def change execute "create extension hstore"

    create_table :articles do |t| t.string :name t.text :content t.date :published_on t.string :tags, array: true t.hstore :properties t.timestamps end end end 13೥4݄20೔౔༵೔
  20. create_table :examples do |t| t.uuid :unique_id t.inet :ip_address t.cidr :subnet

    t.macaddr :mac_address t.integer :array, :array => true end 13೥4݄20೔౔༵೔
  21. inetExample = InetExample.new inetExample.ip_address = '127.0.0.0/24' inetExample.ip_address # => #<IPAddr:

    IPv4:127.0.0.0/255.255.255.0> inetExample.save 13೥4݄20೔౔༵೔
  22. class CreateArticles < ActiveRecord::Migration def change execute "create extension hstore"

    create_table :articles do |t| t.string :name t.text :content t.date :published_on t.string :tags, array: true t.hstore :properties t.timestamps end end end 13೥4݄20೔౔༵೔
  23. • The Database is not just a "Big Hash in

    the Sky" 13೥4݄20೔౔༵೔
  24. • The Database is not just a "Big Hash in

    the Sky" • Shift computation and logic to the database to maximize performance 13೥4݄20೔౔༵೔
  25. • The Database is not just a "Big Hash in

    the Sky" • Shift computation and logic to the database to maximize performance • Use advanced Postgres data types for simpler data modeling & abstraction 13೥4݄20೔౔༵೔