This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

bino:CodernityDB

By: a guest on May 25th, 2014  |  syntax: Python  |  size: 1.36 KB  |  views: 177  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2.  
  3. from CodernityDB.database import Database
  4. from CodernityDB.hash_index import HashIndex
  5.  
  6.  
  7. class AllQueue(HashIndex):
  8.  
  9.     def __init__(self, *args, **kwargs):
  10.         kwargs['key_format'] = '16s'
  11.         super(AllQueue, self).__init__(*args, **kwargs)
  12.  
  13.     def make_key(self, key):
  14.         return key
  15.  
  16.     def make_key_value(self, data):
  17.         if data.get('_t') == 'queues':
  18.             return data.get('qname'), None
  19.  
  20.  
  21. class QueueItems(HashIndex):
  22.  
  23.     def __init__(self, *args, **kwargs):
  24.         kwargs['key_format'] = '16s'
  25.         super(QueueItems, self).__init__(*args, **kwargs)
  26.  
  27.     def make_key(self, key):
  28.         return key
  29.  
  30.     def make_key_value(self, data):
  31.         if data.get('_t') == 'qitems':
  32.             return data.get('qidx'), None
  33.  
  34.  
  35.  
  36.  
  37. def main():
  38.     db = Database('try02.cnd')
  39.     db.create()
  40.     queues_idx = AllQueue(db.path, 'queues')
  41.     db.add_index(queues_idx)
  42.     qitems_idx = QueueItems(db.path, 'qitems')
  43.     db.add_index(qitems_idx)
  44.  
  45.     names=['sandy','dion','tino']
  46.     for thisname in names :
  47.         db.insert(dict(qname=thisname))
  48.         for i in range(5) :
  49.             qdataval='%s_%i' %(thisname,i)
  50.             thisdict=dict(qidx=thisname, qdata=qdataval)
  51.             db.insert(thisdict)
  52.     for curr in db.all('id'):
  53.         print curr
  54.  
  55. if __name__ == '__main__':
  56.     main()
clone this paste RAW Paste Data