当前位置: 首页>>代码示例>>Python>>正文


Python engine.create_engine方法代码示例

本文整理汇总了Python中sqlalchemy.engine.create_engine方法的典型用法代码示例。如果您正苦于以下问题:Python engine.create_engine方法的具体用法?Python engine.create_engine怎么用?Python engine.create_engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.engine的用法示例。


在下文中一共展示了engine.create_engine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connection_sniff

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def test_connection_sniff(self, mock_elasticsearch):
        """
            SQLAlchemy: test Elasticsearch is called for multiple hosts
        """
        mock_elasticsearch.return_value = None
        self.engine = create_engine(
            "elasticsearch+http://localhost:9200/"
            "?sniff_on_start=True"
            "&sniff_on_connection_fail=True"
            "&sniffer_timeout=3"
            "&sniff_timeout=4"
            "&max_retries=10"
            "&retry_on_timeout=True"
        )
        self.connection = self.engine.connect()
        mock_elasticsearch.assert_called_once_with(
            "http://localhost:9200/",
            sniff_on_start=True,
            sniff_on_connection_fail=True,
            sniffer_timeout=3,
            sniff_timeout=4,
            max_retries=10,
            retry_on_timeout=True,
        ) 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:26,代码来源:test_sqlalchemy.py

示例2: codegen

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def codegen(args):

    # Use reflection to fill in the metadata
    engine = create_engine(args.url)

    metadata = MetaData(engine)
    tables = args.tables.split(",") if args.tables else None
    metadata.reflect(engine, args.schema, not args.noviews, tables)
    if db.session.bind.dialect.name == "sqlite":
        # dirty hack for sqlite
        engine.execute("""PRAGMA journal_mode = OFF""")

    # Write the generated model code to the specified file or standard output

    capture = StringIO()
    # outfile = io.open(args.outfile, 'w', encoding='utf-8') if args.outfile else capture # sys.stdout
    generator = CodeGenerator(metadata, args.noindexes, args.noconstraints, args.nojoined, args.noinflect, args.noclasses)
    generator.render(capture)
    generated = capture.getvalue()
    generated = fix_generated(generated)
    if args.outfile:
        outfile = io.open(args.outfile, "w", encoding="utf-8")
        outfile.write(generated)
    return generated 
开发者ID:thomaxxl,项目名称:safrs,代码行数:26,代码来源:expose_existing.py

示例3: initdb

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def initdb():
    if not settings.IS_IN_DEV:
        raise RuntimeError('Should never use this in production environment')

    engine = get_engine()
    database_name = quote(engine.dialect, engine.url.database)
    schema_ddl = resource_string(*SCHEMA_FILE)

    anonymous_url = deepcopy(engine.url)
    anonymous_url.database = None
    anonymous_url.query = {}
    anonymous_engine = create_engine(anonymous_url)

    with anonymous_engine.connect() as connection:
        connection.execute(
            'drop database if exists {0}'.format(database_name))
        connection.execute(
            'create database {0} character set utf8mb4 '
            'collate utf8mb4_bin'.format(database_name))

    with anonymous_engine.connect() as connection:
        connection.execute('use {0}'.format(database_name))
        connection.execute(schema_ddl) 
开发者ID:huskar-org,项目名称:huskar,代码行数:25,代码来源:db.py

示例4: __init__

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def __init__(self, url, engine_kwargs=None, skip_compatibility_check=False):
        # type: (str, Optional[Dict[str, Any]], bool) -> None

        self.engine_kwargs = engine_kwargs or {}
        self.url = self._fill_storage_url_template(url)
        self.skip_compatibility_check = skip_compatibility_check

        self._set_default_engine_kwargs_for_mysql(url, self.engine_kwargs)

        try:
            self.engine = create_engine(self.url, **self.engine_kwargs)
        except ImportError as e:
            raise ImportError(
                "Failed to import DB access module for the specified storage URL. "
                "Please install appropriate one. (The actual import error is: " + str(e) + ".)"
            )

        self.scoped_session = orm.scoped_session(orm.sessionmaker(bind=self.engine))
        models.BaseModel.metadata.create_all(self.engine)

        self._version_manager = _VersionManager(self.url, self.engine, self.scoped_session)
        if not skip_compatibility_check:
            self._version_manager.check_table_schema_compatibility()

        weakref.finalize(self, self._finalize) 
开发者ID:optuna,项目名称:optuna,代码行数:27,代码来源:storage.py

示例5: __setstate__

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def __setstate__(self, state):
        # type: (Dict[Any, Any]) -> None

        self.__dict__.update(state)
        try:
            self.engine = create_engine(self.url, **self.engine_kwargs)
        except ImportError as e:
            raise ImportError(
                "Failed to import DB access module for the specified storage URL. "
                "Please install appropriate one. (The actual import error is: " + str(e) + ".)"
            )

        self.scoped_session = orm.scoped_session(orm.sessionmaker(bind=self.engine))
        models.BaseModel.metadata.create_all(self.engine)
        self._version_manager = _VersionManager(self.url, self.engine, self.scoped_session)
        if not self.skip_compatibility_check:
            self._version_manager.check_table_schema_compatibility() 
开发者ID:optuna,项目名称:optuna,代码行数:19,代码来源:storage.py

