database-drizzle

A SQLite database setup for Electron desktop applications, using better-sqlite3 and Drizzle to define data and write type-checked queries. It also covers migrations, connections, and hierarchical data structures.

In plain words
What is it for?
Use it to design SQLite schemas, create queries, manage database connections, run migrations, enable write-ahead logging, and represent tree-like data.
Why use it?
It provides a consistent way to store application data locally while reducing mistakes in database queries and schema changes.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/macromania/agentop/database-drizzle
Any agent
npx skills add macromania/agentop --skill database-drizzle
Clone the repo
git clone --depth 1 https://github.com/macromania/agentop

Made for: Claude Code, Codex.

Per session 78 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,898 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00078 $0.03898
Opus 5 $0.00039 $0.01949
Sonnet 5 $0.00016 $0.00780
Haiku 4.5 $0.00008 $0.00390

Measured 2d ago against content hash 9561b2b056df, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

database-drizzle scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.github/skills/database-drizzle/SKILL.md · 543 lines

How it starts

The opening of the file, as written. The whole thing — 543 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SQLite + Drizzle ORM Database Layer

Type-safe database operations with better-sqlite3 and Drizzle ORM, optimized for Electron desktop applications.

When to Use This Skill

  • Designing SQLite database schemas
  • Implementing type-safe database queries
  • Setting up database connections with WAL mode
  • Creating and running migrations
  • Implementing closure tables for hierarchical data
  • Managing database lifecycle in Electron

Database Setup

Connection Manager

// packages/shared/src/database/connection.ts
import Database from 'better-sqlite3';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import * as schema from './schema';
import path from 'path';
import { app } from 'electron';

let db: ReturnType<typeof drizzle> | null = null;
let sqlite: Database.Database | null = null;

export function initDatabase() {
  const dbPath = path.join(app.getPath('userData'), 'agentop.db');
  
  sqlite = new Database(dbPath);
  
  // Enable WAL mode for better concurrency
  sqlite.pragma('journal_mode = WAL');
  sqlite.pragma('synchronous = NORMAL');
  sqlite.pragma('foreign_keys = ON');
  sqlite.pragma('busy_timeout = 5000');
  
  db = drizzle(sqlite, { schema });
  
  return db;
}

export function getDatabase() {
  if (!db) {
    throw new Error('Database not initialized. Call initDatabase() first.');
  }
  return db;
}

export function closeDatabase() {
  if (sqlite) {
    sqlite.close();
    sqlite = null;
    db = null;
  }
}

Schema Definition

Tables with Drizzle

// packages/shared/src/database/schema.ts
import { sqliteTable, text, integer, real } from 'drizzle-orm/sqlite-core';
import { relations } from 'drizzle-orm';

// Tasks table
export const tasks = sqliteTable('tasks', {
  id: text('id').primaryKey(),
  title: text('title').notNull(),
  description: text('description'),
  status: text('status', { 
    enum: ['pending', 'active', 'completed', 'failed'] 
  }).default('pending'),
  parentId: text('parent_id').references(() => tasks.id),
  attentionType: text('attention_type', {
    enum: ['supervised', 'delegated', 'sensitive']
  }).default('supervised'),
  orderIndex: real('order_index').notNull().default(0.5),
  createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
  updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

// Closure table for efficient hierarchy queries
export const taskClosure = sqliteTable('task_closure', {
  ancestorId: text('ancestor_id').notNull().references(() => tasks.id),
  descendantId: text('descendant_id').notNull().references(() => tasks.id),
  depth: integer('depth').notNull(),
}, (table) => ({
  pk: primaryKey({ columns: [table.ancestorId, table.descendantId] }),
}));

// Outcomes table
export const outcomes = sqliteTable('outcomes', {
  id: text('id').primaryKey(),
  taskId: text('task_id').notNull().references(() => tasks.id),
  title: text('title').notNull(),
  summary: text('summary'),
  status: text('status', {
    enum: ['pending', 'running', 'completed', 'failed']
  }).default('pending'),
  createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
  updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

// Agent sessions table
export const agentSessions = sqliteTable('agent_sessions', {
  id: text('id').primaryKey(),
  outcomeId: text('outcome_id').notNull().references(() => outcomes.id),
  provider: text('provider', {
    enum: ['copilot', 'anthropic', 'openai']
  }).notNull(),
  status: text('status', {
    enum: ['idle', 'running', 'paused', 'completed', 'error']
  }).default('idle'),
  startedAt: integer('started_at', { mode: 'timestamp' }),
  completedAt: integer('completed_at', { mode: 'timestamp' }),
});

// Agent steps (mind map nodes)
export const agentSteps = sqliteTable('agent_steps', {
  id: text('id').primaryKey(),
  sessionId: text('session_id').notNull().references(() => agentSessions.id),
  parentStepId: text('parent_step_id').references(() => agentSteps.id),
  type: text('type', {
    enum: ['thinking', 'tool_call', 'tool_result', 'decision_point', 'output']
  }).notNull(),
  content: text('content', { mode: 'json' }).notNull(),
  status: text('status', {
    enum: ['pending', 'running', 'completed', 'error']
  }).default('pending'),
  positionX: real('position_x'),
  positionY: real('position_y'),
  createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
});

// Decision points
export const decisionPoints = sqliteTable('decision_points', {
  id: text('id').primaryKey(),
  stepId: text('step_id').notNull().references(() => agentSteps.id).unique(),
  confidence: text('confidence', {
    enum: ['high', 'medium', 'low']
  }).notNull(),
  options: text('options', { mode: 'json' }).notNull(),
  tradeOffs: text('trade_offs', { mode: 'json' }),
  suggestedQuestions: text('suggested_questions', { mode: 'json' }),
  resolution: text('resolution', {
    enum: ['approved', 'rejected', 'cancelled']
  }),
  resolvedOption: text('resolved_option'),
  resolvedAt: integer('resolved_at', { mode: 'timestamp' }),
});

// Event log for replay
export const eventLog = sqliteTable('event_log', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  sessionId: text('session_id').references(() => agentSessions.id),
  eventType: text('event_type').notNull(),
  payload: text('payload', { mode: 'json' }).notNull(),
  timestamp: integer('timestamp', { mode: 'timestamp' }).notNull(),
});

Read the full file on GitHub · 543 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 543 lines · 78 tokens per session scan A 9561b2b056df

Subscribe to this mod's changes

database-drizzle is a skill published in the GitHub repository macromania/agentop (10 stars, last pushed 5mo ago), licensed MIT. It adds 78 tokens to every session and 3,898 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.