Supercharged
Todo Application
Learn how to build a lightning-fast task management system using VelocityDB's List and Key-Value primitives.
Architecture
Unlike traditional SQL databases where you'd create tables and schemas, VelocityDB allows you to store entire user states or lists directly in memory. For a Todo app, we can utilize two main approaches: JSON Documents or Linked Lists.
approach_1: JSON Storage
Store the entire todo list as a single JSON object. Best for simple apps with small lists.
approach_2: List Primitive
Use built-in List commands to append items individually. Better for larger, append-only logs.
Live Playground
Try it yourself. Every action below sends a real-time command to the Velocity engine simulator.
Interactive Todo Engine
Live Binary Protocol Logs
Initialize Client
First, connect to your VelocityDB instance. The client manages the connection pool automatically.
const { VelocityClient } = require('velocitydb-client');
const client = new VelocityClient({
host: '127.0.0.1',
port: 2005
});
await client.connect();Add Task (API Route)
In your backend API route, simply generate an ID and push the JSON string to the user's list.
app.post('/api/todos', async (req, res) => {
const { userId, task } = req.body;
const todo = {
id: Date.now(),
text: task,
completed: false,
createdAt: new Date().toISOString()
};
// Store as atomic JSON string in a List
await client.rpush(`todos:${userId}`, JSON.stringify(todo));
res.json(todo);
});Fetch All Tasks
Retrieve the entire range of the list. `LRANGE 0 -1` fetches everything from the first element to the last.
app.get('/api/todos', async (req, res) => {
const { userId } = req.query;
// LRANGE key start end
const items = await client.lrange(`todos:${userId}`, 0, -1);
// Parse JSON strings back to objects
const todos = items.map(item => JSON.parse(item));
res.json(todos);
});Quick Commands
RPUSH todos:1 "Buy Milk"LRANGE todos:1 0 -1LLEN todos:1Performance Tip
For lists with millions of items, avoid `LRANGE 0 -1`. Use pagination with `LRANGE 0 50` to keep your application snappy and memory efficient.