Skip to content

Commit 53d9491

Browse files
committed
feat: add DatabaseTaskStore with Drizzle ORM support
- Add `delete` method to TaskStore interface and InMemoryTaskStore - Add DatabaseTaskStore for persistent task storage using Drizzle ORM - Support SQLite, PostgreSQL, and MySQL databases - Export via new entry point `@a2a-js/sdk/server/drizzle` - Add drizzle-orm as optional peer dependency - Update README with installation and usage examples
1 parent b1f50dd commit 53d9491

8 files changed

Lines changed: 599 additions & 25 deletions

File tree

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,32 @@ You can install the A2A SDK using `npm`.
2121
npm install @a2a-js/sdk
2222
```
2323

24-
### For Server Usage
24+
### A2A Server
2525

2626
If you plan to use the A2A server functionality (`A2AExpressApp`), you'll also need to install Express as it's a peer dependency:
2727

2828
```bash
2929
npm install express
3030
```
3131

32+
### Persistent Task Storage
33+
34+
For production deployments requiring persistent task storage, install Drizzle ORM, a database driver, and drizzle-kit for migrations:
35+
36+
```bash
37+
# SQLite
38+
npm install drizzle-orm better-sqlite3
39+
npm install -D drizzle-kit
40+
41+
# PostgreSQL
42+
npm install drizzle-orm pg
43+
npm install -D drizzle-kit
44+
45+
# MySQL
46+
npm install drizzle-orm mysql2
47+
npm install -D drizzle-kit
48+
```
49+
3250
You can also find JavaScript samples [here](https://github.com/google-a2a/a2a-samples/tree/main/samples/js).
3351

3452
---
@@ -669,6 +687,87 @@ app.post('/webhook/task-updates', (req, res) => {
669687
});
670688
```
671689

690+
---
691+
692+
## Persistent Task Storage
693+
694+
By default, the SDK provides an `InMemoryTaskStore` which stores tasks in memory. For production deployments, use the `DatabaseTaskStore` with Drizzle ORM to persist tasks to SQLite, PostgreSQL, or MySQL.
695+
696+
### Quick Setup
697+
698+
**1. Create a schema file** (e.g., `src/schema.ts`):
699+
700+
```typescript
701+
// For SQLite
702+
export { sqliteTasks as tasks } from '@a2a-js/sdk/server/drizzle';
703+
// For PostgreSQL: export { pgTasks as tasks } from '@a2a-js/sdk/server/drizzle';
704+
// For MySQL: export { mysqlTasks as tasks } from '@a2a-js/sdk/server/drizzle';
705+
```
706+
707+
**2. Create `drizzle.config.ts`** in your project root:
708+
709+
```typescript
710+
import { defineConfig } from 'drizzle-kit';
711+
712+
export default defineConfig({
713+
schema: './src/schema.ts',
714+
out: './drizzle',
715+
dialect: 'sqlite', // or 'postgresql' or 'mysql'
716+
dbCredentials: {
717+
url: 'tasks.db', // or your connection string
718+
},
719+
});
720+
```
721+
722+
**3. Apply the schema:**
723+
724+
```bash
725+
# For development (applies changes directly):
726+
npx drizzle-kit push
727+
728+
# For production (version-controlled migrations):
729+
npx drizzle-kit generate
730+
npx drizzle-kit migrate
731+
```
732+
733+
### Usage Examples
734+
735+
**SQLite:**
736+
737+
```typescript
738+
import { drizzle } from 'drizzle-orm/better-sqlite3';
739+
import Database from 'better-sqlite3';
740+
import { DatabaseTaskStore, sqliteTasks } from '@a2a-js/sdk/server/drizzle';
741+
742+
const sqlite = new Database('tasks.db');
743+
const db = drizzle(sqlite);
744+
const taskStore = new DatabaseTaskStore({ db, table: sqliteTasks, dialect: 'sqlite' });
745+
```
746+
747+
**PostgreSQL** (with connection pooling):
748+
749+
```typescript
750+
import { drizzle } from 'drizzle-orm/node-postgres';
751+
import { Pool } from 'pg';
752+
import { DatabaseTaskStore, pgTasks } from '@a2a-js/sdk/server/drizzle';
753+
754+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
755+
const db = drizzle(pool);
756+
const taskStore = new DatabaseTaskStore({ db, table: pgTasks, dialect: 'postgresql' });
757+
```
758+
759+
**MySQL** (with connection pooling):
760+
761+
```typescript
762+
import { drizzle } from 'drizzle-orm/mysql2';
763+
import mysql from 'mysql2/promise';
764+
import { DatabaseTaskStore, mysqlTasks } from '@a2a-js/sdk/server/drizzle';
765+
766+
const pool = mysql.createPool(process.env.DATABASE_URL);
767+
const db = drizzle(pool);
768+
const taskStore = new DatabaseTaskStore({ db, table: mysqlTasks, dialect: 'mysql' });
769+
```
770+
672771
## License
673772

674773
This project is licensed under the terms of the [Apache 2.0 License](https://raw.githubusercontent.com/google-a2a/a2a-python/refs/heads/main/LICENSE).

0 commit comments

Comments
 (0)