Update sqlite3/README.md
This commit is contained in:
@@ -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
|
||||
```
|
||||
Reference in New Issue
Block a user