Foreign Data Objects

The foreign module defines nine classes related to Postgres foreign data wrappers (FDWs), namely: 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 class for 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 with options

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 Postgres foreign data wrapper. 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

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

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 Postgres foreign server.

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

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

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 mapping of a Postgres user to a foreign server.

class pyrseas.dbobject.foreign.UserMapping(name, options, wrapper, server, oid=None)

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(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.

Foreign Table

ForeignTable is derived from DbObjectWithOptions and Table. It represents a Postgres foreign table.

class pyrseas.dbobject.foreign.ForeignTable(name, schema, description, owner, privileges, server=None, options={}, oid=None)

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

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)

Initialize 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