本文整理匯總了Python中sqlalchemy.func.concat方法的典型用法代碼示例。如果您正苦於以下問題:Python func.concat方法的具體用法?Python func.concat怎麽用?Python func.concat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.func
的用法示例。
在下文中一共展示了func.concat方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_session_query
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def test_session_query(session, table, session_using_test_dataset, table_using_test_dataset):
for session, table in [(session, table), (session_using_test_dataset, table_using_test_dataset)]:
col_concat = func.concat(table.c.string).label('concat')
result = (
session
.query(
table.c.string,
col_concat,
func.avg(table.c.integer),
func.sum(case([(table.c.boolean == True, 1)], else_=0))
)
.group_by(table.c.string, col_concat)
.having(func.avg(table.c.integer) > 10)
).all()
assert len(result) > 0
示例2: define_field_function
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def define_field_function():
@register(Model)
class Test:
id = Integer(primary_key=True)
first_name = String()
last_name = String()
name = Function(fget='fget', fset='fset', fdel='fdel',
fexpr='fexpr')
def fget(self):
return '{0} {1}'.format(self.first_name, self.last_name)
def fset(self, value):
self.first_name, self.last_name = value.split(' ', 1)
def fdel(self):
self.first_name = self.last_name = None
@classmethod
def fexpr(cls):
return func.concat(cls.first_name, ' ', cls.last_name)
示例3: test_on_duplicate_key_update_expression
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def test_on_duplicate_key_update_expression(self):
foos = self.tables.foos
with testing.db.connect() as conn:
conn.execute(insert(foos, dict(id=1, bar="b", baz="bz")))
stmt = insert(foos).values(
[dict(id=1, bar="ab"), dict(id=2, bar="b")]
)
stmt = stmt.on_duplicate_key_update(
bar=func.concat(stmt.inserted.bar, "_foo")
)
result = conn.execute(stmt)
eq_(result.inserted_primary_key, (2,))
eq_(
conn.execute(foos.select().where(foos.c.id == 1)).fetchall(),
[(1, "ab_foo", "bz", False)],
)
示例4: _order_by
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def _order_by(self, query, joins, sort_joins, sort_field, sort_desc):
query, joins = super(AffiliationView, self)._order_by(query, joins, sort_joins, sort_field, sort_desc)
if sort_field.name == 'code':
# sort by the code field, which has entries like:
# 1
# 1.1
# 1.2
# 1.10
# 1.11
# 10.1
#
# these are hard to sort, because they don't sort correctly
# numerically or lexicographically. Instead, we treat them
# as parts of dotted-quad IP addresses and use mysql's inet_aton
# to sort them.
sort_field = func.inet_aton(
func.if_(func.instr(sort_field, '.') > 0,
func.concat(sort_field, '.0.0'), # eg. 10.2
func.concat(sort_field, '.0.0.0'))) # eg. 10
if sort_desc:
sort_field = desc(sort_field)
query = query.order_by(None).order_by(sort_field)
return query, joins
示例5: test_return_type_detection
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def test_return_type_detection(self):
for fn in [func.coalesce, func.max, func.min, func.sum]:
for args, type_ in [
(
(datetime.date(2007, 10, 5), datetime.date(2005, 10, 15)),
sqltypes.Date,
),
((3, 5), sqltypes.Integer),
((decimal.Decimal(3), decimal.Decimal(5)), sqltypes.Numeric),
(("foo", "bar"), sqltypes.String),
(
(
datetime.datetime(2007, 10, 5, 8, 3, 34),
datetime.datetime(2005, 10, 15, 14, 45, 33),
),
sqltypes.DateTime,
),
]:
assert isinstance(fn(*args).type, type_), "%s / %r != %s" % (
fn(),
fn(*args).type,
type_,
)
assert isinstance(func.concat("foo", "bar").type, sqltypes.String)
示例6: test_override_expr
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def test_override_expr(self):
Person, _, _, OverrideExpr, _ = self._fixture()
self.assert_compile(Person.name.__clause_element__(), "person._name")
self.assert_compile(
OverrideExpr.name.__clause_element__(),
"concat(:concat_1, person._name)",
)
示例7: test_override_comparator
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def test_override_comparator(self):
Person, _, _, _, OverrideComparator = self._fixture()
self.assert_compile(Person.name.__clause_element__(), "person._name")
self.assert_compile(
OverrideComparator.name.__clause_element__(),
"concat(:concat_1, person._name)",
)
示例8: setup_classes
# 需要導入模塊: from sqlalchemy import func [as 別名]
# 或者: from sqlalchemy.func import concat [as 別名]
def setup_classes(cls):
Base = cls.DeclarativeBasic
class Person(Base):
__tablename__ = "person"
id = Column(Integer, primary_key=True)
first_name = Column(String(10))
last_name = Column(String(10))
@hybrid.hybrid_property
def name(self):
return self.first_name + " " + self.last_name
@name.setter
def name(self, value):
self.first_name, self.last_name = value.split(" ", 1)
@name.expression
def name(cls):
return func.concat(cls.first_name, " ", cls.last_name)
@name.update_expression
def name(cls, value):
f, l = value.split(" ", 1)
return [(cls.first_name, f), (cls.last_name, l)]
@hybrid.hybrid_property
def uname(self):
return self.name
@hybrid.hybrid_property
def fname(self):
return self.first_name
@hybrid.hybrid_property
def fname2(self):
return self.fname