def __init__(self): """ Initializes a database instance and binds the models to it. Arguement(s) - self """ # Bind Models to local variables self.City = city self.Country = country self.CountryInfo = countryinfo self.CountryLanguage = countrylanguage # Set config self.config = { 'mysql': { 'driver': 'mysql', 'host': os.getenv('DB_HOST'), 'database': os.getenv('DB_NAME'), 'user': os.getenv('DB_USER'), 'password': os.getenv('DB_PASSWORD'), 'prefix': '' } } # Create database from config self.db = DatabaseManager(self.config) # Auto-resolve connection Model.set_connection_resolver(self.db)
def connect_db_orator(env): config = { 'default': 'read', 'read': { 'host': env("POSTGRE_HOST_READ"), 'driver': 'pgsql', 'database': env("POSTGRE_DATABASE"), 'user': env("POSTGRE_USERNAME"), 'password': env("POSTGRE_PASSWORD"), 'prefix': '', 'port': env("POSTGRE_PORT") }, 'write': { 'host': env("POSTGRE_HOST_READ"), 'driver': 'pgsql', 'database': env("POSTGRE_DATABASE"), 'user': env("POSTGRE_USERNAME"), 'password': env("POSTGRE_PASSWORD"), 'prefix': '', 'port': env("POSTGRE_PORT") } } db = DatabaseManager(config) Model.set_connection_resolver(db) return db
def setup_database(): """ enable database """ from orator import DatabaseManager, Model db = DatabaseManager(config.DATABASES) Model.set_connection_resolver(db)
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
def main(): # 準備 database_manager = DatabaseManager(DEV_DB_CONFIG) Model.set_connection_resolver(database_manager) reservation_repository = OratorReservationRepository() find_available_reservation_usecase = FindAvalibleReservationUsecase(reservation_repository) task_キャンセル対象 = Taskキャンセル対象(find_available_reservation_usecase) cancel_meeting_room_usecase = CancelMeetingRoomUsecase(reservation_repository) find_reservation_usecase = FindReservatnionUsecase() meeting_room_repository = OratorMeetingRoomRepository() meeting_room_domain_service = MeetingRoomDomainService(meeting_room_repository) find_meeting_room_usecase = FindMeetingRoomUseCase(meeting_room_repository, meeting_room_domain_service) message_builder = CliSuccessToCancelMessageBuilder(find_reservation_usecase=find_reservation_usecase, find_meeting_room_usecase=find_meeting_room_usecase) coordinator = CancelMeetingCoordinator(task_キャンセル対象, cancel_meeting_room_usecase, message_builder) # 実行 try: coordinator.cancel_meeting_room() except Exception as e: print('Internal Server Error') # TODO: logging print(e)
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 setup(self): database_manager = DatabaseManager(TEST_DB_CONFIG) Model.set_connection_resolver(database_manager) migrate_in_memory(database_manager) self.repository = OratorEmployeeRepository()
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 __init__(self): """ Initializes a database instance and binds the models to it. Arguement(s) - self """ # Set config self.config = { 'mysql': { 'driver': 'mysql', 'host': os.getenv('DB_HOST'), 'database': os.getenv('DB_NAME'), 'user': os.getenv('DB_USER'), 'password': os.getenv('DB_PASSWORD'), 'prefix': '' } } # Bind Models to local variables self.Posts = posts self.Drafts = drafts self.Users = users self.Notes = notes # Create database from config self.db = DatabaseManager(self.config) # Auto-resolve connection Model.set_connection_resolver(self.db)
async def connect_to_mysql(): logging.info("Connecting to database") db.pool = DatabaseManager(CONFIG) Model.set_connection_resolver(db.pool) logging.info("Connected to database")
def init_orator(settings): import yaml from orator import DatabaseManager from orator import Model dbconfig = get_dbconfig(settings) if Model.get_connection_resolver(): Model.get_connection_resolver().disconnect() Model.set_connection_resolver(DatabaseManager(dbconfig))
def setup(self): database_manager = DatabaseManager(TEST_DB_CONFIG) Model.set_connection_resolver(database_manager) migrate_in_memory(database_manager) self.repository = OratorReservationRepository() domain_service = ReservationDomainService(self.repository) self.usecase = ChangeTimeRangeUsecase(self.repository, domain_service)
def setup(self): database_manager = DatabaseManager(TEST_DB_CONFIG) Model.set_connection_resolver(database_manager) migrate_in_memory(database_manager) self.repository = OratorReservationRepository() self.usecase = CancelMeetingRoomUsecase(self.repository)
def connect_to_db(self): config = { 'default': { 'driver': 'sqlite', 'database': self.db_path, 'log_queries': ENABLE_QUERY_LOGGING } } self.db = DatabaseManager(config) Model.set_connection_resolver(self.db)
def __init__(self): self.fsm = FSManager() self.db_config = {'postgres': config(section='postgresql')} self.db = DatabaseManager(self.db_config) Model.set_connection_resolver(self.db) if PetPersistence.__instance != None: raise Exception("This class is a singleton!") else: PetPersistence.__instance = self
def _setup(self): # Set the connection for Orator Models Model.set_connection_resolver(self._metaclient) # Register Orator Model observers to handle callback events RootSystem.observe(RootSystemObserver()) System.observe(SystemObserver()) DataModel.observe(DataModelObserver()) Entity.observe(EntityObserver()) Attribute.observe(AttributeObserver()) DataSet.observe(DataSetObserver())
def 新規予約(): database_manager = DatabaseManager(DEV_DB_CONFIG) Model.set_connection_resolver(database_manager) # TODO: ここのDIの仕方も、違うところでやるんだろう( Python Injectorとか?) reservation_repository = OratorReservationRepository() domain_service = ReservationDomainService(reservation_repository) usecase = ReserveMeetingRoomUsecase(reservation_repository, domain_service) # MeetingRoom に関する準備 meeting_room_repository = OratorMeetingRoomRepository() meeting_room_domain_service = MeetingRoomDomainService(meeting_room_repository) find_meeting_room_usecase = FindMeetingRoomUseCase(meeting_room_repository, meeting_room_domain_service) # Employee に関する準備 employee_repository = OratorEmployeeRepository() employee_domain_service = EmployeeDomainService(employee_repository) find_employee_usecase = FindEmployeeUseCase(employee_repository, employee_domain_service) success_message_builder = CliNewReservationSuccessMessageBuilder(find_meeting_room_usecase, find_employee_usecase) reservation_factory = ReservationFactory(meeting_room_repository, employee_repository) # ユーザー入力 date = Task使用日().exe() start_time = Task開始時刻().exe() end_time = Task終了時刻().exe() meeting_room_id = Task会議室ID().exe() reserver_id = Task社員ID().exe() number_of_participants = Task使用人数().exe() try: reservation = reservation_factory.create(date, start_time, end_time, meeting_room_id, reserver_id, number_of_participants) except (ReservationDomainObjectError, NotFoundMeetingRoomIdError, NotFoundEmployeeIdError) as e: print(e) exit() try: usecase.reserve_meeting_room(reservation) except ReservationUsecaseError as e: print(e) exit() success_message = success_message_builder.build(reservation) print(success_message)
def __init__(self, dst_dir=None, src_dir=None, db_url=None): self.dst_dir = dst_dir self.src_dir = src_dir self.abs_dst_dir = os.path.abspath(dst_dir) if dst_dir else None self.abs_src_dir = os.path.abspath(src_dir) if src_dir else None if db_url: # not the most elegant way... pass db settings for orator from orator import DatabaseManager, Model self.db = DatabaseManager({'default': parse_db_url(db_url)}) Model.set_connection_resolver(self.db)
def _connect(self): config = { 'mysql': { 'driver': 'mysql', 'host': '127.0.0.1', 'database': 'mlalgorith', 'user': '******', 'password': '******', 'prefix': '' } } db = DatabaseManager(config) Model.set_connection_resolver(db)
def boot_database(): config = { "default": "sqlite", "sqlite": { "driver": "sqlite", "database": "divinity.db", "prefix": "", "log_queries": True, }, } db = DatabaseManager(config) Model.set_connection_resolver(db)
def init(db_config, alternative=False): if alternative is False: if Connection.__db is None: Connection.__db = DatabaseManager(db_config) if Connection.__Model is None: Model.set_connection_resolver(Connection.__db) Connection.__Model = Model else: conn = psycopg2.connect( "host='{0}' dbname='{1}' user='******' password='******'".format( db_config['host'], db_config['database'], db_config['user'], db_config['password'])) Connection.__db = conn.cursor()
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).first() except: esp.status = falcon.HTTP_503 return try: resp.set_header("Content-Disposition", "attachment; filename=" + key + ".pdf") resp.content_type = "application/pdf" resp.data = val['file'] resp.status = falcon.HTTP_200 except: resp.status = falcon.HTTP_404
def __set_db(): config = { 'mysql': { 'driver': 'mysql', 'host': db_host, 'database': db_database, 'user': db_user, 'password': db_password, 'prefix': '' } } db = DatabaseManager(config) Model.set_connection_resolver(db) return db
def __init__(self): self.sego_home = Path.home() / ".sego" self.database = self.sego_home / "sego_database.db" self.config = { 'sqlite': { 'driver': 'sqlite', 'database': str(self.database), 'prefix': '', } } self.db = DatabaseManager(self.config) self.schema = Schema(self.db) Model.set_connection_resolver(self.db)
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) return dbm
def __init__(self): conf_obj = ConfigParser() conf_obj.read('db.ini') conf = { 'mysql': { 'driver': 'mysql', 'host': conf_obj.get('stats', 'host'), 'user': conf_obj.get('stats', 'user'), 'password': conf_obj.get('stats', 'password'), 'database': conf_obj.get('stats', 'db'), 'prefix': '', } } db = DatabaseManager(conf) Model.set_connection_resolver(db)
def setup_database(): DATABASES = {"sqlite": {"driver": "sqlite", "database": "test.db"}} db = DatabaseManager(DATABASES) Schema(db) Model.set_connection_resolver(db) repository = DatabaseMigrationRepository(db, "migrations") migrator = Migrator(repository, db) if not repository.repository_exists(): repository.create_repository() migrator.reset("app/migrations") migrator.run("app/migrations")
def setup(self): database_manager = DatabaseManager(TEST_DB_CONFIG) Model.set_connection_resolver(database_manager) migrate_in_memory(database_manager) employee_repository = OratorEmployeeRepository() employee_id = EmployeeId('001') employee = Employee(employee_id, 'Bob') OratorEmployeeModel.to_orator_model(employee).save() meeting_room_repository = OratorMeetingRoomRepository() meeting_room_id = MeetingRoomId('A') meeting_room = MeetingRoom(meeting_room_id, '大会議室') OratorMeetingRoomModel.to_orator_model(meeting_room).save() self.reservation_factory = ReservationFactory(meeting_room_repository, employee_repository)
def __init__(self, parent=None): self.parent = parent #Configure DB self.config = { 'mysql': { 'driver': 'mysql', 'host': 'localhost', 'database': 'mydb', 'user': '******', 'password': '******', 'prefix': '' } } self.db = DatabaseManager(self.config) Model.set_connection_resolver(self.db)
def __init__(self, *args, **kwargs): if not os.path.exists(_databaseDir): print("Database not yet created...") print("Creating database...") os.mkdir(_databaseDir) super(DatabaseManager, self).__init__(*args, **kwargs, config=config) Model.set_connection_resolver(self) self.schema = Schema(self) if not os.path.exists(_databaseLocation): self._create() Database.instance = self
def __init__(self): # Set config self.config = { 'mysql': { 'driver': 'mysql', 'host': os.getenv('DB_HOST'), 'database': os.getenv('DB_NAME'), 'user': os.getenv('DB_USER'), 'password': os.getenv('DB_PASSWORD'), 'prefix': '' } } # Create database from config self.db = DatabaseManager(self.config) # Auto-resolve connection Model.set_connection_resolver(self.db)
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
def setUp(self): self.db = DatabaseManager(self.databases) Model.set_connection_resolver(self.db) self.create_schema()
def setUpClass(cls): Model.set_connection_resolver(cls.get_connection_resolver())
def setUpClass(cls): cls.db = DatabaseIntegrationConnectionResolver({}, cache=cache) Model.set_connection_resolver(cls.db)
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 setUpClass(cls): Model.set_connection_resolver(DatabaseIntegrationConnectionResolver())
def setUpClass(cls): Model.set_connection_resolver(DatabaseIntegrationConnectionWithoutForeignKeysResolver())
def setup_database(): """Setup a connection with the database""" db = DatabaseManager(config.DATABASES) Model.set_connection_resolver(db) return db
| ''' 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)