本文整理汇总了Python中meta.Session.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Session.remove方法的具体用法?Python Session.remove怎么用?Python Session.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meta.Session
的用法示例。
在下文中一共展示了Session.remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install
# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import remove [as 别名]
def install():
Base.metadata.create_all(Session().bind)
data = [
("Chicago", "United States", ("60601", "60602", "60603", "60604")),
("Montreal", "Canada", ("H2S 3K9", "H2B 1V4", "H7G 2T8")),
("Edmonton", "Canada", ("T5J 1R9", "T5J 1Z4", "T5H 1P6")),
("New York", "United States", ("10001", "10002", "10003", "10004", "10005", "10006")),
("San Francisco", "United States", ("94102", "94103", "94104", "94105", "94107", "94108")),
]
countries = {}
all_post_codes = []
for city, country, postcodes in data:
try:
country = countries[country]
except KeyError:
countries[country] = country = Country(country)
city = City(city, country)
pc = [PostalCode(code, city) for code in postcodes]
Session.add_all(pc)
all_post_codes.extend(pc)
for i in xrange(1, 51):
person = Person(
"person %.2d" % i,
Address(street="street %.2d" % i, postal_code=all_post_codes[random.randint(0, len(all_post_codes) - 1)]),
)
Session.add(person)
Session.commit()
# start the demo fresh
Session.remove()
示例2: options
# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import remove [as 别名]
"""helloworld.py
Illustrate how to load some data, and cache the results.
"""
import environment
from model import Person
from meta import Session, FromCache
# load Person objects. cache the result under the namespace "all_people".
print "loading people...."
people = Session.query(Person).options(FromCache("default", "all_people")).all()
# remove the Session. next query starts from scratch.
Session.remove()
# load again, using the same FromCache option. now they're cached
# under "all_people", no SQL is emitted.
print "loading people....again!"
people = Session.query(Person).options(FromCache("default", "all_people")).all()
# want to load on some different kind of query ? change the namespace
# you send to FromCache
print "loading people two through twelve"
people_two_through_twelve = Session.query(Person).\
options(FromCache("default", "people_on_range")).\
filter(Person.name.between("person 02", "person 12")).\
all()
# the data is cached under the "namespace" you send to FromCache, *plus*