当前位置: 首页>>代码示例>>Python>>正文


Python Session.remove方法代码示例

本文整理汇总了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()
开发者ID:simplegeo,项目名称:sqlalchemy,代码行数:37,代码来源:fixture_data.py

示例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*
开发者ID:clones,项目名称:sqlalchemy,代码行数:33,代码来源:helloworld.py


注:本文中的meta.Session.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。