Skip to content

Instantly share code, notes, and snippets.

@val314159
Last active August 29, 2015 14:07
Show Gist options
  • Save val314159/88aeea80c483cb222365 to your computer and use it in GitHub Desktop.
Save val314159/88aeea80c483cb222365 to your computer and use it in GitHub Desktop.
db driver for leveldb
from leveldb import LevelDB as _LevelDB
def _DB(_=[]): return (_ or _.append(_LevelDB('.db')) or 1) and _[0]
def ZAP(): list(DLT(k) for k,v in RNG([]))
def DLT(k): _DB().Delete(':'.join(k))
def GET(k): return json.loads(_DB().Get(':'.join(k)))
def PUT(k,v): _DB().Put(':'.join(k),json.dumps(v))
def RNGP(pfx=''):return (((k.split(':'),json.loads(v)) for k,v in
_DB().RangeIter(pfx,pfx+'~~~')))
def RNG(k=[]): return RNGP(':'.join(k))
def DLT1P(del_pfx): return ( DLT( k ) for k,v in RNG(del_pfx) )
def DLTSP(pfx_itr): return ( DLT1P(pfx) for pfx in pfx_itr )
def DUMP(pfx=''): return (((k,v) for k,v in _DB().RangeIter(pfx,pfx+'~~~')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment