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


Python types.DateTime方法代码示例

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


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

示例1: initialize

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def initialize(self, connection):
        super(FBDialect, self).initialize(connection)
        self._version_two = ('firebird' in self.server_version_info and
                             self.server_version_info >= (2, )
                             ) or \
                            ('interbase' in self.server_version_info and
                                self.server_version_info >= (6, )
                             )

        if not self._version_two:
            # TODO: whatever other pre < 2.0 stuff goes here
            self.ischema_names = ischema_names.copy()
            self.ischema_names['TIMESTAMP'] = sqltypes.DATE
            self.colspecs = {
                sqltypes.DateTime: sqltypes.DATE
            }

        self.implicit_returning = self._version_two and \
            self.__dict__.get('implicit_returning', True) 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:base.py

示例2: get_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def get_type(data_type):
    type_map = {
        "bytes": types.LargeBinary,
        "boolean": types.Boolean,
        "date": types.Date,
        "datetime": types.DateTime,
        "double": types.Numeric,
        "text": types.String,
        "keyword": types.String,
        "integer": types.Integer,
        "half_float": types.Float,
        "geo_point": types.String,
        # TODO get a solution for nested type
        "nested": types.String,
        # TODO get a solution for object
        "object": types.BLOB,
        "long": types.BigInteger,
        "float": types.Float,
        "ip": types.String,
    }
    type_ = type_map.get(data_type)
    if not type_:
        logger.warning(f"Unknown type found {data_type} reverting to string")
        type_ = types.String
    return type_ 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:27,代码来源:basesqlalchemy.py

示例3: fields_map

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def fields_map(self, field_type):
        if field_type == "primary":
            return ID(stored=True, unique=True)
        type_map = {
            'date': types.Date,
            'datetime': types.DateTime,
            'boolean': types.Boolean,
            'integer': types.Integer,
            'float': types.Float
        }
        if isinstance(field_type, str):
            field_type = type_map.get(field_type, types.Text)

        if not isinstance(field_type, type):
            field_type = field_type.__class__

        if issubclass(field_type, (types.DateTime, types.Date)):
            return DATETIME(stored=True, sortable=True)
        elif issubclass(field_type, types.Integer):
            return NUMERIC(stored=True, numtype=int)
        elif issubclass(field_type, types.Float):
            return NUMERIC(stored=True, numtype=float)
        elif issubclass(field_type, types.Boolean):
            return BOOLEAN(stored=True)
        return TEXT(stored=True, analyzer=self.analyzer, sortable=False) 
开发者ID:honmaple,项目名称:flask-msearch,代码行数:27,代码来源:whoosh_backend.py

