0% found this document useful (0 votes)
140 views

Chapter 14

This chapter discusses working with databases in web development. It covers SQL and NoSQL databases, how they are used in websites, and common SQL commands like SELECT, INSERT, UPDATE and DELETE. It also discusses database design principles, relationships between tables, and how to access and manage databases from PHP and Node.js applications. Transactions and ensuring data integrity are also covered.

Uploaded by

washma.zubair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views

Chapter 14

This chapter discusses working with databases in web development. It covers SQL and NoSQL databases, how they are used in websites, and common SQL commands like SELECT, INSERT, UPDATE and DELETE. It also discusses database design principles, relationships between tables, and how to access and manage databases from PHP and Node.js applications. Transactions and ensuring data integrity are also covered.

Uploaded by

washma.zubair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Fundamentals of Web Development

Third Edition by Randy Connolly and Ricardo Hoar

Chapter 14

Working with Databases

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
In this chapter you will learn . . .
• The role that databases play in web development

• What are the most common commands in SQL

• How to access SQL databases in PHP

• How NoSQL database systems work

• How to work with NoSQL databases using Node

• What is GraphQL

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Databases and Web Development
In this book, the relational DBMS used will be either SQLite or MySQL ( or
MariaDB) There are many other open-source and proprietary relational DBMS
alternates to MySQL, such as PostgreSQL, Oracle Database, IBM DB2, and
Microsoft SQL Server.

In addition to relational database systems, there are non-relational models for


database systems that will also be explored in this chapter. These systems
are usually categorized with the term NoSQL and includes systems such as
Cassandra and MongoDB

Databases provide data integrity (accuracy and consistency of data) and


can reduce the amount of data duplication

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
The Role of Databases in Web Development

Databases provide a way to


implement an important software
design principles: namely, that
one should separate that which
varies from that which stays the
same.

On the web the visual


appearance (i.e., the HTML and
CSS) is that which stays the
same, while the data content is
that which varies.
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
How websites use databases

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Managing Databases
Running the SQLite lab exercises for PHP and Node, you don't actually have
to install anything, since it is a file-based, in-memory database.

To run the PHP exercises in this chapter's lab, you will need access to
MySQL. If you have installed XAMPP to run your PHP, MySQL is already
installed.

To run the Node exercises in this chapter, you will either need to install
MongoDB or make use of a cloud service such as MongoDB Atlas.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Managing Databases (Tools)
The tools available to you range from the original command-line approach,
through to the modern workbench, where an easy-to-use toolset supports the
most common operations.

• Command-Line Interface

• phpMyAdmin

• MySQL Workbench

• SQLite Tools

• MongoDB Tools

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
SQL
A table is the principal unit of storage in a database. It is a two-dimensional
container for data that consists of records (rows); each record has the same
number of columns. These columns are called fields, which contain the actual
data. Each table will have a primary key—a field (or sometimes combination
of fields) that is used to uniquely identify each record in a table.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Table Design
Data types that are akin to those in a statically typed programming language
and contribute to data integrity. (BIT,BLOB,CHAR(n),
DATE,FLOAT,INT,VARCHAR(n))

As we discuss database tables and their design, it will be helpful to have a


condensed way to visually represent a table. It is normally enough to see the
field names, and perhaps their data types.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Foreign Key
Foreign key relates a
field in one table to a
primary key in another
table

Tables that are linked via


foreign keys are said to
have a relationship.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Table relationships
Most often, two related
tables will be in a one-to-
many relationship.

There are two other


table relationships: the
one-to-one relationship
and the many-to-many
relationship.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Composite Key
• Note that in this example, the two foreign keys in the intermediate table are
combined to create a composite key. Alternatively, the intermediate table
could contain a separate primary key field.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
SELECT Statement
The SELECT statement is
used to retrieve data from
the database. The term
query is sometimes used
as a synonym for running
a SELECT statement

The result of a SELECT


statement is a block of
data typically called a
result set which can be
ordered
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
WHERE Clause
The WHERE keyword is used to supply a comparison expression that the data
must match in order for a record to be included in the result set.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Join
Retrieving data from
multiple tables is more
complex and requires the
use of a join.

When two tables are joined


