Update playwright/README.md

This commit is contained in:
2024-08-23 15:26:21 -04:00
parent 106501aec0
commit 8beb76ba81

View File

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