From the course: Advanced SQL for Application Development
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Solution: Create an ORM model
From the course: Advanced SQL for Application Development
Solution: Create an ORM model
- [Narrator] Now, the solution to the challenge of creating a supplier class is shown here. It's a very simple pattern. We are going to build a class and we're going to build it off the base class which we have defined using the declarative statement we had created earlier. Now, we always need to specify a table name, and the table name has two underscores as a prefix and as a suffix. So we specify __tablename__ as suppliers. The supplier_id is an integer, so we specify an Integer, and since it's the primary key we pass in the primary_key Boolean and specify True. The supplier_name and supplier_region are both strings so we specify Columns of type String. And then finally, the supplier_level is an integer so we specify a Column of type Integer.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Overview of object-relational mapping1m 23s
-
Introduction to SQLAlchemy3m 5s
-
(Locked)
Installing SQLAlchemy1m 20s
-
(Locked)
Query with SQLAlchemy9m 47s
-
(Locked)
Limitations of ORM and cautionary advice2m 10s
-
(Locked)
Challenge: Create an ORM model37s
-
(Locked)
Solution: Create an ORM model54s
-
(Locked)
-
-
-
-