⚜What is an ORM?

 ⚜What is an ORM? 

🛡ORM stands for Object Relational Mapper. It allows you to create and manage your databases easily using models.

🔱A typical model in SQLalchemy might be like that:


    __tablename__ = 'articles'

    id = Column(Integer, primary_key=True)

    title = Column(String)

    author = Column(String)

⚜The advantages are:

- You don't have to use SQL codes

- You don't have to create the table

- Easy CRUD operations.

Adding a record is as easy as

record = Article(title="Religion And Civilisation", author="A. True Scholar")


other queries demo:

session.query(Task).filter(record.id == some_id).first()


💠To Note:

- You might still need SQL for complex operations

- Change in models require the change to propagate. This is achieved using migrations.


No comments: