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


Python sqltypes.Boolean方法代码示例

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


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

示例1: test_notna_dtype

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Boolean [as 别名]
def test_notna_dtype(self):
        cols = {'Bool': Series([True, None]),
                'Date': Series([datetime(2012, 5, 1), None]),
                'Int': Series([1, None], dtype='object'),
                'Float': Series([1.1, None])
                }
        df = DataFrame(cols)

        tbl = 'notna_dtype_test'
        df.to_sql(tbl, self.conn)
        returned_df = sql.read_sql_table(tbl, self.conn)  # noqa
        meta = sqlalchemy.schema.MetaData(bind=self.conn)
        meta.reflect()
        if self.flavor == 'mysql':
            my_type = sqltypes.Integer
        else:
            my_type = sqltypes.Boolean

        col_dict = meta.tables[tbl].columns

        assert isinstance(col_dict['Bool'].type, my_type)
        assert isinstance(col_dict['Date'].type, sqltypes.DateTime)
        assert isinstance(col_dict['Int'].type, sqltypes.Integer)
        assert isinstance(col_dict['Float'].type, sqltypes.Float) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:test_sql.py

示例2: test_dtype

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Boolean [as 别名]
def test_dtype(self):
        if self.flavor == 'mysql':
            pytest.skip('Not applicable to MySQL legacy')
        cols = ['A', 'B']
        data = [(0.8, True),
                (0.9, None)]
        df = DataFrame(data, columns=cols)
        df.to_sql('dtype_test', self.conn)
        df.to_sql('dtype_test2', self.conn, dtype={'B': 'STRING'})

        # sqlite stores Boolean values as INTEGER
        assert self._get_sqlite_column_type(
            'dtype_test', 'B') == 'INTEGER'

        assert self._get_sqlite_column_type(
            'dtype_test2', 'B') == 'STRING'
        pytest.raises(ValueError, df.to_sql,
                      'error', self.conn, dtype={'B': bool})

        # single dtype
        df.to_sql('single_dtype_test', self.conn, dtype='STRING')
        assert self._get_sqlite_column_type(
            'single_dtype_test', 'A') == 'STRING'
        assert self._get_sqlite_column_type(
            'single_dtype_test', 'B') == 'STRING' 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_sql.py

示例3: test_datatype

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Boolean [as 别名]
def test_datatype(self, table, column):
        """Tests that database column datatype matches the one defined in the
        models.
        """
        database_column = self.find_database_column(table, column)

        if isinstance(column.type, sqltypes.String):
            expected_type = sqltypes.VARCHAR
        elif isinstance(column.type, sqltypes.Integer):
            expected_type = sqltypes.INTEGER
        elif isinstance(column.type, sqltypes.Boolean):
            expected_type = sqltypes.BOOLEAN
        elif isinstance(column.type, sqltypes.DateTime):
            expected_type = sqltypes.DATETIME

        if not isinstance(database_column['type'], expected_type):
            self.errors.append(
                DatatypeMismatch(table, database_column, expected_type,
                                 parent=self)
            ) 
开发者ID:Hamuko,项目名称:cum,代码行数:22,代码来源:sanity.py

示例4: sql_func_astype

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Boolean [as 别名]
def sql_func_astype(col, _type):
    mappings = {
            str: types.Text,
            'str': types.Text,
            int: types.Integer,
            'int': types.Integer,
            float: types.Numeric,
            'float': types.Numeric,
            bool: types.Boolean,
            'bool': types.Boolean
            }
    try:
        sa_type = mappings[_type]
    except KeyError:
        raise ValueError("sql astype currently only supports type objects: str, int, float, bool")
    return sql.cast(col, sa_type)


# Base translations =========================================================== 
开发者ID:machow,项目名称:siuba,代码行数:21,代码来源:translate.py

示例5: init_modify_type

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Boolean [as 别名]
def init_modify_type(self, diff):
        if sgdb_in(self.migration.conn.engine, ['MySQL', 'MariaDB']):
            if isinstance(diff[5], TINYINT) and isinstance(diff[6], Boolean):
                # Boolean are TINYINT in MySQL DataBase
                return True
        if sgdb_in(self.migration.conn.engine, ['MsSQL']):
            if isinstance(diff[5], BIT) and isinstance(diff[6], Boolean):
                # Boolean are TINYINT in MySQL DataBase
                return True

        table = "%s.%s" % diff[1:3] if diff[1] else diff[2]
        self.log_names.append("Modify column type %s.%s : %s => %s" % (
            table, diff[3], diff[5], diff[6]))
        return False 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:16,代码来源:migration.py

示例6: test_get_columns

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Boolean [as 别名]
def test_get_columns(self):
        description = [
            ('datetime', Type.DATETIME, None, None, None, None, True),
            ('number', Type.NUMBER, None, None, None, None, True),
            ('boolean', Type.BOOLEAN, None, None, None, None, True),
            ('date', Type.DATE, None, None, None, None, True),
            ('timeofday', Type.TIMEOFDAY, None, None, None, None, True),
            ('string', Type.STRING, None, None, None, None, True),
        ]
        connection = Mock()
        connection.execute = Mock()
        result = Mock()
        result._cursor_description = Mock()
        result._cursor_description.return_value = description
        connection.execute.return_value = result

        dialect = GSheetsDialect()
        url = make_url('gsheets://docs.google.com/')
        dialect.create_connect_args(url)

        result = dialect.get_columns(connection, 'SOME TABLE')
        expected = [
            {
                'name': 'datetime',
                'type': sqltypes.DATETIME,
                'nullable': True,
                'default': None,
            },
            {
                'name': 'number',
                'type': sqltypes.Numeric,
                'nullable': True,
                'default': None,
            },
            {
                'name': 'boolean',
                'type': sqltypes.Boolean,
                'nullable': True,
                'default': None,
            },
            {
                'name': 'date',
                'type': sqltypes.DATE,
                'nullable': True,
                'default': None,
            },
            {
                'name': 'timeofday',
                'type': sqltypes.TIME,
                'nullable': True,
                'default': None,
            },
            {
                'name': 'string',
                'type': sqltypes.String,
                'nullable': True,
                'default': None,
            },
        ]
        self.assertEqual(result, expected) 
开发者ID:betodealmeida,项目名称:gsheets-db-api,代码行数:62,代码来源:test_dialect.py


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