Opinionated persistence with SQLite
Project description
microcosm-sqlite
Opinionated data loading with SQLite.
While most distributed application runtimes will use a networked data store for mutable state, the usage patterns of data that is read-only at runtime are great fit for SQLite.
In particular, microcosm-sqlite
assumes that applications will
- Build data sets in advance and ship them as static artifacts (e.g. in source control)
- Load data immutable sets at runtime without loading entire data sets into memory
Writing Models
Persistent data is expected to use SQLAlchemy's declarative base classes. Because different data sets
may be shipped in different SQLite databases, each declarative base class needs to have a unique
name and a separate engine configuration, which is achieved by adding DataSet
as the base of the
declarative base class:
Base = DataSet.create("some_name")
class SomeModel(Base):
__tablename__ = "sometable"
id = Column(Integer, primary_key=True)
Using Stores
Basic persistence operations are abstracted through a store:
class SomeStore(Store):
@property
def model_class(self):
return SomeModel
store = SomeStore()
results = store.search()
Configuring SQLite
Each DataSet
defaults to using :memory:
storage, but can be customized in two ways:
-
The
SQLiteBindFactory
can be configured with custom paths:loader = load_from_dict( sqlite=dict( paths={ "some_name": "/path/to/database", }, ), ) graph = create_object_graph("example", loader=loader)
-
The
microcosm.sqlite
entrypoint can contain a mapping from a data set name to a function that returns a path.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file microcosm_sqlite-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: microcosm_sqlite-2.0.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c24013278555c906d275e05bd43ef2ca759b639f64423f135b38cb58adfc6341 |
|
MD5 | 9c202492830eaec672c75449b803c60f |
|
BLAKE2b-256 | 09e812cf5ae0dea41c045021243a5b34cc19c79ceceed69cdea7893e8c710958 |