def dump(db_path): """Dump the DB contents to STDOUT, requiring only that the DB is a version that has an otus table in sqlite3 form (i.e. version 2 and 3 at least). """ sqlite_db = os.path.join(db_path, SequenceDatabase.SQLITE_DB_NAME) logging.debug("Connecting to DB {}".format(sqlite_db)) if not os.path.exists(sqlite_db): raise Exception("SQLite3 database does not appear to exist in the SingleM database - perhaps it is the wrong version?") db = DatabaseManager({ 'sqlite3': { 'driver': 'sqlite', 'database': sqlite_db }}) Model.set_connection_resolver(db) print "\t".join(OtuTable.DEFAULT_OUTPUT_FIELDS) for chunk in db.table('otus').chunk(1000): for entry in chunk: otu = OtuTableEntry() otu.marker = entry.marker otu.sample_name = entry.sample_name otu.sequence = entry.sequence otu.count = entry.num_hits otu.coverage = entry.coverage otu.taxonomy = entry.taxonomy print str(otu)
def test_reconnection(self): db = Model.get_connection_resolver() db.disconnect() db.reconnect() db.disconnect()
def _connect_to_sqlite(self, db): sqlite_db_path = db.sqlite_file if not os.path.exists(sqlite_db_path): raise Exception("Sqlite database not found at '%s', indicating that either the SingleM database was built with an out-dated SingleM version, or that the database is corrupt. Please generate a new database with the current version of SingleM.") logging.debug("Connecting to %s" % sqlite_db_path) dbm = DatabaseManager({ 'sqlite3': { 'driver': 'sqlite', 'database': sqlite_db_path }}) Model.set_connection_resolver(dbm) try: len(dbm.table('otus').limit(1).get()) except Exception as e: logging.error("Failure to extract any data from the otus table of the SQ Lite DB indicates this SingleM DB is either too old or is corrupt.") raise(e) try: len(dbm.table('clusters').limit(1).get()) except QueryException: logging.error("Failure to extract any data from the 'clusters' table indicates this SingleM DB is out-dated, and cannot be used with query implemented in this version of SingleM") sys.exit(1) return dbm
| ''' load_dotenv(find_dotenv()) ''' |-------------------------------------------------------------------------- | Database Settings |-------------------------------------------------------------------------- | | Set connection database settings here as a dictionary. Follow the | format below to create additional connection settings. | | @see Orator migrations documentation for more info | ''' DATABASES = { 'default': { 'driver': os.environ.get('DB_DRIVER'), 'host': os.environ.get('DB_HOST'), 'database': os.environ.get('DB_DATABASE'), 'user': os.environ.get('DB_USERNAME'), 'password': os.environ.get('DB_PASSWORD'), 'prefix': '' } } DB = DatabaseManager(DATABASES) Model.set_connection_resolver(DB)
|-------------------------------------------------------------------------- | Database Settings |-------------------------------------------------------------------------- | | Set connection database settings here as a dictionary. Follow the | format below to create additional connection settings. | | @see Orator migrations documentation for more info | """ DATABASES = { 'default': os.environ.get('DB_DRIVER'), 'sqlite': { 'driver': 'sqlite', 'database': os.environ.get('DB_DATABASE') }, 'postgres': { 'driver': 'postgres', 'host': env('DB_HOST'), 'database': env('DB_DATABASE'), 'port': env('DB_PORT'), 'user': env('DB_USERNAME'), 'password': env('DB_PASSWORD'), 'log_queries': env('DB_LOG'), }, } DB = DatabaseManager(DATABASES) Model.set_connection_resolver(DB)
def model(self): conn = self.initialize() Model.set_connection_resolver(conn) return Model
def setUpClass(cls): Model.set_connection_resolver( DatabaseIntegrationConnectionWithoutForeignKeysResolver())
def setup(self): database_manager = DatabaseManager(TEST_DB_CONFIG) Model.set_connection_resolver(database_manager) migrate_in_memory(database_manager)
from orator import DatabaseManager, Model from webwhatsapi import WhatsAPIDriver driver = WhatsAPIDriver(username="******") config = { 'postgres': { 'driver': 'postgres', 'host': '35.247.235.153', 'database': 'tbc_wpp', 'user': '******', 'password': '******', } } class Driver(Model): pass db = DatabaseManager(config) Model.set_connection_resolver(db)
def tearDownClass(cls): Model.unset_connection_resolver()
def on_post(self, req, resp): resp.set_header('Access-Control-Allow-Origin', '*') resp.set_header('Access-Control-Allow-Methods', 'GET') resp.set_header('Access-Control-Allow-Headers', 'Content-Type') # reading config config = configparser.ConfigParser() config.readfp(open('config.ini')) dbhost = config.get('database', 'host') dbdatabase = config.get('database', 'database') dbuser = config.get('database', 'user') dbpassword = config.get('database', 'password') prefix = config.get('database', 'prefix') wkhtmltopdf_path = config.get('wkhtmltopdf', 'path') baseurl = config.get('frontend', 'baseurl') #Setup DB config = { 'mysql': { 'driver': 'mysql', 'host': dbhost, 'database': dbdatabase, 'user': dbuser, 'password': dbpassword, 'prefix': '' } } #TODO create tables db = DatabaseManager(config) Model.set_connection_resolver(db) data = {"status": "failure", "data": {}} try: title = req.params['title'] data = {"status": "success", "data": {}} except: title = '' try: md = req.params['markdown'] data = {"status": "success", "data": {}} except: data = {"status": "failure", "data": {}} md = False if md != False: md = head + convertMarkdownToHtml(md.replace("/n", "<br>")) #md += "<br><div class='end'>www.piratenpartei.de</div>" key = datetime.datetime.now().strftime( "%Y-%m-%d_") + randomString() font_config = FontConfiguration() file_ = HTML(string=md).write_pdf(font_config=font_config) try: db.table(prefix + 'files').insert({ 'file_key': key, 'file': file_ }) data = { "status": "success", "data": { "key": key, "url": baseurl + key } } except Exception as e: print(e) data = {"status": "failure", "data": {}} resp.status = falcon.HTTP_503 return else: data = {"status": "failure", "data": {}} resp.body = json.dumps(data)
def __init__(self): super(ServiceInstanceSQL, self).__init__() Model.set_connection_resolver(Helper.db)
def __init__(self): super(ManifestSQL, self).__init__() Model.set_connection_resolver(Helper.db)
def configure_mysql(): db = DatabaseManager(DATABASES) Model.set_connection_resolver(db)
def __post_init__(self, config: Dict): self.db = DatabaseManager(config) Model.set_connection_resolver(self.db)
def connection(self): return Model.get_connection_resolver().connection()
def on_get(self, req, resp): resp.set_header('Access-Control-Allow-Origin', '*') resp.set_header('Access-Control-Allow-Methods', 'GET') resp.set_header('Access-Control-Allow-Headers', 'Content-Type') # reading config config = configparser.ConfigParser() config.readfp(open('config.ini')) dbhost = config.get('database', 'host') dbdatabase = config.get('database', 'database') dbuser = config.get('database', 'user') dbpassword = config.get('database', 'password') prefix = config.get('database', 'prefix') wkhtmltopdf_path = config.get('wkhtmltopdf', 'path') baseurl = config.get('frontend', 'baseurl') #Setup DB config = { 'mysql': { 'driver': 'mysql', 'host': dbhost, 'database': dbdatabase, 'user': dbuser, 'password': dbpassword, 'prefix': '' } } db = DatabaseManager(config) Model.set_connection_resolver(db) try: key = req.params['key'] data = {"status": "success", "data": {}} except: resp.status = falcon.HTTP_404 return try: val = db.table(prefix + 'files').where('file_key', key).count() except: esp.status = falcon.HTTP_503 return if val > 0: try: resp.body = json.dumps({ "status": "success", "data": { "file_status": "exists", "url": baseurl + "file?key=" + key } }) resp.status = falcon.HTTP_200 except: resp.status = falcon.HTTP_404 else: resp.body = json.dumps({ "status": "success", "data": { "file_status": "not exists" } })
def setUpClass(cls): Model.set_connection_resolver(DatabaseIntegrationConnectionWithoutForeignKeysResolver())
#!/usr/bin/env python # encoding: utf-8 """ @version: v1.0 @author: william wei @license: Apache Licence @contact: [email protected] @file: models.py @time: 19/01/2018 1:21 PM """ from orator import Model from core import config, db Model.set_connection_resolver(db.get_mysql_client(config.get('material.db.mysql'))) class Material(Model): """ 原始物料信息 """ pass class Creative(Model): """ 创意,即由原始物料产出的用于最终投放的广告创意 """ pass
def setUpClass(cls): cls.db = DatabaseIntegrationConnectionResolver({}, cache=cache) Model.set_connection_resolver(cls.db)
def connect(): Model.set_connection_resolver(db)
def setUpClass(cls): Model.set_connection_resolver(cls.get_connection_resolver())
self, connection, database="", table_prefix="", config=None, builder_class=MTQueryBuilder, builder_default_kwargs=None, ): super(MTPostgresConnection, self).__init__(connection, database, table_prefix, config, builder_class, builder_default_kwargs) def get_default_query_grammar(self): return MTQueryGrammar(marker=self._marker) class MTConnectionFactory(connection_factory.ConnectionFactory): CONNECTIONS = { "postgres": MTPostgresConnection, "pgsql": MTPostgresConnection, } class MTDatabaseManager(DatabaseManager): def __init__(self, config, factory=MTConnectionFactory()): super(MTDatabaseManager, self).__init__(config, factory) Model.set_connection_resolver(MTDatabaseManager(DATABASES))
def set_connection(db): from orator import Model Model.set_connection_resolver(db)
from orator import Model from db.connection import get_connection Model.set_connection_resolver(get_connection()) class Sample(Model): @classmethod def from_proto(cls, proto): sample = cls() sample.timestamp = proto.timestamp.ToDatetime() sample.save() return sample
def __init__(self): super(PlanSQL, self).__init__() Model.set_connection_resolver(Helper().db)
def register_database(self): config = self.configuration_manager.get('database') self.database = DatabaseManager(config) self.schema = Schema(self.database) Model.set_connection_resolver(self.database)
def __init__(self): super(ServiceTypeSQL, self).__init__() Model.set_connection_resolver(Helper().db)
from decouple import config from orator import DatabaseManager, Model from .book import Book from .chapter import Chapter from .course import Course from .forum import Forum from .resource import Resource from .type_resource import TypeResource Model.set_connection_resolver(DatabaseManager({ 'mysql': { 'driver': 'mysql', 'host': config('DB_HOST'), 'database': config('DB_DATABASE'), 'user': config('DB_USER'), 'password': config('DB_PASSWORD'), 'prefix': '', } }))
def connection(self, connection=None): return Model.get_connection_resolver().connection(connection)
from orator import Model from database import database as db Model.set_connection_resolver(db) class SdsIndex(Model): __table__ = 'sds_indexes' __fillable__ = ['filename', 'scnl', 'date', 'sampling_rate', 'min_amplitude', 'max_amplitude', 'availability'] pass
""" how to start using db = DatabaseManager(config) """ import os from orator import Model, DatabaseManager from dotenv import load_dotenv load_dotenv() mysql_config = { 'default': 'data', 'data': { 'driver': os.getenv("DB_DRIVER", "postgres"), 'host': os.getenv("DB_HOST", "localhost"), 'database': os.getenv("DB_DATABASE", "data"), 'user': os.getenv("DB_USER", "user"), 'password': os.getenv("DB_PASS", "pass"), 'prefix': '' }, } database = DatabaseManager(mysql_config) Model.set_connection_resolver(database)
def setUpClass(cls): Model.set_connection_resolver(DatabaseConnectionResolver())
def connect_db(): db = DatabaseManager(DATABASES) Model.set_connection_resolver(db)
def setup_database(): """Setup a connection with the database""" db = DatabaseManager(config.DATABASES) Model.set_connection_resolver(db) return db
from orator import DatabaseManager from orator import Model DB_CONFIG = { 'sqlite3': { 'driver': 'sqlite', 'database': 'chess_server.db', 'log_queries': True } } DATABASE = DatabaseManager(DB_CONFIG) Model.set_connection_resolver(DATABASE)
def setUpClass(cls): Model.set_connection_resolver(DatabaseIntegrationConnectionResolver())
def setUp(self): self.db = DatabaseManager(self.databases) Model.set_connection_resolver(self.db) self.create_schema()
def tearDown(self): self.schema().drop('users') self.schema().drop('posts') self.schema().drop('comments') Model.unset_connection_resolver()
def init_orator(): with open('./db/orator.yml') as f: config = yaml.load(f.read()) db = DatabaseManager(config['databases']) Model.set_connection_resolver(db)