本文整理汇总了Python中orator.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump
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)
示例2: test_reconnection
def test_reconnection(self):
db = Model.get_connection_resolver()
db.disconnect()
db.reconnect()
db.disconnect()
示例3: _connect_to_sqlite
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
示例4: tearDownClass
def tearDownClass(cls):
Model.unset_connection_resolver()
示例5: setUpClass
def setUpClass(cls):
cls.db = DatabaseIntegrationConnectionResolver({}, cache=cache)
Model.set_connection_resolver(cls.db)
示例6: connection
def connection(self):
return Model.get_connection_resolver().connection()
示例7: WhatsAPIDriver
from orator import DatabaseManager, Model
from webwhatsapi import WhatsAPIDriver
driver = WhatsAPIDriver(username="hifenhur")
config = {
'postgres': {
'driver': 'postgres',
'host': '35.247.235.153',
'database': 'tbc_wpp',
'user': 'hifenhur',
'password': 'numero04',
}
}
class Driver(Model):
pass
db = DatabaseManager(config)
Model.set_connection_resolver(db)
示例8: setUpClass
def setUpClass(cls):
Model.set_connection_resolver(DatabaseIntegrationConnectionResolver())
示例9: setUpClass
def setUpClass(cls):
Model.set_connection_resolver(DatabaseIntegrationConnectionWithoutForeignKeysResolver())
示例10: setup_database
def setup_database():
"""Setup a connection with the database"""
db = DatabaseManager(config.DATABASES)
Model.set_connection_resolver(db)
return db
示例11: load_dotenv
|
'''
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)
示例12: setUpClass
def setUpClass(cls):
Model.set_connection_resolver(cls.get_connection_resolver())
示例13: tearDown
def tearDown(self):
self.schema().drop('users')
self.schema().drop('posts')
self.schema().drop('comments')
Model.unset_connection_resolver()
示例14: setUp
def setUp(self):
self.db = DatabaseManager(self.databases)
Model.set_connection_resolver(self.db)
self.create_schema()