Update sqlite3-python/README.md
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Simple
|
||||
# Simplest
|
||||
```python
|
||||
def SQL():
|
||||
import sqlite3
|
||||
@@ -8,6 +8,26 @@ def SQL():
|
||||
return lambda *args: [dict(row) for row in conn.execute(*args)]
|
||||
sql = SQL()
|
||||
```
|
||||
|
||||
# Simple
|
||||
```python
|
||||
def SQL():
|
||||
import sqlite3
|
||||
sql = sqlite3.connect('db.sqlite', isolation_level=None).execute
|
||||
sql('PRAGMA journal_mode=WAL')
|
||||
sql('CREATE TABLE IF NOT EXISTS dict (key TEXT PRIMARY KEY, value)')
|
||||
return type('', (), dict(__call__=lambda _, *args: [*sql(*args)],
|
||||
__setitem__=lambda _, k, v: sql(
|
||||
'INSERT OR REPLACE INTO dict VALUES (?, ?)', (k, v)),
|
||||
__getitem__=lambda _, k: sql(
|
||||
'SELECT value FROM dict WHERE key = ?', (k,)).fetchone()[0]
|
||||
))()
|
||||
#
|
||||
sql = SQL()
|
||||
sql[4] = 2
|
||||
print(sql[4]) # 2
|
||||
```
|
||||
|
||||
# Class
|
||||
```python
|
||||
class SQL:
|
||||
|
||||
Reference in New Issue
Block a user