Update jimm.py
This commit is contained in:
6
jimm.py
6
jimm.py
@@ -22,17 +22,17 @@ def SQL():
|
|||||||
con.execute('PRAGMA journal_mode=wal')
|
con.execute('PRAGMA journal_mode=wal')
|
||||||
con.execute('PRAGMA busy_timeout='f'{1e9}')
|
con.execute('PRAGMA busy_timeout='f'{1e9}')
|
||||||
con.execute('CREATE TABLE IF NOT EXISTS kv(k, v, t DEFAULT CURRENT_TIMESTAMP)')
|
con.execute('CREATE TABLE IF NOT EXISTS kv(k, v, t DEFAULT CURRENT_TIMESTAMP)')
|
||||||
os.makedirs('.blob', exist_ok=True)
|
os.makedirs('.db-blob', exist_ok=True)
|
||||||
def put(sql, filename, blob):
|
def put(sql, filename, blob):
|
||||||
sha1 = hashlib.sha1(blob).hexdigest()
|
sha1 = hashlib.sha1(blob).hexdigest()
|
||||||
if not sql('SELECT 1 FROM kv WHERE v=?', sha1):
|
if not sql('SELECT 1 FROM kv WHERE v=?', sha1):
|
||||||
try:
|
try:
|
||||||
with open(f'.blob/{sha1}', 'xb') as f: f.write(blob)
|
with open(f'.db-blob/{sha1}', 'xb') as f: f.write(blob)
|
||||||
print(f'{G(len(blob)):>16} {filename}')
|
print(f'{G(len(blob)):>16} {filename}')
|
||||||
except FileExistsError: pass
|
except FileExistsError: pass
|
||||||
sql[filename] = sha1
|
sql[filename] = sha1
|
||||||
def get(sql, filename):
|
def get(sql, filename):
|
||||||
return open(f'.blob/{sql[filename]}', 'rb').read()
|
return open(f'.db-blob/{sql[filename]}', 'rb').read()
|
||||||
|
|
||||||
return type('', (), dict(put=put, get=get,
|
return type('', (), dict(put=put, get=get,
|
||||||
__call__=lambda _, q, *p: list(map(dict, con.execute(q, p))),
|
__call__=lambda _, q, *p: list(map(dict, con.execute(q, p))),
|
||||||
|
|||||||
Reference in New Issue
Block a user