This repository is a Python data access and ORM learning project using SQLAlchemy SQL Toolkit and Object Relational Mapper version 1.4+ / 2.0. The Postgres DVD rental database is selected as the sample database as it has all the common table relationship patterns used in many typical web and standalone applications.
This learning project focus on the SQLAlchemy foundational usage:
- Connection
- Session
- Object & data mapping
- Object relationships
- one to one
- one to many
- many to many
- Use of built-in & user defined database functions
- Use docker Python API to setup test DVD rental database that can be reuse for each test session
pip install -r requirements.txt
pytest tests
Follow instruction in this Load PostgreSQL Sample Database article to setup sample database in Postgres if you are having problem use the Postgres database docker image in this repository.
The DVD rental database represents the business processes of a DVD rental store. The DVD rental database has many objects including:
- 15 tables
- 1 trigger
- 7 views
- 8 functions
- 1 domain
- 13 sequences
These are PEP-484 typing stubs for SQLAlchemy 1.4 and 2.0. They are released concurrently along with a Mypy extension which is designed to work with these stubs, which assists primarily in the area of ORM mappings. The stubs replace the use of the “sqlalchemy-stubs” package published by Dropbox. Differences include that these stubs are generated against 1.4’s API as well as some adjustments to the use of generics
A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.
This is a SQLAlchemy model generation tool that reads the structure of an existing database and generates the appropriate SQLAlchemy model code, using the declarative style if possible.
This tool was written as a replacement for sqlautocode, which was suffering from several issues (including, but not limited to, incompatibility with Python 3 and the latest SQLAlchemy version).
The following default command is used to generate a sample of the model that can be used as a reference to see the differences between your code and an auto gen code.
sqlacodegen --outfile models_from_sqlacodegen.py postgressql://postgres:postgres@localhost/dvdrental
Here's how we suggest you to go about proposing a change to this project:
- Fork this project to your account.
- Create a branch for the change you intent to make.
- Make your changes to your fork.
- Send a pull request from your fork's branch to our
main
branch.