You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
eprintln!("{}: Failed to execute query {query} as {err}","ERROR".bold().red(), query = statement.bright_blue(), err = err.to_string().red());
27
-
})?;
28
-
Ok(())
29
-
}
30
-
31
-
pubfnbegin(&self) -> Result<(),()>{
32
-
// TODO: Add error logging
33
-
self.execute("BEGIN;")
34
-
}
35
-
36
-
pubfncommit(&self) -> Result<(),()>{
37
-
// TODO: Add error logging
38
-
self.execute("COMMIT;")
39
-
}
40
-
41
-
pubfnopen(path:&Path) -> Result<Self,()>{
42
-
let connection = sqlite::open(path).map_err(|err| {
43
-
eprintln!("{}: Could not open sqlite database {path} as {err}","ERROR".bold().red(), path = path.display().to_string().bright_blue(), err = err.to_string().red());
44
-
})?;
45
-
46
-
let this = Self{connection};
47
-
48
-
// Table Documents (Contains path and term_count)
49
-
this.execute("
50
-
CREATE TABLE IF NOT EXISTS Documents (
51
-
id INTEGER NOT NULL PRIMARY KEY,
52
-
path TEXT,
53
-
term_count INTEGER,
54
-
UNIQUE(path)
55
-
);
56
-
")?;
57
-
58
-
// Table FreqTable (Contains map of term with its count refering to a document)
59
-
this.execute("
60
-
CREATE TABLE IF NOT EXISTS FreqTable (
61
-
term TEXT,
62
-
doc_id INTEGER,
63
-
freq INTEGER,
64
-
UNIQUE(term, doc_id),
65
-
FOREIGN KEY(doc_id) REFERENCES Documents(id)
66
-
);
67
-
")?;
68
-
69
-
// Table GlobalTermFreq (Contains map of term with its frequency of occurence in entire document corpus)
70
-
this.execute("
71
-
CREATE TABLE IF NOT EXISTS GlobalTermFreq (
72
-
term TEXT,
73
-
freq INTEGER,
74
-
UNIQUE(term)
75
-
);
76
-
")?;
77
-
78
-
Ok(this)
79
-
}
80
-
81
-
pubfncheck(&self) -> Result<u64,()>{
82
-
let count = {
83
-
let query = "SELECT COUNT(*) as count FROM Documents";
84
-
let log_err = |err: sqlite::Error| {
85
-
eprintln!("{ERROR}: Could not execute query {query} as {err}",ERROR = "ERROR".bold().red(), err = err.to_string().red());
0 commit comments