feat: add complete D1 database endpoints implementation#279
Open
EmilLindfors wants to merge 2 commits into
Open
feat: add complete D1 database endpoints implementation#279EmilLindfors wants to merge 2 commits into
EmilLindfors wants to merge 2 commits into
Conversation
Implements comprehensive D1 database management endpoints providing full API coverage based on the official Cloudflare OpenAPI specification. ## Endpoints Added ### Database Management - `ListDatabases`: List all D1 databases in an account - `CreateDatabase`: Create new D1 database with optional location hint - `GetDatabase`: Get detailed information about a specific database - `DeleteDatabase`: Delete a D1 database permanently - `UpdateDatabase`: Update database configuration (read replication) - `UpdatePartialDatabase`: Partially update database configuration ### Data Operations - `QueryDatabase`: Execute parameterized SQL queries - `RawQuery`: Execute raw SQL with optimized response format - `ExportDatabase`: Export database as SQL with polling support - `ImportDatabase`: Import SQL data with upload URL generation ## Data Structures ### Core Types - `D1Database`: Complete database metadata with read replication details - `D1QueryResult`: Standard query results with metadata - `D1RawQueryResult`: Performance-optimized query results - `D1QueryMeta`: Comprehensive query execution metadata ### Configuration Types - `D1PrimaryLocationHint`: All 6 official regions (wnam, enam, weur, eeur, apac, oc) - `D1ReadReplicationMode`: Auto/disabled replication modes - `D1ReadReplicationConfig`: Read replication configuration ### Request Parameters - `CreateDatabaseParams`: Database creation with optional location hint - `UpdateDatabaseParams`: Full database configuration updates - `UpdatePartialDatabaseParams`: Partial configuration updates - `QueryDatabaseParams`: Parameterized SQL query execution - `RawQueryParams`: Raw SQL execution - `ExportDatabaseParams`: Database export configuration - `ImportDatabaseParams`: Database import configuration ## Testing Added comprehensive test coverage (11 tests) including: - Parameter serialization/deserialization - Response structure validation - Enum value handling - Optional field handling - Complex nested object deserialization ## API Specification Compliance Implementation is 100% compliant with the official Cloudflare OpenAPI specification (openapi.yaml from github.com/cloudflare/api-schemas): - All 10 D1 endpoints implemented - Request/response schemas match exactly - All optional parameters supported - Proper HTTP methods and paths - Complete metadata support This fills a significant gap in cloudflare-rs by providing complete D1 database management capabilities that were previously missing from the library.
- Use serde_with::skip_serializing_none instead of manual skip_serializing_if - Move shared data structures to data_structures.rs module - Update API documentation links to api.cloudflare.com format - Move tests inline to each module following project patterns - Restructure mod.rs exports to match project conventions - Maintain 100% API specification compliance All tests passing (6/6).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements comprehensive D1 database management endpoints for cloudflare-rs, providing full API coverage based on the official Cloudflare OpenAPI specification.
Closes #278
Changes
Database Management Endpoints
ListDatabases: List all D1 databases in an accountCreateDatabase: Create new D1 database with optional location hintGetDatabase: Get detailed information about a specific databaseDeleteDatabase: Delete a D1 database permanentlyUpdateDatabase: Update database configuration (read replication)UpdatePartialDatabase: Partially update database configurationData Operations Endpoints
QueryDatabase: Execute parameterized SQL queriesRawQuery: Execute raw SQL with optimized response formatExportDatabase: Export database as SQL with polling supportImportDatabase: Import SQL data with upload URL generationData Structures
Core Types
D1Database: Complete database metadata with read replication detailsD1QueryResult: Standard query results with metadataD1RawQueryResult: Performance-optimized query resultsD1QueryMeta: Comprehensive query execution metadataConfiguration Types
D1PrimaryLocationHint: All 6 official regions (wnam, enam, weur, eeur, apac, oc)D1ReadReplicationMode: Auto/disabled replication modesD1ReadReplicationConfig: Read replication configurationRequest Parameters
CreateDatabaseParams: Database creation with optional location hintUpdateDatabaseParams: Full database configuration updatesUpdatePartialDatabaseParams: Partial configuration updatesQueryDatabaseParams: Parameterized SQL query executionRawQueryParams: Raw SQL executionExportDatabaseParams: Database export configurationImportDatabaseParams: Database import configurationCode Organization
Follows cloudflare-rs conventions exactly:
data_structures.rs#[cfg(test)]modules#[serde_with::skip_serializing_none]api.cloudflare.comTesting
Comprehensive test coverage (6 test modules):
All tests pass: ✅ 6/6
API Specification Compliance
Implementation is 100% compliant with the official Cloudflare OpenAPI specification:
Impact
This fills a significant gap in cloudflare-rs by providing complete D1 database management capabilities that were previously missing from the library. Developers can now:
Verification
cargo check --features blockingcargo test d1 --features blockingBreaking Changes
None. This is a pure addition that doesn't modify existing APIs.
Documentation
All endpoints include comprehensive documentation with:
Development Process
This implementation was developed with assistance from Claude Code to ensure: