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
0
77
Intro to Databases (Rails Girls PHL)
A quick intro to databases for Rails Girls PHL.
Ernesto Tagwerker
December 03, 2016
Tweet
Share
More Decks by Ernesto Tagwerker
See All by Ernesto Tagwerker
Teaching Claude Code to Upgrade Rails (Artificial Ruby NYC, March, 2026)
etagwerker
0
10
Stuck in the Tar Pit at Sin City Ruby '24
etagwerker
1
320
Lightning Talk: Escaping the Tar Pit
etagwerker
1
150
Fortify Rails Webinar
etagwerker
0
2.5k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
270
Lessons Learned from Open Source
etagwerker
0
120
Upgrading Rails: The Dual-Boot Way
etagwerker
1
490
Ruby 3.0 & Rails 6.1
etagwerker
0
210
RubyMem: The Leaky Gems Database for Bundler at Ruby Kaigi Takeout 2020
etagwerker
0
270
Other Decks in Programming
See All in Programming
20260320登壇資料
pharct
0
120
Migration to Signals, Signal Forms, Resource API, and NgRx Signal Store @Angular Days 03/2026 Munich
manfredsteyer
PRO
0
150
20260228_JAWS_Beginner_Kansai
takuyay0ne
5
620
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
400
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
1
160
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
470
SourceGeneratorのマーカー属性問題について
htkym
0
220
存在論的プログラミング: 時間と存在を記述する
koriym
5
500
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
500
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
190
Java 21/25 Virtual Threads 소개
debop
0
270
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
150
Featured
See All Featured
Music & Morning Musume
bryan
47
7.1k
Why Our Code Smells
bkeepers
PRO
340
58k
For a Future-Friendly Web
brad_frost
183
10k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
120
Speed Design
sergeychernyshev
33
1.6k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
280
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
650
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.2k
Navigating Weather and Climate Data
rabernat
0
150
Evolving SEO for Evolving Search Engines
ryanjones
0
170
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?