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
- static applyNullForGeoPosition(locationType, geoPositionFilter)¶
Creates sql filter for geo position
- Parameters:
locationType (
Type
[Location
|GeneralLocation
]) – Location modelgeoPositionFilter – filter for geo position
- Return type:
BinaryExpression
|bool
- Returns:
True or filter expression
- static applyNullForInFilter(eventField, attributeFilters)¶
Creates sql ‘in’ filter for list and nullable value
- Parameters:
eventField – sql column to filter
attributeFilters (
list
) – filters to compare with
- Return type:
BinaryExpression
|bool
- Returns:
True or filter expression
- 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 idaccountId (
str
|None
) – account iddescriptorVersion (
int
|None
) – descriptor versiondescriptorModel (
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
- prepareBaseFilters(eventEntity, filters)¶
Builds base filters by given event model and filters
- eventEntity¶
event model
- filters¶
query filters
- Return type:
list
[bool
]- Returns:
list of bools
- prepareLocationFilters(locationType, filters)¶
Builds location filters
- locationType¶
location model
- filters¶
query filters
- Return type:
list
[bool
]- Returns:
list of bools
- 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
- prepareSearchQueryGeneralEventsFilters(filters, eventFilters)¶
Prepare search query filters.
- Parameters:
filters (
GeneralEventsFilters
) – query filterseventFilters (
list
[UDFilter
]) – user-defined inner event’s content filters
- Return type:
tuple
[list
[bool
],list
]- Returns:
filters for GeneralEvent 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 onfilters (
SearchEventsFilters
) – raw search request filtersmeta (
list
[UDFilter
] |None
) – user-defined event meta’s filterspage (
int
|None
) – number of result pagepageSize (
int
|None
) – count of results in pageorder (
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 (
int
|None
) – number of result pagepageSize (
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, *, eventFilters=None, page=1, pageSize=100, order='desc')¶
Search events by given filters.
- Parameters:
filters (
GeneralEventsFilters
) – raw search request filterseventFilters (
list
[UDFilter
] |None
) – user defined filters for event JSONB fieldpage (
int
|None
) – number of result pagepageSize (
int
|None
) – count of results in pageorder (
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 idaccountId (
str
|None
) – account ideventForUpdate (
dict
) – event containing data to update
- Raises:
VLException(Error.EventNotFound) if no event found –
- Return type:
None