Пример #1
0
 def deleteObject(self, key, bucket, commit=True):
     if self._bucket_exists(bucket):
         self.conn.execute(
             "DELETE from `{}` where key = ?".format(hash(bucket)), (key, ))
         if not self._has_keys(bucket):
             self.conn.execute("DROP TABLE IF EXISTS `{}`".format(
                 hash(bucket)))
         if commit:
             self.conn.commit()
Пример #2
0
 def deleteObject(self, key, bucket, commit=True):
     if self._bucket_exists(bucket):
         self.conn.execute("DELETE from `{}` where key = ?"
                           .format(hash(bucket)), (key,))
         if not self._has_keys(bucket):
             self.conn.execute("DROP TABLE IF EXISTS `{}`"
                               .format(hash(bucket)))
         if commit:
             self.conn.commit()
Пример #3
0
 def setObject(self, obj, key, bucket):
     if not self._bucket_exists(bucket):
         self._create_bucket(bucket)
     self.conn.execute(
         "REPLACE INTO `{}` (key, value) VALUES (?, ?)".format(
             hash(bucket)), (key, memoryview(compress(jsonify(obj)))))
     self.conn.commit()
Пример #4
0
 def setObject(self, obj, key, bucket):
     if not self._bucket_exists(bucket):
         self._create_bucket(bucket)
     self.conn.execute("REPLACE INTO `{}` (key, value) VALUES (?, ?)"
                       .format(hash(bucket)),
                       (key, memoryview(compress(jsonify(obj)))))
     self.conn.commit()
Пример #5
0
 def _has_keys(self, bucket):
     c = self.conn.execute("SELECT count(*) from `{}`".format(hash(bucket)))
     row = c.fetchone()
     if row[0]:
         return True
     else:
         return False
Пример #6
0
 def _has_keys(self, bucket):
     c = self.conn.execute("SELECT count(*) from `{}`".format(hash(bucket)))
     row = c.fetchone()
     if row[0]:
         return True
     else:
         return False
Пример #7
0
 def _bucket_exists(self, bucket):
     c = self.conn.execute("SELECT name from sqlite_master "
                           "WHERE type='table' and name=?",
                           (hash(bucket),))
     if c.fetchone():
         return True
     else:
         return False
Пример #8
0
 def _bucket_exists(self, bucket):
     c = self.conn.execute(
         "SELECT name from sqlite_master "
         "WHERE type='table' and name=?", (hash(bucket), ))
     if c.fetchone():
         return True
     else:
         return False
Пример #9
0
    def setObject(self, obj, key, bucket):
        if not self._bucket_exists(bucket):
            self._create_bucket(bucket)
        blob = sqlite3.Binary(compress(jsonify(obj).encode('utf-8')))
        self.conn.execute("REPLACE INTO `{}` (key, value) VALUES (?, ?)"
                          .format(hash(bucket)),
                          (key, blob))

        self.conn.commit()
Пример #10
0
 def getObject(self, key, bucket):
     if not self._bucket_exists(bucket):
         return key, None
     c = self.conn.execute("SELECT key, value from `{}` WHERE key=?"
                           .format(hash(bucket)), (key,))
     row = c.fetchone()
     if row:
         k, v = row
         return (k, dejsonify(decompress(v).decode('utf-8')))
     else:
         return key, None
Пример #11
0
 def getObject(self, key, bucket):
     if not self._bucket_exists(bucket):
         return key, None
     c = self.conn.execute("SELECT key, value from `{}` WHERE key=?"
                           .format(hash(bucket)), (key,))
     row = c.fetchone()
     if row:
         k, v = row
         return (k, dejsonify(decompress(v)))
     else:
         return key, None
Пример #12
0
 def _create_bucket(self, bucket):
     self.conn.execute("CREATE TABLE `{}` (key blob UNIQUE, value blob)"
                       .format(hash(bucket)))
Пример #13
0
 def updateObjectKey(self, bucket, oldkey, newkey):
     self.conn.execute(
         "UPDATE `{}` set key = ? where key=?".format(hash(bucket)),
         (newkey, oldkey))
     self.conn.commit()
Пример #14
0
 def getAllObjects(self, bucket):
     if not self._bucket_exists(bucket):
         return
     for k, v in self.conn.execute("SELECT key, value from `{}`"
                                   .format(hash(bucket))):
         yield (k, dejsonify(decompress(v)))
Пример #15
0
 def updateObjectKey(self, bucket, oldkey, newkey):
     self.conn.execute("UPDATE `{}` set key = ? where key=?"
                       .format(hash(bucket)), (newkey, oldkey))
     self.conn.commit()
Пример #16
0
 def _create_bucket(self, bucket):
     self.conn.execute(
         "CREATE TABLE `{}` (key blob UNIQUE, value blob)".format(
             hash(bucket)))
Пример #17
0
 def getAllObjects(self, bucket):
     if not self._bucket_exists(bucket):
         return
     for k, v in self.conn.execute("SELECT key, value from `{}`".format(
             hash(bucket))):
         yield (k, dejsonify(decompress(v)))