我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用sqlalchemy.types.NUMERIC。
def test_fancy_coltypes(self): Table( 'simple_items', self.metadata, Column('enum', ENUM('A', 'B', name='blah')), Column('bool', BOOLEAN), Column('number', NUMERIC(10, asdecimal=False)), ) assert self.generate_code() == """\ # coding: utf-8 from sqlalchemy import Boolean, Column, Enum, MetaData, Numeric, Table metadata = MetaData() t_simple_items = Table( 'simple_items', metadata, Column('enum', Enum('A', 'B', name='blah')), Column('bool', Boolean), Column('number', Numeric(10, asdecimal=False)) ) """
def fake_dialect(name): def _type_descriptor_mock(desc): if type(desc) == DECIMAL: return NUMERIC(precision=desc.precision, scale=desc.scale) dialect = mock.MagicMock() dialect.name = name dialect.type_descriptor = _type_descriptor_mock return dialect
def test_load_dialect_impl_mysql(self): result = self._type.load_dialect_impl(self._mysql_dialect) self.assertEqual(NUMERIC, type(result)) self.assertEqual(20, result.precision) self.assertEqual(6, result.scale) self.assertTrue(result.asdecimal)
def __init__(self, precision=None, scale=None, asdecimal=True, **kw): """Construct a NUMERIC. :param precision: Total digits in this number. If scale and precision are both None, values are stored to limits allowed by the server. :param scale: The number of digits after the decimal point. """ super(NUMERIC, self).__init__(precision=precision, scale=scale, asdecimal=asdecimal, **kw)
def sqltype_to_stdtype(sqltype): import sqlalchemy.types as sqltypes if isinstance(sqltype, (sqltypes.VARCHAR, sqltypes.CHAR, sqltypes.TEXT, sqltypes.Enum, sqltypes.String)): return _STRING_TYPE if isinstance(sqltype, (sqltypes.DATETIME, sqltypes.DATE, sqltypes.TIME, sqltypes.TIMESTAMP)): return _DATE_TYPE if isinstance(sqltype, (sqltypes.INTEGER, sqltypes.BIGINT, sqltypes.SMALLINT, sqltypes.Integer)): return _INTEGER_TYPE if isinstance(sqltype, (sqltypes.REAL, sqltypes.DECIMAL, sqltypes.NUMERIC, sqltypes.FLOAT)): return _DECIMAL_TYPE if isinstance(sqltype, sqltypes.BOOLEAN): return _BOOLEAN_TYPE