Skip to main content

uni_db/api/
builder.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2026 Dragonscale Team
3
4use serde_json::Value;
5use std::collections::HashMap;
6
7/// A fluent builder for constructing property maps.
8#[derive(Debug, Default, Clone)]
9pub struct PropertiesBuilder {
10    properties: HashMap<String, Value>,
11}
12
13impl PropertiesBuilder {
14    /// Create a new empty properties builder.
15    pub fn new() -> Self {
16        Self {
17            properties: HashMap::new(),
18        }
19    }
20
21    /// Add a property to the builder.
22    /// The value can be anything that converts into `serde_json::Value`.
23    pub fn add(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
24        self.properties.insert(key.into(), value.into());
25        self
26    }
27
28    /// Build the properties map.
29    pub fn build(self) -> HashMap<String, Value> {
30        self.properties
31    }
32}