(
&self,
event: &AnalyticsEventInsert,
)
| 2186 | } |
| 2187 | |
| 2188 | pub async fn append_analytics_event( |
| 2189 | &self, |
| 2190 | event: &AnalyticsEventInsert, |
| 2191 | ) -> Result<i64, String> { |
| 2192 | let mut rows = self |
| 2193 | .conn |
| 2194 | .query( |
| 2195 | "INSERT INTO analytics_events |
| 2196 | (provider, project_id, session_id, timestamp, event_kind, hook_name, |
| 2197 | tool_name, tool_category, skill_name, hint_category, hint_id, outcome, |
| 2198 | metadata_json) |
| 2199 | VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13) |
| 2200 | RETURNING id", |
| 2201 | params![ |
| 2202 | event.provider.as_str(), |
| 2203 | event.project_id.as_str(), |
| 2204 | opt_text(event.session_id.as_deref()), |
| 2205 | event.timestamp, |
| 2206 | event.event_kind.as_str(), |
| 2207 | opt_text(event.hook_name.as_deref()), |
| 2208 | opt_text(event.tool_name.as_deref()), |
| 2209 | opt_text(event.tool_category.as_deref()), |
| 2210 | opt_text(event.skill_name.as_deref()), |
| 2211 | opt_text(event.hint_category.as_deref()), |
| 2212 | opt_text(event.hint_id.as_deref()), |
| 2213 | opt_text(event.outcome.as_deref()), |
| 2214 | opt_text(event.metadata_json.as_deref()), |
| 2215 | ], |
| 2216 | ) |
| 2217 | .await |
| 2218 | .map_err(|e| format!("failed to append analytics event: {e}"))?; |
| 2219 | let row = rows |
| 2220 | .next() |
| 2221 | .await |
| 2222 | .map_err(|e| format!("failed to read appended analytics event id: {e}"))? |
| 2223 | .ok_or_else(|| "append analytics event returned no id".to_string())?; |
| 2224 | row.get::<i64>(0) |
| 2225 | .map_err(|e| format!("failed to decode appended analytics event id: {e}")) |
| 2226 | } |
| 2227 | |
| 2228 | pub async fn append_analytics_events( |
| 2229 | &self, |
no outgoing calls