Python sqlalchemy.dialects.mysql.TIMESTAMP Examples
The following are 30
code examples of sqlalchemy.dialects.mysql.TIMESTAMP().
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.dialects.mysql
, or try the search function
.
Example #1
Source File: end_to_end_test.py From mysql_streamer with Apache License 2.0 | 7 votes |
def actual_complex_data(self, complex_table_schema): res = {'id': 1} for indx, complex_column_schema in enumerate(complex_table_schema): if isinstance(complex_column_schema.sqla_obj, mysql.DATE): data = complex_column_schema.data.strftime('%Y-%m-%d') elif isinstance(complex_column_schema.sqla_obj, mysql.DATETIME): data = complex_column_schema.data.strftime('%Y-%m-%d %H:%M:%S.%f') elif isinstance(complex_column_schema.sqla_obj, mysql.TIMESTAMP): data = complex_column_schema.data.strftime('%Y-%m-%d %H:%M:%S.%f') elif isinstance(complex_column_schema.sqla_obj, mysql.TIME): time = datetime.time( complex_column_schema.data.seconds / 3600, (complex_column_schema.data.seconds / 60) % 60, complex_column_schema.data.seconds % 60, complex_column_schema.data.microseconds ) data = time.strftime('%H:%M:%S.%f') else: data = complex_column_schema.data res.update({self._build_sql_column_name(indx): data}) return res
Example #2
Source File: base.py From jbox with MIT License | 6 votes |
def __init__(self, timezone=False, fsp=None): """Construct a MySQL TIMESTAMP type. :param timezone: not used by the MySQL dialect. :param fsp: fractional seconds precision value. MySQL 5.6.4 supports storage of fractional seconds; this parameter will be used when emitting DDL for the TIMESTAMP type. .. note:: DBAPI driver support for fractional seconds may be limited; current support includes MySQL Connector/Python. .. versionadded:: 0.8.5 Added MySQL-specific :class:`.mysql.TIMESTAMP` with fractional seconds support. """ super(TIMESTAMP, self).__init__(timezone=timezone) self.fsp = fsp
Example #3
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def __init__(self, timezone=False, fsp=None): """Construct a MySQL TIMESTAMP type. :param timezone: not used by the MySQL dialect. :param fsp: fractional seconds precision value. MySQL 5.6.4 supports storage of fractional seconds; this parameter will be used when emitting DDL for the TIMESTAMP type. .. note:: DBAPI driver support for fractional seconds may be limited; current support includes MySQL Connector/Python. .. versionadded:: 0.8.5 Added MySQL-specific :class:`.mysql.TIMESTAMP` with fractional seconds support. """ super(TIMESTAMP, self).__init__(timezone=timezone) self.fsp = fsp
Example #4
Source File: test_codegen.py From safrs with GNU General Public License v3.0 | 6 votes |
def test_mysql_timestamp(metadata): Table("simple", metadata, Column("id", INTEGER, primary_key=True), Column("timestamp", mysql.TIMESTAMP)) assert ( generate_code(metadata) == """\ # coding: utf-8 from sqlalchemy import Column, Integer, TIMESTAMP from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() metadata = Base.metadata class Simple(Base): __tablename__ = 'simple' id = Column(Integer, primary_key=True) timestamp = Column(TIMESTAMP) """ )
Example #5
Source File: end_to_end_test.py From mysql_streamer with Apache License 2.0 | 6 votes |
def expected_complex_data(self, actual_complex_data, complex_table_schema): expected_complex_data_dict = {'id': 1} for indx, complex_column_schema in enumerate(complex_table_schema): column_name = self._build_sql_column_name(indx) if isinstance(complex_column_schema.sqla_obj, mysql.SET): expected_complex_data_dict[column_name] = \ sorted(actual_complex_data[column_name]) elif isinstance(complex_column_schema.sqla_obj, mysql.DATETIME): date_time_obj = \ complex_column_schema.data.isoformat() expected_complex_data_dict[column_name] = date_time_obj elif isinstance(complex_column_schema.sqla_obj, mysql.TIMESTAMP): date_time_obj = \ complex_column_schema.data.replace(tzinfo=pytz.utc) expected_complex_data_dict[column_name] = date_time_obj elif isinstance(complex_column_schema.sqla_obj, mysql.TIME): number_of_micros = transform_timedelta_to_number_of_microseconds( complex_column_schema.data ) expected_complex_data_dict[column_name] = number_of_micros else: expected_complex_data_dict[column_name] = \ complex_column_schema.data return expected_complex_data_dict
Example #6
Source File: base.py From planespotter with MIT License | 5 votes |
def visit_TIMESTAMP(self, type_, **kw): if getattr(type_, 'fsp', None): return "TIMESTAMP(%d)" % type_.fsp else: return "TIMESTAMP"
Example #7
Source File: base.py From planespotter with MIT License | 5 votes |
def visit_typeclause(self, typeclause, type_=None, **kw): if type_ is None: type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.TypeDecorator): return self.visit_typeclause(typeclause, type_.impl, **kw) elif isinstance(type_, sqltypes.Integer): if getattr(type_, 'unsigned', False): return 'UNSIGNED INTEGER' else: return 'SIGNED INTEGER' elif isinstance(type_, sqltypes.TIMESTAMP): return 'DATETIME' elif isinstance(type_, (sqltypes.DECIMAL, sqltypes.DateTime, sqltypes.Date, sqltypes.Time)): return self.dialect.type_compiler.process(type_) elif isinstance(type_, sqltypes.String) \ and not isinstance(type_, (ENUM, SET)): adapted = CHAR._adapt_string_for_cast(type_) return self.dialect.type_compiler.process(adapted) elif isinstance(type_, sqltypes._Binary): return 'BINARY' elif isinstance(type_, sqltypes.JSON): return "JSON" elif isinstance(type_, sqltypes.NUMERIC): return self.dialect.type_compiler.process( type_).replace('NUMERIC', 'DECIMAL') else: return None
Example #8
Source File: base.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def visit_typeclause(self, typeclause, type_=None): if type_ is None: type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.TypeDecorator): return self.visit_typeclause(typeclause, type_.impl) elif isinstance(type_, sqltypes.Integer): if getattr(type_, 'unsigned', False): return 'UNSIGNED INTEGER' else: return 'SIGNED INTEGER' elif isinstance(type_, sqltypes.TIMESTAMP): return 'DATETIME' elif isinstance(type_, (sqltypes.DECIMAL, sqltypes.DateTime, sqltypes.Date, sqltypes.Time)): return self.dialect.type_compiler.process(type_) elif isinstance(type_, sqltypes.String) \ and not isinstance(type_, (ENUM, SET)): adapted = CHAR._adapt_string_for_cast(type_) return self.dialect.type_compiler.process(adapted) elif isinstance(type_, sqltypes._Binary): return 'BINARY' elif isinstance(type_, sqltypes.JSON): return "JSON" elif isinstance(type_, sqltypes.NUMERIC): return self.dialect.type_compiler.process( type_).replace('NUMERIC', 'DECIMAL') else: return None
Example #9
Source File: base.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def get_column_specification(self, column, **kw): """Builds column DDL.""" colspec = [ self.preparer.format_column(column), self.dialect.type_compiler.process( column.type, type_expression=column) ] is_timestamp = isinstance(column.type, sqltypes.TIMESTAMP) if not column.nullable: colspec.append('NOT NULL') # see: http://docs.sqlalchemy.org/en/latest/dialects/ # mysql.html#mysql_timestamp_null elif column.nullable and is_timestamp: colspec.append('NULL') default = self.get_column_default_string(column) if default is not None: colspec.append('DEFAULT ' + default) if column.table is not None \ and column is column.table._autoincrement_column and \ column.server_default is None: colspec.append('AUTO_INCREMENT') return ' '.join(colspec)
Example #10
Source File: base.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def visit_TIMESTAMP(self, type_, **kw): if getattr(type_, 'fsp', None): return "TIMESTAMP(%d)" % type_.fsp else: return "TIMESTAMP"
Example #11
Source File: base.py From sqlalchemy with MIT License | 5 votes |
def visit_typeclause(self, typeclause, type_=None, **kw): if type_ is None: type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.TypeDecorator): return self.visit_typeclause(typeclause, type_.impl, **kw) elif isinstance(type_, sqltypes.Integer): if getattr(type_, "unsigned", False): return "UNSIGNED INTEGER" else: return "SIGNED INTEGER" elif isinstance(type_, sqltypes.TIMESTAMP): return "DATETIME" elif isinstance( type_, ( sqltypes.DECIMAL, sqltypes.DateTime, sqltypes.Date, sqltypes.Time, ), ): return self.dialect.type_compiler.process(type_) elif isinstance(type_, sqltypes.String) and not isinstance( type_, (ENUM, SET) ): adapted = CHAR._adapt_string_for_cast(type_) return self.dialect.type_compiler.process(adapted) elif isinstance(type_, sqltypes._Binary): return "BINARY" elif isinstance(type_, sqltypes.JSON): return "JSON" elif isinstance(type_, sqltypes.NUMERIC): return self.dialect.type_compiler.process(type_).replace( "NUMERIC", "DECIMAL" ) else: return None
Example #12
Source File: base.py From sqlalchemy with MIT License | 5 votes |
def visit_TIMESTAMP(self, type_, **kw): if getattr(type_, "fsp", None): return "TIMESTAMP(%d)" % type_.fsp else: return "TIMESTAMP"
Example #13
Source File: base.py From jarvis with GNU General Public License v2.0 | 5 votes |
def visit_typeclause(self, typeclause, type_=None, **kw): if type_ is None: type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.TypeDecorator): return self.visit_typeclause(typeclause, type_.impl, **kw) elif isinstance(type_, sqltypes.Integer): if getattr(type_, 'unsigned', False): return 'UNSIGNED INTEGER' else: return 'SIGNED INTEGER' elif isinstance(type_, sqltypes.TIMESTAMP): return 'DATETIME' elif isinstance(type_, (sqltypes.DECIMAL, sqltypes.DateTime, sqltypes.Date, sqltypes.Time)): return self.dialect.type_compiler.process(type_) elif isinstance(type_, sqltypes.String) \ and not isinstance(type_, (ENUM, SET)): adapted = CHAR._adapt_string_for_cast(type_) return self.dialect.type_compiler.process(adapted) elif isinstance(type_, sqltypes._Binary): return 'BINARY' elif isinstance(type_, sqltypes.JSON): return "JSON" elif isinstance(type_, sqltypes.NUMERIC): return self.dialect.type_compiler.process( type_).replace('NUMERIC', 'DECIMAL') else: return None
Example #14
Source File: base.py From jarvis with GNU General Public License v2.0 | 5 votes |
def get_column_specification(self, column, **kw): """Builds column DDL.""" colspec = [ self.preparer.format_column(column), self.dialect.type_compiler.process( column.type, type_expression=column) ] is_timestamp = isinstance(column.type, sqltypes.TIMESTAMP) if not column.nullable: colspec.append('NOT NULL') # see: http://docs.sqlalchemy.org/en/latest/dialects/ # mysql.html#mysql_timestamp_null elif column.nullable and is_timestamp: colspec.append('NULL') default = self.get_column_default_string(column) if default is not None: colspec.append('DEFAULT ' + default) comment = column.comment if comment is not None: literal = self.sql_compiler.render_literal_value( comment, sqltypes.String()) colspec.append('COMMENT ' + literal) if column.table is not None \ and column is column.table._autoincrement_column and \ column.server_default is None: colspec.append('AUTO_INCREMENT') return ' '.join(colspec)
Example #15
Source File: base.py From jarvis with GNU General Public License v2.0 | 5 votes |
def visit_TIMESTAMP(self, type_, **kw): if getattr(type_, 'fsp', None): return "TIMESTAMP(%d)" % type_.fsp else: return "TIMESTAMP"
Example #16
Source File: base.py From android_universal with MIT License | 5 votes |
def visit_typeclause(self, typeclause, type_=None, **kw): if type_ is None: type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.TypeDecorator): return self.visit_typeclause(typeclause, type_.impl, **kw) elif isinstance(type_, sqltypes.Integer): if getattr(type_, 'unsigned', False): return 'UNSIGNED INTEGER' else: return 'SIGNED INTEGER' elif isinstance(type_, sqltypes.TIMESTAMP): return 'DATETIME' elif isinstance(type_, (sqltypes.DECIMAL, sqltypes.DateTime, sqltypes.Date, sqltypes.Time)): return self.dialect.type_compiler.process(type_) elif isinstance(type_, sqltypes.String) \ and not isinstance(type_, (ENUM, SET)): adapted = CHAR._adapt_string_for_cast(type_) return self.dialect.type_compiler.process(adapted) elif isinstance(type_, sqltypes._Binary): return 'BINARY' elif isinstance(type_, sqltypes.JSON): return "JSON" elif isinstance(type_, sqltypes.NUMERIC): return self.dialect.type_compiler.process( type_).replace('NUMERIC', 'DECIMAL') else: return None
Example #17
Source File: base.py From android_universal with MIT License | 5 votes |
def get_column_specification(self, column, **kw): """Builds column DDL.""" colspec = [ self.preparer.format_column(column), self.dialect.type_compiler.process( column.type, type_expression=column) ] is_timestamp = isinstance(column.type, sqltypes.TIMESTAMP) if not column.nullable: colspec.append('NOT NULL') # see: http://docs.sqlalchemy.org/en/latest/dialects/ # mysql.html#mysql_timestamp_null elif column.nullable and is_timestamp: colspec.append('NULL') default = self.get_column_default_string(column) if default is not None: colspec.append('DEFAULT ' + default) comment = column.comment if comment is not None: literal = self.sql_compiler.render_literal_value( comment, sqltypes.String()) colspec.append('COMMENT ' + literal) if column.table is not None \ and column is column.table._autoincrement_column and \ column.server_default is None: colspec.append('AUTO_INCREMENT') return ' '.join(colspec)
Example #18
Source File: base.py From android_universal with MIT License | 5 votes |
def visit_TIMESTAMP(self, type_, **kw): if getattr(type_, 'fsp', None): return "TIMESTAMP(%d)" % type_.fsp else: return "TIMESTAMP"
Example #19
Source File: base.py From planespotter with MIT License | 5 votes |
def get_column_specification(self, column, **kw): """Builds column DDL.""" colspec = [ self.preparer.format_column(column), self.dialect.type_compiler.process( column.type, type_expression=column) ] is_timestamp = isinstance(column.type, sqltypes.TIMESTAMP) if not column.nullable: colspec.append('NOT NULL') # see: http://docs.sqlalchemy.org/en/latest/dialects/ # mysql.html#mysql_timestamp_null elif column.nullable and is_timestamp: colspec.append('NULL') default = self.get_column_default_string(column) if default is not None: colspec.append('DEFAULT ' + default) comment = column.comment if comment is not None: literal = self.sql_compiler.render_literal_value( comment, sqltypes.String()) colspec.append('COMMENT ' + literal) if column.table is not None \ and column is column.table._autoincrement_column and \ column.server_default is None: colspec.append('AUTO_INCREMENT') return ' '.join(colspec)
Example #20
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def visit_TIMESTAMP(self, type_, **kw): if getattr(type_, 'fsp', None): return "TIMESTAMP(%d)" % type_.fsp else: return "TIMESTAMP"
Example #21
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def get_column_specification(self, column, **kw): """Builds column DDL.""" colspec = [ self.preparer.format_column(column), self.dialect.type_compiler.process( column.type, type_expression=column) ] is_timestamp = isinstance(column.type, sqltypes.TIMESTAMP) if not column.nullable: colspec.append('NOT NULL') # see: http://docs.sqlalchemy.org/en/latest/dialects/ # mysql.html#mysql_timestamp_null elif column.nullable and is_timestamp: colspec.append('NULL') default = self.get_column_default_string(column) if default is not None: colspec.append('DEFAULT ' + default) if column.table is not None \ and column is column.table._autoincrement_column and \ column.server_default is None: colspec.append('AUTO_INCREMENT') return ' '.join(colspec)
Example #22
Source File: base.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def visit_typeclause(self, typeclause, type_=None): if type_ is None: type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.TypeDecorator): return self.visit_typeclause(typeclause, type_.impl) elif isinstance(type_, sqltypes.Integer): if getattr(type_, 'unsigned', False): return 'UNSIGNED INTEGER' else: return 'SIGNED INTEGER' elif isinstance(type_, sqltypes.TIMESTAMP): return 'DATETIME' elif isinstance(type_, (sqltypes.DECIMAL, sqltypes.DateTime, sqltypes.Date, sqltypes.Time)): return self.dialect.type_compiler.process(type_) elif isinstance(type_, sqltypes.String) \ and not isinstance(type_, (ENUM, SET)): adapted = CHAR._adapt_string_for_cast(type_) return self.dialect.type_compiler.process(adapted) elif isinstance(type_, sqltypes._Binary): return 'BINARY' elif isinstance(type_, sqltypes.NUMERIC): return self.dialect.type_compiler.process( type_).replace('NUMERIC', 'DECIMAL') else: return None
Example #23
Source File: f23433877c24_fix_mysql_not_null_constraint.py From airflow with Apache License 2.0 | 5 votes |
def downgrade(): # noqa: D103 conn = op.get_bind() if conn.dialect.name == 'mysql': conn.execute("SET time_zone = '+00:00'") op.alter_column('xcom', 'timestamp', existing_type=mysql.TIMESTAMP(fsp=6), nullable=True) op.alter_column('xcom', 'execution_date', existing_type=mysql.TIMESTAMP(fsp=6), nullable=True) op.alter_column('task_fail', 'execution_date', existing_type=mysql.TIMESTAMP(fsp=6), nullable=True)
Example #24
Source File: f23433877c24_fix_mysql_not_null_constraint.py From airflow with Apache License 2.0 | 5 votes |
def upgrade(): # noqa: D103 conn = op.get_bind() if conn.dialect.name == 'mysql': conn.execute("SET time_zone = '+00:00'") op.alter_column('task_fail', 'execution_date', existing_type=mysql.TIMESTAMP(fsp=6), nullable=False) op.alter_column('xcom', 'execution_date', existing_type=mysql.TIMESTAMP(fsp=6), nullable=False) op.alter_column('xcom', 'timestamp', existing_type=mysql.TIMESTAMP(fsp=6), nullable=False)
Example #25
Source File: a66efa278eea_add_precision_to_execution_date_in_mysql.py From airflow with Apache License 2.0 | 5 votes |
def downgrade(): """Unapply Add Precision to execution_date in RenderedTaskInstanceFields table""" conn = op.get_bind() if conn.dialect.name == "mysql": op.alter_column( table_name=TABLE_NAME, column_name=COLUMN_NAME, type_=mysql.TIMESTAMP(), nullable=False )
Example #26
Source File: a66efa278eea_add_precision_to_execution_date_in_mysql.py From airflow with Apache License 2.0 | 5 votes |
def upgrade(): """Add Precision to execution_date in RenderedTaskInstanceFields table for MySQL""" conn = op.get_bind() if conn.dialect.name == "mysql": op.alter_column( table_name=TABLE_NAME, column_name=COLUMN_NAME, type_=mysql.TIMESTAMP(fsp=6), nullable=False )
Example #27
Source File: 0a2a5b66e19d_add_task_reschedule_table.py From airflow with Apache License 2.0 | 5 votes |
def sa_timestamp(): # noqa: D103 return sa.TIMESTAMP(timezone=True)
Example #28
Source File: 0a2a5b66e19d_add_task_reschedule_table.py From airflow with Apache License 2.0 | 5 votes |
def mysql_timestamp(): # noqa: D103 return mysql.TIMESTAMP(fsp=6)
Example #29
Source File: base.py From jbox with MIT License | 5 votes |
def visit_TIMESTAMP(self, type_, **kw): if getattr(type_, 'fsp', None): return "TIMESTAMP(%d)" % type_.fsp else: return "TIMESTAMP"
Example #30
Source File: base.py From jbox with MIT License | 5 votes |
def get_column_specification(self, column, **kw): """Builds column DDL.""" colspec = [ self.preparer.format_column(column), self.dialect.type_compiler.process( column.type, type_expression=column) ] is_timestamp = isinstance(column.type, sqltypes.TIMESTAMP) if not column.nullable: colspec.append('NOT NULL') # see: http://docs.sqlalchemy.org/en/latest/dialects/ # mysql.html#mysql_timestamp_null elif column.nullable and is_timestamp: colspec.append('NULL') default = self.get_column_default_string(column) if default is not None: colspec.append('DEFAULT ' + default) if column.table is not None \ and column is column.table._autoincrement_column and \ column.server_default is None: colspec.append('AUTO_INCREMENT') return ' '.join(colspec)