type DatabaseQuery = {
where?: FilterGroup
sort?: SortClause[]
limit?: number
offset?: number
}
type FilterGroup = {
logic: string // "and" or "or"
conditions: FilterCondition[]
}
type FilterCondition = {
type: string // "comparison" or "group"
columnId?: string // comparison only
operator?: string // comparison only: eq, neq, gt, gte, lt, lte, contains, not_contains, starts_with, ends_with, is_empty, is_not_empty
value?: string // comparison only
group?: FilterGroup // group only
}
type SortClause = {
columnId: string
direction: string // "asc", "desc" or "random"
}
Database Lookup (Iterator)
Find multiple rows from a database and iterate over each one.
- Loop block: the blocks placed inside it run once for each item, and can use the current item's outputs.
- Gets an extra input or output for each column of the database you pick.
Inputs
Select the database to query.
Maximum number of rows to return (default: 100, max: 1000).
Example: 100
Number of rows to skip before returning results (default: 0).
Example: 0
Define filters to find rows.
Set up in the editor. The JSON format is under advanced documentation below.
Blocks to run for each row found.
Holds blocks
Outputs
0-based iteration index.
Example: 0
Total number of rows found.
Example: 10
The unique ID of the current row.
Example: abc123xyz
The full row as a JSON object, including system fields (__id, __created_at, __updated_at, __created_at_unix, __updated_at_unix).
Example: {"__id":"abc123","name":"example"}
Use this block in our visual flow editor. Bots are hosted 24/7 for free on inventor.bot.
Advanced Documentation
This documentation can be useful when using code mode. View as Markdown
db_lookup_iterator- Loop block: write
for item := range db_lookup_iterator(Args{...}) { ... }and read the current item's outputs fromitem. See loops. - Database columns are extra inputs/outputs named
dbcol_<column name>.
Inputs
| Field | InventScript name | Value |
|---|---|---|
| Database | database_id | |
| Limit | limit | e.g. "100" |
| Offset | offset | e.g. "0" |
| Query | query_json | JSON text |
| Loop Body | body | blocks: func() { ... } |
query_json format: JSON text of type DatabaseQuery. Fields marked ? are optional.Outputs
| Field | InventScript name | Value |
|---|---|---|
| Iteration Number | iteration_number | e.g. "0" |
| Total Rows | total_iterations | e.g. "10" |
| Row ID | row_id | e.g. "abc123xyz" |
| Row JSON | row_json | e.g. "{\"__id\":\"abc123\",\"name\":\"example\"}" |
Example InventScript
for row := range db_lookup_iterator(Args{database_id: "..."}) {
send_text_message(Args{channel_id: trigger.channel_id, message_content: "Row ID: " + row.row_id})
}