Update sqlite3-python/README.md
This commit is contained in:
@@ -12,17 +12,16 @@ sql = SQL()
|
|||||||
# Simple
|
# Simple
|
||||||
```python
|
```python
|
||||||
def sql():
|
def sql():
|
||||||
import sqlite3
|
sql = __import__('sqlite3').connect('sql.db', 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:
|
||||||
'INSERT OR REPLACE INTO dict VALUES (?, ?)', (k, v)) or {k: v},
|
sql('INSERT OR REPLACE INTO dict VALUES (?, ?)', (k, v)) or {k: v},
|
||||||
__getitem__=lambda _, k: sql(
|
__getitem__=lambda _, k:
|
||||||
'SELECT value FROM dict WHERE key = ?', (k,)).fetchone()[0]
|
sql('SELECT value FROM dict WHERE key = ?', (k,)).fetchone()[0]
|
||||||
))()
|
))()
|
||||||
#
|
|
||||||
sql()[4] = 2
|
sql()[4] = 2
|
||||||
print(sql()[4]) # 2
|
print(sql()[4]) # 2
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user