flatisfy.database package¶
Submodules¶
flatisfy.database.base module¶
This module contains the definition of the declarative SQLAlchemy base.
flatisfy.database.types module¶
This modules implements custom types in SQLAlchemy.
-
class
flatisfy.database.types.
StringyJSON
(*args, **kwargs)[source]¶ Bases:
sqlalchemy.sql.type_api.TypeDecorator
Stores and retrieves JSON as TEXT for SQLite.
From https://avacariu.me/articles/2016/compiling-json-as-text-for-sqlite-with-sqlalchemy.
Note
The associated field is immutable. That is, changes to the data (typically, changing the value of a dict field) will not trigger an update on the SQL side upon
commit
as the reference to the object will not have been updated. One should force the update by forcing an update of the reference (by performing acopy
operation on the dict for instance).-
impl
¶ alias of
sqlalchemy.sql.sqltypes.TEXT
-
flatisfy.database.whooshalchemy module¶
This file comes from https://github.com/sfermigier/WhooshAlchemy.
WhooshAlchemy¶
Adds Whoosh indexing capabilities to SQLAlchemy models.
Based on Flask-whooshalchemy by Karl Gyllstrom (Flask is still supported, but not mandatory).
copyright: |
|
---|---|
copyright: |
|
license: | BSD (see LICENSE.txt) |
-
class
flatisfy.database.whooshalchemy.
IndexService
(config=None, whoosh_base=None)[source]¶ Bases:
object
-
after_commit
(session)[source]¶ Any db updates go through here. We check if any of these models have
__searchable__
fields, indicating they need to be indexed. With these we update the whoosh index for the model. If no index exists, it will be created here; this could impose a penalty on the initial commit of a model.
-
index_for_model_class
(model_class)[source]¶ Gets the whoosh index for this model, creating one if it does not exist. in creating one, a schema is created based on the fields of the model. Currently we only support primary key -> whoosh.ID, and sqlalchemy.TEXT -> whoosh.TEXT, but can add more later. A dict of model -> whoosh index is added to the
app
variable.
-
Module contents¶
This module contains functions related to the database.
-
flatisfy.database.
init_db
(database_uri=None, search_db_uri=None)[source]¶ Initialize the database, ensuring tables exist etc.
Parameters: - database_uri – An URI describing an engine to use. Defaults to in-memory SQLite database.
- search_db_uri – Path to the Whoosh index file to use.
Returns: A tuple of an SQLAlchemy session maker and the created engine.