AbstractDatabase

AbstractDatabase defines operations for the underlying database, which can be either SQL or MongoDB. It provides a unified interface that abstracts away the differences in database implementations.

Abstract Interfaces

class quantnet_controller.core.abstractdatabase.AbstractDatabase[source]

AbstractDatabase class

handler(model='Blob')[source]

return the table handler

static get_broker(broker: Broker) Broker[source]

Get the broker instance

static drop_database(broker: Broker, **kwargs)[source]

Drop the entire DB

static drop(model, broker: Broker, **kwargs)[source]

Drop the current model (collection)

static add(model, data, broker: Broker, **kwargs)[source]

Insert data into the database table or collection.

Parameters:
  • model (enum DBModel) – table or collection.

  • data (dict) – data to insert

Returns:

the inserted data with id

Return type:

tuple (id, data) or tuple list [(id, data)…]

Example:

add(DBmodel.Blob, {"name":"alice", "remote":"bob"})
static get(model, id, broker: Broker, **kwargs)[source]

Get the records from the database table or collection. It allows filtering based on “id”

Parameters:
  • model (enum DBModel) – table or collection

  • id (either index string or filter dict) – id of data

Returns:

data

Return type:

dict or None

Example:

get(DBmodel.Blob, "1234")
get(DBmodel.Blob, {"name":"alice"})
static find(model, broker: Broker, **kwargs) list[source]

Find all records of the database table or collection.

Parameters:

model – table or collection

Returns:

data or list of data

Return type:

list of dicts or empty list

Example:

find(DBmodel.Blob)
static update(model, id, key, value, broker: Broker, **kwargs)[source]
Update with {key:value} the database table or collection based on the id.

If nothing matching the id, nothing happens.

Parameters:
  • model (enum DBModel) – table or collection

  • id (index str or filter dict) – id of data

  • key (string) – data key

  • value (string) – data value

Example:

update(DBmodel.Blob, "1234", key = "name", value="alice")
static upsert(model, id, *args, broker: Broker, **kwargs)[source]

It updates a record if exists or adds a new record if it does not. Unmodified fields retain their original values.

param model: table or collection type model: enum DBModel param id: id of data type id: index str or filter dict param args: new data type args: dicts

Example:

upsert(DBmodel.Blob, "1234", {"name":"alice"}, {remote":"bob})
upsert(DBmodel.Blob, {"name":"alice"}, {"name":"charlie"}, {remote":"bob})
static delete(model, id, broker: Broker, **kwargs)[source]

Remove records from the database table or collection, with the option to filter by “id”.

Parameters:
  • model (enum DBModel) – table or collection

  • id (either index string or filter dict) – id of data

Returns:

number of items deleted

Return type:

int

Example:

delete(DBmodel.Blob, "1234")
delete(DBmodel.Blob, {"name":"alice", "remote": "bob"})
static exist(model, id, broker: Broker, **kwargs)[source]

Verify the existence of records in the database, with the option to filter by “id”

Parameters:
  • model (enum DBModel) – table or collection

  • id (either index string or filter dict) – id of data

Returns:

result

Return type:

boolean

Example:

exist(DBmodel.Blob, "1234")