Skip to content

Commit

Permalink
feat: remote database backend (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Oct 30, 2023
1 parent ba84c38 commit bbd938d
Show file tree
Hide file tree
Showing 9 changed files with 1,206 additions and 13 deletions.
551 changes: 547 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["proto", "sqlite"]
members = ["proto", "remote", "sqlite"]
resolver = "2"

[workspace.package]
Expand All @@ -13,15 +13,18 @@ denokv_proto = { version = "0.1.0", path = "./proto" }

anyhow = "1"
async-trait = "0.1"
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3.28"
log = "0.4.20"
num-bigint = "0.4"
prost = "0.11"
prost-build = "0.11"
rand = "0.8.5"
reqwest = { version = "0.11", features = ["json"] }
rusqlite = { version = "0.29.0" }
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.107"
tokio = { version = "1.33.0", features = ["full"] }
url = "2"
uuid = { version = "1.4.1", features = ["v4", "serde"] }
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Deno
Copyright (c) 2023 the Deno authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This repository contains two crates:
- `denokv_proto` (`/proto`): Shared interfaces backing KV, like definitions of
`Key`, `Database`, and `Value`.
- `denokv_sqlite` (`/sqlite`): An implementation of `Database` backed by SQLite.
- `denokv_remote` (`/remote`): An implementation of `Database` backed by a
remote KV database, acessible via the KV Connect protocol.

These crates are used by the `deno_kv` crate in the Deno repository to provide a
JavaScript API for interacting with Deno KV.
Expand Down
8 changes: 7 additions & 1 deletion proto/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,16 @@ pub struct CommitResult {
pub versionstamp: Versionstamp,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetadataExchangeRequest {
#[serde(default)]
pub supported_versions: Vec<u64>,
}

/// The database metadata that is returned by the KV Connect metadata endpoint.
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[allow(dead_code)]
pub struct DatabaseMetadata {
pub version: u64,
pub database_id: Uuid,
Expand Down
9 changes: 5 additions & 4 deletions proto/kv-connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ exponential backoff strategy with unlimited retries.
The client MUST verify that the response is a 200 OK, 3xx class redirect
response, or 4xx class HTTP status response. If the response is a 3xx class
redirect response, the client MUST follow the redirect and perform the metadata
exchange with the new URL as the base URL. If the response is a 4xx class HTTP
status response, the client MUST fatally abort the metadata exchange and display
the error message to the user. If the response is a 200 OK response, the client
MUST verify that the response body adheres to the JSON schema defined in the
exchange with the new URL as the base URL (the client MAY impose a maximum
redirect depth). If the response is a 4xx class HTTP status response, the client
MUST fatally abort the metadata exchange and display the error message to the
user. If the response is a 200 OK response, the client MUST verify that the
response body adheres to the JSON schema defined in the
`schema/kv-metadata-exchange-response.v<protocolversion>.json` file. If the
response body is invalid, the client MUST fatally abort the metadata exchange
and display the error message to the user.
Expand Down
4 changes: 2 additions & 2 deletions proto/schema/datapath.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ enum MutationType {
M_UNSPECIFIED = 0;
// Set the value.
M_SET = 1;
// Clear the value.
M_CLEAR = 2;
// Delete the value.
M_DELETE = 2;
// Sum the stored value with the new value. Both values must be LE64 encoded.
M_SUM = 3;
// Min the stored value with the new value. Both values must be LE64 encoded.
Expand Down
27 changes: 27 additions & 0 deletions remote/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "denokv_remote"
description = "Remote (KV Connect) backend for Deno KV"
version = "0.1.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
authors.workspace = true

[lib]
path = "lib.rs"

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
bytes.workspace = true
chrono.workspace = true
denokv_proto.workspace = true
log.workspace = true
prost.workspace = true
rand.workspace = true
reqwest.workspace = true
serde_json.workspace = true
serde.workspace = true
tokio.workspace = true
url.workspace = true
uuid.workspace = true
Loading

0 comments on commit bbd938d

Please sign in to comment.