Storage Service
Access all storage services - Key-Value, Dataset, Object, and Queue - through the unified storage interface.
Access
client.storage.kv // KVService
client.storage.dataset // DatasetService
client.storage.object // ObjectStorageService
client.storage.queue // QueueServiceStorage Mode
The SDK supports both remote (HTTP) and local (filesystem) storage:
// Remote storage (connects to Scrayle Storage API)
SCRAYLE_IS_ONLINE=true
// Local storage (saves to ./storage/ directory)
SCRAYLE_IS_ONLINE=false (default)When running locally, data is stored in the ./storage/ directory with sub-directories for each storage type.
KV Service
// Create namespace
await client.storage.kv.createNamespace('config');
// Set / Get
await client.storage.kv.set('config', 'theme', 'dark');
const value = await client.storage.kv.get('config', 'theme');
// 'dark'
// Set bulk
await client.storage.kv.setBulk('config', { theme: 'dark', lang: 'en' });
// List keys
const keys = await client.storage.kv.listKeys('config');
// Delete
await client.storage.kv.delete('config', 'theme');Dataset Service
// Create
const ds = await client.storage.dataset.createDataset('products');
// Add items
await client.storage.dataset.addItems(ds.id, [
{ name: 'A', price: 10 },
{ name: 'B', price: 20 },
]);
// Read items
const items = await client.storage.dataset.getItems(ds.id);
// Delete
await client.storage.dataset.delDataset(ds.id);Object Storage Service
// Create bucket
const bucket = await client.storage.object.createBucket({ name: 'files' });
// Upload
await client.storage.object.put(bucket.id, { file: './data.json' });
// Download
const blob = await client.storage.object.get(bucket.id, 'object-id');
// List
const objects = await client.storage.object.list(bucket.id);
// Delete
await client.storage.object.delete(bucket.id, 'object-id');Queue Service
// Create
const queue = await client.storage.queue.create({ name: 'tasks' });
// Push
await client.storage.queue.push(queue.id, {
name: 'task-1',
payload: JSON.stringify({ url: 'https://example.com' }),
});
// Pull
const msgs = await client.storage.queue.pull(queue.id, 5);
// Acknowledge
await client.storage.queue.ack(queue.id, msgs[0].id);
// Delete
await client.storage.queue.delete(queue.id);