Update sqlite3-python/README.md

This commit is contained in:
2024-09-24 09:30:56 -04:00
parent b628ce637f
commit 1fa013dd00

View File

@@ -11,21 +11,20 @@ sql = SQL()
# Simple # Simple
```python ```python
def SQL(): def sql():
import sqlite3 import sqlite3
sql = sqlite3.connect('db.sqlite', isolation_level=None).execute sql = sqlite3.connect('db.sqlite', isolation_level=None).execute
sql('PRAGMA journal_mode=WAL') sql('PRAGMA journal_mode=WAL')
sql('CREATE TABLE IF NOT EXISTS dict (key TEXT PRIMARY KEY, value)') sql('CREATE TABLE IF NOT EXISTS dict (key TEXT PRIMARY KEY, value)')
return type('', (), dict(__call__=lambda _, *args: [*sql(*args)], return type('', (), dict(__call__=lambda _, *args: [*sql(*args)],
__setitem__=lambda _, k, v: sql( __setitem__=lambda _, k, v: sql(
'INSERT OR REPLACE INTO dict VALUES (?, ?)', (k, v)), 'INSERT OR REPLACE INTO dict VALUES (?, ?)', (k, v)) or {k: v},
__getitem__=lambda _, k: sql( __getitem__=lambda _, k: sql(
'SELECT value FROM dict WHERE key = ?', (k,)).fetchone()[0] 'SELECT value FROM dict WHERE key = ?', (k,)).fetchone()[0]
))() ))()
# #
sql = SQL() sql()[4] = 2
sql[4] = 2 print(sql()[4]) # 2
print(sql[4]) # 2
``` ```
# Class # Class