def get_metadata(self, key=None): """Retrieve a value from the key-value store in the database's metadata table. If `key` is |None| all of the keys will be retrieved and returned as a |dict|. Parameters ---------- key : str, optional The key value to retrieve. Returns ------- any or |dict| """ if key is None: return { row[0]: pickle.loads(bytes(row[1])) for row in self.execute("SELECT name, content FROM metadata") } res = [pickle.loads(bytes(row[0])) for row in self.execute("SELECT content FROM metadata WHERE name = ?", (key,))] if len(res) > 0: return res[0] else: raise KeyError("Key {} not found".format(key))
def from_sql(cls, row, *args, **kwargs): ''' Translate a Row object from sqlite3 into a GlycanRecord object Parameters ---------- row: sqlite3.Row A dict-like object containing the pickled value of the record in the `structure` field Returns ------- GlycanRecord: The unpickled :class:`GlycanRecord` object. Sub-classes may perform more complex operations like decompressing or joining other tables in the database. ''' record = pickle.loads(bytes(row["structure"])) record._bound_db = kwargs.get("database") return record