Essential SQLAlchemy introduces a high-level open-source code library that makes it easier for Python programmers to access relational databases such as Oracle, DB2, MySQL, PostgreSQL, and SQLite. SQLAlchemy has become increasingly popular since its release, but it still lacks good offline documenta
Essential SQLAlchemy
✍ Scribed by Rick Copeland
- Publisher
- O'Reilly Media
- Year
- 2008
- Tongue
- English
- Leaves
- 230
- Edition
- 1
- Category
- Library
No coin nor oath required. For personal study only.
✦ Synopsis
Essential SQLAlchemy introduces a high-level open-source code library that makes it easier for Python programmers to access relational databases such as Oracle, DB2, MySQL, PostgreSQL, and SQLite. SQLAlchemy has become increasingly popular since its release, but it still lacks good offline documentation. This practical book fills the gap, and because a developer wrote it, you get an objective look at SQLAlchemy's tools rather than an advocate's description of all the "cool" features. SQLAlchemy includes both a database server-independent SQL expression language and an object-relational mapper (ORM) that lets you map "plain old Python objects" (POPOs) to database tables without substantially changing your existing Python code. Essential SQLAlchemy demonstrates how to use the library to create a simple database application, walks you through simple queries, and explains how to use SQLAlchemy to connect to multiple databases simultaneously with the same Metadata. You also learn how to:Create custom types to be used in your schema, and when it's useful to use custom rather than built-in types Run queries, updates, and deletes with SQLAlchemy's SQL expression language Build an object mapper with SQLAlchemy, and understand the differences between this and active record patterns used in other ORMs Create objects, save them to a session, and flush them to the database Use SQLAlchemy to model object oriented inheritance Provide a declarative, active record pattern for use with SQLAlchemy using the Elixir extension Use the SQLSoup extension to provide an automatic metadata and object model based on database reflection In addition, you'll learn how and when to use other extensions to SQLAlchemy, including AssociationProxy, OrderingList, and more.Essential SQLAlchemy is the much-needed guide for every Python developer using this code library. Instead of a feature-by-feature documentation, this book takes an "essentials" approach that gives you exactly what you need to become productive with SQLAlchemy right away.
✦ Table of Contents
Table of Contents......Page 7
Audience......Page 9
Contents of this Book......Page 10
Conventions Used in This Book......Page 11
How to Contact Us......Page 12
Acknowledgments......Page 13
What Is SQLAlch......Page 15
The Object/Relational “Impedance Mismatch”......Page 18
SQLAlchemy Philosophy......Page 21
Engine......Page 24
Connection Pooling......Page 25
MetaData Management......Page 26
SQL Expression Language......Page 28
Object Relational Mapper (ORM)......Page 30
Installing setup tools......Page 35
Installing SQLAlchemy with easy_install......Page 36
Installing the SQLite driver on Python versions before 2.5......Page 37
Connecting to the Database and Creating Some Tables......Page 38
Performing Queries and Updates......Page 40
Mapping Objects to Tables......Page 42
Engines and Connectables......Page 47
Configuring SQLAlchemy Logging......Page 49
Database Connections and ResultProxys......Page 50
Connection Pooling......Page 51
Getting Started with MetaData......Page 53
Defining Tables......Page 54
Table reflection......Page 56
Column Definitions......Page 57
Primary keys......Page 58
Foreign keys......Page 59
CHECK constraints......Page 61
Active defaults......Page 62
Passive defaults......Page 64
Defining Indexes......Page 66
The Index object......Page 67
Creating Explicit Sequences......Page 68
Binding MetaData......Page 69
Create/drop MetaData and schema objects......Page 70
Adapt Tables from one MetaData to another......Page 71
Built-in Types......Page 73
Generic Types......Page 74
Dialect-Specific Types......Page 75
Implementing a TypeDecorator......Page 77
Creating a New TypeEngine......Page 79
Inserts, Updates, and Deletes......Page 81
Insert Statements......Page 82
Update Statements......Page 83
Delete Statements......Page 85
The select() function versus the select() method......Page 86
Result set objects......Page 88
Operators and functions in WHERE clauses......Page 89
Using custom bind parameters......Page 92
Using literal text in queries......Page 93
Ordering and grouping results, returning distinct values......Page 94
Using the “generative” query interface......Page 96
Joining selectables......Page 100
Set operations (UNION, INTERSECT, EXCEPT)......Page 102
Using aliases......Page 103
Correlated versus uncorrelated subqueries......Page 104
Embedding subqueries in the FROM clause......Page 105
The data mapper pattern......Page 107
The unit of work pattern......Page 108
Declaring Object Mappers......Page 109
Basic Object Mapping......Page 111
Using include_properties and exclude_properties......Page 113
Using synonyms......Page 114
Mapping subqueries......Page 115
Mapping composite values......Page 116
Eager versus deferred loading......Page 118
Other mapper() Parameters......Page 119
1:N relations......Page 122
M:N relations......Page 123
1:1 relations......Page 124
Using BackRefs......Page 125
Using a Self-Referential Mapper......Page 127
Cascading Changes to Related Objects......Page 128
Other relation() and backref() Parameters......Page 129
Using custom collections in relations......Page 131
Extending Mappers......Page 134
Vertical Partitioning......Page 136
Horizontal Partitioning......Page 138
Creating a Session......Page 141
Saving Objects to the Session......Page 143
Embedding SQL expressions in a flush......Page 148
Deleting Objects from the Session......Page 149
Other Session Methods......Page 150
Extending Sessions......Page 152
Querying at the ORM Level......Page 153
ORM Querying with Joins......Page 156
Customizing the Select Statement in ORM Queries......Page 161
Other Query Methods......Page 164
Contextual or Thread-Local Sessions......Page 167
Using Contextual Sessions with Mappers and Classes......Page 168
Overview of Inheritance Mapping......Page 171
Single Table Inheritance Mapping......Page 172
Concrete Table Inheritance Mapping......Page 175
Joined Table Inheritance Mapping......Page 177
Optimizing Performance with Joined Table Inheritance Mapping......Page 179
Using deferred loading......Page 180
Using select_table......Page 181
Relations and Inheritance......Page 182
Introduction to Elixir......Page 185
Using Elixir......Page 188
Fields and Properties......Page 189
Elixir deferred properties......Page 191
Attribute-based syntax......Page 192
DSL syntax......Page 194
Inheritance......Page 195
Querying Using Elixir......Page 197
Associable Extension......Page 198
Versioned Extension......Page 200
Introduction to SqlSoup......Page 203
Using SqlSoup for ORM-Style Queries and Updates......Page 205
Joins with SqlSoup......Page 206
Mapping Arbitrary Selectables......Page 208
SqlSoup Pros and Cons......Page 209
Elixir Pros and Cons......Page 210
Association Proxy......Page 213
Ordering List......Page 217
Deprecated Extensions......Page 219
Index......Page 221
✦ Subjects
Библиотека;Компьютерная литература;SQL;
📜 SIMILAR VOLUMES
Essential SQLAlchemy introduces a high-level open-source code library that makes it easier for Python programmers to access relational databases such as Oracle, DB2, MySQL, PostgreSQL, and SQLite. SQLAlchemy has become increasingly popular since its release, but it still lacks good offline documenta
Essential SQLAlchemy introduces a high-level open-source code library that makes it easier for Python programmers to access relational databases such as Oracle, DB2, MySQL, PostgreSQL, and SQLite. SQLAlchemy has become increasingly popular since its release, but it still lacks good offline documenta
<p>This new edition of <i>Essential SQLAlchemy</i> is the tool developers need to understand the technology. Rather than being a simple tutorial or API reference, this book builds an application step by step. This application is comprised of many of the most common usages of SQLAlchemy, thus showing