File: serializer.html

package info (click to toggle)
sqlalchemy 0.9.8%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,952 kB
  • ctags: 24,534
  • sloc: python: 152,282; ansic: 1,346; makefile: 257; xml: 17
file content (232 lines) | stat: -rw-r--r-- 8,337 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
        <title>
            
    
                Expression Serializer Extension
             &mdash;
    SQLAlchemy 0.9 Documentation

        </title>

        
            <!-- begin iterate through SQLA + sphinx environment css_files -->
                <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
                <link rel="stylesheet" href="../_static/docs.css" type="text/css" />
                <link rel="stylesheet" href="../_static/sphinx_paramlinks.css" type="text/css" />
                <link rel="stylesheet" href="../_static/changelog.css" type="text/css" />
            <!-- end iterate through SQLA + sphinx environment css_files -->
        

        

    

    <!-- begin layout.mako headers -->

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '../',
          VERSION:     '0.9.8',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>

    <!-- begin iterate through sphinx environment script_files -->
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
    <!-- end iterate through sphinx environment script_files -->

    <script type="text/javascript" src="../_static/detectmobile.js"></script>
    <script type="text/javascript" src="../_static/init.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
        <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="SQLAlchemy 0.9 Documentation" href="../index.html" />
        <link rel="up" title="SQLAlchemy Core" href="index.html" />
        <link rel="next" title="Deprecated Event Interfaces" href="interfaces.html" />
        <link rel="prev" title="Runtime Inspection API" href="inspection.html" />
    <!-- end layout.mako headers -->


    </head>
    <body>
        















<div id="docs-container">





<div id="docs-top-navigation-container" class="body-background">
<div id="docs-header">
    <div id="docs-version-header">
        Release: <span class="version-num">0.9.8</span> | Release Date: October 13, 2014
    </div>

    <h1>SQLAlchemy 0.9 Documentation</h1>

</div>
</div>

<div id="docs-body-container">

    <div id="fixed-sidebar" class="withsidebar">


        <div id="docs-sidebar-popout">
            <h3><a href="../index.html">SQLAlchemy 0.9 Documentation</a></h3>

            <p id="sidebar-paginate">
                    <a href="index.html" title="SQLAlchemy Core">Up</a> |

                    <a href="inspection.html" title="Runtime Inspection API">Prev</a> |
                    <a href="interfaces.html" title="Deprecated Event Interfaces">Next</a>
            </p>

            <p id="sidebar-topnav">
                <a href="../index.html">Contents</a> |
                <a href="../genindex.html">Index</a>
            </p>

            <div id="sidebar-search">
                <form class="search" action="../search.html" method="get">
                  <input type="text" name="q" size="12" /> <input type="submit" value="Search" />
                  <input type="hidden" name="check_keywords" value="yes" />
                  <input type="hidden" name="area" value="default" />
                </form>
            </div>

        </div>

        <div id="docs-sidebar">

        <h3><a href="#">            
                Expression Serializer Extension
            
        </a></h3>
        <ul>
<li><a class="reference internal" href="#">Expression Serializer Extension</a></li>
</ul>




        </div>

    </div>

    

    <div id="docs-body" class="withsidebar" >
        
<div class="section" id="module-sqlalchemy.ext.serializer">
<span id="expression-serializer-extension"></span><h1>Expression Serializer Extension<a class="headerlink" href="#module-sqlalchemy.ext.serializer" title="Permalink to this headline">¶</a></h1>
<p>Serializer/Deserializer objects for usage with SQLAlchemy query structures,
allowing &#8220;contextual&#8221; deserialization.</p>
<p>Any SQLAlchemy query structure, either based on sqlalchemy.sql.*
or sqlalchemy.orm.* can be used.  The mappers, Tables, Columns, Session
etc. which are referenced by the structure are not persisted in serialized
form, but are instead re-associated with the query structure
when it is deserialized.</p>
<p>Usage is nearly the same as that of the standard Python pickle module:</p>
<div class="highlight-python"><pre>from sqlalchemy.ext.serializer import loads, dumps
metadata = MetaData(bind=some_engine)
Session = scoped_session(sessionmaker())

# ... define mappers

query = Session.query(MyClass).
    filter(MyClass.somedata=='foo').order_by(MyClass.sortkey)

# pickle the query
serialized = dumps(query)

# unpickle.  Pass in metadata + scoped_session
query2 = loads(serialized, metadata, Session)

print query2.all()</pre>
</div>
<p>Similar restrictions as when using raw pickle apply; mapped classes must be
themselves be pickleable, meaning they are importable from a module-level
namespace.</p>
<p>The serializer module is only appropriate for query structures.  It is not
needed for:</p>
<ul class="simple">
<li>instances of user-defined classes.   These contain no references to engines,
sessions or expression constructs in the typical case and can be serialized
directly.</li>
<li>Table metadata that is to be loaded entirely from the serialized structure
(i.e. is not already declared in the application).   Regular
pickle.loads()/dumps() can be used to fully dump any <tt class="docutils literal"><span class="pre">MetaData</span></tt> object,
typically one which was reflected from an existing database at some previous
point in time.  The serializer module is specifically for the opposite case,
where the Table metadata is already present in memory.</li>
</ul>
<dl class="function">
<dt id="sqlalchemy.ext.serializer.Serializer">
<tt class="descclassname">sqlalchemy.ext.serializer.</tt><tt class="descname">Serializer</tt><big>(</big><em>*args</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.serializer.Serializer" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="sqlalchemy.ext.serializer.Deserializer">
<tt class="descclassname">sqlalchemy.ext.serializer.</tt><tt class="descname">Deserializer</tt><big>(</big><em>file</em>, <em>metadata=None</em>, <em>scoped_session=None</em>, <em>engine=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.serializer.Deserializer" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="sqlalchemy.ext.serializer.dumps">
<tt class="descclassname">sqlalchemy.ext.serializer.</tt><tt class="descname">dumps</tt><big>(</big><em>obj</em>, <em>protocol=0</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.serializer.dumps" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="sqlalchemy.ext.serializer.loads">
<tt class="descclassname">sqlalchemy.ext.serializer.</tt><tt class="descname">loads</tt><big>(</big><em>data</em>, <em>metadata=None</em>, <em>scoped_session=None</em>, <em>engine=None</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.serializer.loads" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</div>

    </div>

</div>

<div id="docs-bottom-navigation" class="docs-navigation-links">
        Previous:
        <a href="inspection.html" title="previous chapter">Runtime Inspection API</a>
        Next:
        <a href="interfaces.html" title="next chapter">Deprecated Event Interfaces</a>

    <div id="docs-copyright">
        &copy; <a href="../copyright.html">Copyright</a> 2007-2014, the SQLAlchemy authors and contributors.
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2b1.
    </div>
</div>

</div>

        
    </body>
</html>