[sqlalchemy] Re: access the fields in a record as a dict

2008-07-06 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi ilya, everybody,

that time, i was using elixir and not the select() function in sa.
elixir.query.filter() returned a list of objects, with their fields as
attributes (same as the entity definition in elixir).

thus, to have each record transformed in a dict, i have used a transformation
function, and an iterator converter, like the following:

~def prep_record(record):
~values = {}
~for field in allfields: #a list of field names
~values[field] = getattr(record, field)

~records = itertools.imap(prep_record, query)

now i'm using sa 0.4.6, and when i'm executing a select() on a session, i'm
getting a resultproxy object, which may be iterated by rows, and each field of
each row may be got by row[fieldname]

hope this helps,

alex

zipito wrote:
| good day alex
|
|
| Did you find the solution for this ?
|
|
| Best regards,
| Ilya Dyohsin
|
| On 17 янв, 06:06, alex bodnaru [EMAIL PROTECTED] wrote:
| hi mike,
|
| thanks for your prompt answer.
|
| it doesn't work anymore, indeed :(
|
| alex
|
|
|
| Michael Bayer wrote:
|
| what, likedict(row) ?  that should workno ?
| On Jan 16, 2008, at 6:29 PM, alex bodnaru wrote:
| hi friends,
| in older sa i could cast a record to adict, in order to access their
| fields by their name, especially if the field name is not a valid
| python
| identifier, like a calculated or fixed numeric column.
| how could i do it again please?
| tia,
| alex
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBSHCg8dpwN1sq38njAQKIxAP/Y8eKEMm18qI12ZEtmw2nwq+z9HB8ykjY
g/w3ErQvfcOp3K9bFqL7/1MHgIIVATy636rQbe1F7wZYkR3NaQlKlkdVt8Z+YSxu
zmLeR4EL+q1CgnuJTsRh5+xRxqzdUZf4vEAFKipjGwrOvJT4EglY/CqUNx0AZpwP
LTQC456nCPQ=
=imB5
-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 sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: access the fields in a record as a dict

2008-01-16 Thread Michael Bayer


what, like dict(row) ?  that should workno ?

On Jan 16, 2008, at 6:29 PM, alex bodnaru wrote:


 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1


 hi friends,

 in older sa i could cast a record to a dict, in order to access their
 fields by their name, especially if the field name is not a valid  
 python
 identifier, like a calculated or fixed numeric column.

 how could i do it again please?

 tia,

 alex
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.6 (GNU/Linux)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

 iQCVAwUBR46TPdpwN1sq38njAQKv7wQArF0nV0WRTZVI/3qdLC5+7yZDspw1bGhT
 6H8vPFQKDZCsJNNP98nbV1zKjMC/OfypPOqJvS7T9SpD2XZ9G7LOYeAQpSakzNOO
 DiJE/vY4SzX83cwfFj218EfzqtOeg0L010sIrkj9IG9ZETkXQjAG9iZIF/i3hujq
 CoOV31EiB4k=
 =bBud
 -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 sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: access the fields in a record as a dict

2008-01-16 Thread alex bodnaru

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


hi mike,

thanks for your prompt answer.

it doesn't work anymore, indeed :(

alex

Michael Bayer wrote:
 
 what, like dict(row) ?  that should workno ?
 
 On Jan 16, 2008, at 6:29 PM, alex bodnaru wrote:
 
 
 hi friends,
 
 in older sa i could cast a record to a dict, in order to access their
 fields by their name, especially if the field name is not a valid  
 python
 identifier, like a calculated or fixed numeric column.
 
 how could i do it again please?
 
 tia,
 
 alex


 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQCVAwUBR47GONpwN1sq38njAQKiKwP7BhcGfQIbqXRdoJRSyELSsuDlc8JCoa2W
qAsWBARQ8uRdmO/EhDglRN/K/60sMVVUWDbarLH8F/qerC4pwTOrZwQcKyRG/LPL
zIftKU9uNg/yS2Q6kmPSPsXbbA1Kjwe/JwbHm0LXPk15fB5vzwXk76F6ae1oDRAO
kgb7oQTIbOw=
=jmyV
-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 sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---