Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Intro to Databases (Rails Girls PHL)
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ernesto Tagwerker
December 03, 2016
Programming
90
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Intro to Databases (Rails Girls PHL)
A quick intro to databases for Rails Girls PHL.
Ernesto Tagwerker
December 03, 2016
More Decks by Ernesto Tagwerker
See All by Ernesto Tagwerker
An AI Ops Team for a Services Business
etagwerker
0
27
Teaching Claude Code to Upgrade Rails at Blue Ridge Ruby '26
etagwerker
0
90
Teaching Code How To Upgrade Rails at Philly.rb
etagwerker
0
50
Teaching Claude Code to Upgrade Rails (Artificial Ruby NYC, March, 2026)
etagwerker
0
85
Stuck in the Tar Pit at Sin City Ruby '24
etagwerker
1
360
Lightning Talk: Escaping the Tar Pit
etagwerker
1
190
Fortify Rails Webinar
etagwerker
0
2.8k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
330
Lessons Learned from Open Source
etagwerker
0
150
Other Decks in Programming
See All in Programming
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
610
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
430
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.6k
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
160
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
Workers Cache を知る
syumai
0
370
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
520
phperだってパンチカードでコーディングしたい
o0h
PRO
0
340
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.8k
Crafting Experiences
bethany
1
380
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
Ruling the World: When Life Gets Gamed
codingconduct
0
400
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
Building Adaptive Systems
keathley
44
3.2k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
480
Designing for humans not robots
tammielis
254
26k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Transcript
Intro to Databases Rails Bridge Philadelphia December 2016
Ernesto Tagwerker @etagwerker
Spreadsheets
None
From spreadsheets to databases
None
None
None
Primary Keys
Primary Keys
None
Relational Databases
Relations (Tables)
Relational Database Management Systems (DBMS)
MySQL Postgres SQLite* MS SQL Server and more … DBMS
Alternatives
Databases in Rails
$ rails new --help # database # (options: mysql/oracle/postgresql/sqlite3/ frontbase/ibm_db/sqlserver/jdbcmysql/
jdbcsqlite3/jdbcpostgresql/jdbc) $ rails new polls —database=postgresql $ rails new polls # defaults to sqlite3
Where is the database?
SQL (for data) • Create • Retrieve • Update •
Delete
Rails Migrations # db/migrate/20161124163416_create_topics.rb class CreateTopics < ActiveRecord::Migration def change
create_table :topics do |t| t.string :title t.text :description t.timestamps null: false end end end
Rails Migrations $ rake db:migrate == 20161124163416 CreateTopics: migrating =====================================
-- create_table(:topics) -> 0.0496s == 20161124163416 CreateTopics: migrated (0.0497s) ============================
Rails Migrations CREATE TABLE `topics` ( `id` int(11) NOT NULL
AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `description` text, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, PRIMARY KEY (`id`) )
SQL (for table definitions) • Create table • Modify table
• Drop table
Models # app/models/vote.rb class Vote < ActiveRecord::Base belongs_to :user belongs_to
:topic end # app/models/topic.rb class Topic < ActiveRecord::Base has_many :votes end # app/models/user.rb class User < ActiveRecord::Base has_many :votes end
Models (create) $ rails console > Topic.create(title: 'Intro to Database',
description: 'This is awesome!') SQL (1.4ms) INSERT INTO `topics` (`title`, `description`, `created_at`, `updated_at`) VALUES ('Intro to Database', 'This is awesome!', '2016-11-24 16:57:13', '2016-11-24 16:57:13') => #<Topic id: 1, title: "Intro to Database", description: "This is awesome!", created_at: "2016-11-24 16:57:13", updated_at: "2016-11-24 16:57:13">
Models (retrieve) > topic = Topic.find 1 Topic Load (1.6ms)
SELECT `topics`.* FROM `topics` WHERE `topics`.`id` = 1 LIMIT 1 => #<Topic id: 1, title: "Intro to Database", description: "This is awesome!", created_at: "2016-11-24 16:57:13", updated_at: "2016-11-24 16:57:13">
None
Models (update) > topic.title = "Intro to Databases" => "Intro
to Databases" > topic.save SQL (2.3ms) UPDATE `topics` SET `title` = 'Intro to Databases', `updated_at` = '2016-11-24 17:00:47' WHERE `topics`.`id` = 1 => true
Models (destroy) > topic.delete SQL (10.0ms) DELETE FROM `topics` WHERE
`topics`.`id` = 1 => #<Topic id: 1, title: "Intro to Databases", description: "This is awesome!", created_at: "2016-11-24 16:57:13", updated_at: "2016-11-24 17:00:47">
Models (count) > Topic.count (2.1ms) SELECT COUNT(*) FROM `topics` =>
0
How to use models
Topic.find 123 Topic.first Topic.last Topic.count To interact with tables
topic = Topic.find 123 topic.title = “New title” topic.save To
modify records
Thank you!
Questions?