Junior — Middle
Have you ever worked with the declarative style of defining models in SQLAlchemy?
sobes.tech AI
Answer from AI
Yes, I have worked with the declarative style of defining models in SQLAlchemy. In this style, models are described as Python classes inheriting from a base class Base, using attributes to define columns and relationships.
Example:
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
email = Column(String, unique=True)
This approach allows for convenient description of table structures and using ORM for database operations.