Locospec

Action Spec

Define low-level database operations like insert, update, delete, and select in a consistent format.

Action Spec describe direct, low-level database operations—insert, update, delete, and select. They are the foundation for any server-side data manipulation and power all backend logic within Locospec.

They are typically used behind the scenes by features like Mutators and Views but can also be triggered manually when fine-grained control is needed.


✨ Supported Actions

TypePurpose
insertCreate one or more records
updateModify existing records
deleteRemove (or soft delete) records
selectFetch and filter records

📥 insert

Inserts one or more records into a model’s table.

{
  "type": "insert",
  "modelName": "user",
  "data": [
    {
      "uuid": "123",
      "name": "Rajesh"
    }
  ]
}

Required Fields

FieldTypeDescription
typestringMust be "insert"
modelNamestringTarget model name
dataarrayArray of records to insert

ℹ️ Supports multiple inserts in one operation.


✏️ update

Updates one or more records matching the given filters.

{
  "type": "update",
  "modelName": "user",
  "filters": {
    "op": "and",
    "conditions": [{ "attribute": "status", "op": "is", "value": "pending" }]
  },
  "data": {
    "status": "approved"
  }
}

Required Fields

FieldTypeDescription
typestringMust be "update"
modelNamestringTarget model name
filtersobjectConditions to match records
dataobjectKey-value pairs to update

🗑 delete

Deletes (or soft-deletes) records based on filters.

{
  "type": "delete",
  "modelName": "user",
  "softDelete": true,
  "deleteColumn": "deleted_at",
  "filters": {
    "op": "and",
    "conditions": [{ "attribute": "status", "op": "is", "value": "inactive" }]
  }
}

Required Fields

FieldTypeDescription
typestringMust be "delete"
modelNamestringTarget model name
filtersobjectConditions to match records
softDeletebooleanIf true, marks the record as deleted
deleteColumnstringColumn used for soft delete timestamp

📊 select

Retrieves data from the database with filters, scopes, sorts, and pagination.

{
  "type": "select",
  "modelName": "user",
  "attributes": ["uuid", "name", "email"],
  "filters": {
    "op": "and",
    "conditions": [{ "attribute": "status", "op": "is", "value": "active" }]
  },
  "sorts": [{ "attribute": "created_at", "order": "desc" }],
  "pagination": {
    "type": "cursor",
    "limit": 10
  },
  "expand": ["role"]
}

Required Fields

FieldTypeDescription
typestringMust be "select"
modelNamestringThe model to query from

🔍 Filter Format

Actions like select, update, and delete support all three filter formats:

  1. Filter Group
{
  "op": "and",
  "conditions": [{ "attribute": "status", "op": "is", "value": "active" }]
}
  1. Array of Conditions
[{ "attribute": "status", "op": "is", "value": "active" }]
  1. Key-Value Object
{
  "status": "active"
}

See the Filter Spec for full reference.


📎 Specs References

On this page