MCPcopy Create free account
hub / github.com/ElementsProject/lightning / Sqlite3Db

Class Sqlite3Db

tests/db.py:16–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15
16class Sqlite3Db(object):
17 def __init__(self, path):
18 self.path = path
19 self.provider = None
20
21 def get_dsn(self):
22 """SQLite3 doesn't provide a DSN, resulting in no CLI-option.
23 """
24 return None
25
26 def query(self, query):
27 db = sqlite3.connect(self.path)
28
29 db.row_factory = sqlite3.Row
30 c = db.cursor()
31 # Don't get upset by concurrent writes; wait for up to 5 seconds!
32 c.execute("PRAGMA busy_timeout = 5000")
33 c.execute(query)
34 rows = c.fetchall()
35
36 result = []
37 for row in rows:
38 result.append(dict(zip(row.keys(), row)))
39
40 db.commit()
41 c.close()
42 db.close()
43 return result
44
45 def execute(self, query):
46 db = sqlite3.connect(self.path)
47 c = db.cursor()
48 c.execute(query)
49 db.commit()
50 c.close()
51 db.close()
52
53
54class PostgresDb(object):

Callers 2

get_dbMethod · 0.70

Calls

no outgoing calls

Tested by 1