[alpha_api]: javascript:alphaApi()
[alpha_implementation]: javascript:alphaImplementation()
-Data Mapping {@name=datamapping}
+Object Relational Tutorial {@name=datamapping}
============
+**TUTORIAL FORMAT IS TODO**
+
### Basic Data Mapping {@name=datamapping}
Data mapping describes the process of defining `Mapper` objects, which associate table metadata with user-defined classes.
The general structure is this:
+ {diagram}
+-----------+ __________
/---| Pool |---\ (__________)
+-------------+ / +-----------+ \ +--------+ | |
-Constructing SQL Queries via Python Expressions {@name=sql}
+SQL Expression Language Tutorial {@name=sql}
===============================================
-*Note:* This section describes how to use SQLAlchemy to construct SQL queries and receive result sets. It does *not* cover the object relational mapping capabilities of SQLAlchemy; that is covered later on in [datamapping](rel:datamapping). However, both areas of functionality work similarly in how selection criterion is constructed, so if you are interested just in ORM, you should probably skim through basic [sql_whereclause](rel:sql_whereclause) construction before moving on.
-
-Once you have used the `sqlalchemy.schema` module to construct your tables and/or reflect them from the database, performing SQL queries using those table meta data objects is done via the `sqlalchemy.sql` package. This package defines a large set of classes, each of which represents a particular kind of lexical construct within a SQL query; all are descendants of the common base class `sqlalchemy.sql.ClauseElement`. A full query is represented via a structure of `ClauseElement`s. A set of reasonably intuitive creation functions is provided by the `sqlalchemy.sql` package to create these structures; these functions are described in the rest of this section.
-
-Executing a `ClauseElement` structure can be performed in two general ways. You can use an `Engine` or a `Connection` object's `execute()` method to which you pass the query structure; this is known as **explicit style**. Or, if the `ClauseElement` structure is built upon Table metadata which is bound to an `Engine` directly, you can simply call `execute()` on the structure itself, known as **implicit style**. In both cases, the execution returns a cursor-like object (more on that later). The same clause structure can be executed repeatedly. The `ClauseElement` is compiled into a string representation by an underlying `Compiler` object which is associated with the `Engine` via its `Dialect`.
-
-The examples below all include a dump of the generated SQL corresponding to the query object, as well as a dump of the statement's bind parameters. In all cases, bind parameters are shown as named parameters using the colon format (i.e. ':name'). When the statement is compiled into a database-specific version, the named-parameter statement and its bind values are converted to the proper paramstyle for that database automatically.
+**TUTORIAL FORMAT IS TODO**
For this section, we will mostly use the implcit style of execution, meaning the `Table` objects are associated with a bound instance of `MetaData`, and constructed `ClauseElement` objects support self-execution. Assume the following configuration:
+++ /dev/null
-The threadlocal mod {@name=threadlocal}
-============
files = [
'index',
'documentation',
- 'tutorial',
- 'dbengine',
- 'metadata',
- 'sqlconstruction',
+ 'intro',
'datamapping',
- 'unitofwork',
'adv_datamapping',
+ 'unitofwork',
+ 'sqlconstruction',
+ 'dbengine',
+ 'metadata',
'types',
'pooling',
'plugins',
sqlre2 = re.compile(r'{opensql}(.*?\n)((?:BEGIN|SELECT|INSERT|DELETE|UPDATE|CREATE|DROP).*?)\n\s*(\n|$)', re.S)
text = sqlre2.sub(r"<%call expr='formatting.poppedcode()' >\1\n\2</%call>\n\n", text)
- tag = et.Element("MAKO:formatting.code")
+ tag = et.Element("MAKO:formatting.code", extension='extension', paged='paged', toc='toc')
if code:
tag.attrib["syntaxtype"] = repr(code)
if title:
parents = get_parent_map(tree)
for precode in tree.findall('.//pre/code'):
- reg = re.compile(r'\{(python|code)(?: title="(.*?)"){0,1}\}(.*)', re.S)
+ reg = re.compile(r'\{(python|code|diagram)(?: title="(.*?)"){0,1}\}(.*)', re.S)
m = reg.match(precode[0].text.lstrip())
if m:
code = m.group(1)
title = m.group(2)
text = m.group(3)
- text = re.sub(r'{(python|code).*?}(\n\s*)?', '', text)
+ text = re.sub(r'{(python|code|diagram).*?}(\n\s*)?', '', text)
splice_code_tag(parents[precode], text, code=code, title=title)
elif precode.text.lstrip().startswith('>>> '):
splice_code_tag(parents[precode], precode.text)
<span class="codeline">${ caller.body() }</span>
</%def>
-<%def name="code(title=None, syntaxtype='mako', html_escape=False, use_sliders=False)">
+<%def name="code(toc, paged, extension, title=None, syntaxtype='mako', html_escape=False, use_sliders=False)">
<%
def fix_indent(f):
f =string.expandtabs(f, 4)
return g.rstrip()
-
+
p = re.compile(r'<pre>(.*?)</pre>', re.S)
def hlight(match):
return "<pre>" + highlight.highlight(fix_indent(match.group(1)), html_escape = html_escape, syntaxtype = syntaxtype) + "</pre>"
- try:
- content = p.sub(hlight, "<pre>" + capture(caller.body) + "</pre>")
- except:
- raise "the content is " + str(capture(caller.body))
-
+
+ def link(match):
+ return capture(nav.toclink, toc, match.group(2), extension, paged, description=match.group(1))
+
+ content = re.sub(r'\[(.+?)\]\(rel:(.+?)\)', link, capture(caller.body))
+ if syntaxtype != 'diagram':
+ content = p.sub(hlight, "<pre>" + content + "</pre>")
+ else:
+ content = "<pre>" + content + "</pre>"
%>
<div class="${ use_sliders and "sliding_code" or "code" }">
% if item:
<a href="${ item.get_link(extension=extension, anchor=anchor, usefilename=paged) }">${ description }</a>
% else:
+ <%
+ #raise Exception("Can't find TOC link for '%s'" % path)
+ %>
<b>${ description }</b>
% endif
</%def>