没有合适的资源?快使用搜索试试~ 我知道了~
首页sqlalchemy工具书--英文原版
sqlalchemy工具书--英文原版

高清版的sqlalchemy书籍,不同于文档,注重用法。可直接选择文字。目录详细。珍藏许久,献给大家。一起进步
资源详情
资源评论
资源推荐

Jason Myers & Rick Copeland
E s s e n t i a l
SQLAlchemy
MAPPING PYTHON TO DATABASES
2nd Edition

Jason Myers and Rick Copeland
Boston
Essential SQLAlchemy
SECOND EDITION

978-1-491-91646-9
[LSI]
Essential SQLAlchemy
by Jason Myers and Rick Copeland
Copyright © 2016 Jason Myers and Rick Copeland. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editors: Dawn Schanafelt and Meghan Blanchette
Production Editor: Shiny Kalapurakkel
Copyeditor: Charles Roumeliotis
Proofreader: Jasmine Kwityn
Indexer: Angela Howard
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Rebecca Demarest
June 2008: First Edition
December 2015: Second Edition
Revision History for the Second Edition
2015-11-20: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491916469 for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Essential SQLAlchemy, the cover image,
and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the authors have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.

Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Introduction to SQLAlchemy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I. SQLAlchemy Core
1.
Schema and Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Types 1
Metadata 3
Tables 4
Columns 5
Keys and Constraints 6
Indexes 7
Relationships and ForeignKeyConstraints 7
Persisting the Tables 9
2.
Working with Data via SQLAlchemy Core. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Inserting Data 13
Querying Data 17
ResultProxy 18
Controlling the Columns in the Query 20
Ordering 20
Limiting 21
Built-In SQL Functions and Labels 22
Filtering 24
ClauseElements 25
Operators 26
iii

Boolean Operators 27
Conjunctions 27
Updating Data 28
Deleting Data 29
Joins 31
Aliases 32
Grouping 33
Chaining 34
Raw Queries 35
3. Exceptions and Transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exceptions 37
AttributeError 38
IntegrityError 40
Handling Errors 41
Transactions 43
4.
Testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Testing with a Test Database 51
Using Mocks 58
5.
Reection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Reflecting Individual Tables 63
Reflecting a Whole Database 66
Query Building with Reflected Objects 66
Part II. SQLAlchemy ORM
6.
Dening Schema with SQLAlchemy ORM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Defining Tables via ORM Classes 71
Keys, Constraints, and Indexes 73
Relationships 74
Persisting the Schema 75
7.
Working with Data via SQLAlchemy ORM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
The Session 77
Inserting Data 80
Querying Data 83
Controlling the Columns in the Query 86
Ordering 86
Limiting 87
iv | Table of Contents
剩余205页未读,继续阅读

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论1