Database Lookup (Iterator)

LoopDatabases

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

DatabaseRequired

Select the database to query.

Limit

Maximum number of rows to return (default: 100, max: 1000).

Example: 100

Offset

Number of rows to skip before returning results (default: 0).

Example: 0

Query

Define filters to find rows.

Set up in the editor. The JSON format is under advanced documentation below.

Loop Body

Blocks to run for each row found.

Holds blocks

Outputs

Iteration Number

0-based iteration index.

Example: 0

Total Rows

Total number of rows found.

Example: 10

Row ID

The unique ID of the current row.

Example: abc123xyz

Row JSON

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"}

Build a bot using blocks like Database Lookup (Iterator)

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

ID: db_lookup_iterator
  • Loop block: write for item := range db_lookup_iterator(Args{...}) { ... } and read the current item's outputs from item. See loops.
  • Database columns are extra inputs/outputs named dbcol_<column name>.

Inputs

FieldInventScript nameValue
Databasedatabase_id
Limitlimite.g. "100"
Offsetoffsete.g. "0"
Queryquery_jsonJSON text
Loop Bodybodyblocks: func() { ... }
query_json format: JSON text of type DatabaseQuery. Fields marked ? are optional.
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"
}

Outputs

FieldInventScript nameValue
Iteration Numberiteration_numbere.g. "0"
Total Rowstotal_iterationse.g. "10"
Row IDrow_ide.g. "abc123xyz"
Row JSONrow_jsone.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})
}

More databases blocks