Skip to content

Add D1 database endpoints support #278

@EmilLindfors

Description

@EmilLindfors

Summary

This issue requests the addition of comprehensive D1 database endpoint support to cloudflare-rs. Currently, the library only includes D1 bindings for Workers but lacks the database management endpoints needed for full D1 operations.

Background

D1 is Cloudflare's serverless SQL database service that provides SQLite-compatible databases with global distribution. While cloudflare-rs supports D1 bindings in the Workers module, it's missing the core database management functionality.

Missing Functionality

The following D1 API endpoints are currently not implemented:

Database Management

  • GET /accounts/{account_id}/d1/database - List databases
  • POST /accounts/{account_id}/d1/database - Create database
  • GET /accounts/{account_id}/d1/database/{database_id} - Get database details
  • DELETE /accounts/{account_id}/d1/database/{database_id} - Delete database
  • PUT /accounts/{account_id}/d1/database/{database_id} - Update database
  • PATCH /accounts/{account_id}/d1/database/{database_id} - Partial update database

Data Operations

  • POST /accounts/{account_id}/d1/database/{database_id}/query - Execute SQL queries
  • POST /accounts/{account_id}/d1/database/{database_id}/raw - Execute raw SQL queries
  • POST /accounts/{account_id}/d1/database/{database_id}/export - Export database
  • POST /accounts/{account_id}/d1/database/{database_id}/import - Import database

Proposed Solution

Implement a complete d1 endpoints module that provides:

  1. Database Management: Full CRUD operations for D1 databases
  2. Query Execution: Both parameterized and raw SQL query support
  3. Data Import/Export: Database backup and restore capabilities
  4. Configuration Management: Read replication and location hint support
  5. Comprehensive Testing: Full test coverage for all endpoints
  6. API Specification Compliance: 100% compliance with official OpenAPI spec

Implementation Details

  • Follow existing cloudflare-rs patterns and conventions
  • Use official Cloudflare OpenAPI specification as source of truth
  • Implement proper error handling and response types
  • Include comprehensive documentation and examples
  • Maintain both blocking and async API support

Impact

This would fill a significant gap in cloudflare-rs functionality and enable developers to:

  • Manage D1 databases programmatically from Rust applications
  • Execute SQL queries and manage database schemas
  • Implement automated backup/restore workflows
  • Build complete database-driven applications on Cloudflare's platform

References

I have a complete implementation ready that follows all project conventions and passes comprehensive tests. I would be happy to submit a PR if this feature addition is welcomed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions