Skip to content

Database Modules

Database Modules

Database modules use the db component. Configure which database connection to use in component settings, then reference the component per flowlet.

Generic SQL Operations

These modules work with any configured SQL database (PostgreSQL, F8DB).

Query

{
"appId": "db-query",
"ref": "getOrders",
"args": {
"sql": "SELECT id, customer_id, amount, status FROM orders WHERE status = $1 AND created_at > $2",
"params": ["pending", "{{ $prev.args.sinceDate }}"],
"limit": 100
}
}

Output: { "rows": [{...}, {...}], "count": 42 }

Insert

{
"appId": "db-insert",
"ref": "createRecord",
"args": {
"table": "processed_invoices",
"data": {
"invoice_id": "{{ $prev.args.invoiceId }}",
"processed_at": "{{ $date.now }}",
"amount": "{{ $prev.extractData.amount }}",
"status": "complete"
}
}
}

Output: { "id": "123", "rowsAffected": 1 }

Update / Upsert / Delete

{"appId": "db-update", "args": {"table": "orders", "data": {"status": "shipped"}, "where": {"id": "{{ $prev.args.orderId }}"}}}
{"appId": "db-upsert", "args": {"table": "sync_state", "data": {"key": "lastSync", "value": "{{ $date.now }}"}, "conflictKey": "key"}}
{"appId": "db-delete", "args": {"table": "temp_records", "where": {"created_at": {"lt": "{{ $prev.cutoffDate.value }}"}}}}

Full-text or indexed field search:

{"appId": "db-search", "args": {"table": "customers", "query": "{{ $prev.args.searchTerm }}", "fields": ["name","email","phone"], "limit": 20}}

Raw SQL

{
"appId": "db-raw",
"args": {
"sql": "SELECT COUNT(*) as total, SUM(amount) as revenue FROM orders WHERE DATE(created_at) = CURRENT_DATE",
"params": []
}
}

MongoDB-Specific Operations

Array Push / Pull

{"appId": "mongodb-array-push", "args": {"collection": "projects", "id": "{{ $prev.args.projectId }}", "field": "tags", "value": "urgent"}}
{"appId": "mongodb-array-pull", "args": {"collection": "projects", "id": "{{ $prev.args.projectId }}", "field": "tags", "value": "draft"}}

Atomic Increment

{"appId": "mongodb-increment", "args": {"collection": "counters", "id": "invoice-counter", "field": "seq", "amount": 1}}
// Output: {"newValue": 1043}

F8DB — Built-in Database

F8DB is flow8’s built-in relational database backed by MongoDB. No external database needed.

Create Table

{
"appId": "f8db-create-table",
"args": {
"database": "my-app-db",
"table": "customers",
"columns": [
{"name": "name", "type": "string"},
{"name": "email", "type": "string"},
{"name": "balance", "type": "number"},
{"name": "active", "type": "boolean"}
]
}
}

CRUD Operations

{"appId": "f8db-insert", "args": {"database": "my-app-db", "table": "customers", "data": {"name": "John", "email": "john@example.com", "balance": 0, "active": true}}}
{"appId": "f8db-query", "args": {"database": "my-app-db", "table": "customers", "where": {"active": true}, "orderBy": "name", "limit": 50}}
{"appId": "f8db-update", "args": {"database": "my-app-db", "table": "customers", "id": "{{ $prev.args.customerId }}", "data": {"balance": "{{ $prev.calcBalance.total }}"}}}
{"appId": "f8db-delete", "args": {"database": "my-app-db", "table": "customers", "id": "{{ $prev.args.customerId }}"}}