Update playwright/README.md
This commit is contained in:
@@ -49,35 +49,27 @@ class DB(sqlite3.Connection):
|
||||
def __init__(self, db_name=".db.sqlite"):
|
||||
super().__init__(db_name)
|
||||
with self:
|
||||
self.execute(
|
||||
"""
|
||||
cur = self.execute("""
|
||||
CREATE TABLE IF NOT EXISTS kv_store
|
||||
(key TEXT PRIMARY KEY, value BLOB)
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
if not isinstance(value, bytes):
|
||||
value = json.dumps(value)
|
||||
value = value if isinstance(value, bytes) else json.dumps(value)
|
||||
with self:
|
||||
cur = self.execute(
|
||||
"""
|
||||
cur = self.execute("""
|
||||
INSERT OR REPLACE INTO kv_store
|
||||
(key, value) VALUES (?, ?)
|
||||
""",
|
||||
(key, value),
|
||||
)
|
||||
""", (key, value))
|
||||
return {"modified_count": cur.rowcount}
|
||||
|
||||
def __getitem__(self, key):
|
||||
with self:
|
||||
result = self.execute(
|
||||
"""
|
||||
cur = self.execute("""
|
||||
SELECT value FROM kv_store
|
||||
WHERE key = ?
|
||||
""",
|
||||
(key,),
|
||||
).fetchone()
|
||||
""", (key,))
|
||||
result = cur.fetchone()
|
||||
if result:
|
||||
if isinstance(result[0], str):
|
||||
try:
|
||||
@@ -88,42 +80,32 @@ class DB(sqlite3.Connection):
|
||||
|
||||
def delete(self, key):
|
||||
with self:
|
||||
cur = self.execute(
|
||||
"""
|
||||
cur = self.execute("""
|
||||
DELETE FROM kv_store
|
||||
WHERE key = ?
|
||||
""",
|
||||
(key,),
|
||||
)
|
||||
""", (key,))
|
||||
return {"deleted_count": cur.rowcount}
|
||||
|
||||
def keys(self, pattern="*"):
|
||||
pattern = pattern.translate(
|
||||
str.maketrans({"\\": "\\\\", "%": "\\%", "_": "\\_", "*": "%", "?": "_"})
|
||||
)
|
||||
pattern = pattern.translate(str.maketrans(
|
||||
{"\\": "\\\\", "%": "\\%", "_": "\\_", "*": "%", "?": "_"}))
|
||||
with self:
|
||||
result = self.execute(
|
||||
"""
|
||||
cur = self.execute("""
|
||||
SELECT key FROM kv_store
|
||||
WHERE key LIKE ? ESCAPE '\\'
|
||||
""",
|
||||
(pattern,),
|
||||
).fetchall()
|
||||
""", (pattern,))
|
||||
result = cur.fetchall()
|
||||
return [row[0] for row in result]
|
||||
|
||||
def __repr__(self):
|
||||
return repr(self.keys())
|
||||
def __repr__(self): return repr(self.keys())
|
||||
|
||||
def exists(self, key):
|
||||
with self:
|
||||
cur = self.execute(
|
||||
"""
|
||||
cur = self.execute("""
|
||||
SELECT 1 FROM kv_store
|
||||
WHERE key = ?
|
||||
LIMIT 1
|
||||
""",
|
||||
(key,),
|
||||
)
|
||||
""", (key,))
|
||||
return bool(cur.fetchone())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user