Pythonic wrappers for SQL?

Discussion in 'Python' started by Kenneth McDonald, Jan 14, 2006.

  1. 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
     
    Kenneth McDonald, Jan 14, 2006
    #1
    1. Advertising

  2. Il 2006-01-14, Kenneth McDonald <> 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"
     
    Lawrence Oluyede, Jan 14, 2006
    #2
    1. Advertising

  3. Kenneth McDonald

    EleSSaR^ Guest

    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^ <>
    --
    Togli .xyz dalla mia email per contattarmi.
     
    EleSSaR^, Jan 14, 2006
    #3
  4. 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
     
    BartlebyScrivener, Jan 15, 2006
    #4
  5. On 1/14/06, EleSSaR^ <> 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/
    =/\=
     
    Stian Soiland, Jan 16, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mirek
    Replies:
    5
    Views:
    441
    Natty Gur
    Oct 21, 2003
  2. =?Utf-8?B?UGF0cmljaw==?=

    ASP.Net 2.0 and the annoying <div> wrappers

    =?Utf-8?B?UGF0cmljaw==?=, Apr 25, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    582
    Patrice
    Apr 25, 2005
  3. Lucas White
    Replies:
    5
    Views:
    447
    Sudsy
    Oct 15, 2003
  4. Carl J. Van Arsdall
    Replies:
    4
    Views:
    519
    Bruno Desthuilliers
    Feb 7, 2006
  5. Alec Taylor
    Replies:
    2
    Views:
    113
    Alec Taylor
    Jul 19, 2013
Loading...

Share This Page