示例6: test_sqlalchemy_compilation

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def test_sqlalchemy_compilation():
    engine = create_engine('impala://localhost')
    metadata = MetaData(engine)
    # TODO: add other types to this table (e.g., functional.all_types)
    mytable = Table("mytable",
                    metadata,
                    Column('col1', STRING),
                    Column('col2', TINYINT),
                    Column('col3', INT),
                    Column('col4', DOUBLE),
                    impala_partition_by='HASH PARTITIONS 16',
                    impala_stored_as='KUDU',
                    impala_table_properties={
                        'kudu.table_name': 'my_kudu_table',
                        'kudu.master_addresses': 'kudu-master.example.com:7051'
                    })
    observed = str(CreateTable(mytable, bind=engine))
    expected = ('\nCREATE TABLE mytable (\n\tcol1 STRING, \n\tcol2 TINYINT, '
                '\n\tcol3 INT, \n\tcol4 DOUBLE\n)'
                '\nPARTITION BY HASH PARTITIONS 16\nSTORED AS KUDU\n'
                "TBLPROPERTIES ('kudu.table_name' = 'my_kudu_table', "
                "'kudu.master_addresses' = 'kudu-master.example.com:7051')\n\n")
    assert expected == observed 
开发者ID:cloudera,项目名称:impyla,代码行数:25,代码来源:test_sqlalchemy.py

示例7: engine

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def engine(request):
    """Engine configuration."""
    url = request.config.getoption("--sqlalchemy-connect-url")
    from sqlalchemy.engine import create_engine

    engine = create_engine(url)
    yield engine
    engine.dispose() 
开发者ID:IDSIA,项目名称:sacred,代码行数:10,代码来源:test_sql_observer.py

示例8: startDatabase

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def startDatabase(self):
        self.engine = create_engine(

            # sqlite in-memory
            #"sqlite://", reactor=reactor, strategy=TWISTED_STRATEGY

            # sqlite on filesystem
            "sqlite:////tmp/kotori.sqlite", reactor=reactor, strategy=TWISTED_STRATEGY

            # mysql... todo
        )

        # Create the table
        yield self.engine.execute(CreateTable(self.telemetry))
        #yield self.engine 
开发者ID:daq-tools,项目名称:kotori,代码行数:17,代码来源:sql.py

示例9: setUp

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def setUp(self):
        self.engine = create_engine("elasticsearch+http://localhost:9200/")
        self.connection = self.engine.connect()
        self.table_flights = Table("flights", MetaData(bind=self.engine), autoload=True) 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:6,代码来源:test_sqlalchemy.py

示例10: test_auth

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def test_auth(self, mock_elasticsearch):
        """
            SQLAlchemy: test Elasticsearch is called with user password
        """
        mock_elasticsearch.return_value = None
        self.engine = create_engine(
            "elasticsearch+http://user:password@localhost:9200/"
        )
        self.connection = self.engine.connect()
        mock_elasticsearch.assert_called_once_with(
            "http://localhost:9200/", http_auth=("user", "password")
        ) 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:14,代码来源:test_sqlalchemy.py

示例11: test_connection_https_and_auth

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def test_connection_https_and_auth(self, mock_elasticsearch):
        """
            SQLAlchemy: test Elasticsearch is called with https and param
        """
        mock_elasticsearch.return_value = None
        self.engine = create_engine(
            "elasticsearch+https://user:password@localhost:9200/"
        )
        self.connection = self.engine.connect()
        mock_elasticsearch.assert_called_once_with(
            "https://localhost:9200/", http_auth=("user", "password")
        ) 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:14,代码来源:test_sqlalchemy.py

示例12: test_connection_https_and_params

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def test_connection_https_and_params(self, mock_elasticsearch):
        """
            SQLAlchemy: test Elasticsearch is called with https and param
        """
        mock_elasticsearch.return_value = None
        self.engine = create_engine(
            "elasticsearch+https://localhost:9200/"
            "?verify_certs=False"
            "&use_ssl=False"
        )
        self.connection = self.engine.connect()
        mock_elasticsearch.assert_called_once_with(
            "https://localhost:9200/", verify_certs=False, use_ssl=False
        ) 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:16,代码来源:test_sqlalchemy.py

示例13: test_connection_params

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def test_connection_params(self, mock_elasticsearch):
        """
            SQLAlchemy: test Elasticsearch is called with advanced config params
        """
        mock_elasticsearch.return_value = None
        self.engine = create_engine(
            "elasticsearch+http://localhost:9200/"
            "?http_compress=True&maxsize=100&timeout=3"
        )
        self.connection = self.engine.connect()
        mock_elasticsearch.assert_called_once_with(
            "http://localhost:9200/", http_compress=True, maxsize=100, timeout=3
        ) 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:15,代码来源:test_sqlalchemy.py

示例14: engine

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def engine():
    engine = create_engine('bigquery://', echo=True)
    return engine 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:5,代码来源:test_sqlalchemy_bigquery.py

示例15: engine_using_test_dataset

# 需要导入模块: from sqlalchemy import engine [as 别名]
# 或者: from sqlalchemy.engine import create_engine [as 别名]
def engine_using_test_dataset():
    engine = create_engine('bigquery:///test_pybigquery', echo=True)
    return engine 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:5,代码来源:test_sqlalchemy_bigquery.py


注:本文中的sqlalchemy.engine.create_engine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。