本文整理汇总了Python中sqlalchemy.orm.defer函数的典型用法代码示例。如果您正苦于以下问题:Python defer函数的具体用法?Python defer怎么用?Python defer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_all
def get_all(cls, limit=None, offset=0):
"""docstring for get_all"""
# TODO: Don't fetch ALL date (no need for html and mdfield)
if limit:
return cls.query.options(defer('_html')).filter_by(_type=cls._my_type).offset(offset).limit(limit)
else:
return cls.query.options(defer('_html')).filter_by(_type=cls._my_type)
开发者ID:cnf,项目名称:MarkedImp,代码行数:7,代码来源:models.py
示例2: GET
def GET(self):
session=database.Session()
with AutoClose(session) as ac:
allnews=session.query(News).options(defer(News.content),defer(News.image)).order_by(News.id.desc()).limit(6).all()
project=session.query(Project).options(defer(Project.content)).order_by(func.random()).first()
partners=session.query(Partner).all()
tpl=WebSiteBasePage.jinja2_env.get_template('Index.html')
return tpl.render(news=allnews,project=project,partners=partners)
开发者ID:hkg36,项目名称:fantaisi,代码行数:8,代码来源:MainPage.py
示例3: get
def get(self):
# get the topics
topics = self.session.query(Topic)
topics = topics.options(defer(Topic.meta))
topics = topics.options(defer(Topic.content))
topics = topics.options(defer(Topic.order))
topics = topics.order_by(Topic.title)
# get the news
news = self.session.query(News)
news = news.options(defer(News.meta))
news = news.options(defer(News.content))
news = news.options(defer(News.order))
news = news.order_by(News.title)
# get the forms
forms = self.session.query(FormDefinition)
forms = forms.options(defer(FormDefinition.definition))
forms = forms.options(defer(FormDefinition.checksum))
forms = forms.order_by(FormDefinition.title)
# get the resources
resources = self.session.query(Resource)
resources = resources.options(defer(Resource.timezone))
resources = resources.order_by(Resource.title)
return {
'topics': topics.all(),
'news': news.all(),
'forms': forms.all(),
'resources': resources.all(),
}
开发者ID:i18nHub,项目名称:onegov.town,代码行数:32,代码来源:sitecollection.py
示例4: visit_create_json_view
def visit_create_json_view(element, ddlcompiler, **kwargs):
name = element.name
base_query = element.query
json_column = element.json_column
json_schema = element.json_schema
extract_date_parts = element.extract_date_parts
columns = []
properties = get_properties(json_schema)
element.columns = []
for p in properties:
if isinstance(p, Array):
continue
column = p.json_func(json_column, p.path)
column_label = "%s.%s" % (json_column.name, p.path)
if extract_date_parts and \
isinstance(p, (DateTime, DateTimeNoTZ, Date)):
for part in extract_date_parts:
part_column = func.date_part_immutable(part, column)
columns.append(part_column.label(
"%s_%s" % (column_label, part)))
p.date_parts = extract_date_parts
columns.append(column.label(column_label))
p.column_name = column_label
element.columns.append(p)
# Don't include columns in the the view that are part of an == condition in
# the WHERE clause.
for where in inspection.inspect(base_query).whereclause:
if where.operator == operator.eq:
for expr in [where.left, where.right]:
if isinstance(expr, Column):
# Curiously, we can't seem to defer the Column object
# expr._Annotated__element itself.
column_name = expr._Annotated__element.name
base_query = base_query.options(defer(column_name))
# Don't include the JSON column in the view.
base_query = base_query.options(defer(json_column))
query = base_query.add_columns(*columns)
create_view = CreateView(name, query, replace=element.replace)
create_indexes = CreateIndexes(
base_query, columns, drop_existing=element.drop_existing_indexes)
view_sql = visit_create_view(create_view, ddlcompiler)
indexes_sql = visit_create_indexes(create_indexes, ddlcompiler)
return view_sql + "; " + indexes_sql
开发者ID:mwhite,项目名称:JSONAlchemy,代码行数:52,代码来源:__init__.py
示例5: test_state_change_col_to_deferred
def test_state_change_col_to_deferred(self):
"""Behavioral test to verify the current activity of loader callables."""
users, User = self.tables.users, self.classes.User
mapper(User, users)
sess = create_session()
# deferred attribute option, gets the LoadDeferredColumns
# callable
u1 = sess.query(User).options(defer(User.name)).first()
assert isinstance(
attributes.instance_state(u1).callables['name'],
strategies.LoadDeferredColumns
)
# expire the attr, it gets the InstanceState callable
sess.expire(u1, ['name'])
assert isinstance(
attributes.instance_state(u1).callables['name'],
state.InstanceState
)
# load it, callable is gone
u1.name
assert 'name' not in attributes.instance_state(u1).callables
# same for expire all
sess.expunge_all()
u1 = sess.query(User).options(defer(User.name)).first()
sess.expire(u1)
assert isinstance(
attributes.instance_state(u1).callables['name'],
state.InstanceState
)
# load over it. everything normal.
sess.query(User).first()
assert 'name' not in attributes.instance_state(u1).callables
sess.expunge_all()
u1 = sess.query(User).first()
# for non present, still expires the same way
del u1.name
sess.expire(u1)
assert 'name' in attributes.instance_state(u1).callables
开发者ID:afeide,项目名称:LuoYunCloud,代码行数:48,代码来源:test_expire.py
示例6: get
def get(self):
session = self.db_session
# query demo
user_obj = session.query(User) \
.options(defer(User.email), lazyload("address_obj_s").load_only("name")).first()
user_name = self.login_user.email if self.login_user else user_obj.name
if user_obj:
if self.login_user:
self.render_template(DASHBOARD_DIR_NAME, 'page_user_dashboard.html', name=user_name,
address_obj_s=user_obj.address_obj_s)
else:
self.render_template(DASHBOARD_DIR_NAME, 'page_dashboard.html', name=user_name,
address_obj_s=user_obj.address_obj_s)
else:
obj = User(name="jiang", email="[email protected]")
session.add(obj)
session.flush()
address_1 = Address(name="address name 1", address="Rd 1", user_id=obj.id)
address_2 = Address(name="address name 2", address="Rd 2", user_id=obj.id)
session.add(address_1)
session.add(address_2)
session.commit()
self.render_template(DASHBOARD_DIR_NAME, 'page_dashboard.html', name=user_name,
address_obj_s=obj.address_obj_s)
开发者ID:LucasJiang,项目名称:lab,代码行数:25,代码来源:dashboard.py
示例7: test_options
def test_options(self):
"""Options on a mapper to create deferred and undeferred columns"""
orders, Order = self.tables.orders, self.classes.Order
mapper(Order, orders)
sess = create_session()
q = sess.query(Order).order_by(Order.id).options(defer('user_id'))
def go():
q.all()[0].user_id
self.sql_eq_(go, [
("SELECT orders.id AS orders_id, "
"orders.address_id AS orders_address_id, "
"orders.description AS orders_description, "
"orders.isopen AS orders_isopen "
"FROM orders ORDER BY orders.id", {}),
("SELECT orders.user_id AS orders_user_id "
"FROM orders WHERE orders.id = :param_1",
{'param_1':1})])
sess.expunge_all()
q2 = q.options(undefer('user_id'))
self.sql_eq_(q2.all, [
("SELECT orders.id AS orders_id, "
"orders.user_id AS orders_user_id, "
"orders.address_id AS orders_address_id, "
"orders.description AS orders_description, "
"orders.isopen AS orders_isopen "
"FROM orders ORDER BY orders.id",
{})])
开发者ID:DeepakAlevoor,项目名称:sqlalchemy,代码行数:34,代码来源:test_deferred.py
示例8: _select
def _select(model, *fields):
pk_columns = _primary_key_names(model)
all_columns = _get_columns(model).keys()
relations = _get_relations(model).keys()
fields = list(set(fields)) if fields else all_columns
# select all column properties if none is specified
for attr in fields:
if attr in all_columns:
break
else:
fields.extend(all_columns)
options = []
# ensure PKs are included and defer unrequested attributes (including related)
# NB: we intentionally allows fields like "related.attribute" to pass through
for attr in (c.key for c in _get_mapper(model).iterate_properties):
if attr not in fields:
if attr in pk_columns:
fields.append(attr)
elif attr in all_columns:
options.append(defer(attr))
# relationships
elif attr in relations:
options.append(lazyload(attr))
return options
开发者ID:edwardt,项目名称:flask-apputils,代码行数:29,代码来源:active_record.py
示例9: test_path_entity
def test_path_entity(self):
"""test the legacy *addl_attrs argument."""
User = self.classes.User
Order = self.classes.Order
Item = self.classes.Item
users = self.tables.users
orders = self.tables.orders
items = self.tables.items
order_items = self.tables.order_items
mapper(User, users, properties={
"orders": relationship(Order, lazy="joined")
})
mapper(Order, orders, properties={
"items": relationship(Item, secondary=order_items, lazy="joined")
})
mapper(Item, items)
sess = create_session()
exp = ("SELECT users.id AS users_id, users.name AS users_name, "
"items_1.id AS items_1_id, orders_1.id AS orders_1_id, "
"orders_1.user_id AS orders_1_user_id, orders_1.address_id "
"AS orders_1_address_id, orders_1.description AS "
"orders_1_description, orders_1.isopen AS orders_1_isopen "
"FROM users LEFT OUTER JOIN orders AS orders_1 "
"ON users.id = orders_1.user_id LEFT OUTER JOIN "
"(order_items AS order_items_1 JOIN items AS items_1 "
"ON items_1.id = order_items_1.item_id) "
"ON orders_1.id = order_items_1.order_id")
q = sess.query(User).options(defer(User.orders, Order.items, Item.description))
self.assert_compile(q, exp)
开发者ID:DeepakAlevoor,项目名称:sqlalchemy,代码行数:35,代码来源:test_deferred.py
示例10: test_defer_many_cols
def test_defer_many_cols(self):
# with [ticket:2778], this goes from 50805 to 32817,
# as it should be fewer function calls than the baseline
A = self.classes.A
s = Session()
s.query(A).options(
*[defer(letter) for letter in ["x", "y", "z", "p", "q", "r"]]
).all()
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:8,代码来源:test_orm.py
示例11: test_defer_many_cols
def test_defer_many_cols(self):
# with [ticket:2778], this goes from 50805 to 32817,
# as it should be fewer function calls than the baseline
A = self.classes.A
s = Session()
s.query(A).options(
*[defer(letter) for letter in ['x', 'y', 'z', 'p', 'q', 'r']]).\
all()
开发者ID:CyberCollins,项目名称:sqlalchemy,代码行数:8,代码来源:test_orm.py
示例12: test_deref
def test_deref(self):
trans = DBSession.query(Transaction).options(
subqueryload(Transaction.incomeTagGroup).subqueryload(TagGroup.tags),
subqueryload(Transaction.expenseTagGroup).subqueryload(TagGroup.tags)
).options(defer('_user_id'))
tran = trans.first()
print(tran)
print(json.dumps({'fsd': tran.incomeTagGroup.tags[0]}))
开发者ID:MarekSalat,项目名称:Trine,代码行数:9,代码来源:_test_tag.py
示例13: test_subclass_option_pathing
def test_subclass_option_pathing(self):
from sqlalchemy.orm import defer
sess = create_session()
dilbert = sess.query(Person).\
options(defer(Engineer.machines, Machine.name)).\
filter(Person.name == 'dilbert').first()
m = dilbert.machines[0]
assert 'name' not in m.__dict__
eq_(m.name, 'IBM ThinkPad')
开发者ID:afeide,项目名称:LuoYunCloud,代码行数:9,代码来源:test_polymorphic_rel.py
示例14: dynamic_field_data
def dynamic_field_data(self, dynamic_field_id, field_definition_id):
dynamic_field = self.session.query(models.Fields).filter_by(id=dynamic_field_id).all()
dynamic_table = util.get_table(dynamic_field.foreign_key_table_object_id, 'id')
return (self.session.query(dynamic_table).
options(defer('id','name','order','description','date_created','last_modified','active',
'organization_id','display_name')).
filter_by(id=field_definition_id).first())
开发者ID:harvardinformatics,项目名称:iggybase,代码行数:9,代码来源:organization_access_control.py
示例15: _user_has_boards
def _user_has_boards(self):
# Cached version of User.boards()
key = 'user/board/count/' + str(self.id)
count = cache.get(key)
if not count:
count = Board.query.filter(
Board.userid.in_(self.user_organizations_owned_ids())).options(
defer(Board.description)).count()
cache.set(key, count, timeout=300)
return bool(count)
开发者ID:rudimk,项目名称:hasjob,代码行数:10,代码来源:board.py
示例16: test_defer_on_wildcard_subclass
def test_defer_on_wildcard_subclass(self):
# pretty much the same as load_only except doesn't
# exclude the primary key
s = Session()
q = s.query(Manager).options(
defer(".*"), undefer("status"))
self.assert_compile(
q,
"SELECT managers.status AS managers_status "
"FROM people JOIN managers ON "
"people.person_id = managers.person_id ORDER BY people.person_id"
)
开发者ID:DeepakAlevoor,项目名称:sqlalchemy,代码行数:13,代码来源:test_deferred.py
示例17: test_defer_super_name_on_subclass
def test_defer_super_name_on_subclass(self):
s = Session()
q = s.query(Manager).options(defer("name"))
self.assert_compile(
q,
"SELECT managers.person_id AS managers_person_id, "
"people.person_id AS people_person_id, "
"people.company_id AS people_company_id, "
"people.type AS people_type, managers.status AS managers_status, "
"managers.manager_name AS managers_manager_name "
"FROM people JOIN managers "
"ON people.person_id = managers.person_id "
"ORDER BY people.person_id"
)
开发者ID:DeepakAlevoor,项目名称:sqlalchemy,代码行数:14,代码来源:test_deferred.py
示例18: query_model
def query_model(session, sa_class, only_pk=False):
"""
Returns a query for *sa_class* that doesn't load any relationship
attribute.
"""
opts = (noload('*'),)
if only_pk:
pk = get_pk(sa_class)
opts += tuple(
defer(prop.key)
for prop in class_mapper(sa_class).iterate_properties
if isinstance(prop, ColumnProperty)
if prop.key != pk)
return session.query(sa_class).options(*opts)
开发者ID:bintlabs,项目名称:python-sync-db,代码行数:14,代码来源:utils.py
示例19: login
def login():
form = LoginForm(request.form)
if form.validate_on_submit():
try:
user = User.query.filter(User.email == form.email).options(defer("_password")).one()
except NoResultFound:
flash("No such email exists.")
else:
if user.match_password(form.password):
login_user(user)
flash("You are successfully logged in.")
return redirect(url_for("home.home"))
else:
flash("Wrong email/password combination. Try again!")
if current_user.is_authenticated():
flash("You are already logged in.")
redirect("/")
return render_template("users/login.html", form=form)
开发者ID:geoffberger,项目名称:flask-app-structure,代码行数:18,代码来源:views.py
示例20: committee_meeting_list
def committee_meeting_list(id):
cte = Committee.query.get(id)
if not cte:
abort(404)
query = CommitteeMeeting.query.filter(CommitteeMeeting.committee == cte).order_by(desc(CommitteeMeeting.date))
# defer some expensive fields if they're not needed
fields = get_api_fields()
if fields:
for f in ['body', 'summary']:
if f not in fields:
query = query.options(defer(f))
if not any(f == 'committee' or f.startswith('committee.') for f in fields):
query = query.options(noload('committee'))
return api_list_items(query, CommitteeMeetingSchema)
开发者ID:Code4SA,项目名称:pmg-cms-2,代码行数:18,代码来源:v2.py
注:本文中的sqlalchemy.orm.defer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论