def __init__(self, sqluri, standard_collections=False, **dbkwds):

        self.sqluri = sqluri
        self.dbconnector = DBConnector(sqluri, **dbkwds)

        # There doesn't seem to be a reliable cross-database way to set the
        # initial value of an autoincrement column.  Fake it by inserting
        # a row into the table at the desired start id.
        self.standard_collections = standard_collections
        if self.standard_collections and dbkwds.get("create_tables", False):
            zeroth_id = FIRST_CUSTOM_COLLECTION_ID - 1
            with self.dbconnector.connect() as connection:
                params = {"collectionid": zeroth_id, "name": ""}
                try:
                    connection.query("INSERT_COLLECTION", params)
                except IntegrityError:
                    pass

        # A local in-memory cache for the name => collectionid mapping.
        self._collections_by_name = {}
        self._collections_by_id = {}
        if self.standard_collections:
            for id, name in STANDARD_COLLECTIONS.iteritems():
                self._collections_by_name[name] = id
                self._collections_by_id[id] = name

        # A thread-local to track active sessions.
        self._tldata = threading.local()
    def __init__(self, sqluri, standard_collections=False, **dbkwds):
        self.allow_migration = dbkwds.get("allow_migration", False)
        self.sqluri = sqluri
        self.dbconnector = DBConnector(sqluri, **dbkwds)
        self._optimize_table_before_purge = \
            dbkwds.get("optimize_table_before_purge", True)
        self._optimize_table_after_purge = \
            dbkwds.get("optimize_table_after_purge", True)
        self._default_find_params = {
            "force_consistent_sort_order":
            dbkwds.get("force_consistent_sort_order", False),
        }

        # There doesn't seem to be a reliable cross-database way to set the
        # initial value of an autoincrement column.
        self.standard_collections = standard_collections
        if self.standard_collections and dbkwds.get("create_tables", False):
            with self.dbconnector.connect() as connection:
                params = {"collectionid": FIRST_CUSTOM_COLLECTION_ID}
                try:
                    connection.query("SET_MIN_COLLECTION_ID", params)
                except IntegrityError:
                    if self.dbconnector.driver == "postgres":
                        raise

        # A local in-memory cache for the name => collectionid mapping.
        self._collections_by_name = {}
        self._collections_by_id = {}
        if self.standard_collections:
            for id, name in STANDARD_COLLECTIONS.iteritems():
                self._collections_by_name[name] = id
                self._collections_by_id[id] = name

        # A thread-local to track active sessions.
        self._tldata = threading.local()