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
Ernesto Tagwerker
December 03, 2016
Programming
93
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
Transcript
35 slides
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?
More Decks by Ernesto Tagwerker
See All by Ernesto Tagwerker
An AI Ops Team for a Services Business
etagwerker
0
42
Teaching Claude Code to Upgrade Rails at Blue Ridge Ruby '26
etagwerker
0
110
Teaching Code How To Upgrade Rails at Philly.rb
etagwerker
0
64
Teaching Claude Code to Upgrade Rails (Artificial Ruby NYC, March, 2026)
etagwerker
0
110
Stuck in the Tar Pit at Sin City Ruby '24
etagwerker
1
380
Lightning Talk: Escaping the Tar Pit
etagwerker
1
210
Fortify Rails Webinar
etagwerker
0
2.8k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
350
Lessons Learned from Open Source
etagwerker
0
160
Other Decks in Programming
See All in Programming
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
220
Promiseの向こう側へコンテキストを届ける ― proposal-async-context
seriseri
1
1.2k
RaspberryPi 5で軽くはじめるk3sとtailscaleを用いたホームサーバー構築 (1)
nasum
0
460
はじめてのKubernetesコントリビューション
nasa9084
0
340
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
210
R言語プログラミング
profjoesuzuki
0
160
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
2
530
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
660
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
240
Agentic AI with the Power of Jakarta EE
ivargrimstad
0
260
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
300
Featured
See All Featured
Between Models and Reality
mayunak
4
620
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Test your architecture with Archunit
thirion
2
2.5k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
680
Everyday Curiosity
cassininazir
0
440
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
310
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
620
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
380
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
760