This page documents the legacy @logic-bee/flow-query package, which has been superseded by @logic-bee/data-flow. See the migration guide for equivalents. New code should use the new API.
Flow Query
Flow Query is the primary interface for performing database operations on documents within the Logic Bee system.
Core Concepts
Running an operation on a database document requires a naoQueryOptions that indicates which document from what collection the operation will run on.
- Each collection of documents is called a flowCollection
- Each document is called a flowDocument
Getting a Flow Collection
To access a flowCollection, use the cfpPath of the collection and call the flowGlobal variable in the bob request. The bob class is available in all events.
// -->Get: the flow collection using the cfpPath
const flowCollection = bob.flowGlobal.getFlowCollection('contacts/contacts');
// -->Get: the flow collection using the cfpPath from the current request
const flowCollection = bob.flowGlobal.getFlowCollection(bob.cfpPath);
// -->Get: the flow collection using the naoQueryOptions from the current request
const flowCollection = bob.flowGlobal.getFlowCollection(bob.naoQueryOptions);
Building a Flow Query
Once you have the collection, you can run operations on documents using flowQuery():
/**
* Get the flow query for the flow document with the index of "project"
*/
const flowQuery = await flowCollection.docs.flowQuery()
.addPolicy('canUpdate')
.user(bob.flowUser)
.flowOptions({docName: 'project'})
/**
* Get the flow query for the flow document with the index from the current API call
*/
const flowQuery = await flowCollection.docs.flowQuery()
.addPolicy('canUpdate')
.user(bob.flowUser)
.flowOptions(bob.naoQueryOptions);
If the document doesn't exist in the flowCollection, an error will be thrown.
All the operations within an event sequence will be reversed if the operation fails — only if the queries have bob.dbSession() attached to the query. It's good practice to add it to every write query.
CRUD Operations
Flow Query supports the full range of CRUD operations:
- Search —
getOne(),getMany(),query(),count(),sortByFieldValue() - Insert —
insertOne(),insertMany() - Update —
updateOne(),updateMany(),updatePatchOne(),updatePatchMany(),updateStatus() - Delete —
deleteOne(),deleteMany(),expireMany()
Advanced Topics
- Advanced Operations —
flowData()for granular field-level operations - Bulk Transactions — Execute multiple operations atomically
- Aggregations — Group, join, and transform data with aggregation pipelines