-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

are you running from within an Alembic migration ?  Otherwise wondering why 
you're generating an engine and all that, all of that is a given within Alembic 
migration scripts.

An update is done via the update() method but there's no need to generate a 
whole Table like that (you only need the columns that will be rendered in the 
SQL) and obviously all the connection boilerplate goes away and you just use 
op.execute(), see the example in 
http://alembic.readthedocs.org/en/latest/ops.html#alembic.operations.Operations.execute.



On Apr 1, 2012, at 11:07 AM, Cornelius Kölbel wrote:

> Hello again,
> 
> ok, it could work this way:
> 
> 
>      import sqlalchemy as sa
>    from alembic import context
> 
>    config = context.config
>    engine = sa.engine_from_config(
>                config.get_section(config.config_ini_section),
> prefix='sqlalchemy.')
>    engine.echo = False
>    metadata = sa.MetaData(engine)
>    token = sa.Table('Token', metadata, autoload=True)
>    upd =
> token.update(values={token.c.Count:token.c.Count+1}).where(token.c.TokenId
>> 200)
>    engine.execute(upd)
> 
> 
> ...but I wonder, if there would be less lines of code...
> 
> Kind regards
> Cornelius
> 
> Am 01.04.2012 08:48, schrieb Cornelius Koelbel:
>> Hi,
>> 
>> yesterday i stumbled upon alembic to upgrade the database schema. It
>> looks very promising and I am evaluating what is possible with what kind
>> of effort.
>> 
>> What would be the easiest way to update table contents within alembic
>> like this:
>> 
>>    update test set name='Fred' where name='fred'
>> 
>> ...or one day even more complex! ;-)
>> 
>> Kind regards
>> Cornelius
>> 
> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: GPGTools - http://gpgtools.org

iQEcBAEBAgAGBQJPeHQOAAoJEDMCOcHE2v7ha1IH/3yjxO4zJTJ5JmcUg5lgVowC
6UHBQxOisCQy2+smRvpOmb/0tVKDutFHoALchP5O8OY+M+YHg2nwS3MDZQ+QJq1q
0RTyRZcqwbqMOAo+pc78npWD679k96xHsWgDfMynGx5iVDZZMu3Ia6aGcLFZ0R49
oUY0bCopJ2tuLE3Dj48jynguPpgK/hPLrPdjy75yHt+r/tMSW3PLt687Em4JBzrm
rdoQat+Xjv4UHV9ooU0M+/Oyo85YHB+Qt6VVsA+j+03+49KHj7THQc84YLm0DPeu
tTreDBg24JikMKHmNVlMBz378ulxKgG9eGlhZejlM02iMQBaZ90S9A2NeiHdLYw=
=ReHs
-----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to