Re: Pythonic wrappers for SQL?
On 1/14/06, EleSSaR^ [EMAIL PROTECTED] wrote: Kenneth McDonald si è profuso/a a scrivere su comp.lang.python tutte queste elucubrazioni: there any good libraries out there that let one write (basic) queries in a Pythonic syntax, rather than directly in SQL? You need an ORM. Beyond SQLAlchemy (I don't have experience with it) i would suggest you try out SQLObject and PyDO. Just a clue: although they prevent you from writing SQL, you'll have to learn SQL basics anyway, or you won't understand the docs. If you simply want to forget SQL, you can try out Axiom: Or - as a word play in this case - try my module ForgetSQL [1] (Also available in a new and backwards-incompatible beta version [2] which should be easier to get started with, has more extensive unit tests, but has only been tested with MySQL and SQLite) [1] http://soiland.no/software/forgetsql/ [2] http://soiland.no/i/src/forgetsql2/ Example code from [2] import MySQLdb, forgetsql2 # Connect to MySQLdb using keyword parameters db = forgetsql2.generate(MySQLdb, {db='fish'}) # Iterate through generated class from the table postal for postal in db.Postal: # Print normal fields print postal.postal_no, postal.postal_name, postal.municipal_id # Follow the foreign key municipal_id to retrieve the entry # from the Municipal class municipal = postal.get_municipal() print municipal.municipal_name # Retrieve by primary key rogaland = db.County(county_id=11) # Iterate over municipals that have foreign keys to rogaland for municipal in rogaland.get_municipals(): print municipal.municipal_name # Load by primary key, change, and save postal = db.Postal(postal_id=4042) postal.postal_name = Fish land postal.save() -- Stian Søiland In theory there is no difference between theory Birmingham, UK and practice. In practice there is. [Berra] http://soiland.no/ =/\= -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic wrappers for SQL?
Steve Holden wrote: SQLObject is a very popuar object-relational mapper that works with a range of databases including SQLite. But SQL isn't actually that complicated to someone who's already learned Python! I maintain this page for students on the classes I teach, and it has some useful pointers: http://www.holdenweb.com/students/database.html regards Steve -- With all the buzz about ORM these days, you don't hear much about good old DBAPI. Maybe it's a matter of what's currently hip, or maybe DBAPI has not achieved a consistent interface across adapters (e.g. ? vs %s for placeholders). But it seems like to some extent the ORMs achieve back end interchangeability by limiting what you can say. Or maybe that's just my frustration because I am a beginner with SQLObject, using it on a rewrite of an old (1999 or so) application that has a lot of MSSQL-specific SQL expressed via mxODBC. I keep catching myself working backward from what I want the SQL statement to be, which is not very object-oriented on my part. I suppose it's a matter of learning a new language, after a while you stop mentally translating. However, I agree with the earlier comment that you'd better be comfortable with SQL before you start trying to make sense of an ORM, especially for data structures more complicated than you see in a 20 minute screencast. I am persevering with SQLObject, having faith that the extra work I'm putting in to design my table classes will pay off in a more robust and portable application. The module itself is elegant and well written, and it uses metaclasses to boot. -- Wade Leftwich Ithaca, NY -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic wrappers for SQL?
Just to chime in with Steve Holden on taking the why-not-learn-SQL route. Chris Fehily's new book, SQL, A Visual QuickStart Guide (2nd Ed) is a masterpiece and goes well on the bookshelf with his equally lucid Python QuickStart Guide. Cheap, too, for what you get. http://www.amazon.com/exec/obidos/asin/0321334175/richarddooling/ rpd -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic wrappers for SQL?
Il 2006-01-14, Kenneth McDonald [EMAIL PROTECTED] ha scritto: I need to do some data manipulation, and SQLite is a nice little product for it, except of course that I'd need to write SQL. Are there any good libraries out there that let one write (basic) queries in a Pythonic syntax, rather than directly in SQL? You need an ORM Try SQLAlchemy - http://sqlalchemy.org Have fun -- Lawrence - http://www.oluyede.org/blog Anyone can freely use whatever he wants but the light at the end of the tunnel for most of his problems is Python -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic wrappers for SQL?
Quoting Kenneth McDonald [EMAIL PROTECTED]: I need to do some data manipulation, and SQLite is a nice little product for it, except of course that I'd need to write SQL. Are there any good libraries out there that let one write (basic) queries in a Pythonic syntax, rather than directly in SQL? Funny you should bring this up. I was just looking at a few sites about this today. First is an article on Devx that explains a way to do this: http://www.devx.com/dbzone/Article/22093/1954?pf=true Then I found a package that does the heavy lifting: http://www.penguin.cz/~ondrap/sqlabstr_cond.php David This message was sent using IMP, the Internet Messaging Program. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic wrappers for SQL?
Kenneth McDonald si è profuso/a a scrivere su comp.lang.python tutte queste elucubrazioni: there any good libraries out there that let one write (basic) queries in a Pythonic syntax, rather than directly in SQL? You need an ORM. Beyond SQLAlchemy (I don't have experience with it) i would suggest you try out SQLObject and PyDO. Just a clue: although they prevent you from writing SQL, you'll have to learn SQL basics anyway, or you won't understand the docs. If you simply want to forget SQL, you can try out Axiom: http://divmod.org/trac/wiki/DivmodAxiom It's a native object database; it uses sqlite as backend, but that's totally transparent to the user, you'll never be asked to enter a single sql statement. -- EleSSaR^ [EMAIL PROTECTED] -- Togli .xyz dalla mia email per contattarmi. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic wrappers for SQL?
Hi Kenneth. Try SQLAlchemy. Regards, David Kenneth McDonald wrote: I need to do some data manipulation, and SQLite is a nice little product for it, except of course that I'd need to write SQL. Are there any good libraries out there that let one write (basic) queries in a Pythonic syntax, rather than directly in SQL? Thanks, Ken -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic wrappers for SQL?
Kenneth McDonald wrote: I need to do some data manipulation, and SQLite is a nice little product for it, except of course that I'd need to write SQL. Are there any good libraries out there that let one write (basic) queries in a Pythonic syntax, rather than directly in SQL? SQLObject is a very popuar object-relational mapper that works with a range of databases including SQLite. But SQL isn't actually that complicated to someone who's already learned Python! I maintain this page for students on the classes I teach, and it has some useful pointers: http://www.holdenweb.com/students/database.html regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Pythonic wrappers for SQL?
I need to do some data manipulation, and SQLite is a nice little product for it, except of course that I'd need to write SQL. Are there any good libraries out there that let one write (basic) queries in a Pythonic syntax, rather than directly in SQL? Thanks, Ken -- http://mail.python.org/mailman/listinfo/python-list