Database context¶
- class luna_events.db.db_context.DBContext(logger, adaptor, streams, storageTime)¶
Class to work with database.
- logger¶
the current request logger
- streams¶
streams with data
- adaptor¶
A DBAdaptor instance
- storageTime¶
A str, storage time setting
- async checkEvent(eventId, accountId=None)¶
Check event existence :type eventId:
str
:param eventId: event id :type accountId:Optional
[str
,None
] :param accountId: account id- Return type:
bool
- Returns:
True if event exists otherwise False
- property dbType: str¶
Returns a string, database type (‘postgres’ only).
- Return type:
str
- 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:Optional
[datetime
,None
] :param createTimeGte: lower create time boundary :type createTimeLt:Optional
[datetime
,None
] :param createTimeLt: upper create time boundary :type insertTimeGte:Optional
[datetime
,None
] :param insertTimeGte: lower insert time boundary :type insertTimeLt:Optional
[datetime
,None
] :param insertTimeLt: upper insert time boundary :type accountId:Optional
[str
,None
] :param accountId: account id :type handlerId:Optional
[str
,None
] :param handlerId: handler 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 idaccountId (
Optional
[str
,None
]) – account iddescriptorVersion (
Optional
[int
,None
]) – descriptor versiondescriptorModel (
UnionType
[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 filtersmeta (
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 (
Optional
[list
[str
],None
]) – target Event columns’ names to get info onfilters (
SearchEventsFilters
) – raw search request filtersmeta (
Optional
[list
[UDFilter
],None
]) – user-defined event meta’s filterspage (
UnionType
[int
,None
]) – number of result pagepage_size – count of results in page
order (
UnionType
[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 instancepage (
UnionType
[int
,None
]) – number of result pagepageSize (
UnionType
[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 updateEvent(eventId, accountId, eventForUpdate)¶
Update event.
- Parameters:
eventId (
str
) – event idaccountId (
UnionType
[str
,None
]) – account ideventForUpdate (
dict
) – event containing data to update
- Raises:
VLException(Error.EventNotFound) if no event found –
- Return type:
None