Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose better API for querying events #23

Open
lukaszb opened this issue Mar 24, 2017 · 0 comments
Open

Expose better API for querying events #23

lukaszb opened this issue Mar 24, 2017 · 0 comments
Labels

Comments

@lukaszb
Copy link
Owner

lukaszb commented Mar 24, 2017

I believe that cq should be framework/tools agnostic, however I caught myself couple of times running from cq.models import Event within my Django based app.

We should be able to query events in a much better manner. To be specific I would love to be able to query events with explicit ordering and filtering after doing simple library import.

Basically, I'd like to achieve something like:

import cq

for event in cq.query_events('User.StartedSession', limit=50):
    print("{} | User {} logged in".format(event.ts, event.data['email']))

Or something like:

print(cq.query_events(ts="3 days")

which should show events from last 3 days.

Signature of cq.query_events

def query_events(*names, limit=100, order_by='-ts', **filters):
    ...
  • names are not named arguments. Might be empty of course - in this case all events, regardless of their types, would be returned
  • limit results to first 100 by default. If None given, all matching events are returned
  • order_by defaults to -ts, meaning events would be ordered by date of creation, descending. Allows to change or disable order.
  • filters: For now it would probably suffice to filter by ts param. It should be similar to what is possible with Django ORM: ts=datetime(2017, 3, 24) (exact comparison) or ts__gte=datetime(2017, 3, 24) (all events created after 2017-03-24) or ts="day" (if string given, should be human readable and would be treated as "show me events from last day/week/month" or number of those like "2 weeks". I'd say this is optional, however I'd strongly advice to implement it as it would be mostly used in my opinion).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant