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


Python sqlalchemy.engine方法代码示例

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


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

示例1: build_filter

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def build_filter(cls, engine, table, tree):
        try:
            operator, nodes = list(tree.items())[0]
        except Exception:
            raise indexer.QueryError()

        try:
            op = cls.multiple_operators[operator]
        except KeyError:
            try:
                op = cls.binary_operators[operator]
            except KeyError:
                try:
                    op = cls.unary_operators[operator]
                except KeyError:
                    raise indexer.QueryInvalidOperator(operator)
                return cls._handle_unary_op(engine, table, op, nodes)
            return cls._handle_binary_op(engine, table, op, nodes)
        return cls._handle_multiple_op(engine, table, op, nodes) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:21,代码来源:sqlalchemy.py

示例2: setup_method

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def setup_method(self, load_iris_data):
        super(_EngineToConnMixin, self).load_test_data_and_sql()
        engine = self.conn
        conn = engine.connect()
        self.__tx = conn.begin()
        self.pandasSQL = sql.SQLDatabase(conn)
        self.__engine = engine
        self.conn = conn

        yield

        self.__tx.rollback()
        self.conn.close()
        self.conn = self.__engine
        self.pandasSQL = sql.SQLDatabase(self.__engine)
        # XXX:
        # super(_EngineToConnMixin, self).teardown_method(method) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_sql.py

示例3: setup_method

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def setup_method(self, datapath):
        super(_EngineToConnMixin, self).setup_method(datapath)
        engine = self.conn
        conn = engine.connect()
        self.__tx = conn.begin()
        self.pandasSQL = sql.SQLDatabase(conn)
        self.__engine = engine
        self.conn = conn

        yield

        self.__tx.rollback()
        self.conn.close()
        self.conn = self.__engine
        self.pandasSQL = sql.SQLDatabase(self.__engine)
        # XXX:
        # super(_EngineToConnMixin, self).teardown_method(method) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_sql.py

示例4: test_dml

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def test_dml(engine, session, table_dml):
    # test insert
    engine.execute(table_dml.insert(ONE_ROW_CONTENTS_DML))
    result = table_dml.select().execute().fetchall()
    assert len(result) == 1

    # test update
    session.query(table_dml)\
        .filter(table_dml.c.string == 'test')\
        .update({'string': 'updated_row'}, synchronize_session=False)
    updated_result = table_dml.select().execute().fetchone()
    assert updated_result['test_pybigquery.sample_dml_string'] == 'updated_row'

    # test delete
    session.query(table_dml).filter(table_dml.c.string == 'updated_row').delete(synchronize_session=False)
    result = table_dml.select().execute().fetchall()
    assert len(result) == 0 
开发者ID:mxmzdlv,项目名称:pybigquery,代码行数:19,代码来源:test_sqlalchemy_bigquery.py

示例5: test_reflect_table_include_columns

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def test_reflect_table_include_columns(self, engine, conn):
        one_row_complex = Table("one_row_complex", MetaData(bind=engine))
        version = float(
            re.search(r"^([\d]+\.[\d]+)\..+", sqlalchemy.__version__).group(1)
        )
        if version <= 1.2:
            engine.dialect.reflecttable(
                conn, one_row_complex, include_columns=["col_int"], exclude_columns=[]
            )
        else:
            # https://docs.sqlalchemy.org/en/13/changelog/changelog_13.html#
            # change-64ac776996da1a5c3e3460b4c0f0b257
            engine.dialect.reflecttable(
                conn,
                one_row_complex,
                include_columns=["col_int"],
                exclude_columns=[],
                resolve_fks=True,
            )
        self.assertEqual(len(one_row_complex.c), 1)
        self.assertIsNotNone(one_row_complex.c.col_int)
        self.assertRaises(AttributeError, lambda: one_row_complex.c.col_tinyint) 
开发者ID:laughingman7743,项目名称:PyAthena,代码行数:24,代码来源:test_sqlalchemy_athena.py

示例6: test_get_column_type

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def test_get_column_type(self, engine, conn):
        dialect = engine.dialect
        self.assertEqual(dialect._get_column_type("boolean"), "boolean")
        self.assertEqual(dialect._get_column_type("tinyint"), "tinyint")
        self.assertEqual(dialect._get_column_type("smallint"), "smallint")
        self.assertEqual(dialect._get_column_type("integer"), "integer")
        self.assertEqual(dialect._get_column_type("bigint"), "bigint")
        self.assertEqual(dialect._get_column_type("real"), "real")
        self.assertEqual(dialect._get_column_type("double"), "double")
        self.assertEqual(dialect._get_column_type("varchar"), "varchar")
        self.assertEqual(dialect._get_column_type("timestamp"), "timestamp")
        self.assertEqual(dialect._get_column_type("date"), "date")
        self.assertEqual(dialect._get_column_type("varbinary"), "varbinary")
        self.assertEqual(dialect._get_column_type("array(integer)"), "array")
        self.assertEqual(dialect._get_column_type("map(integer, integer)"), "map")
        self.assertEqual(dialect._get_column_type("row(a integer, b integer)"), "row")
        self.assertEqual(dialect._get_column_type("decimal(10,1)"), "decimal") 
