PageRenderTime 64ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/SQLAlchemy-0.7.8/doc/core/compiler.html

#
HTML | 515 lines | 435 code | 80 blank | 0 comment | 0 complexity | c162c6338f13fe361eb44ba27f2e3401 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>
  7. Custom SQL Constructs and Compilation Extension
  8. &mdash;
  9. SQLAlchemy 0.7 Documentation
  10. </title>
  11. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  12. <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
  13. <script type="text/javascript">
  14. var DOCUMENTATION_OPTIONS = {
  15. URL_ROOT: '../',
  16. VERSION: '0.7.8',
  17. COLLAPSE_MODINDEX: false,
  18. FILE_SUFFIX: '.html'
  19. };
  20. </script>
  21. <script type="text/javascript" src="../_static/jquery.js"></script>
  22. <script type="text/javascript" src="../_static/underscore.js"></script>
  23. <script type="text/javascript" src="../_static/doctools.js"></script>
  24. <script type="text/javascript" src="../_static/init.js"></script>
  25. <link rel="index" title="Index" href="../genindex.html" />
  26. <link rel="search" title="Search" href="../search.html" />
  27. <link rel="copyright" title="Copyright" href="../copyright.html" />
  28. <link rel="top" title="SQLAlchemy 0.7 Documentation" href="../index.html" />
  29. <link rel="up" title="SQLAlchemy Core" href="index.html" />
  30. <link rel="next" title="Expression Serializer Extension" href="serializer.html" />
  31. <link rel="prev" title="Core Events" href="events.html" />
  32. </head>
  33. <body>
  34. <div id="docs-container">
  35. <div id="docs-header">
  36. <h1>SQLAlchemy 0.7 Documentation</h1>
  37. <div id="docs-search">
  38. Search:
  39. <form class="search" action="../search.html" method="get">
  40. <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
  41. <input type="hidden" name="check_keywords" value="yes" />
  42. <input type="hidden" name="area" value="default" />
  43. </form>
  44. </div>
  45. <div id="docs-version-header">
  46. Release: <span class="version-num">0.7.8</span> | Release Date: June 16, 2012
  47. </div>
  48. </div>
  49. <div id="docs-top-navigation">
  50. <div id="docs-top-page-control" class="docs-navigation-links">
  51. <ul>
  52. <li>Prev:
  53. <a href="events.html" title="previous chapter">Core Events</a>
  54. </li>
  55. <li>Next:
  56. <a href="serializer.html" title="next chapter">Expression Serializer Extension</a>
  57. </li>
  58. <li>
  59. <a href="../contents.html">Table of Contents</a> |
  60. <a href="../genindex.html">Index</a>
  61. | <a href="../_sources/core/compiler.txt">view source
  62. </li>
  63. </ul>
  64. </div>
  65. <div id="docs-navigation-banner">
  66. <a href="../index.html">SQLAlchemy 0.7 Documentation</a>
  67. ť <a href="index.html" title="SQLAlchemy Core">SQLAlchemy Core</a>
  68. ť
  69. Custom SQL Constructs and Compilation Extension
  70. <h2>
  71. Custom SQL Constructs and Compilation Extension
  72. </h2>
  73. </div>
  74. </div>
  75. <div id="docs-body-container">
  76. <div id="docs-sidebar">
  77. <h3><a href="../index.html">Table of Contents</a></h3>
  78. <ul>
  79. <li><a class="reference internal" href="#">Custom SQL Constructs and Compilation Extension</a><ul>
  80. <li><a class="reference internal" href="#synopsis">Synopsis</a></li>
  81. <li><a class="reference internal" href="#dialect-specific-compilation-rules">Dialect-specific compilation rules</a></li>
  82. <li><a class="reference internal" href="#compiling-sub-elements-of-a-custom-expression-construct">Compiling sub-elements of a custom expression construct</a><ul>
  83. <li><a class="reference internal" href="#cross-compiling-between-sql-and-ddl-compilers">Cross Compiling between SQL and DDL compilers</a></li>
  84. </ul>
  85. </li>
  86. <li><a class="reference internal" href="#enabling-autocommit-on-a-construct">Enabling Autocommit on a Construct</a></li>
  87. <li><a class="reference internal" href="#changing-the-default-compilation-of-existing-constructs">Changing the default compilation of existing constructs</a></li>
  88. <li><a class="reference internal" href="#changing-compilation-of-types">Changing Compilation of Types</a></li>
  89. <li><a class="reference internal" href="#subclassing-guidelines">Subclassing Guidelines</a></li>
  90. <li><a class="reference internal" href="#further-examples">Further Examples</a><ul>
  91. <li><a class="reference internal" href="#utc-timestamp-function">&#8220;UTC timestamp&#8221; function</a></li>
  92. <li><a class="reference internal" href="#greatest-function">&#8220;GREATEST&#8221; function</a></li>
  93. <li><a class="reference internal" href="#false-expression">&#8220;false&#8221; expression</a></li>
  94. </ul>
  95. </li>
  96. </ul>
  97. </li>
  98. </ul>
  99. <h4>Previous Topic</h4>
  100. <p>
  101. <a href="events.html" title="previous chapter">Core Events</a>
  102. </p>
  103. <h4>Next Topic</h4>
  104. <p>
  105. <a href="serializer.html" title="next chapter">Expression Serializer Extension</a>
  106. </p>
  107. <h4>Quick Search</h4>
  108. <p>
  109. <form class="search" action="../search.html" method="get">
  110. <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
  111. <input type="hidden" name="check_keywords" value="yes" />
  112. <input type="hidden" name="area" value="default" />
  113. </form>
  114. </p>
  115. </div>
  116. <div id="docs-body" class="withsidebar" >
  117. <div class="section" id="module-sqlalchemy.ext.compiler">
  118. <span id="custom-sql-constructs-and-compilation-extension"></span><span id="sqlalchemy-ext-compiler-toplevel"></span><h1>Custom SQL Constructs and Compilation Extension<a class="headerlink" href="#module-sqlalchemy.ext.compiler" title="Permalink to this headline">ś</a></h1>
  119. <p>Provides an API for creation of custom ClauseElements and compilers.</p>
  120. <div class="section" id="synopsis">
  121. <h2>Synopsis<a class="headerlink" href="#synopsis" title="Permalink to this headline">ś</a></h2>
  122. <p>Usage involves the creation of one or more <a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a>
  123. subclasses and one or more callables defining its compilation:</p>
  124. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.ext.compiler</span> <span class="kn">import</span> <span class="n">compiles</span>
  125. <span class="kn">from</span> <span class="nn">sqlalchemy.sql.expression</span> <span class="kn">import</span> <span class="n">ColumnClause</span>
  126. <span class="k">class</span> <span class="nc">MyColumn</span><span class="p">(</span><span class="n">ColumnClause</span><span class="p">):</span>
  127. <span class="k">pass</span>
  128. <span class="nd">@compiles</span><span class="p">(</span><span class="n">MyColumn</span><span class="p">)</span>
  129. <span class="k">def</span> <span class="nf">compile_mycolumn</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  130. <span class="k">return</span> <span class="s">&quot;[</span><span class="si">%s</span><span class="s">]&quot;</span> <span class="o">%</span> <span class="n">element</span><span class="o">.</span><span class="n">name</span></pre></div>
  131. </div>
  132. <p>Above, <tt class="docutils literal"><span class="pre">MyColumn</span></tt> extends <a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.ColumnClause" title="sqlalchemy.sql.expression.ColumnClause"><tt class="xref py py-class docutils literal"><span class="pre">ColumnClause</span></tt></a>,
  133. the base expression element for named column objects. The <tt class="docutils literal"><span class="pre">compiles</span></tt>
  134. decorator registers itself with the <tt class="docutils literal"><span class="pre">MyColumn</span></tt> class so that it is invoked
  135. when the object is compiled to a string:</p>
  136. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">select</span>
  137. <span class="n">s</span> <span class="o">=</span> <span class="n">select</span><span class="p">([</span><span class="n">MyColumn</span><span class="p">(</span><span class="s">&#39;x&#39;</span><span class="p">),</span> <span class="n">MyColumn</span><span class="p">(</span><span class="s">&#39;y&#39;</span><span class="p">)])</span>
  138. <span class="k">print</span> <span class="nb">str</span><span class="p">(</span><span class="n">s</span><span class="p">)</span></pre></div>
  139. </div>
  140. <p>Produces:</p>
  141. <div class="highlight-python"><div class="highlight"><pre><span class="n">SELECT</span> <span class="p">[</span><span class="n">x</span><span class="p">],</span> <span class="p">[</span><span class="n">y</span><span class="p">]</span></pre></div>
  142. </div>
  143. </div>
  144. <div class="section" id="dialect-specific-compilation-rules">
  145. <h2>Dialect-specific compilation rules<a class="headerlink" href="#dialect-specific-compilation-rules" title="Permalink to this headline">ś</a></h2>
  146. <p>Compilers can also be made dialect-specific. The appropriate compiler will be
  147. invoked for the dialect in use:</p>
  148. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.schema</span> <span class="kn">import</span> <span class="n">DDLElement</span>
  149. <span class="k">class</span> <span class="nc">AlterColumn</span><span class="p">(</span><span class="n">DDLElement</span><span class="p">):</span>
  150. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">column</span><span class="p">,</span> <span class="n">cmd</span><span class="p">):</span>
  151. <span class="bp">self</span><span class="o">.</span><span class="n">column</span> <span class="o">=</span> <span class="n">column</span>
  152. <span class="bp">self</span><span class="o">.</span><span class="n">cmd</span> <span class="o">=</span> <span class="n">cmd</span>
  153. <span class="nd">@compiles</span><span class="p">(</span><span class="n">AlterColumn</span><span class="p">)</span>
  154. <span class="k">def</span> <span class="nf">visit_alter_column</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  155. <span class="k">return</span> <span class="s">&quot;ALTER COLUMN </span><span class="si">%s</span><span class="s"> ...&quot;</span> <span class="o">%</span> <span class="n">element</span><span class="o">.</span><span class="n">column</span><span class="o">.</span><span class="n">name</span>
  156. <span class="nd">@compiles</span><span class="p">(</span><span class="n">AlterColumn</span><span class="p">,</span> <span class="s">&#39;postgresql&#39;</span><span class="p">)</span>
  157. <span class="k">def</span> <span class="nf">visit_alter_column</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  158. <span class="k">return</span> <span class="s">&quot;ALTER TABLE </span><span class="si">%s</span><span class="s"> ALTER COLUMN </span><span class="si">%s</span><span class="s"> ...&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">element</span><span class="o">.</span><span class="n">column</span><span class="o">.</span><span class="n">name</span><span class="p">)</span></pre></div>
  159. </div>
  160. <p>The second <tt class="docutils literal"><span class="pre">visit_alter_table</span></tt> will be invoked when any <tt class="docutils literal"><span class="pre">postgresql</span></tt> dialect is used.</p>
  161. </div>
  162. <div class="section" id="compiling-sub-elements-of-a-custom-expression-construct">
  163. <h2>Compiling sub-elements of a custom expression construct<a class="headerlink" href="#compiling-sub-elements-of-a-custom-expression-construct" title="Permalink to this headline">ś</a></h2>
  164. <p>The <tt class="docutils literal"><span class="pre">compiler</span></tt> argument is the <a class="reference internal" href="internals.html#sqlalchemy.engine.base.Compiled" title="sqlalchemy.engine.base.Compiled"><tt class="xref py py-class docutils literal"><span class="pre">Compiled</span></tt></a>
  165. object in use. This object can be inspected for any information about the
  166. in-progress compilation, including <tt class="docutils literal"><span class="pre">compiler.dialect</span></tt>,
  167. <tt class="docutils literal"><span class="pre">compiler.statement</span></tt> etc. The <a class="reference internal" href="internals.html#sqlalchemy.sql.compiler.SQLCompiler" title="sqlalchemy.sql.compiler.SQLCompiler"><tt class="xref py py-class docutils literal"><span class="pre">SQLCompiler</span></tt></a>
  168. and <a class="reference internal" href="internals.html#sqlalchemy.sql.compiler.DDLCompiler" title="sqlalchemy.sql.compiler.DDLCompiler"><tt class="xref py py-class docutils literal"><span class="pre">DDLCompiler</span></tt></a> both include a <tt class="docutils literal"><span class="pre">process()</span></tt>
  169. method which can be used for compilation of embedded attributes:</p>
  170. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql.expression</span> <span class="kn">import</span> <span class="n">Executable</span><span class="p">,</span> <span class="n">ClauseElement</span>
  171. <span class="k">class</span> <span class="nc">InsertFromSelect</span><span class="p">(</span><span class="n">Executable</span><span class="p">,</span> <span class="n">ClauseElement</span><span class="p">):</span>
  172. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</span><span class="p">,</span> <span class="n">select</span><span class="p">):</span>
  173. <span class="bp">self</span><span class="o">.</span><span class="n">table</span> <span class="o">=</span> <span class="n">table</span>
  174. <span class="bp">self</span><span class="o">.</span><span class="n">select</span> <span class="o">=</span> <span class="n">select</span>
  175. <span class="nd">@compiles</span><span class="p">(</span><span class="n">InsertFromSelect</span><span class="p">)</span>
  176. <span class="k">def</span> <span class="nf">visit_insert_from_select</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  177. <span class="k">return</span> <span class="s">&quot;INSERT INTO </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span>
  178. <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">table</span><span class="p">,</span> <span class="n">asfrom</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
  179. <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">select</span><span class="p">)</span>
  180. <span class="p">)</span>
  181. <span class="n">insert</span> <span class="o">=</span> <span class="n">InsertFromSelect</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">select</span><span class="p">([</span><span class="n">t1</span><span class="p">])</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">t1</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">x</span><span class="o">&gt;</span><span class="mi">5</span><span class="p">))</span>
  182. <span class="k">print</span> <span class="n">insert</span></pre></div>
  183. </div>
  184. <p>Produces:</p>
  185. <div class="highlight-python"><div class="highlight"><pre><span class="s">&quot;INSERT INTO mytable (SELECT mytable.x, mytable.y, mytable.z FROM mytable WHERE mytable.x &gt; :x_1)&quot;</span></pre></div>
  186. </div>
  187. <div class="admonition note">
  188. <p class="first admonition-title">Note</p>
  189. <p class="last">The above <tt class="docutils literal"><span class="pre">InsertFromSelect</span></tt> construct probably wants to have &#8220;autocommit&#8221;
  190. enabled. See <a class="reference internal" href="#enabling-compiled-autocommit"><em>Enabling Autocommit on a Construct</em></a> for this step.</p>
  191. </div>
  192. <div class="section" id="cross-compiling-between-sql-and-ddl-compilers">
  193. <h3>Cross Compiling between SQL and DDL compilers<a class="headerlink" href="#cross-compiling-between-sql-and-ddl-compilers" title="Permalink to this headline">ś</a></h3>
  194. <p>SQL and DDL constructs are each compiled using different base compilers - <tt class="docutils literal"><span class="pre">SQLCompiler</span></tt>
  195. and <tt class="docutils literal"><span class="pre">DDLCompiler</span></tt>. A common need is to access the compilation rules of SQL expressions
  196. from within a DDL expression. The <tt class="docutils literal"><span class="pre">DDLCompiler</span></tt> includes an accessor <tt class="docutils literal"><span class="pre">sql_compiler</span></tt> for this reason, such as below where we generate a CHECK
  197. constraint that embeds a SQL expression:</p>
  198. <div class="highlight-python"><div class="highlight"><pre><span class="nd">@compiles</span><span class="p">(</span><span class="n">MyConstraint</span><span class="p">)</span>
  199. <span class="k">def</span> <span class="nf">compile_my_constraint</span><span class="p">(</span><span class="n">constraint</span><span class="p">,</span> <span class="n">ddlcompiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  200. <span class="k">return</span> <span class="s">&quot;CONSTRAINT </span><span class="si">%s</span><span class="s"> CHECK (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span>
  201. <span class="n">constraint</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
  202. <span class="n">ddlcompiler</span><span class="o">.</span><span class="n">sql_compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">constraint</span><span class="o">.</span><span class="n">expression</span><span class="p">)</span>
  203. <span class="p">)</span></pre></div>
  204. </div>
  205. </div>
  206. </div>
  207. <div class="section" id="enabling-autocommit-on-a-construct">
  208. <span id="enabling-compiled-autocommit"></span><h2>Enabling Autocommit on a Construct<a class="headerlink" href="#enabling-autocommit-on-a-construct" title="Permalink to this headline">ś</a></h2>
  209. <p>Recall from the section <a class="reference internal" href="connections.html#autocommit"><em>Understanding Autocommit</em></a> that the <a class="reference internal" href="connections.html#sqlalchemy.engine.base.Engine" title="sqlalchemy.engine.base.Engine"><tt class="xref py py-class docutils literal"><span class="pre">Engine</span></tt></a>, when asked to execute
  210. a construct in the absence of a user-defined transaction, detects if the given
  211. construct represents DML or DDL, that is, a data modification or data definition statement, which
  212. requires (or may require, in the case of DDL) that the transaction generated by the DBAPI be committed
  213. (recall that DBAPI always has a transaction going on regardless of what SQLAlchemy does). Checking
  214. for this is actually accomplished
  215. by checking for the &#8220;autocommit&#8221; execution option on the construct. When building a construct like
  216. an INSERT derivation, a new DDL type, or perhaps a stored procedure that alters data, the &#8220;autocommit&#8221;
  217. option needs to be set in order for the statement to function with &#8220;connectionless&#8221; execution
  218. (as described in <a class="reference internal" href="connections.html#dbengine-implicit"><em>Connectionless Execution, Implicit Execution</em></a>).</p>
  219. <p>Currently a quick way to do this is to subclass <a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>, then add the &#8220;autocommit&#8221; flag
  220. to the <tt class="docutils literal"><span class="pre">_execution_options</span></tt> dictionary (note this is a &#8220;frozen&#8221; dictionary which supplies a generative
  221. <tt class="docutils literal"><span class="pre">union()</span></tt> method):</p>
  222. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql.expression</span> <span class="kn">import</span> <span class="n">Executable</span><span class="p">,</span> <span class="n">ClauseElement</span>
  223. <span class="k">class</span> <span class="nc">MyInsertThing</span><span class="p">(</span><span class="n">Executable</span><span class="p">,</span> <span class="n">ClauseElement</span><span class="p">):</span>
  224. <span class="n">_execution_options</span> <span class="o">=</span> \
  225. <span class="n">Executable</span><span class="o">.</span><span class="n">_execution_options</span><span class="o">.</span><span class="n">union</span><span class="p">({</span><span class="s">&#39;autocommit&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span></pre></div>
  226. </div>
  227. <p>More succinctly, if the construct is truly similar to an INSERT, UPDATE, or DELETE, <a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.UpdateBase" title="sqlalchemy.sql.expression.UpdateBase"><tt class="xref py py-class docutils literal"><span class="pre">UpdateBase</span></tt></a>
  228. can be used, which already is a subclass of <a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a>, <a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> and includes the
  229. <tt class="docutils literal"><span class="pre">autocommit</span></tt> flag:</p>
  230. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql.expression</span> <span class="kn">import</span> <span class="n">UpdateBase</span>
  231. <span class="k">class</span> <span class="nc">MyInsertThing</span><span class="p">(</span><span class="n">UpdateBase</span><span class="p">):</span>
  232. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">...</span><span class="p">):</span>
  233. <span class="o">...</span></pre></div>
  234. </div>
  235. <p>DDL elements that subclass <a class="reference internal" href="schema.html#sqlalchemy.schema.DDLElement" title="sqlalchemy.schema.DDLElement"><tt class="xref py py-class docutils literal"><span class="pre">DDLElement</span></tt></a> already have the &#8220;autocommit&#8221; flag turned on.</p>
  236. </div>
  237. <div class="section" id="changing-the-default-compilation-of-existing-constructs">
  238. <h2>Changing the default compilation of existing constructs<a class="headerlink" href="#changing-the-default-compilation-of-existing-constructs" title="Permalink to this headline">ś</a></h2>
  239. <p>The compiler extension applies just as well to the existing constructs. When overriding
  240. the compilation of a built in SQL construct, the &#64;compiles decorator is invoked upon
  241. the appropriate class (be sure to use the class, i.e. <tt class="docutils literal"><span class="pre">Insert</span></tt> or <tt class="docutils literal"><span class="pre">Select</span></tt>, instead of the creation function such as <tt class="docutils literal"><span class="pre">insert()</span></tt> or <tt class="docutils literal"><span class="pre">select()</span></tt>).</p>
  242. <p>Within the new compilation function, to get at the &#8220;original&#8221; compilation routine,
  243. use the appropriate visit_XXX method - this because compiler.process() will call upon the
  244. overriding routine and cause an endless loop. Such as, to add &#8220;prefix&#8221; to all insert statements:</p>
  245. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql.expression</span> <span class="kn">import</span> <span class="n">Insert</span>
  246. <span class="nd">@compiles</span><span class="p">(</span><span class="n">Insert</span><span class="p">)</span>
  247. <span class="k">def</span> <span class="nf">prefix_inserts</span><span class="p">(</span><span class="n">insert</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  248. <span class="k">return</span> <span class="n">compiler</span><span class="o">.</span><span class="n">visit_insert</span><span class="p">(</span><span class="n">insert</span><span class="o">.</span><span class="n">prefix_with</span><span class="p">(</span><span class="s">&quot;some prefix&quot;</span><span class="p">),</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span></pre></div>
  249. </div>
  250. <p>The above compiler will prefix all INSERT statements with &#8220;some prefix&#8221; when compiled.</p>
  251. </div>
  252. <div class="section" id="changing-compilation-of-types">
  253. <span id="type-compilation-extension"></span><h2>Changing Compilation of Types<a class="headerlink" href="#changing-compilation-of-types" title="Permalink to this headline">ś</a></h2>
  254. <p><tt class="docutils literal"><span class="pre">compiler</span></tt> works for types, too, such as below where we implement the MS-SQL specific &#8216;max&#8217; keyword for <tt class="docutils literal"><span class="pre">String</span></tt>/<tt class="docutils literal"><span class="pre">VARCHAR</span></tt>:</p>
  255. <div class="highlight-python"><div class="highlight"><pre><span class="nd">@compiles</span><span class="p">(</span><span class="n">String</span><span class="p">,</span> <span class="s">&#39;mssql&#39;</span><span class="p">)</span>
  256. <span class="nd">@compiles</span><span class="p">(</span><span class="n">VARCHAR</span><span class="p">,</span> <span class="s">&#39;mssql&#39;</span><span class="p">)</span>
  257. <span class="k">def</span> <span class="nf">compile_varchar</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  258. <span class="k">if</span> <span class="n">element</span><span class="o">.</span><span class="n">length</span> <span class="o">==</span> <span class="s">&#39;max&#39;</span><span class="p">:</span>
  259. <span class="k">return</span> <span class="s">&quot;VARCHAR(&#39;max&#39;)&quot;</span>
  260. <span class="k">else</span><span class="p">:</span>
  261. <span class="k">return</span> <span class="n">compiler</span><span class="o">.</span><span class="n">visit_VARCHAR</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">)</span>
  262. <span class="n">foo</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;foo&#39;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
  263. <span class="n">Column</span><span class="p">(</span><span class="s">&#39;data&#39;</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">(</span><span class="s">&#39;max&#39;</span><span class="p">))</span>
  264. <span class="p">)</span></pre></div>
  265. </div>
  266. </div>
  267. <div class="section" id="subclassing-guidelines">
  268. <h2>Subclassing Guidelines<a class="headerlink" href="#subclassing-guidelines" title="Permalink to this headline">ś</a></h2>
  269. <p>A big part of using the compiler extension is subclassing SQLAlchemy
  270. expression constructs. To make this easier, the expression and
  271. schema packages feature a set of &#8220;bases&#8221; intended for common tasks.
  272. A synopsis is as follows:</p>
  273. <ul>
  274. <li><p class="first"><a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> - This is the root
  275. expression class. Any SQL expression can be derived from this base, and is
  276. probably the best choice for longer constructs such as specialized INSERT
  277. statements.</p>
  278. </li>
  279. <li><p class="first"><a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> - The root of all
  280. &#8220;column-like&#8221; elements. Anything that you&#8217;d place in the &#8220;columns&#8221; clause of
  281. a SELECT statement (as well as order by and group by) can derive from this -
  282. the object will automatically have Python &#8220;comparison&#8221; behavior.</p>
  283. <p><a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.ColumnElement" title="sqlalchemy.sql.expression.ColumnElement"><tt class="xref py py-class docutils literal"><span class="pre">ColumnElement</span></tt></a> classes want to have a
  284. <tt class="docutils literal"><span class="pre">type</span></tt> member which is expression&#8217;s return type. This can be established
  285. at the instance level in the constructor, or at the class level if its
  286. generally constant:</p>
  287. <div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">timestamp</span><span class="p">(</span><span class="n">ColumnElement</span><span class="p">):</span>
  288. <span class="nb">type</span> <span class="o">=</span> <span class="n">TIMESTAMP</span><span class="p">()</span></pre></div>
  289. </div>
  290. </li>
  291. <li><p class="first"><a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.FunctionElement" title="sqlalchemy.sql.expression.FunctionElement"><tt class="xref py py-class docutils literal"><span class="pre">FunctionElement</span></tt></a> - This is a hybrid of a
  292. <tt class="docutils literal"><span class="pre">ColumnElement</span></tt> and a &#8220;from clause&#8221; like object, and represents a SQL
  293. function or stored procedure type of call. Since most databases support
  294. statements along the line of &#8220;SELECT FROM &lt;some function&gt;&#8221;
  295. <tt class="docutils literal"><span class="pre">FunctionElement</span></tt> adds in the ability to be used in the FROM clause of a
  296. <tt class="docutils literal"><span class="pre">select()</span></tt> construct:</p>
  297. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql.expression</span> <span class="kn">import</span> <span class="n">FunctionElement</span>
  298. <span class="k">class</span> <span class="nc">coalesce</span><span class="p">(</span><span class="n">FunctionElement</span><span class="p">):</span>
  299. <span class="n">name</span> <span class="o">=</span> <span class="s">&#39;coalesce&#39;</span>
  300. <span class="nd">@compiles</span><span class="p">(</span><span class="n">coalesce</span><span class="p">)</span>
  301. <span class="k">def</span> <span class="nf">compile</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  302. <span class="k">return</span> <span class="s">&quot;coalesce(</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">clauses</span><span class="p">)</span>
  303. <span class="nd">@compiles</span><span class="p">(</span><span class="n">coalesce</span><span class="p">,</span> <span class="s">&#39;oracle&#39;</span><span class="p">)</span>
  304. <span class="k">def</span> <span class="nf">compile</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  305. <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">clauses</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">:</span>
  306. <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;coalesce only supports two arguments on Oracle&quot;</span><span class="p">)</span>
  307. <span class="k">return</span> <span class="s">&quot;nvl(</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">clauses</span><span class="p">)</span></pre></div>
  308. </div>
  309. </li>
  310. <li><p class="first"><a class="reference internal" href="schema.html#sqlalchemy.schema.DDLElement" title="sqlalchemy.schema.DDLElement"><tt class="xref py py-class docutils literal"><span class="pre">DDLElement</span></tt></a> - The root of all DDL expressions,
  311. like CREATE TABLE, ALTER TABLE, etc. Compilation of <tt class="docutils literal"><span class="pre">DDLElement</span></tt>
  312. subclasses is issued by a <tt class="docutils literal"><span class="pre">DDLCompiler</span></tt> instead of a <tt class="docutils literal"><span class="pre">SQLCompiler</span></tt>.
  313. <tt class="docutils literal"><span class="pre">DDLElement</span></tt> also features <tt class="docutils literal"><span class="pre">Table</span></tt> and <tt class="docutils literal"><span class="pre">MetaData</span></tt> event hooks via the
  314. <tt class="docutils literal"><span class="pre">execute_at()</span></tt> method, allowing the construct to be invoked during CREATE
  315. TABLE and DROP TABLE sequences.</p>
  316. </li>
  317. <li><p class="first"><a class="reference internal" href="expression_api.html#sqlalchemy.sql.expression.Executable" title="sqlalchemy.sql.expression.Executable"><tt class="xref py py-class docutils literal"><span class="pre">Executable</span></tt></a> - This is a mixin which should be
  318. used with any expression class that represents a &#8220;standalone&#8221; SQL statement that
  319. can be passed directly to an <tt class="docutils literal"><span class="pre">execute()</span></tt> method. It is already implicit
  320. within <tt class="docutils literal"><span class="pre">DDLElement</span></tt> and <tt class="docutils literal"><span class="pre">FunctionElement</span></tt>.</p>
  321. </li>
  322. </ul>
  323. </div>
  324. <div class="section" id="further-examples">
  325. <h2>Further Examples<a class="headerlink" href="#further-examples" title="Permalink to this headline">ś</a></h2>
  326. <div class="section" id="utc-timestamp-function">
  327. <h3>&#8220;UTC timestamp&#8221; function<a class="headerlink" href="#utc-timestamp-function" title="Permalink to this headline">ś</a></h3>
  328. <p>A function that works like &#8220;CURRENT_TIMESTAMP&#8221; except applies the appropriate conversions
  329. so that the time is in UTC time. Timestamps are best stored in relational databases
  330. as UTC, without time zones. UTC so that your database doesn&#8217;t think time has gone
  331. backwards in the hour when daylight savings ends, without timezones because timezones
  332. are like character encodings - they&#8217;re best applied only at the endpoints of an
  333. application (i.e. convert to UTC upon user input, re-apply desired timezone upon display).</p>
  334. <p>For Postgresql and Microsoft SQL Server:</p>
  335. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">expression</span>
  336. <span class="kn">from</span> <span class="nn">sqlalchemy.ext.compiler</span> <span class="kn">import</span> <span class="n">compiles</span>
  337. <span class="kn">from</span> <span class="nn">sqlalchemy.types</span> <span class="kn">import</span> <span class="n">DateTime</span>
  338. <span class="k">class</span> <span class="nc">utcnow</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">FunctionElement</span><span class="p">):</span>
  339. <span class="nb">type</span> <span class="o">=</span> <span class="n">DateTime</span><span class="p">()</span>
  340. <span class="nd">@compiles</span><span class="p">(</span><span class="n">utcnow</span><span class="p">,</span> <span class="s">&#39;postgresql&#39;</span><span class="p">)</span>
  341. <span class="k">def</span> <span class="nf">pg_utcnow</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  342. <span class="k">return</span> <span class="s">&quot;TIMEZONE(&#39;utc&#39;, CURRENT_TIMESTAMP)&quot;</span>
  343. <span class="nd">@compiles</span><span class="p">(</span><span class="n">utcnow</span><span class="p">,</span> <span class="s">&#39;mssql&#39;</span><span class="p">)</span>
  344. <span class="k">def</span> <span class="nf">ms_utcnow</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  345. <span class="k">return</span> <span class="s">&quot;GETUTCDATE()&quot;</span></pre></div>
  346. </div>
  347. <p>Example usage:</p>
  348. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="p">(</span>
  349. <span class="n">Table</span><span class="p">,</span> <span class="n">Column</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">DateTime</span><span class="p">,</span> <span class="n">MetaData</span>
  350. <span class="p">)</span>
  351. <span class="n">metadata</span> <span class="o">=</span> <span class="n">MetaData</span><span class="p">()</span>
  352. <span class="n">event</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&quot;event&quot;</span><span class="p">,</span> <span class="n">metadata</span><span class="p">,</span>
  353. <span class="n">Column</span><span class="p">(</span><span class="s">&quot;id&quot;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
  354. <span class="n">Column</span><span class="p">(</span><span class="s">&quot;description&quot;</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
  355. <span class="n">Column</span><span class="p">(</span><span class="s">&quot;timestamp&quot;</span><span class="p">,</span> <span class="n">DateTime</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">utcnow</span><span class="p">())</span>
  356. <span class="p">)</span></pre></div>
  357. </div>
  358. </div>
  359. <div class="section" id="greatest-function">
  360. <h3>&#8220;GREATEST&#8221; function<a class="headerlink" href="#greatest-function" title="Permalink to this headline">ś</a></h3>
  361. <p>The &#8220;GREATEST&#8221; function is given any number of arguments and returns the one that is
  362. of the highest value - it&#8217;s equivalent to Python&#8217;s <tt class="docutils literal"><span class="pre">max</span></tt> function. A SQL
  363. standard version versus a CASE based version which only accommodates two
  364. arguments:</p>
  365. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">expression</span>
  366. <span class="kn">from</span> <span class="nn">sqlalchemy.ext.compiler</span> <span class="kn">import</span> <span class="n">compiles</span>
  367. <span class="kn">from</span> <span class="nn">sqlalchemy.types</span> <span class="kn">import</span> <span class="n">Numeric</span>
  368. <span class="k">class</span> <span class="nc">greatest</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">FunctionElement</span><span class="p">):</span>
  369. <span class="nb">type</span> <span class="o">=</span> <span class="n">Numeric</span><span class="p">()</span>
  370. <span class="n">name</span> <span class="o">=</span> <span class="s">&#39;greatest&#39;</span>
  371. <span class="nd">@compiles</span><span class="p">(</span><span class="n">greatest</span><span class="p">)</span>
  372. <span class="k">def</span> <span class="nf">default_greatest</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  373. <span class="k">return</span> <span class="n">compiler</span><span class="o">.</span><span class="n">visit_function</span><span class="p">(</span><span class="n">element</span><span class="p">)</span>
  374. <span class="nd">@compiles</span><span class="p">(</span><span class="n">greatest</span><span class="p">,</span> <span class="s">&#39;sqlite&#39;</span><span class="p">)</span>
  375. <span class="nd">@compiles</span><span class="p">(</span><span class="n">greatest</span><span class="p">,</span> <span class="s">&#39;mssql&#39;</span><span class="p">)</span>
  376. <span class="nd">@compiles</span><span class="p">(</span><span class="n">greatest</span><span class="p">,</span> <span class="s">&#39;oracle&#39;</span><span class="p">)</span>
  377. <span class="k">def</span> <span class="nf">case_greatest</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  378. <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">element</span><span class="o">.</span><span class="n">clauses</span><span class="p">)</span>
  379. <span class="k">return</span> <span class="s">&quot;CASE WHEN </span><span class="si">%s</span><span class="s"> &gt; </span><span class="si">%s</span><span class="s"> THEN </span><span class="si">%s</span><span class="s"> ELSE </span><span class="si">%s</span><span class="s"> END&quot;</span> <span class="o">%</span> <span class="p">(</span>
  380. <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">arg1</span><span class="p">),</span>
  381. <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">arg2</span><span class="p">),</span>
  382. <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">arg1</span><span class="p">),</span>
  383. <span class="n">compiler</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">arg2</span><span class="p">),</span>
  384. <span class="p">)</span></pre></div>
  385. </div>
  386. <p>Example usage:</p>
  387. <div class="highlight-python"><div class="highlight"><pre><span class="n">Session</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">Account</span><span class="p">)</span><span class="o">.</span>\
  388. <span class="nb">filter</span><span class="p">(</span>
  389. <span class="n">greatest</span><span class="p">(</span>
  390. <span class="n">Account</span><span class="o">.</span><span class="n">checking_balance</span><span class="p">,</span>
  391. <span class="n">Account</span><span class="o">.</span><span class="n">savings_balance</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">10000</span>
  392. <span class="p">)</span></pre></div>
  393. </div>
  394. </div>
  395. <div class="section" id="false-expression">
  396. <h3>&#8220;false&#8221; expression<a class="headerlink" href="#false-expression" title="Permalink to this headline">ś</a></h3>
  397. <p>Render a &#8220;false&#8221; constant expression, rendering as &#8220;0&#8221; on platforms that don&#8217;t have a &#8220;false&#8221; constant:</p>
  398. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="kn">import</span> <span class="n">expression</span>
  399. <span class="kn">from</span> <span class="nn">sqlalchemy.ext.compiler</span> <span class="kn">import</span> <span class="n">compiles</span>
  400. <span class="k">class</span> <span class="nc">sql_false</span><span class="p">(</span><span class="n">expression</span><span class="o">.</span><span class="n">ColumnElement</span><span class="p">):</span>
  401. <span class="k">pass</span>
  402. <span class="nd">@compiles</span><span class="p">(</span><span class="n">sql_false</span><span class="p">)</span>
  403. <span class="k">def</span> <span class="nf">default_false</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  404. <span class="k">return</span> <span class="s">&quot;false&quot;</span>
  405. <span class="nd">@compiles</span><span class="p">(</span><span class="n">sql_false</span><span class="p">,</span> <span class="s">&#39;mssql&#39;</span><span class="p">)</span>
  406. <span class="nd">@compiles</span><span class="p">(</span><span class="n">sql_false</span><span class="p">,</span> <span class="s">&#39;mysql&#39;</span><span class="p">)</span>
  407. <span class="nd">@compiles</span><span class="p">(</span><span class="n">sql_false</span><span class="p">,</span> <span class="s">&#39;oracle&#39;</span><span class="p">)</span>
  408. <span class="k">def</span> <span class="nf">int_false</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">compiler</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">):</span>
  409. <span class="k">return</span> <span class="s">&quot;0&quot;</span></pre></div>
  410. </div>
  411. <p>Example usage:</p>
  412. <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">select</span><span class="p">,</span> <span class="n">union_all</span>
  413. <span class="n">exp</span> <span class="o">=</span> <span class="n">union_all</span><span class="p">(</span>
  414. <span class="n">select</span><span class="p">([</span><span class="n">users</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">sql_false</span><span class="p">()</span><span class="o">.</span><span class="n">label</span><span class="p">(</span><span class="s">&quot;enrolled&quot;</span><span class="p">)]),</span>
  415. <span class="n">select</span><span class="p">([</span><span class="n">customers</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">customers</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">enrolled</span><span class="p">])</span>
  416. <span class="p">)</span></pre></div>
  417. </div>
  418. </div>
  419. </div>
  420. </div>
  421. </div>
  422. </div>
  423. <div id="docs-bottom-navigation" class="docs-navigation-links">
  424. Previous:
  425. <a href="events.html" title="previous chapter">Core Events</a>
  426. Next:
  427. <a href="serializer.html" title="next chapter">Expression Serializer Extension</a>
  428. <div id="docs-copyright">
  429. &copy; <a href="../copyright.html">Copyright</a> 2007-2012, the SQLAlchemy authors and contributors.
  430. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
  431. </div>
  432. </div>
  433. </div>
  434. </body>
  435. </html>