def __init__(self): db_url = os.environ.get('DATABASE_URL', None) self.conn_db = db_connect(db_url)
def init(uri): _database = db_connect(uri) database.initialize(_database) database.create_tables([Schedule], safe=True) if not _test_mode: database.close()
def select_on(self, items, selector): for s in selector: key, operator, values = s.key, s.__class__, s.value field = self.fields[key] if operator == dom.Operator.Equals: items = items.where(field == values) elif operator == dom.Operator.NotEquals: items = items.where(field != values) else: raise Exception('unsupported') return items if __name__ == '__main__': Model.make_trpc_endpoint=PeeweeEndpoint url = os.environ.get("DATABASE_URL","sqlite:///trpc.db") db = db_connect(url) db.connect() introspector = Introspector.from_database(db) endpoints = introspector.generate_models() database = introspector.introspect() app = App('Database', endpoints) app.main()
def add(self, name, uri, allow_sync=False): LOG.info(f'{name} database {uri} initialized') conn = db_connect(Replications._connection_string(uri)) conn.set_allow_sync(allow_sync) self._connections[name] = conn
from pprint import pprint import attr from playhouse.db_url import connect as db_connect from playhouse.reflection import Introspector from munch import Munch from .utils import log_it, now from .db_config import db_config log = log_it(logname='otudb.database') otudb = db_connect(db_config['url']) # pprint(otudb.__dict__) db_table_names = [ 'sample_info', 'otu_seq', 'analysis_set', 'sample_analysis_sets', 'otu_counts', 'otu_annotation', 'otu_xref', ] @attr.s(cmp=False) class OTUTables(object): """set of table names as reflections of existing OTU tables in the database"""