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


Python sqltypes.Numeric方法代码示例

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


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

示例1: sql_func_astype

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Numeric [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

示例2: register_model

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Numeric [as 别名]
def register_model(cls, admin=None):
    """Register *cls* to be included in the API service

    :param cls: Class deriving from :class:`sandman2.models.Model`
    """
    cls.__url__ = '/{}'.format(cls.__name__.lower())
    service_class = type(
        cls.__name__ + 'Service',
        (Service,),
        {
            '__model__': cls,
        })

    # inspect primary key
    cols = list(cls().__table__.primary_key.columns)

    # composite keys not supported (yet)
    primary_key_type = 'string'
    if len(cols) == 1:
        col_type = cols[0].type
        # types defined at http://flask.pocoo.org/docs/0.10/api/#url-route-registrations
        if isinstance(col_type, sqltypes.String):
            primary_key_type = 'string'
        elif isinstance(col_type, sqltypes.Integer):
            primary_key_type = 'int'
        elif isinstance(col_type, sqltypes.Numeric):
            primary_key_type = 'float'

    # registration
    register_service(service_class, primary_key_type)
    if admin is not None:
        admin.add_view(CustomAdminView(cls, db.session)) 
开发者ID:jeffknupp,项目名称:sandman2,代码行数:34,代码来源:app.py

示例3: _caster_combinations

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Numeric [as 别名]
def _caster_combinations(fn):
        return testing.combinations(
            ("integer", Integer),
            ("boolean", Boolean),
            ("float", Numeric),
            ("string", String),
        )(fn) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:9,代码来源:test_operators.py

示例4: sql_func_extract_dow_monday

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Numeric [as 别名]
def sql_func_extract_dow_monday(col):
    # make monday = 0 rather than sunday
    monday0 = sql.cast(sql.func.extract('dow', col) + 6, types.Integer) % 7
    # cast to numeric, since that's what extract('dow') returns
    return sql.cast(monday0, types.Numeric) 
开发者ID:machow,项目名称:siuba,代码行数:7,代码来源:translate.py

示例5: sql_round

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Numeric [as 别名]
def sql_round(col, n):
    return sql.func.round(sql.cast(col, sa_types.Numeric()), n) 
开发者ID:machow,项目名称:siuba,代码行数:4,代码来源:postgresql.py

示例6: __init__

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Numeric [as 别名]
def __init__(self, config):
        ApplicationSession.__init__(self, config)
        self.count = 0
        self.engine = None


        metadata = MetaData()
        self.telemetry = Table("telemetry", metadata,
            Column("id", Integer(), primary_key=True),
            Column("MSG_ID", Integer()),
            Column("V_FC", Integer()),
            Column("V_CAP", Integer()),
            Column("A_ENG", Integer()),
            Column("A_CAP", Integer()),
            Column("T_O2_In", Integer()),
            Column("T_O2_Out", Integer()),
            Column("T_FC_H2O_Out", Integer()),
            Column("Water_In", Integer()),
            Column("Water_Out", Integer()),
            Column("Master_SW", Integer()),
            Column("CAP_Down_SW", Integer()),
            Column("Drive_SW", Integer()),
            Column("FC_state", Integer()),
            Column("Mosfet_state", Integer()),
            Column("Safety_state", Integer()),
            Column("Air_Pump_load", Numeric()),
            Column("Mosfet_load", Integer()),
            Column("Water_Pump_load", Integer()),
            Column("Fan_load", Integer()),
            Column("Acc_X", Integer()),
            Column("Acc_Y", Integer()),
            Column("Acc_Z", Integer()),
            Column("AUX", Numeric()),
            Column("GPS_X", Integer()),
            Column("GPS_Y", Integer()),
            Column("GPS_Z", Integer()),
            Column("GPS_Speed", Integer()),
            Column("V_Safety", Integer()),
            Column("H2_Level", Integer()),
            Column("O2_calc", Numeric()),
            Column("lat", Numeric()),
            Column("lng", Numeric()),
            )


#        metadata = MetaData()
#        self.telemetry = Table("telemetry", metadata,
#            Column("id", Integer(), primary_key=True),
#            Column("mma_x", Integer()),
#            Column("mma_y", Integer()),
#            Column("temp", Numeric()),
#	    Column("lat", Numeric()),
#	    Column("lng", Numeric()),
#        )

    #@inlineCallbacks 
开发者ID:daq-tools,项目名称:kotori,代码行数:58,代码来源:sql.py

示例7: test_get_columns

# 需要导入模块: from sqlalchemy.sql import sqltypes [as 别名]
# 或者: from sqlalchemy.sql.sqltypes import Numeric [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.Numeric方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。