Databases and the MVC Model

Slides:



Advertisements
Similar presentations
Oct 31, 2000Database Management -- Fall R. Larson Database Management: Introduction to Terms and Concepts University of California, Berkeley School.
Advertisements

Copyright © 2003 Addison-Wesley Your name here. Copyright © 2003 Addison-Wesley Overview of Information Systems What is the Internet? Why are databases.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
1 Intro to Info Tech Database Management Systems Copyright 2003 by Janson Industries This presentation can be viewed on line at:
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Database System Concepts and Architecture
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Introduction to Database Programming with Python Gary Stewart
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
MVC Controllers TestsMigrations Ye Olde Internet Model DB Server Router View Browser Today’s focus Controller.
Fundamental of Database Systems
Databases Stefano Grazioli.
Building Enterprise Applications Using Visual Studio®
CompSci 280 S Introduction to Software Development
Databases and the MVC Model
Introduction to Entity framework
Chapter 1 Introduction.
Roles in the Database Environment
Introduction to Entity Framework
Security: Exploits & Countermeasures
Security: Exploits & Countermeasures
Database Programming in Java
Designing software applications
Database Management:.
Information Systems Today: Managing in the Digital World
Object Relational DBMSs
Server Concepts Dr. Charles W. Kann.
CS1222 Using Relational Databases and SQL
Tools for Memory: Database Management Systems
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 2 Database Environment Pearson Education © 2009.
Chapter 2 Database Environment.
Database.
Chapter 22 - SQL, MySQL, DBI and ADO
Introduction to Databases Transparencies
PHP and MySQL.
2018, Fall Pusan National University Ki-Joune Li
Structured Query Language
Database Design Hacettepe University
CS1222 Using Relational Databases and SQL
Painted Shadows - Not Allowed
CS1222 Using Relational Databases and SQL
Databases and the MVC Model
Databases and the MVC Model
Database Management Systems
Security: Exploits & Countermeasures
Behavioral Modeling with UML
MVC Controllers.
MVC Controllers.
Security: Exploits & Countermeasures
Databases and the MVC Model
Chapter 3 Database Management
Security: Exploits & Countermeasures
MIS2502: Data Analytics MySQL and MySQL Workbench
Version Control with Git
Painted Shadows - Not Allowed
MVC Controllers.
CS1222 Using Relational Databases and SQL
Software Configuration Management.
Database SQL.
Chapter 2 Database Environment Pearson Education © 2009.
The Database Environment
Course Instructor: Supriya Gupta Asstt. Prof
Security: Attacks & Countermeasures
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management
CS1222 Using Relational Databases and SQL
Presentation transcript:

Databases and the MVC Model http://flic.kr/p/ar4nLn Databases and the MVC Model

Ye Olde Internet Browser Migrations DB Server View Router Controller Model

Today’s focus Ye Olde Internet Browser Migrations DB Server View Router Controller Model

SWEBOK Knowledge Areas Software Requirements Software Design Software Construction Software Testing Software Maintenance Software Configuration Management Software Engineering Management Software Engineering Process Software Engineering Models and Methods Software Quality Software Engineering Professional Practice Software Engineering Economics Computing Foundations Mathematical Foundations Engineering Foundations Today’s topic

Rails uses a DBMS Ye Olde Internet Browser Migrations DB Server View Router Controller Model

Database (DB): Organized collection of data Database Management System (DBMS): Controls the creation, maintenance, and use of a DB E.g.: MySQL, Postgres http://flic.kr/p/ar4nLn

Migrations set up the database Browser Migrations set up the database Migrations Ye Olde Internet DB Model classes use the database Server View Router Controller Model

Outline DBs and DBMSs Rails Object–Relational Mapping Migrations DBs and DBMSs Rails Object–Relational Mapping Rails Model Programming DB Model

Outline DBs and DBMSs Rails Object–Relational Mapping Migrations DBs and DBMSs Rails Object–Relational Mapping Rails Model Programming DB Model

