Foreign Data Objects

The foreign module defines nine classes: DbObjectWithOptions derived from DbObject, classes ForeignDataWrapper, ForeignServer and UserMapping derived from DbObjectWithOptions, ForeignTable derived from DbObjectWithOptions and Table, classes ForeignDataWrapperDict, ForeignServerDict and UserMappingDict derived from DbObjectDict, and ForeignTableDict derived from ClassDict.

Database Object With Options

DbObjectWithOptions is derived from DbObject. It is a helper function dealing with the OPTIONS clauses common to the foreign data objects.

class pyrseas.dbobject.foreign.DbObjectWithOptions(name, description=None, **attrs)

Helper class for database objects with OPTIONS clauses

DbObjectWithOptions.options_clause()

Create the OPTIONS clause

Parameters:optdict – the dictionary of options
Returns:SQL OPTIONS clause
DbObjectWithOptions.diff_options(newopts)

Compare options lists and generate SQL OPTIONS clause

Newopts:list of new options
Returns:SQL OPTIONS clause

Generate ([ADD|SET|DROP key ‘value’) clauses from two lists in the form of ‘key=value’ strings.

Foreign Data Wrapper

ForeignDataWrapper is derived from DbObjectWithOptions and represents a PostgreSQL foreign data wrapper. For PostgreSQL versions 9.1 and later see also Foreign Data and Writing A Foreign Data Wrapper.

class pyrseas.dbobject.foreign.ForeignDataWrapper(name, description=None, **attrs)

A foreign data wrapper definition

ForeignDataWrapper.to_map(db, no_owner, no_privs)

Convert wrappers and subsidiary objects to a YAML-suitable format

Parameters:
  • no_owner – exclude object owner information
  • no_privs – exclude privilege information
Returns:

dictionary

ForeignDataWrapper.create(obj, *args, **kwargs)

Return SQL statements to CREATE the data wrapper

Returns:SQL statements

Foreign Data Wrapper Dictionary

ForeignDataWrapperDict is derived from DbObjectDict. It is a dictionary that represents the collection of foreign data wrappers in a database.

class pyrseas.dbobject.foreign.ForeignDataWrapperDict(dbconn=None)

The collection of foreign data wrappers in a database

ForeignDataWrapperDict.from_map(inwrappers, newdb)

Initialize the dictionary of wrappers by examining the input map

Parameters:
  • inwrappers – input YAML map defining the data wrappers
  • newdb – collection of dictionaries defining the database

Connect servers to their respective foreign data wrappers

Parameters:dbservers – dictionary of foreign servers

Foreign Server

ForeignServer is derived from DbObjectWithOptions and represents a PostgreSQL foreign server.

class pyrseas.dbobject.foreign.ForeignServer(name, description=None, **attrs)

A foreign server definition

ForeignServer.identifier()

Returns a full identifier for the foreign server

Returns:string
ForeignServer.to_map(db, no_owner, no_privs)

Convert servers and subsidiary objects to a YAML-suitable format

Parameters:
  • no_owner – exclude server owner information
  • no_privs – exclude privilege information
Returns:

dictionary

ForeignServer.create(obj, *args, **kwargs)

Return SQL statements to CREATE the server

Returns:SQL statements

Foreign Server Dictionary

ForeignServerDict is derived from DbObjectDict. It is a Python dictionary that represents the collection of foreign servers in a database.

class pyrseas.dbobject.foreign.ForeignServerDict(dbconn=None)

The collection of foreign servers in a database

ForeignServerDict.from_map(wrapper, inservers, newdb)

Initialize the dictionary of servers by examining the input map

Parameters:
  • wrapper – associated foreign data wrapper
  • inservers – input YAML map defining the foreign servers
  • newdb – collection of dictionaries defining the database
ForeignServerDict.to_map(db, no_owner, no_privs)

Convert the server dictionary to a regular dictionary

Parameters:
  • no_owner – exclude server owner information
  • no_privs – exclude privilege information
Returns:

dictionary

Invokes the to_map method of each server to construct a dictionary of foreign servers.

Connect user mappings to their respective servers

Parameters:dbusermaps – dictionary of user mappings

User Mapping

UserMapping is derived from DbObjectWithOptions and represents a PostgreSQL user mapping of a user to a foreign server.

class pyrseas.dbobject.foreign.UserMapping(name, description=None, **attrs)

A user mapping definition

UserMapping.extern_key()

Return the key to be used in external maps for this user mapping

Returns:string
UserMapping.identifier()

Return a full identifier for a user mapping object

Returns:string
UserMapping.create()

Return SQL statements to CREATE the user mapping

Returns:SQL statements

User Mapping Dictionary

UserMappingDict is derived from DbObjectDict. It is a dictionary that represents the collection of user mappings in a database.

class pyrseas.dbobject.foreign.UserMappingDict(dbconn=None)

The collection of user mappings in a database

UserMappingDict.from_map(server, inusermaps)

Initialize the dictionary of mappings by examining the input map

Parameters:
  • server – foreign server associated with mappings
  • inusermaps – input YAML map defining the user mappings
UserMappingDict.to_map(db)

Convert the user mapping dictionary to a regular dictionary

Returns:dictionary

Invokes the to_map method of each mapping to construct a dictionary of user mappings.

Foreign Table

ForeignTable is derived from DbObjectWithOptions and Table. It represents a PostgreSQL foreign table (available on PostgreSQL 9.1 or later).

class pyrseas.dbobject.foreign.ForeignTable(name, schema='public', description=None, **attrs)

A foreign table definition

ForeignTable.to_map(db, opts)

Convert a foreign table to a YAML-suitable format

Parameters:opts – options to include/exclude tables, etc.
Returns:dictionary
ForeignTable.create(obj, *args, **kwargs)

Return SQL statements to CREATE the foreign table

Returns:SQL statements
ForeignTable.drop()

Return a SQL DROP statement for the foreign table

Returns:SQL statement

Foreign Table Dictionary

ForeignTableDict is derived from ClassDict. It is a dictionary that represents the collection of foreign tables in a database.

class pyrseas.dbobject.foreign.ForeignTableDict(dbconn=None)

The collection of foreign tables in a database

ForeignTableDict.from_map(schema, inobjs, newdb)

Initalize the dictionary of tables by converting the input map

Parameters:
  • schema – schema owning the tables
  • inobjs – YAML map defining the schema objects
  • newdb – collection of dictionaries defining the database

Connect columns to their respective foreign tables

Parameters:dbcolumns – dictionary of columns