Database access¶
-
class
mandarin.database.Base(**kwargs)¶ The base class of the class hierarchy.
When called, it accepts no arguments and returns a new featureless instance that has no instance attributes and cannot be given any.
-
__init__(**kwargs)¶ 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.
-
metadata= MetaData(bind=None)¶
-
-
mandarin.database.gin_index(name: str, tsvector: sqlalchemy_utils.types.ts_vector.TSVectorType) → sqlalchemy.sql.schema.Index¶ Create a new GIN index.
- Parameters
name – The name of the index.
tsvector – The tsvector to use for the index.
- Returns
The Index object.
-
mandarin.database.gist_index(name: str, tsvector: sqlalchemy_utils.types.ts_vector.TSVectorType) → sqlalchemy.sql.schema.Index¶ Create a new GiST index.
- Parameters
name – The name of the index.
tsvector – The tsvector to use for the index.
- Returns
The Index object.
-
mandarin.database.to_tsvector(*, a: Optional[List[sqlalchemy.sql.schema.Column]] = None, b: Optional[List[sqlalchemy.sql.schema.Column]] = None, c: Optional[List[sqlalchemy.sql.schema.Column]] = None, d: Optional[List[sqlalchemy.sql.schema.Column]] = None, regconfig: str = 'pg_catalog.english') → sqlalchemy_utils.types.ts_vector.TSVectorType¶ Create a new weighted tsvector type.
- Parameters
a – A
listof columns that should be in theAweighting group.b – A
listof columns that should be in theBweighting group.c – A
listof columns that should be in theCweighting group.d – A
listof columns that should be in theDweighting group.regconfig – The dictionary to use in the tsvector conversion.
- Returns
The created
sqlalchemy_utils.TSVectorType.
Tables¶
-
class
mandarin.database.tables.Album(**kwargs)¶ An album, composed of multiple songs.
-
id¶
-
title¶
-
description¶
-
involvements: List[mandarin.database.tables.albuminvolvements.AlbumInvolvement]¶
-
songs¶
-
genres¶
-
search¶
-
involve(people: Iterable[Person], role: Role) → List[mandarin.database.tables.albuminvolvements.AlbumInvolvement]¶ Involve a list of people with this album, and return the resulting involvements.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.AlbumInvolvement(**kwargs)¶ The involment of a person in an album.
-
person_id¶
-
person¶
-
album_id¶
-
album¶
-
role_id¶
-
role¶
-
classmethod
make(session: sqlalchemy.orm.session.Session, **kwargs) → T¶ Find the item with the specified name, or create it if it doesn’t exist.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
- Returns
The retrieved or created item.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
classmethod
unmake(session: sqlalchemy.orm.session.Session, **kwargs) → None¶ Find the item with the specified name, and delete it if it exists.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.AuditLog(**kwargs)¶ A record of an action done by an user.
-
id¶
-
user_id¶
-
user¶
-
action¶
-
timestamp¶
-
obj¶
-
-
class
mandarin.database.tables.File(**kwargs)¶ A file that has been uploaded to Mandarin.
-
id¶
-
name¶
-
mime_type¶
-
mime_software¶
-
uploader_id¶
-
uploader¶
-
used_as_layer¶
-
classmethod
make(session: sqlalchemy.orm.session.Session, **kwargs) → T¶ Find the item with the specified name, or create it if it doesn’t exist.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
- Returns
The retrieved or created item.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
classmethod
unmake(session: sqlalchemy.orm.session.Session, **kwargs) → None¶ Find the item with the specified name, and delete it if it exists.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.Genre(**kwargs)¶ A genre of music.
-
id¶
-
name¶
-
description¶
-
supergenre_id¶
-
supergenre¶
-
subgenres¶
-
songs¶
-
albums¶
-
search¶
-
classmethod
make(session: sqlalchemy.orm.session.Session, **kwargs) → T¶ Find the item with the specified name, or create it if it doesn’t exist.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
- Returns
The retrieved or created item.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
classmethod
unmake(session: sqlalchemy.orm.session.Session, **kwargs) → None¶ Find the item with the specified name, and delete it if it exists.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.Layer(**kwargs)¶ A single layer of a song.
-
id¶
-
name¶
-
description¶
-
song_id¶
-
song¶
-
file_id¶
-
file¶
-
search¶
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.Person(**kwargs)¶ A person who is referenced by at least one song in the catalog.
-
id¶
-
name¶
-
description¶
-
song_involvements¶
-
album_involvements¶
-
search¶
-
classmethod
make(session: sqlalchemy.orm.session.Session, **kwargs) → T¶ Find the item with the specified name, or create it if it doesn’t exist.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
- Returns
The retrieved or created item.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
classmethod
unmake(session: sqlalchemy.orm.session.Session, **kwargs) → None¶ Find the item with the specified name, and delete it if it exists.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.Role(**kwargs)¶ A role for a person involved with an album or a song.
-
id¶
-
name¶
-
description¶
-
album_involvements¶
-
song_involvements¶
-
search¶
-
classmethod
make(session: sqlalchemy.orm.session.Session, **kwargs) → T¶ Find the item with the specified name, or create it if it doesn’t exist.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
- Returns
The retrieved or created item.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
classmethod
unmake(session: sqlalchemy.orm.session.Session, **kwargs) → None¶ Find the item with the specified name, and delete it if it exists.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.Song(**kwargs)¶ A single song, composed from multiple layers.
-
id¶
-
title¶
-
description¶
-
disc¶
-
track¶
-
year¶
-
lyrics¶
-
album_id¶
-
album¶
-
layers¶
-
involvements: List[mandarin.database.tables.songinvolvements.SongInvolvement]¶
-
genres¶
-
search¶
-
involve(people: Iterable[Person], role: Role) → Set[mandarin.database.tables.songinvolvements.SongInvolvement]¶ Involve people with this song, assigning them the specified role, and return all the resulting involvements.
If the involvement already exists, it won’t be created, but it will be returned.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.SongInvolvement(**kwargs)¶ The involment of a person in a song.
-
person_id¶
-
person¶
-
song_id¶
-
song¶
-
role_id¶
-
role¶
-
classmethod
make(session: sqlalchemy.orm.session.Session, **kwargs) → T¶ Find the item with the specified name, or create it if it doesn’t exist.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
- Returns
The retrieved or created item.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
classmethod
unmake(session: sqlalchemy.orm.session.Session, **kwargs) → None¶ Find the item with the specified name, and delete it if it exists.
- Parameters
session – The session to be used in the query and creation.
kwargs – Arguments to use in the
filter_by()clause and in the item constructor.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-
-
class
mandarin.database.tables.User(**kwargs)¶ An user, as returned by OAuth2.
-
id¶
-
sub¶
-
name¶
-
nickname¶
-
picture¶
-
email¶
-
email_verified¶
-
updated_at¶
-
uploads¶
-
audit_logs¶
-
log(action: str, obj: Optional[int]) → mandarin.database.tables.auditlogs.AuditLog¶ Log an action and add it to the session.
-
set(**kwargs)¶ Set attributes from the
kwargs, without checking for non-existant key/columns.
-
update(**kwargs)¶ Set attributes from the
kwargs, ignoring non-existant key/columns.
-