Skip to content

Building a CRUD Flow

This guide walks through building list, create, get, and delete flows using call:lancedb.

  1. Create the database resource

    Terminal window
    # Create a LanceDB resource
    curl -X POST http://localhost:3002/message \
    -H "Content-Type: application/json" \
    -d '{
    "jsonrpc": "2.0", "method": "tools/call", "id": 1,
    "params": {
    "name": "create_resource",
    "arguments": {
    "name": "my-db", "namespace": "default",
    "type_ref": "lancedb",
    "config": {"db_path": "/data/my-app.lance"}
    }
    }
    }'
  2. Create the table (schema install)

    namespace: default
    name: products-schema
    version: "1.0.0"
    enabled: true
    steps:
    - name: create-table
    type: call:lancedb
    resource: my-db
    config:
    operation: create_table
    mode: create_if_not_exists
    table: products
    schema:
    id: string
    name: string
    price: string
    created_at: string
    then: end
  3. List flow

    namespace: default
    name: products-list
    version: "1.0.0"
    enabled: true
    steps:
    - name: query
    type: call:lancedb
    resource: my-db
    config:
    operation: query
    table: products
    limit: 100
    then: end
  4. Create flow

    Input: { data: { id, name, price }, timestamp }

    namespace: default
    name: products-create
    version: "1.0.0"
    enabled: true
    steps:
    - name: insert
    type: call:lancedb
    resource: my-db
    config:
    operation: insert
    table: products
    records:
    - id: "${ .data.id }"
    name: "${ .data.name }"
    price: "${ .data.price }"
    created_at: "${ .timestamp }"
    then: end
  5. Get flow

    Input: { id }

    namespace: default
    name: products-get
    version: "1.0.0"
    enabled: true
    steps:
    - name: query
    type: call:lancedb
    resource: my-db
    config:
    operation: query
    table: products
    filter: "id = '${ .id }'"
    limit: 1
    then: end
  6. Delete flow

    Input: { id }

    namespace: default
    name: products-delete
    version: "1.0.0"
    enabled: true
    steps:
    - name: del
    type: call:lancedb
    resource: my-db
    config:
    operation: delete
    table: products
    filter: "id = '${ .id }'"
    then: end

The UI service calls these flows directly:

const result = await flows.execute('products-list', 'default');
// Poll for completion
const status = await flows.status(instanceId);
// status.output = { count: N, rows: [...] }