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, options)

Helper class for database objects with OPTIONS clauses

DbObjectWithOptions.to_map(db, no_owner=False, no_privs=False)

Convert objects to a YAML-suitable format

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

dictionary

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.alter(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, options, description, owner, privileges, handler=None, validator=None, oid=None)

A foreign data wrapper definition

static ForeignDataWrapper.from_map(name, inobj)

Initialize an FDW instance from a YAML map

Parameters:
  • name – FDW name
  • inobj – YAML map of the FDW
Returns:

FDW instance

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

Foreign Server

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

class pyrseas.dbobject.foreign.ForeignServer(name, options, description, owner, privileges, wrapper, type=None, version=None, oid=None)

A foreign server definition

static ForeignServer.from_map(name, wrapper, inobj)

Initialize a foreign server instance from a YAML map

Parameters:
  • name – server name
  • wrapper – FDW name
  • inobj – YAML map of the server
Returns:

foreign server instance

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.

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, options, wrapper, server, oid=None)

A user mapping definition

static UserMapping.from_map(name, server, inobj)

Initialize a user mapping instance from a YAML map

Parameters:
  • name – mapping name
  • server – foreign server map
  • inobj – YAML map of the user mapping
Returns:

user mapping instance

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(dbversion=None)

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.

UserMappingDict.alter(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(name, schema, description, owner, privileges, server=None, options={}, oid=None)

A foreign table definition

static ForeignTable.from_map(name, schema, inobj)

Initialize a foreign table instance from a YAML map

Parameters:
  • name – foreign table name
  • name – schema name
  • inobj – YAML map of the table
Returns:

foreign table instance

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