1use std::path::{Path, PathBuf};
2use workspace::WorkspaceDb;
3
4use db::sqlez_macros::sql;
5use db::{define_connection, query};
6
7define_connection!(
8 pub static ref DB: ZetaDb<WorkspaceDb> = &[
9 sql! (
10 CREATE TABLE zeta_preferences(
11 worktree_path BLOB NOT NULL PRIMARY KEY,
12 accepted_data_collection INTEGER
13 ) STRICT;
14 ),
15 ];
16);
17
18impl ZetaDb {
19 query! {
20 pub fn get_all_data_collection_preferences() -> Result<Vec<(PathBuf, bool)>> {
21 SELECT worktree_path, accepted_data_collection FROM zeta_preferences
22 }
23 }
24
25 query! {
26 pub fn get_accepted_data_collection(worktree_path: &Path) -> Result<Option<bool>> {
27 SELECT accepted_data_collection FROM zeta_preferences
28 WHERE worktree_path = ?
29 }
30 }
31
32 query! {
33 pub async fn save_data_collection_choice(worktree_path: PathBuf, accepted_data_collection: bool) -> Result<()> {
34 INSERT INTO zeta_preferences
35 (worktree_path, accepted_data_collection)
36 VALUES
37 (?1, ?2)
38 ON CONFLICT (worktree_path) DO UPDATE SET
39 accepted_data_collection = ?2
40 }
41 }
42
43 query! {
44 pub async fn clear_all_zeta_preferences() -> Result<()> {
45 DELETE FROM zeta_preferences
46 }
47 }
48}