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=None, description=None, owner=None, privileges=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.

DbObjectWithOptions.diff_map(inobj)

Generate SQL to transform an existing object

Parameters:inobj – a YAML map defining the new object
Returns:list of SQL statements

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=None, description=None, owner=None, privileges=None, **attrs)

A foreign data wrapper definition

ForeignDataWrapper.to_map(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
ForeignDataWrapper.diff_map(inwrapper)

Generate SQL to transform an existing wrapper

Parameters:inwrapper – a YAML map defining the new wrapper
Returns:list of 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
ForeignDataWrapperDict.diff_map(inwrappers)

Generate SQL to transform existing data wrappers

Parameters:input_map – a YAML map defining the new data wrappers
Returns:list of SQL statements

Compares the existing data wrapper definitions, as fetched from the catalogs, to the input map and generates SQL statements to transform the data wrappers accordingly.

Foreign Server

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

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

A foreign server definition

ForeignServer.identifier()

Returns a full identifier for the foreign server

Returns:string
ForeignServer.to_map(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
ForeignServer.diff_map(inserver)

Generate SQL to transform an existing server

Parameters:inserver – a YAML map defining the new server
Returns:list of 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(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
ForeignServerDict.diff_map(inservers)

Generate SQL to transform existing foreign servers

Parameters:inservers – a YAML map defining the new foreign servers
Returns:list of SQL statements

Compares the existing server definitions, as fetched from the catalogs, to the input map and generates SQL statements to transform the foreign servers accordingly.

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=None, description=None, owner=None, privileges=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()

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.

UserMappingDict.diff_map(inusermaps)

Generate SQL to transform existing user mappings

Parameters:input_map – a YAML map defining the new user mappings
Returns:list of SQL statements

Compares the existing user mapping definitions, as fetched from the catalogs, to the input map and generates SQL statements to transform the user mappings accordingly.

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(schema, name, description=None, owner=None, privileges=None, **attrs)

A foreign table definition

ForeignTable.to_map(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
ForeignTable.diff_map(intable)

Generate SQL to transform an existing table

Parameters:intable – a YAML map defining the new table
Returns:list of SQL statements

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
ForeignTableDict.diff_map(intables)

Generate SQL to transform existing foreign tables

Parameters:intables – a YAML map defining the new foreign tables
Returns:list of SQL statements

Compares the existing foreign table definitions, as fetched from the catalogs, to the input map and generates SQL statements to transform the foreign tables accordingly.