DB access without object-relation mapping?

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

    DB access without object-relation mapping?




    Python noob here.

    I want to write a script that creates and populates a simple Postgres
    database.

    The word on the street is to use something like SQLAlchemy for
    database access in Python, but my experience in the past with
    packages that perform automated SQL generation has been awful, so
    I always return to lighter-weight solutions that allow me to write
    my own SQL. (E.g. when coding in Perl I've used Perl's DBI package
    and drivers, rather than the likes of Class::DBI.) So what's the
    standard Python way to send SQL directly to a Postgres database
    and get back results?

    TIA!

    kynn

    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
  • Tim Henderson

    #2
    Re: DB access without object-relation mapping?

    On Jul 29, 11:20 am, kj <so...@987jk.co m.invalidwrote:
    Python noob here.
    >
    I want to write a script that creates and populates a simple Postgres
    database.
    >
    The word on the street is to use something like SQLAlchemy for
    database access in Python, but my experience in the past with
    packages that perform automated SQL generation has been awful, so
    I always return to lighter-weight solutions that allow me to write
    my own SQL.  (E.g. when coding in Perl I've used Perl's DBI package
    and drivers, rather than the likes of Class::DBI.)  So what's the
    standard Python way to send SQL directly to a Postgres database
    and get back results?
    >
    TIA!
    >
    kynn
    >
    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
    Hi,

    I believe there are a couple of options but pyscopg, and PyGreSQL seem
    to be popular.

    Tim

    Comment

    • Paul Boddie

      #3
      Re: DB access without object-relation mapping?

      On 29 Jul, 17:20, kj <so...@987jk.co m.invalidwrote:
      >
       So what's the
      standard Python way to send SQL directly to a Postgres database
      and get back results?
      Take a look at this page:



      I've used psycopg2 and pyPgSQL successfully, although pg_proboscis
      looks very interesting, too.

      Paul

      Comment

      • kj

        #4
        Re: DB access without object-relation mapping?

        In <cbe3cdad-c437-46a9-98df-2eb5b2cef3ce@56 g2000hsm.google groups.comTim Henderson <tim.tadh@gmail .comwrites:
        >I believe there are a couple of options but pyscopg, and PyGreSQL seem
        >to be popular.
        Great. Thanks!

        kynn
        --
        NOTE: In my address everything before the first period is backwards;
        and the last period, and everything after it, should be discarded.

        Comment

        • Ben Finney

          #5
          Re: DB access without object-relation mapping?

          kj <socyl@987jk.co m.invalidwrites :
          The word on the street is to use something like SQLAlchemy for
          database access in Python, but my experience in the past with
          packages that perform automated SQL generation has been awful, so I
          always return to lighter-weight solutions that allow me to write my
          own SQL.
          Using SQLAlchemy, you *can* write your own SQL (with its 'text' query
          type to feed explicit SQL text on the connection); you just don't
          *need* to for the majority of simple and not-so-simple cases.

          I've been using SQLAlchemy for some time and have found its
          combination of "make the simple cases simple" and "allow full control
          when needed" to be close to ideal. I can use exactly the same
          interface to leverage the SQL generation for mundane tasks and to
          craft custom weird SQL that I need.

          Combine that with active, level-headed maintenance, and comprehensive
          documentation, and I don't even need to consider using the ORM layer
          :-)

          --
          \ “Know what I hate most? Rhetorical questions.” —Henry N. Camp |
          `\ |
          _o__) |
          Ben Finney

          Comment

          Working...