Update sqlite3/README.md

This commit is contained in:
2024-08-23 08:07:01 -04:00
parent de775913e8
commit db0af1a6a3

View File

@@ -53,6 +53,15 @@ class DB(sqlite3.Connection):
return [row[0] for row in result]
def __repr__(self): return repr(self.keys())
def exists(self, key):
with self:
cur = self.execute('''
SELECT 1 FROM kv_store
WHERE key = ?
LIMIT 1
''', (key,))
return bool(cur.fetchone())
```
# Usage
```python
@@ -75,4 +84,9 @@ complex_obj = {'name': 'John', 'age': 30, 'city': 'New York'}
db['complex'] = complex_obj
loaded_obj = db['complex']
print(loaded_obj) # 출력: {'name': 'John', 'age': 30, 'city': 'New York'} (dict 타입)
db['test_key'] = 'test_value'
print(db.exists('test_key')) # True
print(db.exists('non_existent_key')) # False
```