Sobes.tech
Junior — Middle

Describe your experience in developing and working with databases during programming.

sobes.tech AI

Answer from AI

During my development work in Python, I have worked with various databases, including relational ones (PostgreSQL, SQLite) and NoSQL (MongoDB). To interact with relational databases, I used ORM libraries such as SQLAlchemy and Django ORM, which allowed me to write more readable and maintainable code without directly writing SQL queries.

An example of a simple connection and query using SQLite and the sqlite3 module:

import sqlite3

conn = sqlite3.connect('example.db')
cursor = conn.cursor()

# Creating a table
cursor.execute('''CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)''')

# Inserting data
cursor.execute("INSERT INTO users (name) VALUES (?)", ('Ivan',))
conn.commit()

# Fetching data
cursor.execute('SELECT * FROM users')
rows = cursor.fetchall()
for row in rows:
    print(row)

conn.close()

I also have experience optimizing queries, creating indexes, and working with transactions to ensure data integrity.