Python playhouse.db_url.connect() Examples

The following are 8 code examples of playhouse.db_url.connect(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module playhouse.db_url , or try the search function .
Example #1
Source File: dataset.py    From Quiver-alfred with MIT License 6 votes vote down vote up
def __init__(self, url):
        self._url = url
        parse_result = urlparse(url)
        self._database_path = parse_result.path[1:]

        # Connect to the database.
        self._database = connect(url)
        self._database.connect()

        # Introspect the database and generate models.
        self._introspector = Introspector.from_database(self._database)
        self._models = self._introspector.generate_models(skip_invalid=True)
        self._migrator = SchemaMigrator.from_database(self._database)

        class BaseModel(Model):
            class Meta:
                database = self._database
        self._base_model = BaseModel
        self._export_formats = self.get_export_formats()
        self._import_formats = self.get_import_formats() 
Example #2
Source File: flask_utils.py    From Quiver-alfred with MIT License 5 votes vote down vote up
def _load_database(self, app, config_value):
        if isinstance(config_value, Database):
            database = config_value
        elif isinstance(config_value, dict):
            database = self._load_from_config_dict(dict(config_value))
        else:
            # Assume a database connection URL.
            database = db_url_connect(config_value)

        if isinstance(self.database, Proxy):
            self.database.initialize(database)
        else:
            self.database = database 
Example #3
Source File: dataset.py    From Quiver-alfred with MIT License 5 votes vote down vote up
def connect(self):
        self._database.connect() 
Example #4
Source File: dataset.py    From Quiver-alfred with MIT License 5 votes vote down vote up
def __enter__(self):
        self.connect()
        return self 
Example #5
Source File: __init__.py    From slim with zlib License 5 votes vote down vote up
def asyncpg_init(db_uri):
    import asyncpg

    async def create_conn():
        global asyncpg_conn
        asyncpg_conn = await asyncpg.connect(db_uri)

    async_run(create_conn)


# asyncpg_init(config.DATABASE_URI) 
Example #6
Source File: database.py    From graphql-over-kafka with MIT License 5 votes vote down vote up
def init_db(database_url):
    """
        This function initializes the global database with the given url.
    """
    # utility function to parse database urls
    from playhouse.db_url import connect
    # initialize the peewee database with the appropriate engine
    db.initialize(connect(database_url)) 
Example #7
Source File: __init__.py    From diffengine with MIT License 5 votes vote down vote up
def setup_db():
    global home, database
    database_url = config.get("db", "sqlite:///diffengine.db")
    logging.debug("connecting to db %s", database_url)
    database_handler = connect(database_url)
    database.initialize(database_handler)
    database.connect()
    database.create_tables([Feed, Entry, FeedEntry, EntryVersion, Diff], safe=True)

    if isinstance(database_handler, SqliteDatabase):
        try:
            migrator = SqliteMigrator(database_handler)
            migrate(migrator.add_index("entryversion", ("url",), False))
        except OperationalError as e:
            logging.debug(e) 
Example #8
Source File: models.py    From pogom with MIT License 5 votes vote down vote up
def create_tables():
    db.connect()
    db.create_tables([Pokemon, Pokestop, Gym], safe=True)
    db.close()