py-sqlalchemy/README.rst

136 lines
4.9 KiB
ReStructuredText
Raw Permalink Normal View History

2012-01-26 18:44:34 +02:00
SQLAlchemy
==========
The Python SQL Toolkit and Object Relational Mapper
Introduction
-------------
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper
that gives application developers the full power and
flexibility of SQL. SQLAlchemy provides a full suite
of well known enterprise-level persistence patterns,
designed for efficient and high-performing database
access, adapted into a simple and Pythonic domain
language.
Major SQLAlchemy features include:
2012-08-10 18:22:37 +03:00
* An industrial strength ORM, built
2012-01-26 18:44:34 +02:00
from the core on the identity map, unit of work,
and data mapper patterns. These patterns
2012-08-10 18:22:37 +03:00
allow transparent persistence of objects
2012-06-17 04:29:47 +03:00
using a declarative configuration system.
Domain models
2012-01-26 18:44:34 +02:00
can be constructed and manipulated naturally,
and changes are synchronized with the
current transaction automatically.
* A relationally-oriented query system, exposing
2012-08-10 18:22:37 +03:00
the full range of SQL's capabilities
explicitly, including joins, subqueries,
correlation, and most everything else,
2012-06-17 04:29:47 +03:00
in terms of the object model.
2012-08-10 18:22:37 +03:00
Writing queries with the ORM uses the same
techniques of relational composition you use
2012-01-26 18:44:34 +02:00
when writing SQL. While you can drop into
literal SQL at any time, it's virtually never
needed.
2012-08-10 18:22:37 +03:00
* A comprehensive and flexible system
2012-06-17 04:29:47 +03:00
of eager loading for related collections and objects.
Collections are cached within a session,
2012-08-10 18:22:37 +03:00
and can be loaded on individual access, all
2012-01-26 18:44:34 +02:00
at once using joins, or by query per collection
across the full result set.
2012-08-10 18:22:37 +03:00
* A Core SQL construction system and DBAPI
2012-01-26 18:44:34 +02:00
interaction layer. The SQLAlchemy Core is
separate from the ORM and is a full database
2012-06-17 04:29:47 +03:00
abstraction layer in its own right, and includes
2012-08-10 18:22:37 +03:00
an extensible Python-based SQL expression
language, schema metadata, connection pooling,
2012-01-26 18:44:34 +02:00
type coercion, and custom types.
2012-08-10 18:22:37 +03:00
* All primary and foreign key constraints are
2012-01-26 18:44:34 +02:00
assumed to be composite and natural. Surrogate
2012-08-10 18:22:37 +03:00
integer primary keys are of course still the
2012-01-26 18:44:34 +02:00
norm, but SQLAlchemy never assumes or hardcodes
to this model.
* Database introspection and generation. Database
schemas can be "reflected" in one step into
Python structures representing database metadata;
2012-08-10 18:22:37 +03:00
those same structures can then generate
2012-01-26 18:44:34 +02:00
CREATE statements right back out - all within
the Core, independent of the ORM.
SQLAlchemy's philosophy:
* SQL databases behave less and less like object
collections the more size and performance start to
matter; object collections behave less and less like
tables and rows the more abstraction starts to matter.
SQLAlchemy aims to accommodate both of these
principles.
* An ORM doesn't need to hide the "R". A relational
database provides rich, set-based functionality
that should be fully exposed. SQLAlchemy's
ORM provides an open-ended set of patterns
that allow a developer to construct a custom
2012-08-10 18:22:37 +03:00
mediation layer between a domain model and
2012-01-26 18:44:34 +02:00
a relational schema, turning the so-called
"object relational impedance" issue into
a distant memory.
* The developer, in all cases, makes all decisions
regarding the design, structure, and naming conventions
of both the object model as well as the relational
schema. SQLAlchemy only provides the means
to automate the execution of these decisions.
2012-08-10 18:22:37 +03:00
* With SQLAlchemy, there's no such thing as
"the ORM generated a bad query" - you
retain full control over the structure of
2012-01-26 18:44:34 +02:00
queries, including how joins are organized,
2012-08-10 18:22:37 +03:00
how subqueries and correlation is used, what
2012-01-26 18:50:40 +02:00
columns are requested. Everything SQLAlchemy
does is ultimately the result of a developer-
initiated decision.
2012-01-26 18:44:34 +02:00
* Don't use an ORM if the problem doesn't need one.
SQLAlchemy consists of a Core and separate ORM
component. The Core offers a full SQL expression
2012-08-10 18:22:37 +03:00
language that allows Pythonic construction
2012-01-26 18:44:34 +02:00
of SQL constructs that render directly to SQL
strings for a target database, returning
result sets that are essentially enhanced DBAPI
cursors.
* Transactions should be the norm. With SQLAlchemy's
ORM, nothing goes to permanent storage until
commit() is called. SQLAlchemy encourages applications
to create a consistent means of delineating
the start and end of a series of operations.
* Never render a literal value in a SQL statement.
Bound parameters are used to the greatest degree
2012-08-10 18:22:37 +03:00
possible, allowing query optimizers to cache
2012-01-26 19:15:43 +02:00
query plans effectively and making SQL injection
2012-01-26 18:44:34 +02:00
attacks a non-issue.
Documentation
-------------
Latest documentation is at:
http://www.sqlalchemy.org/docs/
Installation / Requirements
---------------------------
2012-08-10 18:22:37 +03:00
Full documentation for installation is at
2012-01-26 18:44:34 +02:00
`Installation <http://www.sqlalchemy.org/docs/intro.html#installation>`_.
Getting Help / Development / Bug reporting
------------------------------------------
Please refer to the `SQLAlchemy Community Guide <http://www.sqlalchemy.org/support.html>`_.
License
-------
SQLAlchemy is distributed under the `MIT license
<http://www.opensource.org/licenses/mit-license.php>`_.