[Sqlalchemy-commits] [1520] sqlalchemy/trunk/doc/build/content: doc updates, added 'save' method to
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-05-27 16:59:21
|
<!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>[1520] sqlalchemy/trunk/doc/build/content: doc updates, added 'save' method to assignmapper</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1520</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-05-27 11:59:07 -0500 (Sat, 27 May 2006)</dd> </dl> <h3>Log Message</h3> <pre>doc updates, added 'save' method to assignmapper</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkdocbuildcontentpluginstxt">sqlalchemy/trunk/doc/build/content/plugins.txt</a></li> <li><a href="#sqlalchemytrunkdocbuildcontentunitofworktxt">sqlalchemy/trunk/doc/build/content/unitofwork.txt</a></li> <li><a href="#sqlalchemytrunklibsqlalchemyextassignmapperpy">sqlalchemy/trunk/lib/sqlalchemy/ext/assignmapper.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkdocbuildcontentpluginstxt"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/doc/build/content/plugins.txt (1519 => 1520)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/doc/build/content/plugins.txt 2006-05-27 16:39:05 UTC (rev 1519) +++ sqlalchemy/trunk/doc/build/content/plugins.txt 2006-05-27 16:59:07 UTC (rev 1520) </span><span class="lines">@@ -84,7 +84,7 @@ </span><span class="cx"> </span><span class="cx"> #### Attaching Mappers to their Class {@name=attaching} </span><span class="cx"> </span><del>-With `get_session()` handling the details of providing a `Session` in all cases, the `assign_mapper` function provides some of the functionality of `Query` and `Session` directly off the mapped instances themselves. This is a "monkeypatch" function that creates a primary mapper, attaches the mapper to the class, and also the methods `get, get_by, select, select_by, selectone, selectfirst, commit, expire, refresh, expunge` and `delete`: </del><ins>+With `get_session()` handling the details of providing a `Session` in all cases, the `assign_mapper` function provides some of the functionality of `Query` and `Session` directly off the mapped instances themselves. This is a "monkeypatch" function that creates a primary mapper, attaches the mapper to the class, and also the methods `get`, `select`, `select_by`, `selectone`, `get_by`, `join_to`, `join_via`, `flush`, `delete`, `expire`, `refresh`, `expunge`, `merge`, `update`, `save`, and `save_or_update`: </ins><span class="cx"> </span><span class="cx"> {python} </span><span class="cx"> # "assign" a mapper to the User class/users table </span><span class="lines">@@ -101,6 +101,8 @@ </span><span class="cx"> # flush the changes on a specific object </span><span class="cx"> myotheruser.flush() </span><span class="cx"> </span><ins>+A more generic version of `assign_mapper` that works with any `SessionContext` is available in the [plugins_assignmapper](rel:plugins_assignmapper) plugin. + </ins><span class="cx"> #### Engine Strategy Set to threadlocal By Default {@name=engine} </span><span class="cx"> </span><span class="cx"> The `threadlocal` mod also establishes `threadlocal` as the default *strategy* when calling the `create_engine()` function. This strategy is specified by the `strategy` keyword argument to `create_engine()` and can still be overridden to be "`plain`" or "`threadlocal`" explicitly. </span><span class="lines">@@ -181,7 +183,24 @@ </span><span class="cx"> # get the session corresponding to "scope2", bound to engine "someengine": </span><span class="cx"> session = ctx.current </span><span class="cx"> </span><ins>+### assignmapper </ins><span class="cx"> </span><ins>+**Author:** Mike Bayer + +This is a generic version of the `assign_mapper` function present in the [plugins_threadlocal](rel:plugins_threadlocal) mod. It requires an explicit [plugins_sessioncontext](rel:plugins_sessioncontext). + + {python} + import sqlalchemy + from sqlalchemy.ext.sessioncontext import SessionContext + from sqlalchemy.ext.assignmapper import assign_mapper + + # session context + ctx = SessionContext(sqlalchemy.create_session) + + # assign mapper to class MyClass using table 'sometable', getting + # Sessions from 'ctx'. + assign_mapper(ctx, MyClass, sometable) + </ins><span class="cx"> ### ActiveMapper </span><span class="cx"> </span><span class="cx"> **Author:** Jonathan LaCour </span><span class="lines">@@ -243,11 +262,11 @@ </span><span class="cx"> </span><span class="cx"> **Author:** Jonathan Ellis </span><span class="cx"> </span><del>-SqlSoup creates mapped classes on the fly from tables. It is essentially a nicer version of the "row data gateway" pattern. </del><ins>+SqlSoup creates mapped classes on the fly from tables, which are automatically reflected from the database based on name. It is essentially a nicer version of the "row data gateway" pattern. </ins><span class="cx"> </span><span class="cx"> {python} </span><span class="cx"> >>> from sqlalchemy.ext.sqlsoup import SqlSoup </span><del>- >>> soup = SqlSoup('sqlite://filename=:memory:') </del><ins>+ >>> soup = SqlSoup('sqlite:///') </ins><span class="cx"> </span><span class="cx"> >>> users = soup.users.select() </span><span class="cx"> >>> users.sort() </span></span></pre></div> <a id="sqlalchemytrunkdocbuildcontentunitofworktxt"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/doc/build/content/unitofwork.txt (1519 => 1520)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/doc/build/content/unitofwork.txt 2006-05-27 16:39:05 UTC (rev 1519) +++ sqlalchemy/trunk/doc/build/content/unitofwork.txt 2006-05-27 16:59:07 UTC (rev 1520) </span><span class="lines">@@ -216,7 +216,7 @@ </span><span class="cx"> {python} </span><span class="cx"> # saves only user1 and address2. all other modified </span><span class="cx"> # objects remain present in the session. </span><del>- session.flush(user1, address2) </del><ins>+ session.flush([user1, address2]) </ins><span class="cx"> </span><span class="cx"> This second form of flush should be used carefully as it will not necessarily locate other dependent objects within the session, whose database representation may have foreign constraint relationships with the objects being operated upon. </span><span class="cx"> </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemyextassignmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/ext/assignmapper.py (1519 => 1520)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/ext/assignmapper.py 2006-05-27 16:39:05 UTC (rev 1519) +++ sqlalchemy/trunk/lib/sqlalchemy/ext/assignmapper.py 2006-05-27 16:59:07 UTC (rev 1520) </span><span class="lines">@@ -33,5 +33,5 @@ </span><span class="cx"> class_.mapper = m </span><span class="cx"> for name in ['get', 'select', 'select_by', 'selectone', 'get_by', 'join_to', 'join_via']: </span><span class="cx"> monkeypatch_query_method(ctx, class_, name) </span><del>- for name in ['flush', 'delete', 'expire', 'refresh', 'expunge', 'merge', 'update', 'save_or_update']: </del><ins>+ for name in ['flush', 'delete', 'expire', 'refresh', 'expunge', 'merge', 'save', 'update', 'save_or_update']: </ins><span class="cx"> monkeypatch_objectstore_method(ctx, class_, name) </span></span></pre> </div> </div> </body> </html> |