Pythonic wrappers for SQL?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenneth McDonald

    #1

    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
  • Lawrence Oluyede

    #2
    Re: Pythonic wrappers for SQL?

    Il 2006-01-14, Kenneth McDonald <kenneth.m.mcdo nald@sbcglobal. net> ha scritto:[color=blue]
    > 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?[/color]

    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"

    Comment

    • EleSSaR^

      #3
      Re: Pythonic wrappers for SQL?

      Kenneth McDonald si è profuso/a a scrivere su comp.lang.pytho n tutte queste
      elucubrazioni:
      [color=blue]
      > there any good libraries out there that let one write (basic) queries
      > in a Pythonic syntax, rather than directly in SQL?[/color]

      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:



      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^ <elessar.xyz@de spammed.com>
      --
      Togli .xyz dalla mia email per contattarmi.

      Comment

      • BartlebyScrivener

        #4
        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/as...icharddooling/

        rpd

        Comment

        • Stian Soiland

          #5
          Re: Pythonic wrappers for SQL?

          On 1/14/06, EleSSaR^ <elessar.xyz@de spammed.com> wrote:[color=blue]
          > Kenneth McDonald si è profuso/a a scrivere su comp.lang.pytho n tutte queste
          > elucubrazioni:
          >[color=green]
          > > there any good libraries out there that let one write (basic) queries
          > > in a Pythonic syntax, rather than directly in SQL?[/color]
          >
          > 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:[/color]

          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.gene rate(MySQLdb, {db='fish'})

          # Iterate through generated class from the table "postal"
          for postal in db.Postal:
          # Print normal fields
          print postal.postal_n o, postal.postal_n ame, postal.municipa l_id
          # Follow the foreign key municipal_id to retrieve the entry
          # from the Municipal class
          municipal = postal.get_muni cipal()
          print municipal.munic ipal_name

          # Retrieve by primary key
          rogaland = db.County(count y_id=11)
          # Iterate over municipals that have foreign keys to rogaland
          for municipal in rogaland.get_mu nicipals():
          print municipal.munic ipal_name

          # Load by primary key, change, and save
          postal = db.Postal(posta l_id=4042)
          postal.postal_n ame = "Fish land"
          postal.save()


          --
          Stian Søiland In theory there is no difference between theory
          Birmingham, UK and practice. In practice there is. [Berra]

          =/\=

          Comment

          Working...