trueno_db/experiment/
experiment_record.rs1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
11pub struct ExperimentRecord {
12 experiment_id: String,
13 name: String,
14 created_at: DateTime<Utc>,
15 config: Option<serde_json::Value>,
16}
17
18impl ExperimentRecord {
19 #[must_use]
30 pub fn new(experiment_id: impl Into<String>, name: impl Into<String>) -> Self {
31 Self {
32 experiment_id: experiment_id.into(),
33 name: name.into(),
34 created_at: Utc::now(),
35 config: None,
36 }
37 }
38
39 #[must_use]
41 pub fn builder(
42 experiment_id: impl Into<String>,
43 name: impl Into<String>,
44 ) -> ExperimentRecordBuilder {
45 ExperimentRecordBuilder::new(experiment_id, name)
46 }
47
48 #[must_use]
50 pub fn experiment_id(&self) -> &str {
51 &self.experiment_id
52 }
53
54 #[must_use]
56 pub fn name(&self) -> &str {
57 &self.name
58 }
59
60 #[must_use]
62 pub const fn created_at(&self) -> DateTime<Utc> {
63 self.created_at
64 }
65
66 #[must_use]
68 pub const fn config(&self) -> Option<&serde_json::Value> {
69 self.config.as_ref()
70 }
71}
72
73#[derive(Debug)]
75pub struct ExperimentRecordBuilder {
76 experiment_id: String,
77 name: String,
78 created_at: DateTime<Utc>,
79 config: Option<serde_json::Value>,
80}
81
82impl ExperimentRecordBuilder {
83 #[must_use]
85 pub fn new(experiment_id: impl Into<String>, name: impl Into<String>) -> Self {
86 Self {
87 experiment_id: experiment_id.into(),
88 name: name.into(),
89 created_at: Utc::now(),
90 config: None,
91 }
92 }
93
94 #[must_use]
96 pub fn config(mut self, config: serde_json::Value) -> Self {
97 self.config = Some(config);
98 self
99 }
100
101 #[must_use]
103 pub const fn created_at(mut self, created_at: DateTime<Utc>) -> Self {
104 self.created_at = created_at;
105 self
106 }
107
108 #[must_use]
110 pub fn build(self) -> ExperimentRecord {
111 ExperimentRecord {
112 experiment_id: self.experiment_id,
113 name: self.name,
114 created_at: self.created_at,
115 config: self.config,
116 }
117 }
118}
119
120#[cfg(test)]
121mod tests {
122 use super::*;
123
124 #[test]
125 fn test_experiment_record_new() {
126 let record = ExperimentRecord::new("test-id", "test-name");
127 assert_eq!(record.experiment_id(), "test-id");
128 assert_eq!(record.name(), "test-name");
129 }
130
131 #[test]
132 fn test_experiment_record_builder() {
133 let config = serde_json::json!({"key": "value"});
134 let record =
135 ExperimentRecord::builder("test-id", "test-name").config(config.clone()).build();
136
137 assert_eq!(record.config(), Some(&config));
138 }
139}