via an inner join, records
are returned if there is
matching data (typically
from a primary key in one
table and a foreign key in
the other) in both tables
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Grouping
When you don’t want every
record in your table but
instead want to perform
some type of calculation on
multiple records and then
return the results you use
one or more aggregate
functions such as SUM()
or COUNT(); these are
often used in conjunction
with the GROUP BY
keywords.
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
INSERT Statements

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
UPDATE and DELETE Statements

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Transactions
A transaction refers to a sequence of steps that are treated as a single unit,
and provide a way to gracefully handle errors and keep your data properly
consistent when errors do occur.

Local transaction support in the DBMS can handle the problem of an error
with START TRANSACTION, COMMIT, and ROLLBACK commands.
/* By starting the transaction, all database modifications within will only be permanently saved in the database if they all work */
START TRANSACTION
INSERT INTO orders . . .
INSERT INTO orderDetails . . .
UPDATE inventory . . .
/* if we have made it here everything has worked so commit changes */
COMMIT
LISTING 14.2 SQL commands for transaction processing

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Distributed Transactions
Transactions involving multiple hosts,
several of which we may have no control
over; are typically called distributed
transactions.

A distributed transaction not only requires


local database writes, but also the
involvement of an external credit card
processor, an external legacy ordering
system, and an external shipping system.
Because there are multiple external
resources involved, distributed
transactions are much more complicated
than local transactions.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Data Definition Statements
All of the SQL examples that you will use in this book are examples of the
data manipulation language features of SQL, that is, SELECT, UPDATE,
INSERT, and DELETE. There is also a Data Definition Language (DDL) in
SQL, which is used for creating tables, modifying the structure of a table,
deleting tables, and creating and deleting databases.

Most tools such as the phpMyAdmin, offer interfaces that allow you to
manipulate table indirectly through a GUI.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Database Indexes and Efficiency
Consider the worst-case scenario for searching where we compare a query
against every single record. If there are n elements, we say it takes O(n) time
to do a search (we would say “Order of n”).

In comparison, a balanced binary tree data structure can be searched in


O(log2 n) time.

It is possible to achieve O(1) search speed—that is, one operation to find the
result—with a hash table data structure.

No matter which data structure is used, the application of that structure to


ensure results are quickly accessible is called an index.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Database Index

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Working with SQL in PHP
With PDO, the basic database
connection algorithm is:

1. Connect to the database.


2. Handle connection errors.
3. Execute the SQL query.
4. Process the results.
5. Free resources and close
connection.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Connecting to a Database
With MySQL databases, you supply:

• the host or URL of the database // modify these variables for your installation
server, the $connectionString =
"mysql:host=localhost;dbname=bookcrm";
• database name, and // you may need to add this if db has UTF data
• the database user name and $connectionString .= ";charset=utf8mb4;";
password. $user = "testuser";
$pass = "mypassword";
With SQLite databases, you only need to $pdo = new PDO($connectionString,
supply the path to the file: $user, $pass);
LISTING 14.4 Connecting to a database with PDO
$pdo = new PDO('sqlite:./movies.db'); (object-oriented)

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Storing Connection Details
A common solution is to store connection details in defined constants within a file
named config.inc.php.

