Ejemplo n.º 1
0
 def clear(self):
     with sqlliteConnect(self.__db_path) as conn:
         conn.execute("DROP TABLE IF EXISTS {}_kvs".format(self.__db_name))
         conn.execute(
             "CREATE TABLE IF NOT EXISTS {}_kvs (key TEXT PRIMARY KEY UNIQUE, value BLOB)"
             .format(self.__db_name))
     conn.close()
Ejemplo n.º 2
0
 def __init__(self, db_name: str, user_path: Optional[str] = None):
     self.__db_name = db_name
     self.__db_path = path.join(
         user_path if user_path else path.abspath(
             path.split(getfile(stack()[-1].frame))[0]),
         "{}.sqllite3".format(self.__db_name))
     with sqlliteConnect(self.__db_path) as conn:
         conn.execute(
             "CREATE TABLE IF NOT EXISTS {}_kvs (key TEXT PRIMARY KEY UNIQUE, value BLOB)"
             .format(self.__db_name))
     conn.close()
Ejemplo n.º 3
0
 def delete(self, key):
     with sqlliteConnect(self.__db_path) as conn:
         conn.execute(
             "DELETE FROM {}_kvs WHERE key=(?)".format(self.__db_name),
             (str(key, "UTF-8"), ))
     conn.close()
Ejemplo n.º 4
0
 def update(self, key, value):
     with sqlliteConnect(self.__db_path) as conn:
         conn.execute(
             "UPDATE {}_kvs SET value=(?) WHERE key=(?)".format(
                 self.__db_name), (value, str(key, "UTF-8")))
     conn.close()
Ejemplo n.º 5
0
 def readItems(self):
     with sqlliteConnect(self.__db_path) as conn:
         for row in conn.execute("SELECT * FROM {}_kvs".format(
                 self.__db_name)):
             yield row
     conn.close()
Ejemplo n.º 6
0
 def create(self, key, value):
     with sqlliteConnect(self.__db_path) as conn:
         conn.execute(
             "INSERT INTO {}_kvs (key, value) VALUES (?, ?)".format(
                 self.__db_name), (str(key, "UTF-8"), value))
     conn.close()