Returns - None Input - None ---------- - Initialize database. we use sqlite3 - Check if the tables exist, if not create them - maintain a class level access to the database connection object
(self)
| 11 | """ |
| 12 | |
| 13 | def __init__(self): |
| 14 | """ |
| 15 | Returns - None |
| 16 | Input - None |
| 17 | ---------- |
| 18 | - Initialize database. we use sqlite3 |
| 19 | - Check if the tables exist, if not create them |
| 20 | - maintain a class level access to the database |
| 21 | connection object |
| 22 | """ |
| 23 | self.conn = sqlite3.connect("searchengine.sqlite3", autocommit=True) |
| 24 | cur = self.conn.cursor() |
| 25 | res = cur.execute("SELECT name FROM sqlite_master WHERE name='IdToDoc'") |
| 26 | tables_exist = res.fetchone() |
| 27 | |
| 28 | if not tables_exist: |
| 29 | self.conn.execute( |
| 30 | "CREATE TABLE IdToDoc(id INTEGER PRIMARY KEY, document TEXT)" |
| 31 | ) |
| 32 | self.conn.execute("CREATE TABLE WordToId (name TEXT, value TEXT)") |
| 33 | cur.execute( |
| 34 | "INSERT INTO WordToId VALUES (?, ?)", |
| 35 | ( |
| 36 | "index", |
| 37 | "{}", |
| 38 | ), |
| 39 | ) |
| 40 | |
| 41 | def index_document(self, document): |
| 42 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected