Junior — Middle
Can you give examples of situations or projects where specific databases were used?
sobes.tech AI
Answer from AI
In Python projects, I used different databases depending on the requirements:
- PostgreSQL — for projects with relational data, where integrity and complex queries are important. For example, in a web application for managing orders and users.
- SQLite — for small applications or prototypes, where an embedded database without a separate server is needed.
- MongoDB — in projects with flexible data schemas, such as for storing logs or documents.
- Redis — as a cache and for storing sessions in high-load services.
Example of using SQLite in Python:
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')
cursor.execute('INSERT INTO users (name) VALUES (?)', ('Ivan',))
conn.commit()
cursor.execute('SELECT * FROM users')
print(cursor.fetchall())
conn.close()