| 14 | |
| 15 | |
| 16 | def _db_conn() -> sqlite3.Connection: |
| 17 | global _handle |
| 18 | fn = os.path.expanduser("~/.ghstackcache") |
| 19 | if not _handle: |
| 20 | _handle = sqlite3.connect(fn) |
| 21 | user_version = _handle.execute("PRAGMA user_version").fetchone() |
| 22 | if user_version is None or user_version[0] != CURRENT_VERSION: |
| 23 | _handle.close() |
| 24 | os.remove(fn) |
| 25 | _handle = sqlite3.connect(fn) |
| 26 | _handle.execute( |
| 27 | """ |
| 28 | CREATE TABLE ghstack_cache ( |
| 29 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 30 | domain TEXT, |
| 31 | key TEXT, |
| 32 | value TEXT |
| 33 | ) |
| 34 | """ |
| 35 | ) |
| 36 | _handle.execute( |
| 37 | """ |
| 38 | CREATE UNIQUE INDEX domain_key ON ghstack_cache (domain, key) |
| 39 | """ |
| 40 | ) |
| 41 | _handle.execute("PRAGMA user_version = {}".format(CURRENT_VERSION)) |
| 42 | _handle.commit() |
| 43 | return _handle |
| 44 | |
| 45 | |
| 46 | def get(domain: str, key: str) -> Optional[str]: |