开发者ID:laughingman7743,项目名称:PyAthena,代码行数:19,代码来源:test_sqlalchemy_athena.py

示例7: test_contain_percents_character_query_with_parameter

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def test_contain_percents_character_query_with_parameter(self, engine, conn):
        query = sqlalchemy.sql.text(
            """
            SELECT date_parse('20191030', '%Y%m%d'), :word
            """
        )
        result = engine.execute(query, word="cat")
        self.assertEqual(result.fetchall(), [(datetime(2019, 10, 30), "cat")])

        query = sqlalchemy.sql.text(
            """
            SELECT col_string FROM one_row_complex
            WHERE col_string LIKE 'a%' OR col_string LIKE :param
            """
        )
        result = engine.execute(query, param="b%")
        self.assertEqual(result.fetchall(), [("a string",)]) 
开发者ID:laughingman7743,项目名称:PyAthena,代码行数:19,代码来源:test_sqlalchemy_athena.py

示例8: receive_before_cursor_execute

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def receive_before_cursor_execute(**kw):
        try:
            parent_span = tracer.active_span

            # If we're not tracing, just return
            if parent_span is None:
                return

            scope = tracer.start_active_span("sqlalchemy", child_of=parent_span)
            context = kw['context']
            context._stan_scope = scope

            conn = kw['conn']
            url = str(conn.engine.url)
            scope.span.set_tag('sqlalchemy.sql', kw['statement'])
            scope.span.set_tag('sqlalchemy.eng', conn.engine.name)
            scope.span.set_tag('sqlalchemy.url', url_regexp.sub('//', url))
        except Exception as e:
            logger.debug(e)
        finally:
            return 
开发者ID:instana,项目名称:python-sensor,代码行数:23,代码来源:sqlalchemy.py

示例9: _instrument

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def _instrument(self, **kwargs):
        """Instruments SQLAlchemy engine creation methods and the engine
        if passed as an argument.

        Args:
            **kwargs: Optional arguments
                ``engine``: a SQLAlchemy engine instance
                ``tracer_provider``: a TracerProvider, defaults to global
                ``service``: the name of the service to trace.

        Returns:
            An instrumented engine if passed in as an argument, None otherwise.
        """
        _w("sqlalchemy", "create_engine", _wrap_create_engine)
        _w("sqlalchemy.engine", "create_engine", _wrap_create_engine)
        if kwargs.get("engine") is not None:
            return EngineTracer(
                _get_tracer(
                    kwargs.get("engine"), kwargs.get("tracer_provider")
                ),
                kwargs.get("service"),
                kwargs.get("engine"),
            )
        return None 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:26,代码来源:__init__.py

示例10: delete_resources

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def delete_resources(self, resource_type='generic',
                         attribute_filter=None):
        if not attribute_filter:
            raise ValueError("attribute_filter must be set")

        with self.facade.writer() as session:
            target_cls = self._resource_type_to_mappers(
                session, resource_type)["resource"]

            q = session.query(target_cls.id)

            engine = session.connection()
            try:
                f = QueryTransformer.build_filter(engine.dialect.name,
                                                  target_cls,
                                                  attribute_filter)
            except indexer.QueryAttributeError as e:
                # NOTE(jd) The QueryAttributeError does not know about
                # resource_type, so convert it
                raise indexer.ResourceAttributeError(resource_type,
                                                     e.attribute)

            q = q.filter(f)

            session.query(Metric).filter(
                Metric.resource_id.in_(q)
            ).update({"status": "delete"},
                     synchronize_session=False)
            return q.delete(synchronize_session=False) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:31,代码来源:sqlalchemy.py

示例11: _handle_multiple_op

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def _handle_multiple_op(cls, engine, table, op, nodes):
        return op(*[
            cls.build_filter(engine, table, node)
            for node in nodes
        ]) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:7,代码来源:sqlalchemy.py

示例12: _handle_unary_op

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def _handle_unary_op(cls, engine, table, op, node):
        return op(cls.build_filter(engine, table, node)) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:4,代码来源:sqlalchemy.py

示例13: _get_index_columns

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def _get_index_columns(self, tbl_name):
        from sqlalchemy.engine import reflection
        insp = reflection.Inspector.from_engine(self.conn)
        ixs = insp.get_indexes('test_index_saved')
        ixs = [i['column_names'] for i in ixs]
        return ixs 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_sql.py

示例14: get_table_ref

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def get_table_ref(self, engine, name, metadata):
        metadata.bind = engine
        return sqlalchemy.Table(name, metadata, autoload=True) 
开发者ID:openstack,项目名称:freezer-api,代码行数:5,代码来源:test_migrations.py

示例15: assertColumnExists

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine [as 别名]
def assertColumnExists(self, engine, table, column):
        t = db_utils.get_table(engine, table)
        self.assertIn(column, t.c) 
开发者ID:openstack,项目名称:freezer-api,代码行数:5,代码来源:test_migrations.py


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