MCPcopy Create free account
hub / github.com/ezyang/ghstack / _db_conn

Function _db_conn

src/ghstack/cache.py:16–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15
16def _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
46def get(domain: str, key: str) -> Optional[str]:

Callers 2

getFunction · 0.85
putFunction · 0.85

Calls 1

formatMethod · 0.80

Tested by

no test coverage detected