rattail.importing.sqlalchemy

Data Importers for SQLAlchemy

class rattail.importing.sqlalchemy.FromSQLAlchemy(config=None, key=None, direction='import', fields=None, exclude_fields=None, fuzzy_fields=None, fuzz_factor=None, **kwargs)[source]

Base class for importers whose external data source is a SQLAlchemy query.

query()[source]

Must return the primary query which will define the data set. Default behavior is to leverage host_session and generate a query for the class defined by host_model_class.

class rattail.importing.sqlalchemy.ToSQLAlchemy(config=None, key=None, direction='import', fields=None, exclude_fields=None, fuzzy_fields=None, fuzz_factor=None, **kwargs)[source]

Base class for all data importers which support the common use case of targeting a SQLAlchemy ORM on the local side. This is the base class for all primary Rattail importers.

cache_local_data(host_data=None)[source]

Cache all local objects and data using SA ORM.

cache_query()[source]

Return the query to be used when caching “local” data.

cache_query_options()[source]

Return a list of options to apply to the cache query, if needed.

create_object(key, host_data)[source]

Create and return a new local object for the given key, fully populated from the given host data. This may return None if no object is created.

Note that this also adds the new object to the local database session.

delete_object(obj)[source]

Delete the given object from the local system (or not), and return a boolean indicating whether deletion was successful. Default logic will truly delete and expunge the local object from the session.

flush_create_update()[source]

Flush the database session, to send SQL to the server for all changes made thus far.

flush_delete()[source]

Flush the database session, to send SQL to the server for all changes made thus far.

get_single_local_object(key)[source]

Try to fetch the object from the local database, using SA ORM.

property model_mapper

Reference to the effective SQLAlchemy mapper for the local model class.

property model_table

Reference to the effective SQLAlchemy table for the local model class.

property simple_fields

Returns the list of column names on the underlying local model mapper.

property supported_fields

All/only simple fields are supported by default.