require_once('protected/config.inc.php’);
$pdo = new PDO(DBCONNSTRING,DBUSER,DBPASS);

<?php
define('DBHOST', 'localhost');
define('DBNAME', 'bookcrm');
define('DBUSER', 'testuser');
define('DBPASS', 'mypassword');
define('DBCONNSTRING',"mysql:host=". DBHOST. ";dbname=". DBNAME);
?>
LISTING 14.2 Defining connection details via constants in a separate file (config.inc.php)
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Handling Connection Errors
Unfortunately not every database connection always works. The approach in PDO for
handling connection errors uses try...catch exception- handling blocks.

It should be noted that PDO has three different error-handling approaches/modes.

try {
$pdo = new PDO(DBCONNSTRING,DBUSER,DBPASS);
...
}
catch (PDOException $e) {
die( $e->getMessage() );
}
LISTING 14.7 Handling connection errors with PDO
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Executing the Query
If the connection to the database is successfully created, then you are ready
to construct and execute the query.

$sql = "SELECT * FROM Categories ORDER BY CategoryName";


$result = $pdo->query($sql);
LISTING 14.9 Executing a SELECT query

$sql = "DELETE FROM artists WHERE LastName = 'Connolly'";


// returns number of rows that were deleted
$count = $pdo->exec($sql);
LISTING 14.10 Executing a DELETE query

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Processing the Query Results
If you are running a SELECT query, then you will want to do something with
the retrieved result set, such as displaying it, or performing calculations on it,
or searching for something in it.
$sql = "SELECT * FROM Paintings ORDER BY Title";
$result = $pdo->query($sql);

// fetch a record from result set into an associative array


while ($row = $result->fetch()) {
// the keys match the field names from the table
echo $row['ID']. " - ". $row['Title’];
echo "<br/>";
}
LISTING 14.11 Looping through the result set

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Fetching from a result set

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Fetching into an Object
Given the following simple $sql = "SELECT * FROM Books";
class we can have PHP $result = $pdo->query($sql);
populate an object of type // fetch a record into an object of type Book
Book while ( $b = $result->fetchObject('Book') ) {
// the property names match the table field names
class Book { echo 'ID: '. $b->ID . '<br/>’;
echo 'Title: '. $b->Title . '<br/>’;
public $ID;
echo 'Year: '. $b->CopyrightYear . '<br/>’;
public $Title; echo 'Description: '. $b->Description . '<br/>’;
public $CopyrightYear; echo '<hr>';
public $Description; }
LISTING 14.13 Populating an object from a result set (PDO)
}

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Freeing Resources and Closing Connection

When you are finished retrieving and displaying your requested data, you
should release the memory used by any result sets and then close the
connection so that the database system can allocate it to another process.

try {
$pdo = new PDO(DBCONNSTRING,DBUSER,DBPASS);
...
// closes connection and frees the resources used by the PDO object
$pdo = null;
}
LISTING 14.15 Closing the connection

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Working with Parameters
We can use the same
page design to display
different data records

How does a PHP page


“know” which data
record to display?

query string $pdo = new PDO(DBCONNSTRING,DBUSER,DBPASS);


$sql = "SELECT * FROM Galleries WHERE GalleryID=". $_GET["id"];
parameters $result = $pdo->query($sql);

LISTING 14.16 Integrating user input into a query (first attempt)

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Sanitizing User Data
The last example is vulnerable to SQL injection attack (Chapter 16)

Sanitization uses capabilities built into database systems to remove any


special characters from a desired piece of text.

In MySQL, user inputs can be partly sanitized using the quote() method.

However, it is recommended that you use prepared statements.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Prepared Statements
// retrieve parameter value from query string
A prepared statement $id = $_GET['id’];
is actually a way to /* method 1 – notice the ? parameter */
improve performance $sql = "SELECT Title, CopyrightYear FROM Books WHERE ID = ?";
for queries that need to $statement = $pdo->prepare($sql);
$statement->bindValue(1, $id); // bind to the 1st ? parameter
be executed multiple $statement->execute();
times.
/* method 2 */
$sql = "SELECT Title, CopyrightYear FROM Books WHERE ID = :id";
$statement = $pdo->prepare($sql);
$statement->bindValue(':id', $id);
$statement->execute();
LISTING 14.17 Using a prepared statement

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Named Parameters
/* technique named parameters */
$sql = "INSERT INTO books (ISBN10, Title, CopyrightYear, ImprintId,
A named parameter
ProductionStatusId, TrimSize, Description) VALUES (:isbn,
assigns labels in prepared :title,:year,:imprint,:status,:size,:desc) ";
SQL statements which are $statement = $pdo->prepare($sql);
then explicitly bound to $statement->bindValue(':isbn', $_POST['isbn']);
variables in PHP, reducing $statement->bindValue(':title', $_POST['title']);
opportunities for error. $statement->bindValue(':year', $_POST['year']);
$statement->bindValue(':imprint', $_POST['imprint']);
$statement->bindValue(':status', $_POST['status']);
It is also possible to pass $statement->bindValue(':size', $_POST['size']);
$statement->bindValue(':desc', $_POST['desc']);
in parameter values within $statement->execute();
an array to the execute()
method and cut out the LISTING 14.18 Using names parameters (part b)
calls to bindValue()

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Using Transactions
$pdo = new PDO($connString,$user,$pass);
// turn on exceptions so that exception is thrown if error occurs
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
...
try {
// begin a transaction
$pdo->beginTransaction();
$pdo->exec("INSERT INTO Categories (CategoryName) VALUES ('Philosophy')");
$pdo->exec("INSERT INTO Categories (CategoryName) VALUES ('Art')");
// if we arrive here, it means that no exception was thrown
// which means no query has failed, so we can commit the transaction
$pdo->commit();
} catch (Exception $e) {
// we must rollback the transaction since an error occurred
// with insert
$pdo->rollback();
}

LISTING 14.20 Using transactions (PDO)

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Designing Data Access
Database details such as connection strings and table and field names are
examples of externalities. These details tend to change over the life of a web
application.

Initially, the database for our website might be a SQLite database on our
development machine; later it might change to a MySQL database on a data
server, and even later, to a relational cloud service. Ideally, with each change
in our database infrastructure, we would have to change very little in our code
base.

One simple step might be to extract all PDO code into separate functions or
classes and use those instead.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Designing Data Access (ii)
class DatabaseHelper { $statement = null;
public static function createConnection($values=array()) { If (count($parameters) > 0) {
$connString = $values[0]; // Use a prepared statement if parameters
$user = $values[1]; $statement = $pdo->prepare($sql);
$password = $values[2]; $executedOk = $statement->execute($parameters);
$pdo = new PDO($connString,$user,$password); if (! $executedOk) {
$pdo->setAttribute(PDO::ATTR_ERRMODE, throw new PDOException;
PDO::ERRMODE_EXCEPTION); }
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, } else {
PDO::FETCH_ASSOC); // Execute a normal query
return $pdo; $statement = $pdo->query($sql);
} if (!$statement) {
public static function runQuery($pdo, $sql, $parameters=array()) throw new PDOException;
{ }
// Ensure parameters are in an array }
if (!is_array($parameters)) { return $statement;
$parameters = array($parameters); }
} } //end class

LISTING 14.21 Encapsulating database access via a helper class

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Designing Data Access (iii)
try {
$conn = DatabaseHelper::createConnectionInfo(array(DBCONNECTION, DBUSER, DBPASS));
$sql = "SELECT * FROM Paintings ";
$paintings = DatabaseHelper::runQuery($conn, $sql, null);
foreach ($paintings as $p) {
echo $p["Title"];
}
$sql = "SELECT * FROM Artists WHERE Nationality=?";
$artists = DatabaseHelper::runQuery($conn, $sql, Array("France"));
}

Illustrates two example uses of this class. While an improvement, we still have a
database dependency in this code with the SQL statements and field names.
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
A table gateway
class PaintingDB {
private static $baseSQL = "SELECT * FROM Paintings ";
public function __construct($connection) { public function getAllForArtist($artistID) {
$this->pdo = $connection; $sql = self::$baseSQL . " WHERE Paintings.ArtistID=?";
} $statement = DatabaseHelper::runQuery($this->pdo, $sql,
public function getAll() { Array($artistID));
$sql = self::$baseSQL; return $statement->fetchAll();
$statement = DatabaseHelper::runQuery($this->pdo, }
$sql, null); public function getAllForGallery($galleryID) {
return $statement->fetchAll(); $sql = self::$baseSQL . " WHERE Paintings.GalleryID=?";
} $statement = DatabaseHelper::runQuery($this->pdo, $sql,
public function findById($id) { Array($galleryID));
$sql = self::$baseSQL . " WHERE PaintingID=?"; return $statement->fetchAll();
$statement = DatabaseHelper::runQuery($this->pdo, $sql, }
Array($id)); }
return $statement->fetch();
}

LISTING 14.22 Sample gateway class for painting table

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
NoSQL Databases
NoSQL (which stands for Not-only-SQL) is category of database software that
describes a style of database that doesn’t use the relational table model of
normal SQL databases.

NoSQL databases rely on a different set of ideas for data modeling that put
fast retrieval ahead of other considerations like consistency.

Systems like DynamoDB, Firebase, and MongoDB now power thousands of


sites including household names like Netflix, eBay, Instagram, Forbes,
Facebook, and others.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Why (and Why Not) Choose NoSQL?
NoSQL systems handle huge datasets better than relational systems.

NoSQL databases aren’t the best answer for all scenarios. SQL databases
use schemas for a very good reason: they ensure data consistency and data
integrity.

The data in most NoSQL database systems is identified by a unique key. The
key-value organization often results in faster retrieval of data in comparison to
a relational database

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Key-Value Stores
Key-value stores alone are quite
straightforward in that every value,
whether an integer, string, or other data
structure, has an associated key (i.e.,
they are analogous to PHP associative
arrays)

Here every value has a key. This allows


fast retrieval through means such as a
hash function, and precludes the need
for indexes on multiple fields as is the
case with SQL

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Document Store
Document Stores (also called document-oriented databases) associate keys
with values, but unlike key-value stores, they call that value a document.

• A document can be a binary file like a .doc or .pdf or a semi-structured


XML or JSON document.

• Most NoSQL systems are of this type. MongoDB, AWS DynamoDB,


Google FireBase, and Cloud Datastore are popular examples.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Relational data versus document store data

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Column Stores
In traditional relational database
systems, the data in tables is
stored in a row-wise manner. This
means that the fundamental unit of
data retrieved is a row.

Column Store systems store data


by column instead of by row,
meaning that fetches retrieve a
column of data and retrieving an
entire row requires multiple
operations.
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Graph Stores
In a Graph Store system (often
simply called graph databases),
data is represented as a network
or graph of entities and their
relationships.

Some examples of graph


databases include Neo4j,
OrientDB, and RedisGraph.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Working with MongoDB in Node
MongoDB MongoDB is an open-source, NoSQL, document-oriented
database. It can be used with PHP, it is much more commonly used with Node

You simply package your data as a JSON object, give it to MongoDB, and it
stores this object or document as a binary JavaScript object (BSON).

MongoDB does not support transactions

The ability to run on multiple servers means MongoDB can handle large
datasets

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Comparing relational databases to the
MongoDB data model

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Comparing a MongoDB query to an SQL query

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Working with the MongoDB Shell

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Accessing MongoDB Data in Node.js
const mongoose = require('mongoose');
// define a schema that maps to the structure in MongoDB
const bookSchema = new mongoose.Schema({
id: Number,
isbn10: String,
isbn13: String,
title: String,
require('dotenv').config(); …
console.log(process.env.MONGO_URL); },
const mongoose = require('mongoose'); category: {
mongoose.connect(process.env.MONGO_URL, main: String,
{useNewUrlParser: true, useUnifiedTopology: true}); secondary: String
const db = mongoose.connection; }
db.on('error', console.error.bind(console, });
'connection error:')); // now create model using this schema that maps to books
db.once('open', () => { collection in database
console.log('connected to mongo'); module.exports = mongoose.model('Book',
}); bookSchema,'books');
LISTING 14.23 Connecting to MongoDB using Mongoose LISTING 14.24 Creating a Mongoose model

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Web service using MongoDB
// get our data model app.get('/api/books/:isbn', (req,resp) => {
const Book = require('./models/Book.js’); // use mongoose to retrieve all books from Mongo
Book.find({isbn10: req.params.isbn},
app.get('/api/books', (req,resp) => { function(err, data) {
// use mongoose to retrieve all books if (err) {
Book.find({}, function(err, data) { resp.json({ message: 'Book not found' });
if (err) { } else {
resp.json({ message: resp.json(data);
'Unable to connect to books' }); }
} else { });
// return JSON retrieved by Mongo as response });
resp.json(data);
}
});
});

LISTING 14.25 Web service using MongoDB data and Mongoose ORM
Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Key Terms
aggregate functions data duplication inner join one-to-one single-master
relationship replication
binary tree database join
normalization ORM (Object- SQL
clickstream key-value stores
Relational
distributed SQL script
column store local transactions
transactions Mapping)
table
commodity servers many-to-many
document stores phpMyAdmin
table gateway
composite key relationship
failover clustering prepared statement
transaction
connection multiple-master
fields primary key
two-phase commit
connection string replication
foreign key query
database MySQL
GraphQL record
data integrity named parameter
graph store result set
Data Definition NoSQL
hash table sanitization
Language
one-to-many
index sharding
(DDL) relationship

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved
Copyright

This work is protected by United States copyright laws and is


provided solely for the use of instructors in teaching their
courses and assessing student learning. Dissemination or sale of
any part of this work (including on the World Wide Web) will
destroy the integrity of the work and is not permitted. The work
and materials from it should never be made available to students
except by instructors using the accompanying text in their
classes. All recipients of this work are expected to abide by these
restrictions and to honor the intended pedagogical purposes and
the needs of other instructors who rely on these materials.

Copyright © 2021, 2018, 2015 Pearson Education, Inc. All Rights Reserved

You might also like