Package gavo :: Package base :: Module sqlsupport :: Class PostgresQueryMixin
[frames] | no frames]

Class PostgresQueryMixin

source code

object --+
         |
        PostgresQueryMixin
Known Subclasses:

is a mixin containing various useful queries that are postgres specific.

This mixin expects a parent that mixes is QuerierMixin (that, for now, also mixes in PostgresQueryMixin, so you won't need to mix this in).

Instance Methods
 
getServerVersion(self, digits=2)
returns the version of the connection's server to digits numbers.
source code
 
getPrimaryIndexName(self, tableName)
returns the name of the index corresponding to the primary key on (the unqualified) tableName.
source code
 
schemaExists(self, schema)
returns True if the named schema exists in the database.
source code
 
hasIndex(self, tableName, indexName, schema=None)
returns True if table tablename has and index called indexName.
source code
 
getForeignKeyName(self, srcTableName, destTableName, srcColNames, destColNames, schema=None)
returns True if there's a foreign key constraint on srcTable's srcColNames using destTableName's destColNames.
source code
 
foreignKeyExists(self, srcTableName, destTableName, srcColNames, destColNames, schema=None) source code
 
getColumnsFromDB(self, tableName)
returns a sequence of (name, type) pairs of the columsn this table has in the database.
source code
 
getRowEstimate(self, tableName)
returns the size of the table in rows as estimated by the query planner.
source code
 
roleExists(self, role)
returns True if there role is known to the database.
source code
 
getOIDForTable(self, tableName, schema=None)
returns the current oid of tableName.
source code
 
getTableType(self, tableName, schema=None)
returns the type of the relation relationName.
source code
 
dropTable(self, tableName, cascade=False)
drops a table or view named by tableName.
source code
 
getSchemaPrivileges(self, schema)
returns (owner, readRoles, allRoles) for schema's ACL.
source code
 
getTablePrivileges(self, schema, tableName)
returns (owner, readRoles, allRoles) for the relation tableName and the schema.
source code
 
parsePGACL(self, acl)
returns a dict roleName->acl for acl in postgres' ACL serialization.
source code
 
getACLFromRes(self, thingWithPrivileges)
returns a dict of (role, ACL) as it is defined in thingWithPrivileges.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

hasIndex(self, tableName, indexName, schema=None)

source code 

returns True if table tablename has and index called indexName.

See _parseTableName on the meaning of the arguments.

getForeignKeyName(self, srcTableName, destTableName, srcColNames, destColNames, schema=None)

source code 

returns True if there's a foreign key constraint on srcTable's srcColNames using destTableName's destColNames.

Warning: names in XColNames that are not column names in the respective tables are ignored.

This raises a ValueError if the foreign keys do not exist.

getColumnsFromDB(self, tableName)

source code 

returns a sequence of (name, type) pairs of the columsn this table has in the database.

If the table is not on disk, this will raise a NotFoundError.

*** psycopg2 specific ***

getRowEstimate(self, tableName)

source code 

returns the size of the table in rows as estimated by the query planner.

This will raise a KeyError with tableName if the table isn't known to postgres.

getOIDForTable(self, tableName, schema=None)

source code 

returns the current oid of tableName.

tableName may be schema qualified. If it is not, public is assumed.

getTableType(self, tableName, schema=None)

source code 

returns the type of the relation relationName.

If relationName does not exist, None is returned. Otherwise, it's what is in the information schema for the table, which for postgres currently is one of BASE TABLE, VIEW, FOREIGN TABLE, MATERIALIZED VIEW, or LOCAL TEMPORARY.

The DaCHS-idiomatic way to see if a relation exists is getTableType() is not None.

You can pass in schema-qualified relation names, or the relation name and the schema separately.

*** postgres specific ***

dropTable(self, tableName, cascade=False)

source code 

drops a table or view named by tableName.

This does not raise an error if no such relation exists.

*** postgres specific ***

getTablePrivileges(self, schema, tableName)

source code 

returns (owner, readRoles, allRoles) for the relation tableName and the schema.

*** postgres specific ***

getACLFromRes(self, thingWithPrivileges)

source code 

returns a dict of (role, ACL) as it is defined in thingWithPrivileges.

thingWithPrivileges is something mixing in rscdef.common.PrivilegesMixin. (or has readProfiles and allProfiles attributes containing sequences of profile names).