Skip to content

Instantly share code, notes, and snippets.

@robdmc
Created February 3, 2021 15:28
Show Gist options
  • Save robdmc/3129fe23fd8d50bc4943d0039cea9756 to your computer and use it in GitHub Desktop.
Save robdmc/3129fe23fd8d50bc4943d0039cea9756 to your computer and use it in GitHub Desktop.
# First, from within the docker ambition container run
# lamb.instance sync
# Then run this code in a container
# You'll have to choose an instance, but it doesn't matter
# which one. Multiquery can access all instances from anywhere.
import django
django.setup()
# Example using Multiquery with Django queryset
# In this case grab all org display names
qs = Organization.objects.filter(is_sandbox=False).values('display_name', )
mq = MultiQuery(qs)
df = mq.to_dataframe()
df.to_csv('org_names.csv', index=False)
# Example of Multiquery using SQL
# (in this case getting tirggers fired in a timeframe)
sql = """
SELECT
COUNT(*)
FROM
ambition_trigger_triggerlog
WHERE
date_triggered >='2020-01-01T00:00:00'::TIMESTAMP
AND
date_triggered < '2021-01-01T00:00:00'::TIMESTAMP
"""
mq = MultiQuery(sql)
df = mq.to_dataframe()
df = df.rename(columns={'count': 'num_triggers'})
df.to_csv('triggers_firings.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment