本文整理汇总了Python中sqlalchemy.sql.func.now方法的典型用法代码示例。如果您正苦于以下问题:Python func.now方法的具体用法?Python func.now怎么用?Python func.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql.func
的用法示例。
在下文中一共展示了func.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rename_table
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def rename_table(
cls, operations, old_table_name, new_table_name, schema=None):
"""Emit an ALTER TABLE to rename a table.
:param old_table_name: old name.
:param new_table_name: new name.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
"""
op = cls(old_table_name, new_table_name, schema=schema)
return operations.invoke(op)
示例2: rename_table
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def rename_table(
cls, operations, old_table_name, new_table_name, schema=None
):
"""Emit an ALTER TABLE to rename a table.
:param old_table_name: old name.
:param new_table_name: new name.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
"""
op = cls(old_table_name, new_table_name, schema=schema)
return operations.invoke(op)
示例3: test
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def test(self,user,password,token):
### now test for bad token usage
tokenhash = self.tokendb.hashToken(token)
if self.tokendb.checkToken(user,tokenhash):
if self.debug:
print(" \- - Password is in token library")
return (10,None)
else:
if self.debug:
print(" \- * Password is not in token library")
return (0,None)
示例4: verifyPasswordGood
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def verifyPasswordGood(self,user,password,ip=None,reserve=True,always_true=False):
score = 0
reasons = []
token = self.tokendb.tokenizePassword(password)
tokenhash = self.tokendb.hashToken(token)
for Test in self.Tests:
(code,ctx) = Test.test(user,password,token)
reasons.append(Test.report(code,ctx))
score += code
reasons = list(filter(lambda x: len(x),reasons))
if score == 0:
if reserve == True:
self.tokendb.addToken(user,tokenhash,ip)
reasons.append( "Password is valid and now reserved" )
if self.debug:
print(" \- + Password is a valid entry and is now reserved")
else:
reasons.append( "Password is tested as valid" )
if self.debug:
print(" \- + Password is tested as valid entry")
retval = True
else:
if self.debug:
print(" \- - Password is invalid and unacceptable")
retval = False
if always_true == True and retval == False:
print(" \- - OVERRIDING invalid with Valid (yesman enabled)!!!")
reasons.append( "Invalid Password Approved due to Yesman mode" )
retval = True
return (retval,score,'\n'.join(reasons))
示例5: changed
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def changed(cls):
found = PeriodicTasks.query.filter_by(ident=1).first()
if not found:
found = PeriodicTasks()
found.last_update = datetime.datetime.now()
db.session.add(found)
示例6: drop_constraint
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def drop_constraint(
cls, operations, constraint_name, table_name,
type_=None, schema=None):
"""Drop a constraint of the given name, typically via DROP CONSTRAINT.
:param constraint_name: name of the constraint.
:param table_name: table name.
:param type_: optional, required on MySQL. can be
'foreignkey', 'primary', 'unique', or 'check'.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
.. versionchanged:: 0.8.0 The following positional argument names
have been changed:
* name -> constraint_name
"""
op = cls(constraint_name, table_name, type_=type_, schema=schema)
return operations.invoke(op)
示例7: drop_index
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def drop_index(cls, operations, index_name, table_name=None, schema=None):
"""Issue a "drop index" instruction using the current
migration context.
e.g.::
drop_index("accounts")
:param index_name: name of the index.
:param table_name: name of the owning table. Some
backends such as Microsoft SQL Server require this.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
.. versionchanged:: 0.8.0 The following positional argument names
have been changed:
* name -> index_name
"""
op = cls(index_name, table_name=table_name, schema=schema)
return operations.invoke(op)
示例8: drop_constraint
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def drop_constraint(
cls, operations, constraint_name, table_name, type_=None, schema=None
):
r"""Drop a constraint of the given name, typically via DROP CONSTRAINT.
:param constraint_name: name of the constraint.
:param table_name: table name.
:param type\_: optional, required on MySQL. can be
'foreignkey', 'primary', 'unique', or 'check'.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
.. versionchanged:: 0.8.0 The following positional argument names
have been changed:
* name -> constraint_name
"""
op = cls(constraint_name, table_name, type_=type_, schema=schema)
return operations.invoke(op)
示例9: drop_index
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def drop_index(
cls, operations, index_name, table_name=None, schema=None, **kw
):
r"""Issue a "drop index" instruction using the current
migration context.
e.g.::
drop_index("accounts")
:param index_name: name of the index.
:param table_name: name of the owning table. Some
backends such as Microsoft SQL Server require this.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
:param \**kw: Additional keyword arguments not mentioned above are
dialect specific, and passed in the form
``<dialectname>_<argname>``.
See the documentation regarding an individual dialect at
:ref:`dialect_toplevel` for detail on documented arguments.
.. versionadded:: 0.9.5 Support for dialect-specific keyword
arguments for DROP INDEX
.. versionchanged:: 0.8.0 The following positional argument names
have been changed:
* name -> index_name
"""
op = cls(index_name, table_name=table_name, schema=schema, **kw)
return operations.invoke(op)
示例10: set_url
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def set_url(self, id, url):
ks = {"update_time": datetime.now(), "check": True, "url": url}
self.get_session().query(self._model).filter_by(id=id).update(ks)
# DB End
###############################################################################
示例11: date_created
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def date_created(cls):
return db.Column(
db.TIMESTAMP(timezone=True),
default=timezone.now,
server_default=func.now(),
nullable=False,
)
# https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PreFilteredQuery
示例12: init
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def init(self, auto_create=True):
# TODO handle if user does not pass in table sqlite://path.db
uri_splt = self.uri.split(":")
engine_uri = ":".join(uri_splt[:-1])
table_name = uri_splt[-1]
metadata = MetaData()
postref_table = Table(table_name, metadata,
Column('id', Integer, primary_key=True),
Column('created_at', DateTime, default=func.now()),
Column('updated_at', DateTime, default=func.now(), onupdate=func.current_timestamp()),
Column('uuid', String(512)),
Column('path', String(512)),
Column('revision', Integer, default=0),
Column('status', Integer, default=self.PostStatus.DRAFT.value),
Column('ref', String(512)),
Column('data', LargeBinary))
self.engine = create_engine(engine_uri, pool_recycle=3600)
self.session = scoped_session(sessionmaker(bind=self.engine))
if auto_create:
postref_table.create(self.engine, checkfirst=True)
class PostRef(object):
pass
mapper(PostRef, postref_table)
self.PostRef = PostRef
# ------------- Repository actions / state ------------------------------------
示例13: save_json
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def save_json(self, key, data):
data = json.dumps(data, separators=(",", ":"))
updated = func.now()
try:
s = self.items.insert().values(key=key, data=data, updated=updated)
s.execute()
except IntegrityError:
s = (
self.items.update()
.where(self.items.c.key == key)
.values(key=key, data=data, updated=updated)
)
s.execute()
示例14: statistics
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def statistics():
"""
Show global and per-package statistics about build times etc.
Uses materialized views that are refreshed by backend's polling.
"""
now = db.query(func.now()).scalar()
scalar_stats = db.query(ScalarStats).one()
resource_query = db.query(ResourceConsumptionStats)\
.order_by(ResourceConsumptionStats.time.desc().nullslast())\
.paginate(20)
return render_template("stats.html", now=now, stats=scalar_stats,
packages=resource_query.items,
page=resource_query)
示例15: drop_index
# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import now [as 别名]
def drop_index(cls, operations, index_name,
table_name=None, schema=None, **kw):
r"""Issue a "drop index" instruction using the current
migration context.
e.g.::
drop_index("accounts")
:param index_name: name of the index.
:param table_name: name of the owning table. Some
backends such as Microsoft SQL Server require this.
:param schema: Optional schema name to operate within. To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
:class:`~sqlalchemy.sql.elements.quoted_name`.
.. versionadded:: 0.7.0 'schema' can now accept a
:class:`~sqlalchemy.sql.elements.quoted_name` construct.
:param \**kw: Additional keyword arguments not mentioned above are
dialect specific, and passed in the form
``<dialectname>_<argname>``.
See the documentation regarding an individual dialect at
:ref:`dialect_toplevel` for detail on documented arguments.
.. versionadded:: 0.9.5 Support for dialect-specific keyword
arguments for DROP INDEX
.. versionchanged:: 0.8.0 The following positional argument names
have been changed:
* name -> index_name
"""
op = cls(index_name, table_name=table_name, schema=schema, **kw)
return operations.invoke(op)