Data Management

Loading, updating, and managing your data with dcupl's data API.

Data API Overview

All data operations are accessed through dcupl.data:

  • set() - Replace all data for a model
  • update() - Incremental updates to existing items
  • upsert() - Insert or update items
  • remove() - Delete specific items

After data operations, call dcupl.init() to initialize dcupl, or dcupl.update() to process changes after initialization.

set() - Replace All Data

Use when: You want to completely replace all data for a model.

This method clears existing data and replaces it with the provided items. Useful for initial data loading or full refreshes.

update() - Incremental Update

Use when: You want to modify existing items or add new ones.

Only include changed fields for better performance. The update merges with existing data.

upsert() - Insert or Update

Use when: You don't know if items exist.

If an item with the key exists, it's updated. If not, it's created. Combines the behavior of insert and update.

remove() - Delete Items

Use when: You want to delete specific items.

Provide items with at least the key property to identify which items to remove.

Data Options

All data methods accept an options object:

Option Description
model Required. Specify which model the data belongs to
keyProperty Override the primary key field (default: 'key')
autoGenerateKey Auto-generate keys if missing

Performance Tips

Batch Updates

Always batch multiple items into a single update call. Avoid calling update inside loops.

Use Incremental Updates

Prefer update() over set() when possible. Full replacement is slower than incremental updates.

Only Include Changed Fields

When updating, only include the fields that actually changed. This reduces processing overhead.

Best Practices

Always await dcupl.update()

Data operations are queued and processed when you call dcupl.update(). Always await it before querying to ensure you get the latest data.

Missing the await can lead to stale data bugs that are hard to track down.