(
&self,
events: &[AnalyticsEventInsert],
)
| 2226 | } |
| 2227 | |
| 2228 | pub async fn append_analytics_events( |
| 2229 | &self, |
| 2230 | events: &[AnalyticsEventInsert], |
| 2231 | ) -> Result<Vec<i64>, String> { |
| 2232 | if events.is_empty() { |
| 2233 | return Ok(Vec::new()); |
| 2234 | } |
| 2235 | |
| 2236 | self.conn |
| 2237 | .execute("BEGIN IMMEDIATE", ()) |
| 2238 | .await |
| 2239 | .map_err(|e| format!("failed to begin analytics event batch: {e}"))?; |
| 2240 | |
| 2241 | let mut ids = Vec::with_capacity(events.len()); |
| 2242 | for event in events { |
| 2243 | match self.append_analytics_event(event).await { |
| 2244 | Ok(id) => ids.push(id), |
| 2245 | Err(err) => { |
| 2246 | let _ = self.conn.execute("ROLLBACK", ()).await; |
| 2247 | return Err(err); |
| 2248 | } |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | if let Err(err) = self.conn.execute("COMMIT", ()).await { |
| 2253 | let _ = self.conn.execute("ROLLBACK", ()).await; |
| 2254 | return Err(format!("failed to commit analytics event batch: {err}")); |
| 2255 | } |
| 2256 | |
| 2257 | Ok(ids) |
| 2258 | } |
| 2259 | |
| 2260 | pub async fn session_message_count(&self) -> Result<i64, String> { |
| 2261 | let mut rows = self |
no test coverage detected