Databases and the MVC Model

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
Advertisements

1 Introduction to Web Application Introduction to Data Base.
Exercise SELECT authorID, lastName FROM authors AuthorID FirstName
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 25 – Database: SQL, ADO and RDS Outline 25.1Introduction 25.2Relational Database Model 25.3Relational.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Pemrograman VisualMinggu …10… Page 1 MINGGU Ke Sepuluh Pemrograman Visual Pokok Bahasan: ADO.NET II Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 MySQL and JDBC.
Database: SQL and MySQL
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
THE WEBMASTERS: SENG + WAVERING.  On account of construction, we will be having class in room 1248 next week.
CS453: Databases and State in Web Applications (Part 2) Prof. Tom Horton.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
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.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Databases and the MVC Model
Chapter 1 Introduction.
Roles in the Database Environment
CS320 Web and Internet Programming SQL and MySQL
Database Programming in Java
Database Mysql Hayk Avdalyan.
MongoDB Er. Shiva K. Shrestha ME Computer, NCIT
 2012 Pearson Education, Inc. All rights reserved.
LINQ to DATABASE-2.
JDBC.
Databases Intro (from Deitel)
CS1222 Using Relational Databases and SQL
ADO.NET Entity Framework
Tools for Memory: Database Management Systems
CIS 336 Competitive Success/snaptutorial.com
CIS 336 Education for Service-- snaptutorial.com.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Structured Query Language (SQL) William Klingelsmith
System And Application Software
Database.
CS1222 Using Relational Databases and SQL
Chapter 22 - SQL, MySQL, DBI and ADO
PHP and MySQL.
LINQ to DATABASE-2.
Structured Query Language
Data Model.
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
PHP and MySQL.
MVC Controllers.
MVC Controllers.
Chapter 3 Database Management
Painted Shadows - Not Allowed
MVC Controllers.
CS1222 Using Relational Databases and SQL
Databases and the MVC Model
Database SQL.
Lecuter-1.
CS1222 Using Relational Databases and SQL
Presentation transcript:

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

Today’s focus Ye Olde Internet Browser 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 http://flic.kr/p/ar4nLn

Rails uses a DBMS Ye Olde Internet Browser DB Server View Router Controller 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

You make model classes to use the database Browser Ye Olde Internet You make model classes to use the database DB Server View Router Controller Model

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 AuthorISBN Publishers Titles AuthorID FirstName LastName YearBorn 1 Ayn Rand 1905 2 Peter Benchley 1940 AuthorISBN Publishers PublisherID PublisherName 1 Bobbs Merrill 2 Random House ISBN AuthorID 0452273331 1 0452011876 1400064562 2 Titles ISBN Title EditionNumber YearPublished Description PublisherID 0452273331 The Fountainhead 1 1943 … 0452011876 Atlas Shrugged 1957 2 1400064562 Jaws 1973

How DBs are used by apps Pre-deployment of app: At runtime of app: Tables created Maybe “seeded” with data At runtime of app: CRUD table rows NOTE: Tables/columns don’t change Authors AuthorID FirstName LastName YearBorn 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 AuthorID FirstName LastName YearBorn 1 Ayn Rand 1905 2 Peter Benchley 1940 SELECT * FROM Authors SELECT AuthorID, LastName FROM Authors SELECT * FROM Authors WHERE YearBorn > 1910 SELECT * FROM Authors WHERE LastName LIKE 'r%' SELECT * FROM Authors WHERE LastName REGEXP '[a-r]*' SELECT * FROM Authors WHERE LastName REGEXP '[a-r]*' ORDER BY LastName 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

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 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 Authors

Example Mapping from Class to Table first_name : string last_name : string year_born : integer Authors You get ID for free Authors AuthorID FirstName LastName YearBorn 1 Ayn Rand 1905 2 Peter Benchley 1940

How to make a model class Run Rails command: $ rails g model Author … What it generates: Model class: used by controller classes app/models/authors.rb class Authors DB migration class: used to setup tables in DB db/migrate/20141030033652_create_authors.rb Test class: used to test your model class test/models/author_test.rb Demo time!