[Sqlalchemy-commits] [1385] sqlalchemy/branches/schema/doc/build/content/plugins.txt: plugins doc
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-05-04 00:52:20
|
<!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>[1385] sqlalchemy/branches/schema/doc/build/content/plugins.txt: plugins doc</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1385</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-05-03 19:52:12 -0500 (Wed, 03 May 2006)</dd> </dl> <h3>Log Message</h3> <pre>plugins doc</pre> <h3>Added Paths</h3> <ul> <li><a href="#sqlalchemybranchesschemadocbuildcontentpluginstxt">sqlalchemy/branches/schema/doc/build/content/plugins.txt</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemybranchesschemadocbuildcontentpluginstxt"></a> <div class="addfile"><h4>Added: sqlalchemy/branches/schema/doc/build/content/plugins.txt (1384 => 1385)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/doc/build/content/plugins.txt 2006-05-04 00:51:54 UTC (rev 1384) +++ sqlalchemy/branches/schema/doc/build/content/plugins.txt 2006-05-04 00:52:12 UTC (rev 1385) </span><span class="lines">@@ -0,0 +1,78 @@ </span><ins>+Plugins {@name=plugins} +====================== + +(SECTION UNDER CONSTRUCTION) + +SQLAlchemy has a variety of extensions and "mods" available which provide extra functionality to SA, either via explicit usage or by augmenting the core behavior. + +### threadlocal + + {python} + import sqlalchemy.mods.threadlocal + from sqlalchemy import * + + metadata = BoundMetaData('sqlite:///') + user_table = Table('users', metadata, + Column('user_id', Integer, primary_key=True), + Column('user_name', String(50), nullable=False) + ) + + class User(object): + pass + mapper(User, user_table) + + # thread local session + session = get_session() + + # "user" object is added to the session automatically + user = User() + + session.flush() + +Establishes 'threadlocal' as the default strategy for new `Engine`s, and installs a thread local Session context for the `get_session()` function. Usually this is used in combination with `BoundMetaData` or `DynamicMetaData` for `Table` objects, so that the `Session` does not need to be bound to any `Engine` explicitly. + +#### get_session() Method {@name=getsession} +#### objectstore Namespace {@name=objectstore} +#### Attaching Mappers to their Class {@name=attaching} + +A full-blown "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`: + + {python} + # "assign" a mapper to the User class/users table + assign_mapper(User, users) + + # methods are attached to the class for selecting + userlist = User.select_by(user_id=12) + + myuser = User.get(1) + + # mark an object as deleted for the next commit + myuser.delete() + + # flush the changes on a specific object + myotheruser.flush() + +### SessionContext + +This plugin solves many of the problems that `threadlocal` solves, but does it in a more class-localized way. + + {python} + + ctx = SessionContext() + class User(object): + __session__ = ctx + + mapper(User, users_table) + + # 'u' is automatically added to the current session of 'ctx' + u = User() + + ctx.current.flush() + +### ProxyEngine + +### SelectResults + +### LegacySession + +(this plugin probably doesnt even work right now) </ins><span class="cx">\ No newline at end of file </span></span></pre> </div> </div> </body> </html> |