Python sqlalchemy.sql.sqltypes.Numeric() Examples
The following are 7
code examples of sqlalchemy.sql.sqltypes.Numeric().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.sql.sqltypes
, or try the search function
.
Example #1
Source File: translate.py From siuba with MIT License | 6 votes |
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 ===========================================================
Example #2
Source File: app.py From sandman2 with Apache License 2.0 | 5 votes |
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))
Example #3
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def _caster_combinations(fn): return testing.combinations( ("integer", Integer), ("boolean", Boolean), ("float", Numeric), ("string", String), )(fn)
Example #4
Source File: translate.py From siuba with MIT License | 5 votes |
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)
Example #5
Source File: postgresql.py From siuba with MIT License | 5 votes |
def sql_round(col, n): return sql.func.round(sql.cast(col, sa_types.Numeric()), n)
Example #6
Source File: sql.py From kotori with GNU Affero General Public License v3.0 | 4 votes |
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
Example #7
Source File: test_dialect.py From gsheets-db-api with MIT License | 4 votes |
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)