Relational (SQL)
Store data in structured tables with predefined schemas (rows and columns). Use SQL (Structured Query Language) for querying. Examples: MySQL, PostgreSQL, SQL Server, Oracle
A database is an organized collection of structured information, or data, typically stored electronically in a computer system. Databases are designed to efficiently store, retrieve, and manage data, making it accessible for various applications and users.
Databases come in various types, each suited for different kinds of data and use cases.
Relational (SQL)
Store data in structured tables with predefined schemas (rows and columns). Use SQL (Structured Query Language) for querying. Examples: MySQL, PostgreSQL, SQL Server, Oracle
NoSQL
Designed for unstructured or semi-structured data with flexible schemas. Various models exist:
In-Memory
Store data primarily in main memory (RAM) for extremely fast read/write operations. Often used for caching or real-time analytics. Examples: Redis, Memcached, Hazelcast
Time Series
Optimized for time-stamped or time-series data, like monitoring metrics, IoT sensor data, or financial market data. Examples: InfluxDB, TimescaleDB, Prometheus
Cloud Databases
Managed database services offered by cloud providers. They handle infrastructure, scaling, backups, and maintenance. Can be SQL or NoSQL. Examples: Amazon RDS, Azure SQL Database, Google Cloud SQL, DynamoDB, Cosmos DB, Firestore
Search Engine Databases
Optimized for fast text search and analytics on large volumes of (often text-based) data. Examples: Elasticsearch, OpenSearch, Solr
An Object-Relational Mapper (ORM) is a library or framework that bridges the gap between object-oriented programming languages and relational databases. It allows developers to interact with database tables and rows using familiar programming objects and methods, abstracting away much of the raw SQL.
While ORMs offer convenience, it’s important to understand the trade-offs compared to writing SQL directly.
Code Example:
# Find a user by username using the ORMuser = session.query(User).filter_by(username='john').first()print(f"Found user: {user.name}, Email: {user.email}")
-- Find a user by username using direct SQLsql_query = "SELECT id, name, email FROM users WHERE username = %s"cursor.execute(sql_query, ('john',))user_row = cursor.fetchone()if user_row: print(f"Found user: {user_row[1]}, Email: {user_row[2]}")
Key Differences:
Feature | ORM Approach | Raw SQL Approach |
---|---|---|
Interaction Model | Object-oriented (Classes, Methods) | Procedural (SQL Statements) |
Query Writing | Programmatic (e.g., filter_by , select ) | Manual SQL string composition |
Abstraction Level | High (Hides SQL details) | Low (Direct database interaction) |
Portability | Generally higher across supported databases | Specific to SQL dialect |
Performance Control | Less direct; relies on ORM optimization | Full control over query optimization |
Learning Curve | Requires learning the ORM library | Requires learning SQL |
Boilerplate Code | Less for basic CRUD operations | More for mapping results to objects/structs |
Major cloud providers offer a wide range of managed database services.
AWS (Amazon Web Services)
GCP (Google Cloud Platform)
Azure (Microsoft Azure)