[Sqlalchemy-commits] [1430] sqlalchemy/branches/schema/doc/build/content: a few edits
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-05-09 01:20:17
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1430] sqlalchemy/branches/schema/doc/build/content: a few edits</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1430</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-05-08 20:20:08 -0500 (Mon, 08 May 2006)</dd> </dl> <h3>Log Message</h3> <pre>a few edits</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemybranchesschemadocbuildcontentmetadatatxt">sqlalchemy/branches/schema/doc/build/content/metadata.txt</a></li> <li><a href="#sqlalchemybranchesschemadocbuildcontenttutorialtxt">sqlalchemy/branches/schema/doc/build/content/tutorial.txt</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemybranchesschemadocbuildcontentmetadatatxt"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/doc/build/content/metadata.txt (1429 => 1430)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/doc/build/content/metadata.txt 2006-05-08 22:10:00 UTC (rev 1429) +++ sqlalchemy/branches/schema/doc/build/content/metadata.txt 2006-05-09 01:20:08 UTC (rev 1430) </span><span class="lines">@@ -117,6 +117,8 @@ </span><span class="cx"> </span><span class="cx"> meta.connect('mysql://user@host/dsn') # create a new Engine and connect </span><span class="cx"> </span><ins>+`DynamicMetaData` is ideal for applications that need to use the same set of `Tables` for many different database connections in the same process, such as a CherryPy web application which handles multiple application instances in one process. + </ins><span class="cx"> #### Reflecting Tables </span><span class="cx"> </span><span class="cx"> Once you have a `BoundMetaData` or a connected `DynamicMetaData`, you can create `Table` objects without specifying their columns, just their names, using `autoload=True`: </span></span></pre></div> <a id="sqlalchemybranchesschemadocbuildcontenttutorialtxt"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/doc/build/content/tutorial.txt (1429 => 1430)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/doc/build/content/tutorial.txt 2006-05-08 22:10:00 UTC (rev 1429) +++ sqlalchemy/branches/schema/doc/build/content/tutorial.txt 2006-05-09 01:20:08 UTC (rev 1430) </span><span class="lines">@@ -80,20 +80,10 @@ </span><span class="cx"> {python} </span><span class="cx"> >>> metadata = BoundMetaData('sqlite:///tutorial.db') </span><span class="cx"> </span><del>-When creating MetaData objects that are bound to Engines, all objects within the MetaData or which are derived from it are similarly bound to that engine; this includes tables and SQL statement constructs. A SQL construct that is bound to an Engine supports "connectionless execution", that is, each object knows how to retrieve connections and use them automatically for its own execution, without you having to worry about it. However, note that the "binding" of schema and SQL constructs to engines is **entirely optional**. SQLAlchemy includes full support for explicit Connections used with schema and SQL constructs that are entirely unbound to any Engine. </del><ins>+Now, when we tell "metadata" about the tables in our database, we can issue CREATE statements for those tables, as well as create and execute SQL statements derived from them, without needing to open or close any connections; that will be all done automatically. Note that this feature is **entirely optional**. SQLAlchemy includes full support for explicit Connections used with schema and SQL constructs that are entirely unbound to any Engine. </ins><span class="cx"> </span><del>-For the purposes of this tutorial, we will stick with "bound" objects. There is also a more flexible "dynamic" metadata object that supports runtime binding to multiple engines: </del><ins>+For the purposes of this tutorial, we will stick with "bound" objects, as it makes the code simpler and easier to read. </ins><span class="cx"> </span><del>- {python} - >>> dynamic = DynamicMetaData() # create a Dynamic metadata object - >>> dynamic.connect('sqlite:///:memory:') # connect it to SQLite - >>> dynamic.connect('postgres://scott:tiger@localhost/mydb') # connect it to PostGres - - >>> myengine = create_engine('mysql://127.0.0.1') - >>> dynamic.connect(myengine) # connect to an externally-defined engine - -The `DynamicMetaData` object binds to different engines on a thread local basis. This means that one thread of your application can be connected to one database, while another is connected to a different database. The `DynamicMetaData` object also keeps a reference to each bound engine internally, so that each connection string is only initialized once. - </del><span class="cx"> ### Creating a Table {@name=table} </span><span class="cx"> </span><span class="cx"> With `metadata` as our established home for tables, lets make a Table for it: </span><span class="lines">@@ -389,7 +379,7 @@ </span><span class="cx"> INSERT INTO users (user_name, password) VALUES (?, ?) </span><span class="cx"> ['Ed', 'edspassword'] </span><span class="cx"> DELETE FROM users WHERE users.user_id = ? </span><del>- [[3]] </del><ins>+ [3] </ins><span class="cx"> COMMIT </span><span class="cx"> </span><span class="cx"> ### Relationships </span><span class="lines">@@ -431,7 +421,7 @@ </span><span class="cx"> >>> print [a for a in mary.addresses] </span><span class="cx"> SELECT email_addresses.user_id AS email_addresses_user_id, email_addresses.address_id AS email_addresses_address_id, email_addresses.email_address AS email_addresses_email_address </span><span class="cx"> FROM email_addresses </span><del>- WHERE email_addresses.user_id = ? ORDER BY email_addresses.oid </del><ins>+ WHERE ? = email_addresses.user_id ORDER BY email_addresses.oid </ins><span class="cx"> [1] </span><span class="cx"> [(Address ma...@ma...)] </span><span class="cx"> </span><span class="lines">@@ -476,7 +466,7 @@ </span><span class="cx"> ['Ed', 'Harry', 'Mary'] </span><span class="cx"> SELECT email_addresses.user_id AS email_addresses_user_id, email_addresses.address_id AS email_addresses_address_id, email_addresses.email_address AS email_addresses_email_address </span><span class="cx"> FROM email_addresses </span><del>- WHERE email_addresses.user_id = ? ORDER BY email_addresses.oid </del><ins>+ WHERE ? = email_addresses.user_id ORDER BY email_addresses.oid </ins><span class="cx"> [4] </span><span class="cx"> UPDATE email_addresses SET user_id=? WHERE email_addresses.address_id = ? </span><span class="cx"> [None, 3] </span></span></pre> </div> </div> </body> </html> |