MCPcopy Create free account
hub / github.com/geekcomputers/Python / __init__

Method __init__

AutoComplete_App/backend.py:33–64  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

31 """
32
33 def __init__(self):
34 """
35 Returns - None
36 Input - None
37 ----------
38 - Initialize database. we use sqlite3
39 - Check if the tables exist, if not create them
40 - maintain a class level access to the database
41 connection object
42 """
43 self.conn = sqlite3.connect("autocompleteDB.sqlite3", autocommit=True)
44 cur = self.conn.cursor()
45 res = cur.execute("SELECT name FROM sqlite_master WHERE name='WordMap'")
46 tables_exist = res.fetchone()
47
48 if not tables_exist:
49 self.conn.execute("CREATE TABLE WordMap(name TEXT, value TEXT)")
50 self.conn.execute("CREATE TABLE WordPrediction (name TEXT, value TEXT)")
51 cur.execute(
52 "INSERT INTO WordMap VALUES (?, ?)",
53 (
54 "wordsmap",
55 "{}",
56 ),
57 )
58 cur.execute(
59 "INSERT INTO WordPrediction VALUES (?, ?)",
60 (
61 "predictions",
62 "{}",
63 ),
64 )
65
66 def train(self, sentence):
67 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected