dripline.implementations.postgres_interface module¶
A service for interfacing with SQL database for storage. It is currently only developed and tested against Postgres, but should be relatively straight forward to generalize to support other SQL flavors if there is an interest.
Note: services using this module will require sqlalchemy (and assuming we’re still using postgresql, psycopg2 as the sqlalchemy backend)
-
class
dripline.implementations.postgres_interface.
PostgreSQLInterface
(database_name, database_server, auths_file=None, **kwargs)[source]¶ Bases:
_dripline.core.Service
- Parameters
database_name (str) – name of the ‘database’ to connect to within the database server
database_server (str) – network resolvable hostname of database server
auths_file (str) – expandable path to an authentications file Note, this option is considered temporary and like to be removed in a future version
-
class
dripline.implementations.postgres_interface.
SQLTable
(table_name, schema=None, required_insert_names=[], return_col_names=[], optional_insert_names=[], default_insert_values={}, *args, **kwargs)[source]¶ Bases:
dripline.core.endpoint.Endpoint
A class for making calls to _insert_with_return
table_name (str): name of the table within the database schema (str): name of the schema where the table is located required_insert_names (list): list of names (str||dict) of the table columns which must be included on every requested insert (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value) return_col_names (list): list of names (str) of columns whose values should be returned on completion of the insert optional_insert_names (list): list of names (str||dict) of columns which the user may specify on an insert request, but which may be omitted (if dict: keys are ‘column’ and ‘payload_key’, if string it is assumed that both are that value) default_insert_values (dict): dictionary of {column_names: values} to serve as defaults when inserting, any values provided explicitly on the insert request will override these values
-
do_select
(return_cols=[], where_eq_dict={}, where_lt_dict={}, where_gt_dict={})[source]¶ return_cols (list of str): string names of columns, internally converted to sql reference; if evaluates as false, all columns are returned where_eq_dict (dict): keys are column names (str), and values are tested with ‘==’ where_lt_dict (dict): keys are column names (str), and values are tested with ‘<’ where_gt_dict (dict): keys are column names (str), and values are tested with ‘>’
Other select “where” statements are not supported
Returns: a tuple, 1st element is list of column names, 2nd is a list of tuples of the rows that matched the select
-