[orm-devel] Unified Connection Strings

Diedrich Vorberg orm-devel@mailman.tux4web.de
Fri, 6 Dec 2002 12:59:08 +0100


Hi Julio,

>ds= datasource(driver="pgsql", user="me", 
>password="thispassword",dbname="test",host="myhost")

>ds1= datasource(driver="mysql", user="me", 
>password="thispassword",dbname="test",host="myhost")

I decided to use the PostgreSQL style DSN notation for connection
strings. Thanks to the genius of Guido van Rossum however, your idea
was so easy to implement, that I just couldn't resist ;-)

Here's the new docstring for that datasource function:

    """
    Return a ORM datasource object
    constructed from a connection string or a number of keyword arguments.

    The connection strings follow the conventions for PostgreSQL DSNs:
    they consist of keyword=value pairs seperated with whitespace.
    Keywords recognized are:

    adapter  - name of the ORM adapter used. Use the name from the
               adapters/ directory.
    db       - name of the database to connect to
    user     - Database username
    password - Password used for authentication
    host     - hostname or IP address of the machine the database
               runs on (note that there might be a difference if you
               use 127.0.0.1 or localhost. The first creating a tcp/ip
               connection, the latter a unix/fifo connection. This is
               true for at leas pgsql and mysql

    Each of the database backends may define its own keywords. For
    instance PostgreSQL will understand each of the original keywords
    as aliases. Check the documentation!

    Values may not contain spaces.

    If you prefer to use the keyword argument syntax, the paramters must
    be the keyword and the argument the value:

       datasource('db=test user=diedrich password=kfjdh')

    equals

       datasource(db='test', user='diedrich', password='kfjdh')
    """

Believe it or not: only 2 lines (in words: two) had to be changed to 
implement this. I just **love** Python!

>Ok, just a little idea, (you can flame me if you want ;-P
No flames, please! Being arctic animals my penguins don't take heat
very well :o)


Diedrich

-- 
           _..._                            Diedrich Vorberg
         .'     '.
        /  _   _  \                         http://www.tux4web.de
        | (o)_(o) |                         info@tux4web.de
         \(     ) /            .---.
         //'._.'\ \           /     \       Internet Dienstleistungen
        //   .   \ \          \.@-@./       und 'Consulting'.
       ||   .     \ \         /`\_/`\
       |\   :     / |        //  _  \\      Linux Rules!
       \ `) '   (`  /_      | \     )|_
     _)``".____,.'"` (_    /`\_`>  <_/ \
     )     )'--'(     (    \__/'---'\__/
      '---`      `---`