Some cool things that were impossible in the last release:
------------------------------------------
Define two tables with a circular foreign key dependency on each
other ! (yes, it uses ALTER TABLE):
t1 = Table('table1', meta,
Column('id', Integer, primary_key=True),
Column('t2_id', Integer, ForeignKey('t2.id'))
)
t2 = Table('table2', meta,
Column('id', Integer, primary_key=True),
Column('t1_id', Integer, ForeignKey('t1.id', use_alter=True,
name='t2id_fk'))
)
meta.create_all()
Notice the "use_alter" flag, which also requires explicitly naming
the foreign key.
------------------------------------------
UniqueConstraint :
t1 = Table('sometable', meta, Column(...), UniqueConstraint('id',
'version'))
------------------------------------------
CheckConstraint:
t1 = Table('sometable', meta, Column('x', Integer), Column('y',
Integer), CheckConstraint('x+y>10'))
------------------------------------------
Fancy Query operations - per-query MapperExtensions, SelectResults
can build joins on the fly:
result = session.query(SomeClass).\
options(extension(SelectResultsExt())).select().\
outerjoin_to('orders').outerjoin_to('items').\
select(or_(Order.c.order_id==None,Item.c.item_id==2)).list()
------------------------------------------
Pessimistic Locking (still needs documentation, spec is in ticket 292):
q = session.query(SomeClass).with_lockmode('update').get(5)
------------------------------------------
Multi-column stored procedures as selectables (with supporting
databases, i.e. postgres and oracle):
myproc = select([
column('x', type=Integer),
column('y', type=Integer),
column('status', type=String),
], from_obj=[func.my_stored_procedure(bindparam('x'),
bindparam('y'), bindparam('z'))],
engine=myengine
)
for row in myproc.execute(x=5,y=7,z=10):
print row['x'], row['y'], row['status']
------------------------------------------
Individual TypeEngines now define the method used by the ORM to
detect changes on an attribute (i.e. like Hibernate does), which
supports "mutable" types such as PickleType:
graphs = Table('graphs', meta, Column('id', Integer,
primary_key=True),
Column('data', PickleType)
)
class Graph(object):pass
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
mapper(Graph, graphs)
g = Graph()
g.data = [Point(1,2), Point(3,5), Point(10,15)]
session.save(g)
session.flush()
session.clear()
# changes within the contents of "data" are detected, even though no
# "setter" operation occured on "g"
g = session.query(Graph).get_by(id=g.id)
g.data[2] = Point(19,12)
session.flush()
PickleType can be set up with "mutable=False" if you want to prevent
the comparison operation (or make your own PickleType with your own
comparison operation).
------------------------------------------
full CHANGES list, which includes every enhancement and most bugfixes
(minor bugfixes can be viewed on the timeline), can be viewed on the
site:
http://www.sqlalchemy.org/CHANGES
- mike
On 10/22/06, Michael Bayer <zzz...@gmail.com> wrote:
>
> After a marathon of doc edits and fixes this weekend (and still so
> much on the docs is inaccurate...geez..) I've put out the first
> release of the 0.3.0 series.
--
Jonathan Ellis
http://spyced.blogspot.com
I like the docs too, but would really appreciate a PDF or PS version
since the layout is not printer-friendly to me. Firefox, Konqueror and
Interne Exploder do not wrap correctly the monospaced text. Openoffice
crashes after filling up my RAM. No need for pagenumber and other frills..
The "one-page" options is also missing from 0.3.
Thanks again
I agree with Marco. It's very important to have a printed version
of the documentation. Now is very difficult to print the new
documentation because "one-page" option missing.
Thanks for your wonderful work.
--
-------------------------------------------------------------------
(o_
(o_ //\ Coltivate Linux che tanto Windows si pianta da solo.
(/)_ V_/_
+------------------------------------------------------------------+
| ENRICO MORELLI | email: mor...@CERM.UNIFI.IT |
| * * * * | phone: +39 055 4574269 |
| University of Florence | fax : +39 055 4574253 |
| CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY |
+------------------------------------------------------------------+
--
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: jci...@ulb.ac.be
home: ma...@mordor.ath.cx
might be nicer if someone wants to work on Markdown->PDF, possibly by
way of LaTeX or something like that (since the content for the docs
exists in markdown format).
While you're looking at the doc generation code, you may be interested
to learn about Pygments (http://pygments.pocoo.org/) -- a
general-purpose, extendible syntax highlighter written in Python. You
may not have plans to rewrite the doc/build/lib/highlight.py code
anytime soon -- but if you ever do decide to rewrite it, you'll
probably want to consider existing libraries. And what I've seen of
Pygments so far, I like.
--
Robin Munn
Robin...@gmail.com
GPG key 0xD6497014
had this been around when i wrote the highlighter (like in 2004), i
would most likely have used this (and built the myghty highlighter as
one of its lexers)...it looks really great and just what i was looking
for back then.
~ Daniel
P.S. Sorry for my apparent absence lately. I've been lurking, but haven't had the time to contribute very much. I'm in the middle of a huge project deployment and don't have much time for anything else.
I think I came across a little problem.... I am still using 0.2.8 (+ flush patch), so this may have been solved already...
in which case I apologise
When I do
s=tblRace.select(and_(dbRace.c.id==dbRaceLeg.c.id,dbRaceLeg.c.Date>=bindparam("Race_Date")))
lor=conn.execute((s,Race_Date=datetime.date.today())
I get the expected result...
But when I do
s=tblRace.select(and_(dbRace.c.id==dbRaceLeg.c.id,dbRaceLeg.c.Date>=bindparam("Race_Date"))).compile()
lor=conn.execute((s,Race_Date=datetime.date.today())
I get an exception
File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 246, in execute
return Connection.executors[type(object).__mro__[-2]](self, object, *multiparams, **params)
KeyError: <class 'sqlalchemy.sql.ClauseVisitor'>
Is this a known/solved problem.... or am I doing something wrong?
Cheers,
François