App Dev Part 4
App Dev Part 4
Models
• Models are used to store and retrieve data within the model component.
• THe model represents the data and it's business logic.
class User:
def __init__(self, name, email, password):
self.name = name
self.email = email
self.password = password
OR
But this data will be lost when the application is closed or restarted.
1. RDBMS
RDBMS, such as MySQL, PostgreSQL, Oracle, or SQL Server, provide persistent storage for structured data.
• Models in the MVC architecture can map to database tables, with each table representing an entity or
2. NoSQL
NoSQL databases, such as MongoDB, Cassandra, or Redis, provide flexible and schema-less storage for
unstructured or semi-structured data.
• Models can be designed to work with the data model provided by the NoSQL database.
• The model interacts with the NoSQL database using appropriate APIs or query languages, such as
MongoDB Query Language (MQL) for MongoDB.
3. File System
• Data can be stored in files, such as JSON or XML, and read or written by the model component.
• The model can interact with the file system to store and retrieve data.
• The model needs to handle file I/O operations, including reading, writing, and parsing the data.
4. SpreadSheets
• Data can be stored in multiple inter-linked sheets within single spreadsheet.
• Data is organized into rows and columns.
• It can serve as a persistent storage option for small-scale applications or when dealing with tabular data.
Relationship types
One to One
• A single instance of an entity is associated with a single instance of another entity.
• Example: A person has a single passport.
Many to Many
• Multiple instances of an entity are associated with multiple instances of another entity.
• Example: A student can register for many courses and many students can register for a single course.
ER Diagrams
• Entity-relationship diagrams (ERDs) are a type of graphical notation used to represent the relationships
between entities in a database.
• In Models, ERDs can be used to represent the relationship in different models of an application.
Entities:
• These represent the different types of data that are stored in the database.
• Example: Customer and order are entities in an e-commerce application.
Attributes:
• These represent the properties of the entities.
• Example: Customer name, email and phone number are attributes of the customer entity.
Relationships:
• These represents the connections between entities.
• Example: A customer entity can have a relationship with orders entity, indicating that customer placed the
order.
L4.4: SQL
Example
This statement creates a table named customers with the following columns:
The NOT NULL constraint on the customer_id column ensures that this column cannot be null. The
PRIMARY KEY constraint on the customer_id column ensures that this column is unique.
This statement creates a table called orders with the following columns: