Xiaonuo Gantan's Articles
Xiaonuo loves writing Python programs to solve problems and implement systems. His research and work interests include data mining, web server architecture and relational or document-based database systems.
Migrate SQLAlchemy Databases with Alembic
Alembic Alembic is a lightweight database migration tool for SQLAlchemy. It is created by the author of SQLAlchemy and it has become the de-facto standard tool to perform migrations on SQLAlchemy backed databases. Database Migration in SQLAlchemy A database migration usually changes the schema of a database, such as adding a column or a constraint, […]
Read MoreSQLAlchemy Expression Language, More Advanced Usage
Overview In the previous article SQLAlchemy Expression Language, Advanced Usage, we learned the power of SQLAlchemy’s expression language through a three table database including User, ShoppingCart, and Product. In this article, we are going to review the concept of materialised path in SQLAlchemy and use it to implement product containing relationships, where certain products may […]
Read MoreSQLAlchemy Expression Language, Advanced Usage
Expression Language One of the core components of SQLAlchemy is the Expression Language. It is allows the programmer to specify SQL statements in Python constructs and use the constructs directly in more complex queries. Since the expression language is backend-neutral and comprehensively covers every aspect of raw SQL, it is closer to raw SQL than […]
Read MoreUnderstanding Python SQLAlchemy’s Session
What are SQLAlchemy Sessions? What does the Session do? One of the core concepts in SQLAlchemy is the Session. A Session establishes and maintains all conversations between your program and the databases. It represents an intermediary zone for all the Python model objects you have loaded in it. It is one of the entry points […]
Read MoreSQLAlchemy Association Tables
Association Tables In our previous articles, we used an association table to model many-to-many relationships between tables, such as the relationship between Department and Employee. In this article, we are going to dive deeper into the association table concept and see how we can use it to further solve more complicated problems. DepartmentEmployeeLink and Extra […]
Read MoreSQLAlchemy ORM Examples
ORM Recap In one of the previous articles, we briefly went through an example database with two tables department and employee where one department can have multiple employees and one employee can belong to arbitrary number of departments. We used several code snippets to demonstrate the power of SQLAlchemy’s expression language and show how to […]
Read MoreSQLAlchemy – Some Commonly Asked Questions
Common Questions Before we dive deeper into SQLAlchemy, let’s answer a possible list of questions regarding the ORM: Can you prevent SQLAlchemy from automatically creating a schema? Instead, can you bind SQLAlchemy models to an existing schema? Is there a performance overhead when using SQLAlchemy, compared to writing raw SQL? If so, how much? If […]
Read MoreOverview of SQLAlchemy’s Expression Language and ORM Queries
Overview In the previous article, we made a comparison between SQLAlchemy and other Python ORMs. In this article, we are going to take a deeper look at SQLAlchemy’s ORM and Expression Language and use an example to showcase their empowering API and easy-to-understand Python structures. Not only does the SQLAlchemy ORM provide a way to […]
Read MorePython’s SQLAlchemy vs Other ORMs
Overview of Python ORMs As a wonderful language, Python has lots of ORM libraries besides SQLAlchemy. In this article, we are going to take a look at several popular alternative ORM libraries to better understand the big picture of the Python ORM landscape. By writing a script that reads and writes to a simple database […]
Read MorePython’s Django vs Ruby on Rails
Python vs Ruby Ruby is a dynamic, reflective, object-oriented general-purpose programming language which was designed and developed in the mid-1990s. Compared to Python, which treats code readability above everything else, the philosophy behind Ruby is that programmers should have the flexibility, freedom and power to write concise and compact code. The most important difference between […]
Read More