File: sqlalchemy.rst

package info (click to toggle)
pyamf 0.6.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,692 kB
  • sloc: python: 17,944; xml: 455; makefile: 116; sql: 38; java: 11; sh: 7
file content (66 lines) | stat: -rw-r--r-- 1,855 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
**************
  SQLAlchemy 
**************


.. image:: images/sqlalchemy-logo.gif


.. topic:: Introduction

    SQLAlchemy_ is the Python SQL toolkit and Object Relational Mapper
    that gives application developers the full power and flexibility of
    SQL.


Overview
========

PyAMF 0.4 and newer includes an adapter for decoding/encoding objects
managed by SQLAlchemy. The adapter is enabled by default, and SQLAlchemy
managed objects are transparently encoded/decoded by the adapter.

To use the adapter, make sure any SQLAlchemy managed classes are mapped
**before** assigning an AMF alias for the class.

.. code-block:: python

   # MUST COME FIRST
   sqlalchemy.orm.mapper(MappedClass, mapped_table)

   # MUST COME LATER
   pyamf.register_class(MappedClass, 'mapped_class_alias')


The adapter adds 2 additional attributes to all encoded objects that are
managed by SQLAlchemy.

- ``sa_key`` -- An Array of values that make up the primary key of the
   encoded object (analogous to ``mapper.primary_key_from_instance(obj)``
   in Python)
- ``sa_lazy`` -- An Array of attribute names that have not yet been
   loaded from the database

The additional information contained in these attributes can be used to lazy
load attributes in the client.

Third party packages
====================

PyAMF also provides support for the excellent Elixir_ library, a thin wrapper,
which provides the ability to create simple Python classes that map directly
to relational database tables (this pattern is often referred to as the
Active Record design pattern)


Useful Resources
================

:doc:`../actionscript/addressbook`
   Demonstrates the use of SQLAlchemy and Flex.

http://api.pyamf.org/0.5.1/toc-pyamf.adapters._sqlalchemy_orm-module.html
   API documentation.

.. _SQLAlchemy: http://www.sqlalchemy.org
.. _Elixir: http://elixir.ematia.de