Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 862b9a6

Browse files
committed
Update dev docs: explain columns, validators and converters
1 parent 3c26f6c commit 862b9a6

7 files changed

+1481
-1798
lines changed

‎devel/DeveloperGuide.html‎

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ <h1 class="pudge-member-page-heading">SQLObject Developer Guide</h1>
3535
<p class="topic-title first">Contents</p>
3636
<ul class="simple">
3737
<li><a href="#development-installation" class="reference internal" id="id1">Development Installation</a></li>
38-
<li><a href="#architecture" class="reference internal" id="id2">Architecture</a></li>
39-
<li><a href="#style-guide" class="reference internal" id="id3">Style Guide</a></li>
40-
<li><a href="#testing" class="reference internal" id="id4">Testing</a></li>
41-
<li><a href="#documentation" class="reference internal" id="id5">Documentation</a></li>
38+
<li><a href="#architecture" class="reference internal" id="id2">Architecture</a><ul>
39+
<li><a href="#columns-validators-and-converters" class="reference internal" id="id3">Columns, validators and converters</a></li>
40+
</ul>
41+
</li>
42+
<li><a href="#style-guide" class="reference internal" id="id4">Style Guide</a></li>
43+
<li><a href="#testing" class="reference internal" id="id5">Testing</a></li>
44+
<li><a href="#documentation" class="reference internal" id="id6">Documentation</a></li>
4245
</ul>
4346
</div>
4447
<p id="start">These are some notes on developing SQLObject.</p>
@@ -64,28 +67,59 @@ <h1>Development Installation</h1>
6467
</div>
6568
<div class="section" id="architecture">
6669
<h1>Architecture</h1>
67-
<p>There are four main kinds of objects in SQLObject: tables, columns,
68-
connections and converters.</p>
70+
<p>There are three main kinds of objects in SQLObject: tables, columns and
71+
connections.</p>
6972
<p>Tables-related objects are in <a href="sqlobject/main.py.html" class="reference external">sqlobject/main.py</a> module. There are two
70-
main classes: SQLObject and sqlmeta; the latter is not a metaclass but a
71-
parent class for sqlmeta attribute in every class - the authors tried to
72-
move there all attributes and methods not directly related to columns to
73-
avoid cluttering table namespace.</p>
73+
main classes: <tt class="docutils literal">SQLObject</tt> and <tt class="docutils literal">sqlmeta</tt>; the latter is not a
74+
metaclass but a parent class for <tt class="docutils literal">sqlmeta</tt> attribute in every class -
75+
the authors tried to move there all attributes and methods not directly
76+
related to columns to avoid cluttering table namespace.</p>
77+
<p>Connections are instances of <tt class="docutils literal">DBConnection</tt> class (from
78+
<a href="sqlobject/dbconnection.py.html" class="reference external">sqlobject/dbconnection.py</a>) and its concrete descendants.
79+
<tt class="docutils literal">DBConnection</tt> contains generic code for generating SQL, working with
80+
transactions and so on. Concrete connection classes (like
81+
<tt class="docutils literal">PostgresConnection</tt> and <tt class="docutils literal">SQLiteConnection</tt>) provide
82+
backend-specific functionality.</p>
83+
<div class="section" id="columns-validators-and-converters">
84+
<h2>Columns, validators and converters</h2>
7485
<p>Columns are instances of classes from <a href="sqlobject/col.py.html" class="reference external">sqlobject/col.py</a>. There are two
7586
classes for every column: one is for user to include into an instance of
7687
SQLObject, an instance of the other is automatically created by
77-
SQLObject metaclass. The two classes are names SOCol and Col; for
78-
example, SOBoolCol and BoolCol.</p>
79-
<p>Connections are instances of DBConnection class (from
80-
<a href="sqlobject/dbconnection.py.html" class="reference external">sqlobject/dbconnection.py</a>) and its concrete descendants. DBConnection
81-
contains generic code for generating SQL, working with transactions and
82-
so on. Concrete connection classes (like PostgresConnection and
83-
SQLiteConnection) provides backend-specific functionality.</p>
84-
<p>Converters from <a href="sqlobject/converters.py.html" class="reference external">sqlobject/converters.py</a> aren't visible to the user. They
85-
are used behind the scene to convert object to SQL strings. The most
86-
elaborated converter there is StringConverters. Yes, it converts strings
87-
to strings. It converts python strings to SQL strings using
88-
backend-specific quoting rules.</p>
88+
SQLObject's metaclass. The two classes are usually named <tt class="docutils literal">Col</tt> and
89+
<tt class="docutils literal">SOCol</tt>; for example, <tt class="docutils literal">BoolCol</tt> and <tt class="docutils literal">SOBoolCol</tt>. User-visible
90+
classes, descendants of <tt class="docutils literal">Col</tt>, seldom contain any code; the main code
91+
for a column is in <tt class="docutils literal">SOCol</tt> descendants and in validators.</p>
92+
<p>Every column has a list of validators. Validators validate input data
93+
and convert input data to python data and back. Every validator must
94+
have methods <tt class="docutils literal">from_python</tt> and <tt class="docutils literal">to_python</tt>. The former converts data
95+
from python to internal representation that will be converted by
96+
converters to SQL strings. The latter converts data from SQL data to
97+
python. Also please bear in mind that validators can receive <tt class="docutils literal">None</tt>
98+
(for SQL <tt class="docutils literal">NULL</tt>) and <tt class="docutils literal">SQLExpression</tt> (an object that represents
99+
SQLObject expressions); both objects must be passed unchanged by
100+
validators.</p>
101+
<p>Converters from <a href="sqlobject/converters.py.html" class="reference external">sqlobject/converters.py</a> aren't visible to users. They
102+
are used behind the scene to convert objects returned by validators to
103+
backend-specific SQL strings. The most elaborated converter is
104+
<tt class="docutils literal">StringLikeConverter</tt>. Yes, it converts strings to strings. It
105+
converts python strings to SQL strings using backend-specific quoting
106+
rules.</p>
107+
<p>Let look into <tt class="docutils literal">BoolCol</tt> as an example. The very <tt class="docutils literal">BoolCol</tt> doesn't
108+
have any code. <tt class="docutils literal">SOBoolCol</tt> has a method to create <tt class="docutils literal">BoolValidator</tt>
109+
and methods to create backend-specific column type. <tt class="docutils literal">BoolValidator</tt>
110+
has identical methods <tt class="docutils literal">from_python</tt> and <tt class="docutils literal">to_python</tt>; the method
111+
passes <tt class="docutils literal">None</tt>, <tt class="docutils literal">SQLExpression</tt> and bool values unchanged; int and
112+
objects that have method <tt class="docutils literal">__nonzero__</tt> are converted to bool; other
113+
objects trigger validation error. Bool values that are returned by call
114+
to <tt class="docutils literal">from_python</tt> will be converted to SQL strings by
115+
<tt class="docutils literal">BoolConverter</tt>; bool values from <tt class="docutils literal">to_python</tt> (is is supposed they
116+
are originated from the backend via DB API driver) are passed to the
117+
application.</p>
118+
<p>Objects that are returned from <tt class="docutils literal">from_python</tt> must be registered with
119+
converters. Another approach for <tt class="docutils literal">from_python</tt> is to return an object
120+
that has <tt class="docutils literal">__sqlrepr__</tt> method. Such objects convert to SQL strings
121+
themselves, converters are not used.</p>
122+
</div>
89123
</div>
90124
<div class="section" id="style-guide">
91125
<h1>Style Guide</h1>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /