本文整理匯總了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 ===========================================================
示例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))
示例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)
示例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)
示例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)
示例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
示例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)