Last active
June 15, 2018 21:04
-
-
Save kkimdev/7b85d5de573098ea72c563d5db9ce70f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
class KeyValueFile: | |
def __init__(self, path): | |
self.conn = sqlite3.connect(path) | |
self.c = self.conn.cursor() | |
self.c.execute('CREATE TABLE IF NOT EXISTS keyvalue (key text PRIMARY KEY, value text)') | |
def put(self, key, value): | |
self.c.execute("INSERT OR REPLACE INTO keyvalue VALUES (?,?)", (key, value)) | |
self.conn.commit() | |
def get(self, key): | |
self.c.execute("SELECT * FROM keyvalue WHERE key=?", (key, )) | |
result = self.c.fetchone() | |
if result is None: | |
return None | |
return result[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment