Database context

class luna_events.db.db_context.DBContext(adaptor, streams, storageTime, encryptionCtx)

Class to work with database.

streams

streams with data

adaptor

A DBAdaptor instance

storageTime

A str, storage time setting

encryptionCtx

descriptors encryption context

async checkEvent(eventId, accountId=None, general=False)

Check event existence :type eventId: str :param eventId: event id :type accountId: str | None :param accountId: account id :type general: bool :param general: event type flag

Return type:

bool

Returns:

True if event exists otherwise False

property dbType: str

Returns a string, database type (‘postgres’ only).

async deleteDescriptors(filters)

Delete events descriptors

Parameters:

filters (DescriptorsFilters) – DescriptorsFilters instance

Return type:

list[str]

Returns:

event ids which descriptors have been deleted

async deleteEvents(targets, createTimeGte=None, createTimeLt=None, insertTimeGte=None, insertTimeLt=None, accountId=None, handlerId=None)

Delete events from database :type targets: list[str] :param targets: deletion info targets :type createTimeGte: datetime | None :param createTimeGte: lower create time boundary :type createTimeLt: datetime | None :param createTimeLt: upper create time boundary :type insertTimeGte: datetime | None :param insertTimeGte: lower insert time boundary :type insertTimeLt: datetime | None :param insertTimeLt: upper insert time boundary :type accountId: str | None :param accountId: account id :type handlerId: str | None :param handlerId: handler id

Returns:

event_id with deletion info attributes

Return type:

list with dicts for each deleted event

async deleteGeneralEvents(eventType=None, createTimeGte=None, createTimeLt=None, accountId=None)

Delete events from database :type eventType: str | None :param eventType: multiple general event type filter :type createTimeGte: datetime | None :param createTimeGte: lower create time boundary :type createTimeLt: datetime | None :param createTimeLt: upper create time boundary :type accountId: str | None :param accountId: account id

Returns:

event_id with deletion info attributes

Return type:

list with dicts for each deleted event

async getDescriptorById(eventId, accountId=None, descriptorVersion=None, descriptorModel=<class 'db.events_db_tools.models.events_models.Descriptor'>)

Search event descriptor by event id.

Parameters:
  • eventId (str) – event id

  • accountId (str | None) – account id

  • descriptorVersion (int | None) – descriptor version

  • descriptorModel (Descriptor | BodyDescriptor) – descriptor model. Either Descriptor or BodyDescriptor

Raises:
  • VLException(Error.EventNotFound) if no event found

  • VLException(Error.DescriptorNotFound) if no descriptor of specified version found

Return type:

bytes

Returns:

descriptor as bytes

async getSequenceValues(eventCount)

Get several sequence.next_val values from db for new events :type eventCount: int :param eventCount: count of incoming event

Return type:

list[int]

Returns:

list of ids for incoming events

static prepareSearchQueryFilters(filters, meta)

Prepare search query filters.

Parameters:
  • filters (SearchEventsFilters) – query filters

  • meta (list[UDFilter]) – user-defined event meta’s filters

Return type:

tuple[BooleanClauseList, list[FromClause]]

Returns:

filters for Event select query

static prepareTarget(targets)

Extend query targets if needed.

Return type:

list[str]

async searchEvents(filters, *, meta=None, target=None, page=1, pageSize=100, order='desc')

Search events by given filters.

Parameters:
  • target (list[str] | None) – target Event columns’ names to get info on

  • filters (SearchEventsFilters) – raw search request filters

  • meta (list[UDFilter]) – user-defined event meta’s filters

  • page (int | None) – number of result page

  • page_size – count of results in page

  • order (str | None) – result sort order (ask or desc)

Return type:

list[dict]

Returns:

events

async searchEventsMissing(filters, page=1, pageSize=100)

Get events with samples without specified attributes (filters.kind).

Parameters:
  • filters (SearchEventsMissingFilters) – A SearchEventsMissingFilters instance

  • page (int | None) – number of result page

  • pageSize (int | None) – count of results in page

Return type:

list[dict[str, object]]

Returns:

List of events

async searchEventsMissingCount(filters)

Get number of events with samples without specified attributes (filters.kind).

Parameters:

filters (SearchEventsMissingFilters) – A SearchEventsMissingFilters instance

Return type:

int

Returns:

An integer, count of events.

async searchGeneralEvents(filters, *, page=1, pageSize=100, order='desc')

Search events by given filters.

Parameters:
  • filters (GeneralEventsFilters) – raw search request filters

  • page (int | None) – number of result page

  • page_size – count of results in page

  • order (str | None) – result sort order (ask or desc)

Return type:

list[dict]

Returns:

events

async updateEvent(eventId, accountId, eventForUpdate)

Update event.

Parameters:
  • eventId (str) – event id

  • accountId (str | None) – account id

  • eventForUpdate (dict) – event containing data to update

Raises:

VLException(Error.EventNotFound) if no event found

Return type:

None