Skip to content

Implement SQLite-based KvStore implementation #274

@dahlia

Description

@dahlia

Background

To support the migration from Deno KV to SQLite in our tutorials (see #272 and #273), we need a SQLite-based implementation of the KvStore interface.

This implementation would enable users to use SQLite as their persistent storage backend while maintaining compatibility with Fedify's existing KvStore API.

Proposed Implementation

Create a SqliteKvStore class that implements the KvStore interface using SQLite as the underlying storage mechanism.

Key Requirements

  • Cross-runtime compatibility: Support Node.js (node:sqlite), Deno (node:sqlite compatible), and Bun (bun:sqlite)
  • API compatibility: Full implementation of the existing KvStore interface
  • Performance: Efficient SQLite operations with proper indexing
  • Reliability: Proper error handling and transaction support
  • Type safety: Full TypeScript support with proper type definitions

Packaging Options

Two potential approaches for distribution:

  1. Integrated approach: @fedify/fedify/x/sqlite

    • Pros: Easier discovery, single dependency
    • Cons: Increases main package size
  2. Separate package: @fedify/sqlite

    • Pros: Optional dependency, cleaner separation of concerns
    • Cons: Additional package to maintain, potential version sync issues

Implementation Details

  • Use native SQLite modules across all supported runtimes
  • Implement proper schema migration handling
  • Support for TTL (time-to-live) functionality if needed
  • Comprehensive test coverage across all target runtimes
  • Clear documentation and usage examples

Benefits

  1. Tutorial modernization: Enables migration away from Deno KV in tutorials
  2. Production readiness: Provides a solid SQLite option for production use
  3. Developer experience: Familiar SQLite database with KvStore convenience
  4. Cross-platform: Works consistently across Node.js, Deno, and Bun

Acceptance Criteria

  • SqliteKvStore class implements full KvStore interface
  • Works with Node.js v22+ using node:sqlite
  • Works with Deno v2.2+ using node:sqlite compatible module
  • Works with Bun using bun:sqlite
  • Comprehensive test suite covering all runtimes
  • Documentation and usage examples
  • Decision made on packaging approach (@fedify/fedify/x/sqlite vs @fedify/sqlite)

Metadata

Metadata

Assignees

Labels

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions