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.
DbObjectWithOptions is derived from DbObject. It is a helper function dealing with the OPTIONS clauses common to the foreign data objects.
Helper class for database objects with OPTIONS clauses
Create the OPTIONS clause
| Parameters: | optdict – the dictionary of options |
|---|---|
| Returns: | SQL OPTIONS clause |
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.
Generate SQL to transform an existing object
| Parameters: | inobj – a YAML map defining the new object |
|---|---|
| Returns: | list of SQL statements |
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.
A foreign data wrapper definition
Convert wrappers and subsidiary objects to a YAML-suitable format
| Parameters: |
|
|---|---|
| Returns: | dictionary |
Return SQL statements to CREATE the data wrapper
| Returns: | SQL statements |
|---|
Generate SQL to transform an existing wrapper
| Parameters: | inwrapper – a YAML map defining the new wrapper |
|---|---|
| Returns: | list of SQL statements |
ForeignDataWrapperDict is derived from DbObjectDict. It is a dictionary that represents the collection of foreign data wrappers in a database.
The collection of foreign data wrappers in a database
Initialize the dictionary of wrappers by examining the input map
| Parameters: |
|
|---|
Connect servers to their respective foreign data wrappers
| Parameters: | dbservers – dictionary of foreign servers |
|---|
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.
ForeignServer is derived from DbObjectWithOptions and represents a PostgreSQL foreign server.
A foreign server definition
Returns a full identifier for the foreign server
| Returns: | string |
|---|
Convert servers and subsidiary objects to a YAML-suitable format
| Parameters: |
|
|---|---|
| Returns: | dictionary |
Return SQL statements to CREATE the server
| Returns: | SQL statements |
|---|
Generate SQL to transform an existing server
| Parameters: | inserver – a YAML map defining the new server |
|---|---|
| Returns: | list of SQL statements |
ForeignServerDict is derived from DbObjectDict. It is a Python dictionary that represents the collection of foreign servers in a database.
The collection of foreign servers in a database
Initialize the dictionary of servers by examining the input map
| Parameters: |
|
|---|
Convert the server dictionary to a regular dictionary
| Parameters: |
|
|---|---|
| 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 |
|---|
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.
UserMapping is derived from DbObjectWithOptions and represents a PostgreSQL user mapping of a user to a foreign server.
A user mapping definition
Return the key to be used in external maps for this user mapping
| Returns: | string |
|---|
Return a full identifier for a user mapping object
| Returns: | string |
|---|
Return SQL statements to CREATE the user mapping
| Returns: | SQL statements |
|---|
UserMappingDict is derived from DbObjectDict. It is a dictionary that represents the collection of user mappings in a database.
The collection of user mappings in a database
Initialize the dictionary of mappings by examining the input map
| Parameters: |
|
|---|
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.
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.
ForeignTable is derived from DbObjectWithOptions and Table. It represents a PostgreSQL foreign table (available on PostgreSQL 9.1 or later).
A foreign table definition
Convert a foreign table to a YAML-suitable format
| Parameters: | opts – options to include/exclude tables, etc. |
|---|---|
| Returns: | dictionary |
Return SQL statements to CREATE the foreign table
| Returns: | SQL statements |
|---|
Return a SQL DROP statement for the foreign table
| Returns: | SQL statement |
|---|
Generate SQL to transform an existing table
| Parameters: | intable – a YAML map defining the new table |
|---|---|
| Returns: | list of SQL statements |
ForeignTableDict is derived from ClassDict. It is a dictionary that represents the collection of foreign tables in a database.
The collection of foreign tables in a database
Initalize the dictionary of tables by converting the input map
| Parameters: |
|
|---|
Connect columns to their respective foreign tables
| Parameters: | dbcolumns – dictionary of columns |
|---|
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.