示例4: test_render_server_default_no_context

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_render_server_default_no_context(self):
        uo = ops.UpgradeOps(
            ops=[
                ops.CreateTableOp(
                    "sometable",
                    [Column("x", types.DateTime(), server_default=func.now())],
                )
            ]
        )

        eq_ignore_whitespace(
            autogenerate.render_python_code(uo),
            "# ### commands auto generated by Alembic - please adjust! ###\n"
            "    op.create_table('sometable',\n"
            "    sa.Column('x', sa.DateTime(), "
            "server_default=sa.text(!U'now()'), nullable=True)\n"
            "    )\n"
            "    # ### end Alembic commands ###",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:test_autogen_render.py

示例5: test_render_server_default_context_passed

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_render_server_default_context_passed(self):
        uo = ops.UpgradeOps(
            ops=[
                ops.CreateTableOp(
                    "sometable",
                    [Column("x", types.DateTime(), server_default=func.now())],
                )
            ]
        )
        context = MigrationContext.configure(dialect_name="sqlite")
        eq_ignore_whitespace(
            autogenerate.render_python_code(uo, migration_context=context),
            "# ### commands auto generated by Alembic - please adjust! ###\n"
            "    op.create_table('sometable',\n"
            "    sa.Column('x', sa.DateTime(), "
            "server_default=sa.text(!U'(CURRENT_TIMESTAMP)'), nullable=True)\n"
            "    )\n"
            "    # ### end Alembic commands ###",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:21,代码来源:test_autogen_render.py

示例6: fetch_notification_status_for_service_for_day

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def fetch_notification_status_for_service_for_day(bst_day, service_id):
    return db.session.query(
        # return current month as a datetime so the data has the same shape as the ft_notification_status query
        literal(bst_day.replace(day=1), type_=DateTime).label('month'),
        Notification.notification_type,
        Notification.status.label('notification_status'),
        func.count().label('count')
    ).filter(
        Notification.created_at >= get_london_midnight_in_utc(bst_day),
        Notification.created_at < get_london_midnight_in_utc(bst_day + timedelta(days=1)),
        Notification.service_id == service_id,
        Notification.key_type != KEY_TYPE_TEST
    ).group_by(
        Notification.notification_type,
        Notification.status
    ).all() 
开发者ID:alphagov,项目名称:notifications-api,代码行数:18,代码来源:fact_notification_status_dao.py

示例7: initialize

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def initialize(self, connection):
        super(FBDialect, self).initialize(connection)
        self._version_two = (
            "firebird" in self.server_version_info
            and self.server_version_info >= (2,)
        ) or (
            "interbase" in self.server_version_info
            and self.server_version_info >= (6,)
        )

        if not self._version_two:
            # TODO: whatever other pre < 2.0 stuff goes here
            self.ischema_names = ischema_names.copy()
            self.ischema_names["TIMESTAMP"] = sqltypes.DATE
            self.colspecs = {sqltypes.DateTime: sqltypes.DATE}

        self.implicit_returning = self._version_two and self.__dict__.get(
            "implicit_returning", True
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:base.py

示例8: test_function_default

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_function_default(self):
        t = Table(
            "t",
            self.metadata,
            Column("id", Integer, primary_key=True),
            Column("x", DateTime(), server_default=func.now()),
        )
        t.create(testing.db)
        with testing.db.connect() as conn:
            now = conn.scalar(func.now())
            today = datetime.datetime.today()
            conn.execute(t.insert())
            conn.execute(t.insert().values(x=today))
            eq_(
                conn.execute(select([t.c.x]).order_by(t.c.id)).fetchall(),
                [(now,), (today,)],
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_sqlite.py

示例9: test_python_type

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_python_type(self):
        eq_(types.Integer().python_type, int)
        eq_(types.Numeric().python_type, decimal.Decimal)
        eq_(types.Numeric(asdecimal=False).python_type, float)
        eq_(types.LargeBinary().python_type, util.binary_type)
        eq_(types.Float().python_type, float)
        eq_(types.Interval().python_type, datetime.timedelta)
        eq_(types.Date().python_type, datetime.date)
        eq_(types.DateTime().python_type, datetime.datetime)
        eq_(types.String().python_type, str)
        eq_(types.Unicode().python_type, util.text_type)
        eq_(types.Enum("one", "two", "three").python_type, str)

        assert_raises(
            NotImplementedError, lambda: types.TypeEngine().python_type
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例10: test_round_trip_sqlite_datetime

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_round_trip_sqlite_datetime(self):
        variant = DateTime().with_variant(
            dialects.sqlite.DATETIME(truncate_microseconds=True), "sqlite"
        )

        t = Table("t", self.metadata, Column("x", variant))
        with testing.db.connect() as conn:
            t.create(conn)

            conn.execute(
                t.insert(), x=datetime.datetime(2015, 4, 18, 10, 15, 17, 4839)
            )

            eq_(
                conn.scalar(
                    select([t.c.x]).where(
                        t.c.x
                        == datetime.datetime(2015, 4, 18, 10, 15, 17, 1059)
                    )
                ),
                datetime.datetime(2015, 4, 18, 10, 15, 17),
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_types.py

示例11: test_variant_righthand_coercion_returns_self

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_variant_righthand_coercion_returns_self(self):
        my_datetime_normal = DateTime()
        my_datetime_variant = DateTime().with_variant(
            dialects.sqlite.DATETIME(truncate_microseconds=False), "sqlite"
        )

        tab = table(
            "test",
            column("avalue", my_datetime_normal),
            column("bvalue", my_datetime_variant),
        )
        expr = tab.c.avalue == datetime.datetime(2015, 10, 14, 15, 17, 18)

        is_(expr.right.type._type_affinity, DateTime)
        is_(expr.right.type, my_datetime_normal)

        expr = tab.c.bvalue == datetime.datetime(2015, 10, 14, 15, 17, 18)

        is_(expr.right.type, my_datetime_variant) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例12: test_replace_function

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_replace_function(self):
        class replaceable_func(GenericFunction):
            type = Integer
            identifier = "replaceable_func"

        assert isinstance(func.Replaceable_Func().type, Integer)
        assert isinstance(func.RePlAcEaBlE_fUnC().type, Integer)
        assert isinstance(func.replaceable_func().type, Integer)

        with expect_warnings(
            "The GenericFunction 'replaceable_func' is already registered and "
            "is going to be overridden.",
            regex=False,
        ):

            class replaceable_func_override(GenericFunction):
                type = DateTime
                identifier = "replaceable_func"

        assert isinstance(func.Replaceable_Func().type, DateTime)
        assert isinstance(func.RePlAcEaBlE_fUnC().type, DateTime)
        assert isinstance(func.replaceable_func().type, DateTime) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_functions.py

示例13: test_extract_expression

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_extract_expression(self, connection):
        meta = self.metadata
        table = Table("test", meta, Column("dt", DateTime), Column("d", Date))
        meta.create_all(connection)
        connection.execute(
            table.insert(),
            {
                "dt": datetime.datetime(2010, 5, 1, 12, 11, 10),
                "d": datetime.date(2010, 5, 1),
            },
        )
        rs = connection.execute(
            select([extract("year", table.c.dt), extract("month", table.c.d)])
        )
        row = rs.first()
        assert row[0] == 2010
        assert row[1] == 5
        rs.close() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_functions.py

示例14: initialize

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def initialize(self, connection):
        super(FBDialect, self).initialize(connection)
        self._version_two = ('firebird' in self.server_version_info and \
                                self.server_version_info >= (2, )
                            ) or \
                            ('interbase' in self.server_version_info and \
                                self.server_version_info >= (6, )
                            )

        if not self._version_two:
            # TODO: whatever other pre < 2.0 stuff goes here
            self.ischema_names = ischema_names.copy()
            self.ischema_names['TIMESTAMP'] = sqltypes.DATE
            self.colspecs = {
                sqltypes.DateTime: sqltypes.DATE
            }

        self.implicit_returning = self._version_two  and \
                            self.__dict__.get('implicit_returning', True) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:21,代码来源:base.py

示例15: test_querying_table

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import DateTime [as 别名]
def test_querying_table(metadata):
    """
    Create an object for test table.

    """

    # When using pytest-xdist, we don't want concurrent table creations
    # across test processes so we assign a unique name for table based on
    # the current worker id.
    worker_id = os.environ.get('PYTEST_XDIST_WORKER', 'master')
    return Table(
        'test_querying_table_' + worker_id, metadata,
        Column('id', types.Integer, autoincrement=True, primary_key=True),
        Column('serial', types.Integer, Sequence("serial_seq")),
        Column('t_string', types.String(60), onupdate='updated'),
        Column('t_list', types.ARRAY(types.String(60))),
        Column('t_enum', types.Enum(MyEnum)),
        Column('t_int_enum', types.Enum(MyIntEnum)),
        Column('t_datetime', types.DateTime()),
        Column('t_date', types.DateTime()),
        Column('t_interval', types.Interval()),
        Column('uniq_uuid', PG_UUID, nullable=False, unique=True, default=uuid4),
    ) 
开发者ID:CanopyTax,项目名称:asyncpgsa,代码行数:25,代码来源:test_querying.py


注:本文中的sqlalchemy.types.DateTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。