Why use a DBMS? Data independence: Applications need not be concerned with how data is stored or accessed Provides a lot of functionality that would be silly to implement yourself: Sharing (network) Customizable security Integrity

Two key aspects of a DBMS Database model: How DB is structured and used Examples: Relational, Object-Oriented, Hierarchical Query language: Types of questions you can ask Examples: SQL, XQuery Relational model + SQL is most common and used by Rails

Relational Model Concepts http://en.wikipedia.org/wiki/File:Relational_model_concepts.png

Example Tables authors publishers id first_name last_name year_born 1 Ayn Rand 1905 2 Peter Benchley 1940 publishers id publisher_name 1 Bobbs Merrill 2 Random House

How DBs are used by apps Pre-deployment of app: At runtime of app: Create (empty) tables Rails migrations do this Maybe “seed” with data At runtime of app: CRUD table rows Rails model classes do this NOTE: Tables/columns don’t change authors id first_name last_name year_born 1 Ayn Rand 1905 2 Peter Benchley 1940

CRUD-to-SQL Mapping CRUD Operation SQL Statement Create INSERT Read (Retrieve) SELECT Update (Modify) UPDATE Delete (Destroy) DELETE For complete MySQL documentation, see: http://dev.mysql.com/doc/refman/5.5/en/sql-syntax-data-manipulation.html

Example SELECT Queries authors id first_name last_name year_born 1 Ayn Rand 1905 2 Peter Benchley 1940 SELECT * FROM authors SELECT id, last_name FROM authors SELECT * FROM authors WHERE year_born > 1910 SELECT * FROM authors WHERE last_name REGEXP '[a-r]*' SELECT * FROM authors WHERE last_name REGEXP '[a-r]*' ORDER BY last_name ASC For complete MySQL documentation, see http://dev.mysql.com/doc/refman/5.5/en/select.html, http://dev.mysql.com/doc/refman/5.5/en/pattern-matching.html

Outline DBs and DBMSs Rails Object–Relational Mapping Migrations DBs and DBMSs Rails Object–Relational Mapping Rails Model Programming DB Model

Rails Object-Relational Mapping (ORM) You make object-oriented classes Rails handles the SQL/DBMS DB Model

Quick Intro to UML Class Diagrams I use UML class diagrams a lot Rationale: Easier to see “big picture” relationships than in code Example model class: Box = class Class name Attributes w/ types first_name : string last_name : string year_born : integer Author

Classes Represent Sets of Possible Objects Class Diagram: Object Diagram Class Attribute values Object name first_name = “Ayn” last_name = “Rand” year_born = 1905 rand : Author first_name : string last_name : string year_born : integer Author first_name = “Peter” last_name = “Benchley” year_born = 1940 : Author

Example Mapping from Class to Table first_name : string last_name : string year_born : integer Author You get ID for free authors id first_name last_name year_born 1 Ayn Rand 1905 2 Peter Benchley 1940

What do objects map to? authors first_name = “Ayn” last_name = “Rand” year_born = 1905 : Author first_name = “Peter” last_name = “Benchley” year_born = 1940 : Author authors id first_name last_name year_born 1 Ayn Rand 1905 2 Peter Benchley 1940

What do objects map to? Rows! authors first_name = “Ayn” last_name = “Rand” year_born = 1905 : Author first_name = “Peter” last_name = “Benchley” year_born = 1940 : Author authors id first_name last_name year_born 1 Ayn Rand 1905 2 Peter Benchley 1940

Outline DBs and DBMSs Rails Object–Relational Mapping Migrations DBs and DBMSs Rails Object–Relational Mapping Rails Model Programming DB Model

Ye Olde Internet Browser Migrations Tests DB Server View Router Controller Model

Learn to Use the Rails Model Demo Videos: https://scott-fleming.github.io/web-dev-rails-git- tutorial/demo-07-mvc-model.html https://scott-fleming.github.io/web-dev-rails-git- tutorial/demo-08-model-validations-testing.html

Summary Rails Model Components DBs and DBMSs Rails DB Migrations Rails ORM http://flic.kr/p/aCLor3