Skip to content
ParticleDB

Store application data

This guide uses a small work queue stored as an ordinary SQL table. Run the SQL in a connected SQL client or the SQL editor.

CREATE TABLE work_items (
id BIGINT PRIMARY KEY,
title TEXT NOT NULL,
status TEXT NOT NULL
);
INSERT INTO work_items VALUES
(1, 'Review request', 'pending'),
(2, 'Send response', 'pending');
SELECT id, title
FROM work_items
WHERE status = 'pending'
ORDER BY id;

Use bound parameters for values supplied by users. The placeholder syntax depends on the client; see your language guide.

Use one connection for the transaction:

BEGIN;
UPDATE work_items SET status = 'completed' WHERE id = 1;
UPDATE work_items SET status = 'running' WHERE id = 2;
COMMIT;

If a statement fails, roll back before reusing the connection. Retry from BEGIN when a transaction fails with a retryable conflict.

SELECT id, status FROM work_items ORDER BY id;

The statuses are completed for record 1 and running for record 2.

Transactions · Data types · Indexes and queries