Abstract
Summary of common functions in the SQLAlchemy object-relational database system.
This publication is available in Web form and also as a PDF document.
Please forward any comments to tcc-doc@nmt.edu.
Table of Contents
class MetaDataclass Table: Metadata for one
tableclass ForeignKeyConstraint: Specifying a
relation to another tableclass PrimaryKeyConstraint: Describing a
table's primary keyclass UniqueConstraint: Describing a
uniqueness constraint on a tableclass Index: Specifying an index on a
tableclass Column: Metadata for one table
columnclass ForeignKey: Specifying a column's
foreign key relationclass Sequence: Specifying an
auto-incrementing columnreflector: Script to show an existing database's
structureThis document summarizes some of the more commonly used features of the SQLAlchemy system. The purpose of the SQLAlchemy system is to provide a connection between your Python program and any of several classic database systems built on top of SQL (Structured Query Language) such as MySQL, Postgres, or Oracle.
You should have general knowledge of relational databases, and the additional problems of object-relational mappers, or the current document will not make much sense to you.
Assuming you understand how a classical SQL database works, SQLAlchemy can make life much easier for these applications and many more:
You can use SQLAlchemy to connect to applications in other languages, using classical SQL database engines to interchange data.
You can use SQLAlchemy to provide a persistence layer, so that some of the objects within your Python application can be stored in external databases for later retrieval and translation back into live objects.
This document is not a complete reference. It is intended for daily reference to functions necessary to put up fairly simple applications. SQLAlchemy is a full-featured and highly tuneable system, and we will not cover here many of its useful features for improved performance and simplified programming. Please refer to the SQLAlchemy home page for tutorials and detailed reference information.
Section 9, “reflector: Script to show an existing database's
structure” is a script that uses
reflection to determine the structure of an existing
database.
For a sizeable working example, see pycbc: A
Python interface to the Christmas Bird Count
database.