# Path: huacaya/storage/base.py
# class StorageBase(object):
#     def create_bucket(self, name, index=()):
#         raise NotImplementedError
# 
#     def get_bucket(self, name):
#         raise NotImplementedError
# 
#     def drop(self, bucket):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get_bucket(item)
# 
# class BucketBase(object):
#     def drop(self):
#         raise NotImplementedError
# 
#     def put(self, entity):
#         raise NotImplementedError
# 
#     def get(self, stub):
#         raise NotImplementedError
# 
#     def delete(self, stub):
#         raise NotImplementedError
# 
#     def update(self, entity):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get(item)


import uuid
import sqlite3
import datetime
import itertools
    import cPickle as pickle
    import pickle
from .base import StorageBase, BucketBase
            elif len(row) == 0:
                raise IndexError('entity {0} not found'.format(stub))
            elif len(row) > 1:
                raise IndexError('entity {0} more than one'.format(stub))

    def find(self, index_dict):
        if isinstance(index_dict, dict):
            sql = ' INTERSECT '.join((
                'SELECT entity_id FROM {0}_indexes WHERE index_name=? AND index_val=?'.format(self._name) for i in range(len(index_dict))
            ))
            rows = self._db.cursor().execute(
                'SELECT body FROM {0}_entities WHERE id IN ({1})'.format(self._name, sql),
                tuple(itertools.chain(*index_dict.items()))
            )
            for r in rows:
                yield pickle.loads(r[0])

    def __contains__(self, stub):
        if isinstance(stub, str):
            return self._db.cursor().execute(
                'SELECT COALESCE((SELECT 1 FROM {0}_entities WHERE id=?), 0)'.format(self._name),
                (stub, )).fetchone()[0]
        elif isinstance(stub, dict):
            sql = ' INTERSECT '.join((
                'SELECT entity_id FROM {0}_indexes WHERE index_name=? AND index_val=?'.format(self._name) for i in range(len(stub))
            ))
            return bool(self._db.cursor().execute(
                'SELECT EXISTS({0})'.format(sql), tuple(itertools.chain(*stub.items()))
            ).fetchone()[0])


# Path: huacaya/storage/base.py
# class StorageBase(object):
#     def create_bucket(self, name, index=()):
#         raise NotImplementedError
# 
#     def get_bucket(self, name):
#         raise NotImplementedError
# 
#     def drop(self, bucket):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get_bucket(item)
# 
# class BucketBase(object):
#     def drop(self):
#         raise NotImplementedError
# 
#     def put(self, entity):
#         raise NotImplementedError
# 
#     def get(self, stub):
#         raise NotImplementedError
# 
#     def delete(self, stub):
#         raise NotImplementedError
# 
#     def update(self, entity):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get(item)


# Path: huacaya/storage/sqlite.py
import uuid
import sqlite3
import datetime
import itertools
    import cPickle as pickle
    import pickle
from .base import StorageBase, BucketBase

            elif len(row) == 0:
                raise IndexError('entity {0} not found'.format(stub))
            elif len(row) > 1:
                raise IndexError('entity {0} more than one'.format(stub))

    def find(self, index_dict):
        if isinstance(index_dict, dict):
            sql = ' INTERSECT '.join((
                'SELECT entity_id FROM {0}_indexes WHERE index_name=? AND index_val=?'.format(self._name) for i in range(len(index_dict))
            ))
            rows = self._db.cursor().execute(
                'SELECT body FROM {0}_entities WHERE id IN ({1})'.format(self._name, sql),
                tuple(itertools.chain(*index_dict.items()))
            )
            for r in rows:
                yield pickle.loads(r[0])

    def __contains__(self, stub):
        if isinstance(stub, str):
            return self._db.cursor().execute(
                'SELECT COALESCE((SELECT 1 FROM {0}_entities WHERE id=?), 0)'.format(self._name),
                (stub, )).fetchone()[0]
        elif isinstance(stub, dict):
            sql = ' INTERSECT '.join((
                'SELECT entity_id FROM {0}_indexes WHERE index_name=? AND index_val=?'.format(self._name) for i in range(len(stub))
            ))
            return bool(self._db.cursor().execute(
                'SELECT EXISTS({0})'.format(sql), tuple(itertools.chain(*stub.items()))
            ).fetchone()[0])


class SqliteStorage(StorageBase):