Summary
We looked at the basics of using SQLite in three ways: directly, via an access layer, and via the SQLAlchemy ORM. We have to create SQL DDL statements; we can do this directly in our applications or in an access layer. We can also have DDL built by the SQLAlchemy class definitions. To manipulate data, we'll use SQL DML statements; we can do this directly in a procedural style, or we can use our own access layer or SQLAlchemy to create the SQL.
Design considerations and trade-offs
One of the strengths of the sqlite3
module is that it allows us to persist distinct items. As we're using a database that supports concurrent writes, we can have multiple processes updating the data, relying on SQLite to handle concurrency via its own internal locking.
Using a relational database imposes numerous restrictions. We must consider how to map our objects to rows of tables in the database:
We can use SQL directly, using only the supported SQL column types and largely eschewing object-oriented classes...