ianb / pywebapp

Support library for Python Web Applications
19 stars 1 forks source link

Database URLs #4

Open kennethreitz opened 12 years ago

kennethreitz commented 12 years ago

In the database configuration section, things are a bit verbose:

host:
  The host that the database is on (e.g., ``"localhost"``)

port:
  The port of the database

dbname:
  The name of the database (e.g., ``db_1234``)

user:
  The user to connect as.  May be None.

password:
  The password to connect with.  May be None.

This could easily be consolidated to a single database config.

Example:

postgres://uh1x438ayyz6v:pgpptat9yofmyie7@ec2-50-17-187-253.compute-1.amazonaws.com:5432/dl2jcx3le9wlq

Format:

type://username:password@host:port/dbname

Many other communities are doing this, and many database systems (SQLAlchemy, for example), support this style of URL out of the box. Stdlib's urlparse makes it extremely simple to get the needed values out if not. It saves an amount of verbosity.

ianb commented 12 years ago

In Silver Lining I provided both. DBAPI connections for instance frequently want the separated values. Django does too. SQLAlchemy and SQLObject use URI strings. They don't all agree on the schemes, and sometimes they include database type and database driver in the string (even though the environment probably shouldn't care about database driver, e.g., MySQLdb vs pymysql - that's really an application preference).

In practice it's not that easy to convert between the two, which is why providing both is kind of nice.