文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>sqlalchemy soup raw sql update sql example

sqlalchemy soup raw sql update sql example

时间:2010-10-19  来源:lexus

You can also access the SqlSoup's engine attribute to compose SQL directly. The engine's execute method corresponds to the one of a DBAPI cursor, and returns aResultProxy that has fetch methods you would also see on a cursor:

>>> rp = db.bind.execute('select name, email from users order by name')
>>> for name, email in rp.fetchall(): print name, email
Bhargan Basepair [email protected]
Joe Student [email protected]

The docs for SqlSoup in the 0.3 branch are preserved at SqlSoup03. This page describes the 0.4 branch.

Introduction
SqlSoup provides a convenient way to access database tables without having to declare table or mapper classes ahead of time.


Suppose we have a database with users, books, and loans tables (corresponding to the PyWebOff dataset, if you're curious). For testing purposes, we'll create this db as follows:

>>> from sqlalchemy import create_engine >>> e = create_engine('sqlite:///:memory:') >>> for sql in _testsql: e.execute(sql) #doctest: +ELLIPSIS <...

Creating a SqlSoup gateway is just like creating an SQLAlchemy engine:

>>> from sqlalchemy.ext.sqlsoup import SqlSoup
>>> db = SqlSoup('sqlite:///:memory:')

or, you can re-use an existing metadata or engine:

>>> db = SqlSoup(MetaData(e))

You can optionally specify a schema within the database for your SqlSoup:

# >>> db.schema = myschemaname


http://www.sqlalchemy.org/trac/wiki/SqlSoup
http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载