The seedbox.db.sqlalchemy.models Module

Provides database model compliant with sqlalchemy.

class seedbox.db.sqlalchemy.models.AppState(id, value=None)

Bases: sqlalchemy.ext.declarative.api.Base

Class representing an app state in the database

Parameters:
  • id (string) – primary key of app state (alias for name)
  • value (string, int, bool, or datetime) – value of the app state
dtype
get(key, default=None)

Overrides base class get method to handle primary key of app state

Parameters:
  • key – id/name of app state
  • default – default value if not found
Returns:

an appstate value attribute

Return type:

varies

get_value()

Retrieve the value of an instance of AppState

Returns:value of app state
Return type:varies
name
reset_value()

Resets the value associated with AppState to empty

set_value(value)

Sets the value of an instance of AppState

Parameters:value – the value of an app state instance
Raises TypeError:
 if value type does not map to supported type (string, int, boolean, datetime)
t_bool
t_datetime
t_int
t_string
update(values)

Make the model object behave like a dict.

Parameters:values – key-value pairs to update in database
class seedbox.db.sqlalchemy.models.HasId

Bases: object

Table mixin providing a class/table id attribute

id = Column(None, Integer(), table=None, primary_key=True, nullable=False)
class seedbox.db.sqlalchemy.models.HasTimestamp

Bases: object

Table mixin providing a class/table date attributes

created_at = Column(None, DateTime(), table=None, default=ColumnDefault(<function <lambda> at 0x7f0eb6df06e0>))
updated_at = Column(None, DateTime(), table=None, onupdate=ColumnDefault(<function <lambda> at 0x7f0eb6df0758>))
class seedbox.db.sqlalchemy.models.MediaFile(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base, seedbox.db.sqlalchemy.models.HasId

Class representing a media file in the database

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

compressed
error_msg
file_ext
file_path
filename
id
missing
size
skipped
synced
torrent_id
total_time
class seedbox.db.sqlalchemy.models.QueryTransformer(table, query)

Bases: object

Generates query based on formatted filter.

Provides the ability to transform a query filter into database query in the sqlalchemy compliant manner.

Parameters:
  • table (Base) – an instance of database table
  • query (Query) – an instance of database query
apply_filter(expression_tree)

Uses the filter to update the query

Parameters:expression_tree – query filter to apply
Returns:database query
Return type:Query
complex_operators = {'and': <function and_ at 0x7f0eb7e20e60>, 'not': <function not_ at 0x7f0eb7d30578>, 'or': <function or_ at 0x7f0eb7ae0398>}
operators = {'=>': <built-in function ge>, '>=': <built-in function ge>, '!=': <built-in function ne>, 'in': <function <lambda> at 0x7f0eb6dc6578>, '=<': <built-in function le>, '<=': <built-in function le>, '=': <built-in function eq>, '<': <built-in function lt>, '>': <built-in function gt>}
class seedbox.db.sqlalchemy.models.Torrent(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base, seedbox.db.sqlalchemy.models.HasId, seedbox.db.sqlalchemy.models.HasTimestamp

Class representing a torrent in the database

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at
error_msg
failed
id
invalid
media_files
name
purged
retry_count
state
updated_at
seedbox.db.sqlalchemy.models.purge_all_tables(engine)

Drops all the defined tables within the database

Parameters:engine – database engine instance
seedbox.db.sqlalchemy.models.to_table_name(klass_name)

Generate table name based on class name.

Convention is to take camel-case class name and rewrite it to an underscore form, e.g. ‘ClassName’ to ‘class_name’

Parameters:klass_name – name of class
Returns:properly formatted table name
Return type:string
seedbox.db.sqlalchemy.models.verify_tables(engine)

Creates all the defined tables within the database

Parameters:engine – database engine instance