Pikbase Docs
Open console (opens the console)
Esc

Type to search.

API reference

deleteQuery() — Entity Service

Purpose : Removes multiple entities based on complex query criteria. When to use : Batch deleting records Conditional data removal Filtering entities fo…

Contract source@gsb-core/mcp-docs:deleteQuery

General Description

The deleteQuery operation removes entities from the database based on complex query parameters, providing more flexibility than the standard delete operation.

Detailed Description

This operation allows you to delete entities that match complex query criteria using the same query system as the query operation. It's particularly useful when you need to delete entities based on advanced filtering conditions, relationships, or complex logic that can't be easily expressed with the standard delete operation.

Input Parameters

Parameter Type Required Description
queryParams object Yes The query parameters object that defines what entities to delete. Same structure as used in the query operation.
token string No Authentication token for your request. If not provided, the system will use the default API key from environment variables.
tenantCode string No Tenant code to specify which tenant's data to access. If not provided, the system will extract it from the token or use the default tenant code from environment variables.

QueryParams Object Structure

Same as the standard query operation. See the query operation documentation for details.

Behavioral Limitations

deleteQuery performs a direct bulk deletion. It does not execute cascade deletes configured with cascadeReference, workflow delete triggers, or serverless delete triggers. These behaviors run for the single-entity delete operation only.

When cascades or delete triggers are required, first query the matching entity IDs and then batch multiple single-entity delete requests. Each request is processed as an individual delete, so its recursive cascades and workflow or serverless delete triggers run normally.

Response

Success Response

{
    "success": true,
    "deletedCount": number  // Number of deleted entities
}

Error Response

{
    "success": false,
    "error": "Error message describing what went wrong"
}

Example Usage

Basic DeleteQuery

const result = await deleteQuery({
  queryParams: {
    entDefName: "Order",
    query: [
      {
        propVal: {
          name: "status",
          value: "Cancelled"
        },
        function: "equals"
      },
      {
        propVal: {
          name: "createDate",
          value: "2023-01-01T00:00:00Z"
        },
        function: "smaller"
      }
    ]
  },
  token: "your-auth-token"
});

if (result.success) {
  console.log(`Deleted ${result.deletedCount} cancelled orders from 2022`);
} else {
  console.error("Error:", result.error);
}

Complex DeleteQuery with Nested Conditions

const result = await deleteQuery({
  queryParams: {
    entDefName: "Product",
    query: [
      {
        propVal: {
          name: "category",
          value: "Electronics"
        },
        function: "equals",
        relation: "AND",
        children: [
          {
            propVal: {
              name: "price",
              value: 100
            },
            function: "smaller",
            relation: "OR"
          },
          {
            propVal: {
              name: "inStock",
              value: false
            },
            function: "equals"
          }
        ]
      }
    ]
  },
  token: "your-auth-token"
});

if (result.success) {
  console.log(`Deleted ${result.deletedCount} electronic products that are either under $100 or out of stock`);
}

DeleteQuery with Relationship Filtering

const result = await deleteQuery({
  queryParams: {
    entDefName: "Order",
    includes: [
      {
        propertyName: "customer",
        query: [
          {
            propVal: {
              name: "status",
              value: "Inactive"
            },
            function: "equals"
          }
        ]
      }
    ]
  },
  token: "your-auth-token"
});

if (result.success) {
  console.log(`Deleted ${result.deletedCount} orders from inactive customers`);
}

Additional Information

  • The deleteQuery operation is permanent and cannot be undone. Use it with caution.
  • This operation supports all the query capabilities of the query operation, including complex filtering, nested conditions, and relationship traversal.
  • The operation returns the number of affected rows (deleted entities).
  • For performance reasons, consider using more specific filters when deleting large numbers of entities.
  • Access permissions are enforced based on the provided token.
  • For simple delete operations, use the standard delete operation instead.
  • Do not use deleteQuery when cascade deletion or workflow/serverless delete triggers are required; batch single-entity delete requests instead.
  • For very large deletions, consider breaking the operation into smaller batches to avoid timeouts or performance issues.