|
2 | 2 | import sqlite3 |
3 | 3 | from cloudproof_py.findex import Findex |
4 | 4 |
|
5 | | -from typing import Dict, List, Set, Tuple, Optional |
| 5 | +from typing import Dict, List, Set, Tuple |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class FindexSQLite(Findex.FindexUpsert, Findex.FindexSearch): |
9 | | - """Implementation of Findex traits for a SQLite backend""" |
| 9 | + """Implement Findex callbacks using SQLite.""" |
10 | 10 |
|
11 | 11 | def __init__(self, db_conn: sqlite3.Connection) -> None: |
12 | 12 | super().__init__() |
13 | 13 | self.conn = db_conn |
14 | 14 |
|
15 | 15 | def fetch_entry_table(self, entry_uids: List[bytes]) -> Dict[bytes, bytes]: |
16 | | - """Query the entry table |
| 16 | + """Query the Entry Table. |
17 | 17 |
|
18 | 18 | Args: |
19 | | - entry_uids List[bytes]: uids to query. if None, return the entire table |
| 19 | + entry_uids (List[bytes], optional): uids to query. if None, return the entire table |
20 | 20 |
|
21 | 21 | Returns: |
22 | | - Dict[bytes, bytes] |
| 22 | + Dict[bytes, bytes]: uid -> value mapping |
23 | 23 | """ |
24 | 24 | str_uids = ",".join("?" * len(entry_uids)) |
25 | 25 | cur = self.conn.execute( |
@@ -89,62 +89,11 @@ def upsert_entry_table( |
89 | 89 |
|
90 | 90 | return rejected_lines |
91 | 91 |
|
92 | | - def insert_entry_table(self, entries_items: Dict[bytes, bytes]) -> None: |
93 | | - """Insert new key-value pairs in the entry table |
94 | | -
|
95 | | - Args: |
96 | | - entry_items (Dict[bytes, bytes]) |
97 | | - """ |
98 | | - sql_insert_entry = """INSERT INTO entry_table(uid,value) VALUES(?,?)""" |
99 | | - self.conn.executemany( |
100 | | - sql_insert_entry, entries_items.items() |
101 | | - ) # batch insertions |
102 | | - |
103 | 92 | def insert_chain_table(self, chain_items: Dict[bytes, bytes]) -> None: |
104 | 93 | """Insert new key-value pairs in the chain table |
105 | 94 |
|
106 | 95 | Args: |
107 | 96 | chain_items (Dict[bytes, bytes]) |
108 | 97 | """ |
109 | 98 | sql_insert_chain = """INSERT INTO chain_table(uid,value) VALUES(?,?)""" |
110 | | - self.conn.executemany(sql_insert_chain, chain_items.items()) # batch insertions |
111 | | - |
112 | | - def remove_entry_table(self, entry_uids: Optional[List[bytes]] = None) -> None: |
113 | | - """Remove entries from entry table |
114 | | -
|
115 | | - Args: |
116 | | - entry_uids (List[bytes], optional): uid of entries to delete. |
117 | | - if None, delete all entries |
118 | | - """ |
119 | | - if entry_uids: |
120 | | - self.conn.executemany( |
121 | | - "DELETE FROM entry_table WHERE uid = ?", [(uid,) for uid in entry_uids] |
122 | | - ) |
123 | | - else: |
124 | | - self.conn.execute("DELETE FROM entry_table") |
125 | | - |
126 | | - def remove_chain_table(self, chain_uids: List[bytes]) -> None: |
127 | | - """Remove entries from chain table |
128 | | -
|
129 | | - Args: |
130 | | - chain_uids (List[bytes]): uids to remove from the chain table |
131 | | - """ |
132 | | - self.conn.executemany( |
133 | | - "DELETE FROM chain_table WHERE uid = ?", [(uid,) for uid in chain_uids] |
134 | | - ) |
135 | | - |
136 | | - def list_removed_locations(self, locations: List[bytes]) -> List[bytes]: |
137 | | - """Check whether uids still exist in the database |
138 | | -
|
139 | | - Args: |
140 | | - db_uids (List[bytes]): uids to check |
141 | | -
|
142 | | - Returns: |
143 | | - List[bytes]: list of uids that were removed |
144 | | - """ |
145 | | - res = [] |
146 | | - for uid in locations: |
147 | | - cursor = self.conn.execute("SELECT * FROM users WHERE id = ?", (uid,)) |
148 | | - if not cursor.fetchone(): |
149 | | - res.append(uid) |
150 | | - return res |
| 99 | + self.conn.executemany(sql_insert_chain, chain_items.items()) |
0 commit comments