Add schema support for Postgresql #85

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants

Hi,

I've been playing a bit with peewee and had to add a few things to inspect a Postgresql database within a schema.
I haven't done much testing apart from this local Postgresql (a MusicBrainz DB mirror).

Any thoughts?

Cheers.
Paul.

@coleifer coleifer commented on the diff May 21, 2012

peewee.py
super(PostgresqlDatabase, self).__init__(PostgresqlAdapter(), database, **connect_kwargs)
+ def connect(self):
@coleifer

coleifer May 21, 2012

Owner

probably better rewritten as:

    res = super(PostgresqlDatabase, self).connect()
    if self._schema is not None:
        self.execute('SET search_path TO %s', (self._schema,))
    return res

@coleifer coleifer and 1 other commented on an outdated diff May 21, 2012

@@ -89,9 +89,13 @@ def connect(self, database, **connect):
err('error connecting to %s' % database)
raise
+ def set_schema(self, schema):
+ return
+

@coleifer coleifer and 1 other commented on an outdated diff May 21, 2012

}
def get_conn_class(self):
return PostgresqlDatabase
+ def set_schema(self, schema):
+ self.conn.execute('SET search_path TO %s' % schema)
+ return
+

@coleifer coleifer commented on an outdated diff May 21, 2012

+ schema = connect.pop('schema')
+ db.connect(database, **connect)
+ if schema is not None:
+ db.set_schema(options.schema)
@coleifer

coleifer May 21, 2012

Owner

Is this logic redundant if its built into the postgresqldatabase?

Owner

coleifer commented May 22, 2012

I ran w/some of your ideas and have added functionality for switching search path and specifying schema when introspecting:

bc465f4
963cfe4

coleifer closed this May 22, 2012

Cool.
I'll continue learning peewee.
Cheers,
Paul.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment