Created
February 5, 2016 14:03
-
-
Save msikma/c1ae0c6ab7b9c72c2e8b 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
# Copyright (C) 2014-2016, Reisan Ltd. - All rights reserved. | |
# This file is proprietary and confidential. For more information, | |
# see the 'copyright.md' file, which is part of this source code package. | |
''' | |
Database schema definitions for the site's persistent state information. | |
''' | |
from reisan.flask import db | |
class StateInfo(db.Model): | |
''' | |
Database table for simple namespaced key-value pair persistent information. | |
''' | |
id = db.Column(db.Integer, primary_key=True) | |
ns = db.Column(db.String(500), index=True) | |
key = db.Column(db.String(500), index=True) | |
val = db.Column(db.String(500), index=True) | |
def __init__(self, ns, key, val): | |
self.ns = ns | |
self.key = key | |
self.val = val | |
def __repr__(self): | |
return '<StateInfo %r:%r>' % (self.ns, self.key) | |
@staticmethod | |
def get_state_row(ns, key): | |
''' | |
Used internally FIXME | |
''' | |
return StateInfo.query.filter_by(ns=ns, key=key).first() | |
@staticmethod | |
def get_state(ns, key): | |
row = StateInfo.get_state_row(ns, key) | |
if row is not None: | |
return row.val | |
return None | |
@staticmethod | |
def set_state(ns, key, val): | |
StateInfo.delete_state(ns, key) | |
row = StateInfo(ns, key, val) | |
db.session.add(row) | |
db.session.commit() | |
@staticmethod | |
def delete_state(ns, key): | |
# db.session.query(StateInfo).filter_by(ns=ns, key=key).delete() | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment