From 995bc9f5563b02ae9e329e6a359579e2db28adc4 Mon Sep 17 00:00:00 2001 From: Andreu Date: Fri, 19 Jan 2024 14:11:39 +0100 Subject: [PATCH] Add query env doc. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index bf3f0ee..144acd0 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,29 @@ queries: [ In this case, the integration will combine the fields `Client`, `Value`, `StartDate`, and `EndDate` to form a unique identifier for each event of the type `PlatformEventUsageMetric`. +### Query env + +It's possible to define a set of environment variables for a specific query, we do it by setting the key `env`: + +```yaml +queries: [ + { + query: "SELECT EventName, EventType, UsageType, Client, Value, StartDate, EndDate FROM PlatformEventUsageMetric WHERE TimeSegment='FifteenMinutes' AND StartDate >= {start_date} AND EndDate <= {end_date}", + env: { + end_date: "now()", + start_date: "now(timedelta(minutes=-60))" + }, + } +] +``` + +In this example above we defined two variables: `end_date` and `start_date`. These variables contain python expressions that are evaluated to generate the data that is going to be susbtituted in the query. The following elements are supported: + +- `now()`: Get current time and generate an ISO formatted date-time. It can optionally take a timedelta as argument and add it to the current time. +- `timedelta`: Generate a Python timedelta object. +- `datetime`: Generate a Python datetime object. +- `sf_time()`: Generate an ISO formatted date-time. Takes a Python datetime object as argument. + ## Usage ### Locally