| 14 | |
| 15 | |
| 16 | class 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 | |
| 54 | class PostgresDb(object): |
no outgoing calls