Alex Turner schrieb:
> I am getting an error connecting to Postgresql:
> ImportError: unknown database 'psycopg'
> 
> The back story is that I am attempting to modify an example given in
> Martin Aspeli's Book: Professional Plone Development (Chapter 12 -
> page 274->.  He recommends using SQLAlchemy, and it looks very cool,
> kind of similar to a SQLBuilder class I put together a few years ago,
> but more advanced.
> 
> I don't know really what to provide as I am completely new to
> SQLAlchemy, but the most relevent thing that I can see is the class
> that extends collective.lead.Database and the properties class:
> 
> from persistent import Persistent
> 
> from zope.interface import implements
> from zope.component import getUtility
> 
> from collective.lead import Database
> from mls.agent.interfaces import IDatabaseSettings
> 
> from sqlalchemy.engine.url import URL
> from sqlalchemy import Table, mapper, relation
> 
> from mls.agent.person import Person
> from mls.agent.office import Office
> 
> class MLSDatabaseSettings(Persistent):
>    """Database connection settings
> 
>    We use raw fields here so that we can more easily use a
> zope.formlib
>    form in the control panel to configure it. This is registered as a
>    persistent local utility, with name 'optilux.reservations', which
> is
>    then used by collective.lead.interfaces.IDatabase to find
> connection settings.
>    """
> 
>    implements(IDatabaseSettings)
> 
>    drivername = 'psycopg'
>    hostname = 'localhost'
>    port = 5432
>    username = 'postgres'
>    password = 'postgres'
>    database = 'trend-dev'
> 
> class MLSDatabase(Database):
>    """The reservations database - registered as a utility providing
>    collective.lead.interfaces.IDatabase and named
> 'optilux.reservations'
>    """
> 
>    @property
>    def _url(self):
>       settings = getUtility(IDatabaseSettings)
>       return URL(drivername=settings.drivername,
> username=settings.username,
>                password=settings.password, host=settings.hostname,
>                port=settings.port, database=settings.database)
> 
>    def _setup_tables(self, metadata, tables):
>       """Map the database structure to SQLAlchemy Table objects
>       """
> 
>       tables['person'] = Table('person', metadata, autoload=True)
>       tables['office'] = Table('office', metadata, autoload=True)
> 
>    def _setup_mappers(self, tables, mappers):
>       """Map the database Tables to SQLAlchemy Mapper objects
>       """
> 
>       mappers['person'] = mapper(Person, tables['person'],
>          properties = {'office' : relation(Office),});
> 
>       mappers['office'] = mapper(Office, tables['office'])
> 
> 
> Also the test case that I am running:
> 
>     >>> self.loginAsPortalOwner()
> 
>     >>> from zope.component import getUtility
>     >>> from mls.agent.interfaces import IDatabaseSettings
> 
>     >>> settings = getUtility(IDatabaseSettings)
> 
>     >>> settings.drivername = 'psycopg'
>     >>> settings.username = 'postgres'
>     >>> settings.password = 'postgres'
>     >>> settings.hostname = 'localhost'
>     >>> settings.database = 'trend-dev'
> 
>     >>> from collective.lead.interfaces import IDatabase
>     >>> db=getUtility(IDatabase, name='db.mls')
> 
>     >>> from mls.agent.interfaces import IPersonLocator
>     >>> locator = getUtility(IPersonLocator)
>     >>> locator.persons_for_mls_person_code(<data>).last_name;
>     <answer>
> 
> > 
> 
As far as I know the drivername for PostgreSQL is "postgres" and not 
"psycopg2".
Look at 
http://www.sqlalchemy.org/docs/04/dbengine.html#dbengine_establishing

Bernhard


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to