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
Intro to Databases (Rails Girls PHL)
Search
Ernesto Tagwerker
December 03, 2016
Programming
79
0
Share
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
Teaching Claude Code to Upgrade Rails at Blue Ridge Ruby '26
etagwerker
0
34
Teaching Code How To Upgrade Rails at Philly.rb
etagwerker
0
17
Teaching Claude Code to Upgrade Rails (Artificial Ruby NYC, March, 2026)
etagwerker
0
32
Stuck in the Tar Pit at Sin City Ruby '24
etagwerker
1
330
Lightning Talk: Escaping the Tar Pit
etagwerker
1
160
Fortify Rails Webinar
etagwerker
0
2.6k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
290
Lessons Learned from Open Source
etagwerker
0
130
Upgrading Rails: The Dual-Boot Way
etagwerker
1
500
Other Decks in Programming
See All in Programming
「OSSがあるなら自作するな」は AI時代も正しいか ── Build vs Adopt の新しい判断基準
kumorn5s
7
2.8k
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
160
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
450
Kubernetesを使わない環境にもCloud Nativeなデプロイを実現する / Enabling Cloud Native deployments without the complexity of Kubernetes
linyows
3
420
GitHubCopilotCLIをはじめよう.pdf
htkym
0
340
〜バイブコーディングを超えて〜 チームで実験し続けたAI駆動開発
tigertora7571
0
210
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
720
柔軟なPDFレイアウトエディタを支える型システム設計 — Discriminated UnionとConditional Typeの実践
minako__ph
1
140
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
160
[BalkanRuby 2026] Drop your app/services!
palkan
3
510
GoogleCloudとterraform完全に理解した
terisuke
1
200
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
0
210
Featured
See All Featured
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
300
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Making Projects Easy
brettharned
120
6.6k
We Are The Robots
honzajavorek
0
230
The Language of Interfaces
destraynor
162
26k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
Speed Design
sergeychernyshev
33
1.7k
Become a Pro
speakerdeck
PRO
31
5.9k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
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?