cloudflare / cloudflare/cloudflare-rs

Add D1 database endpoints support

Open
#278 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
316
Forks
111
PR merge metrics
No merged PRs in 30d

Description

## 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

- [Cloudflare D1 Documentation](https://developers.cloudflare.com/d1/)
- [Cloudflare API Documentation](https://api.cloudflare.com/#d1)
- [D1 REST API Reference](https://developers.cloudflare.com/api/operations/cloudflare-d1-list-databases)

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.