當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。