summaryrefslogtreecommitdiff
path: root/ext/kv/lib.rs
diff options
context:
space:
mode:
authorHeyang Zhou <zhy20000919@hotmail.com>2023-03-23 04:53:16 +0800
committerGitHub <noreply@github.com>2023-03-22 21:53:16 +0100
commit533e33131f1d697375f35fb6b7e1be5b9d84d4bf (patch)
treeb4066eed05da5b4d9b244a600a7cb17d2694fb6d /ext/kv/lib.rs
parenta117d3d91ed2d647ed53e79b0f900f0ec4d1b08d (diff)
fix(ext/kv): reverse mapping between `AnyValue::Bool` and `KeyPart::Bool` (#18365)
Previously the mapping between `AnyValue::Bool` and `KeyPart::Bool` was inverted. This patch also allows using the empty key `[]` as range start/end to `snapshot_read`.
Diffstat (limited to 'ext/kv/lib.rs')
-rw-r--r--ext/kv/lib.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs
index 49a59af74..2d4bae6fc 100644
--- a/ext/kv/lib.rs
+++ b/ext/kv/lib.rs
@@ -102,8 +102,8 @@ type KvKey = Vec<AnyValue>;
impl From<AnyValue> for KeyPart {
fn from(value: AnyValue) -> Self {
match value {
- AnyValue::Bool(false) => KeyPart::True,
- AnyValue::Bool(true) => KeyPart::False,
+ AnyValue::Bool(false) => KeyPart::False,
+ AnyValue::Bool(true) => KeyPart::True,
AnyValue::Number(n) => KeyPart::Float(n),
AnyValue::BigInt(n) => KeyPart::Int(n),
AnyValue::String(s) => KeyPart::String(s),
@@ -115,8 +115,8 @@ impl From<AnyValue> for KeyPart {
impl From<KeyPart> for AnyValue {
fn from(value: KeyPart) -> Self {
match value {
- KeyPart::True => AnyValue::Bool(false),
- KeyPart::False => AnyValue::Bool(true),
+ KeyPart::False => AnyValue::Bool(false),
+ KeyPart::True => AnyValue::Bool(true),
KeyPart::Float(n) => AnyValue::Number(n),
KeyPart::Int(n) => AnyValue::BigInt(n),
KeyPart::String(s) => AnyValue::String(s),
@@ -499,6 +499,16 @@ where
resource.db.clone()
};
+ for key in checks
+ .iter()
+ .map(|c| &c.0)
+ .chain(mutations.iter().map(|m| &m.0))
+ {
+ if key.is_empty() {
+ return Err(type_error("key cannot be empty"));
+ }
+ }
+
let checks = checks
.into_iter()
.map(TryInto::try_into)