本文整理匯總了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)
示例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_
示例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)
示例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 ###",
)
示例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 ###",
)
示例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()
示例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
)
示例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,)],
)
示例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
)
示例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),
)
示例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)
示例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)
示例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()
示例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)
示例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),
)