Skip to content
MACHHUB MACHHUB MACHHUB

Every record in a Collection is identified by a RecordID. Understanding its format is the key to relations, updates, and deletes.

application_id.collection_name:record_id

For example: myapp.products:PROD-001.

  • myapp — your application_id
  • products — the collection name
  • PROD-001 — the record’s own id

The SDK also accepts and returns the structured object form:

{ Table: "myapp.products", ID: "PROD-001" }
import { RecordIDToString, StringToRecordID, type RecordID } from '@machhub-dev/sdk-ts';
RecordIDToString({ Table: 'myapp.categories', ID: 'CAT-001' });
// → "myapp.categories:CAT-001"
StringToRecordID('myapp.categories:CAT-001');
// → { Table: "myapp.categories", ID: "CAT-001" }

A common need is the bare id (without the table prefix), e.g. for display or routing. This helper handles strings and reference objects alike:

function extractId(value: any): string {
if (typeof value === 'object' && value?.ID) value = value.ID;
if (typeof value === 'string' && value.includes(':')) return value.split(':')[1];
return value;
}
// Relation written as a reference object:
await sdk.collection('products').create({
name: 'Wireless Mouse',
categoryId: { Table: 'myapp.categories', ID: 'CAT-002' },
});
// Update/delete use the full RecordID string:
await sdk.collection('products').update('myapp.products:PROD-001', { price: 34.99 });
await sdk.collection('products').delete('myapp.products:PROD-001');