Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
grepros.plugins.auto.sqlbase.SqlMixin Class Reference
Inheritance diagram for grepros.plugins.auto.sqlbase.SqlMixin:
Inheritance graph
[legend]

Public Member Functions

def __init__ (self, args=None, **kwargs)
 
def close (self)
 
def validate (self)
 

Static Public Attributes

 DEFAULT_ARGS = dict(META=False, WRITE_OPTIONS={}, MATCH_WRAPPER=None, VERBOSE=False)
 Constructor argument defaults. More...
 
string DEFAULT_DIALECT = "sqlite"
 Default SQL dialect used if dialect not specified. More...
 
dictionary DIALECTS
 Supported SQL dialects and options. More...
 
list KEYWORDS
 Words that need quoting if in name context, like table name. More...
 

Private Member Functions

def _convert_column_value (self, value, typename)
 
def _convert_time_value (self, value, typename)
 
def _get_dialect_option (self, option)
 
def _make_column_names (self, col_names)
 
def _make_column_type (self, typename, fallback=None)
 
def _make_column_value (self, value, typename=None)
 
def _make_entity_name (self, category, args)
 
def _make_message_insert_sql (self, topic, msg, extra_cols=())
 
def _make_name (self, category, name, existing=())
 
def _make_topic_data (self, topic, msg, exclude_cols=())
 
def _make_topic_insert_sql (self, topic, msg)
 
def _make_type_data (self, msg, extra_cols=(), rootmsg=None)
 
def _make_type_insert_sql (self, msg)
 
def _make_update_sql (self, table, values, where=())
 
def _validate_dialect (self)
 
def _validate_dialect_file (self)
 

Private Attributes

 _args
 
 _dialect
 
 _nesting
 
 _schema
 
 _sql_cache
 
 _topics
 
 _types
 

Detailed Description

Base class for producing SQL for topics and messages.

Can load additional SQL dialects or additional options for existing dialects
from a YAML/JSON file.

Definition at line 25 of file sqlbase.py.

Constructor & Destructor Documentation

◆ __init__()

def grepros.plugins.auto.sqlbase.SqlMixin.__init__ (   self,
  args = None,
**  kwargs 
)
@param   args                 arguments as namespace or dictionary, case-insensitive
@param   args.write_options   ```
                      {"dialect": SQL dialect if not default,
                       "nesting": true|false to created nested type tables}
                      ```
@param   kwargs               any and all arguments as keyword overrides, case-insensitive

Reimplemented in grepros.plugins.auto.postgres.PostgresSink, grepros.plugins.auto.dbbase.BaseDataSink, grepros.plugins.auto.sqlite.SqliteSink, and grepros.plugins.sql.SqlSink.

Definition at line 40 of file sqlbase.py.

Member Function Documentation

◆ _convert_column_value()

def grepros.plugins.auto.sqlbase.SqlMixin._convert_column_value (   self,
  value,
  typename 
)
private
Returns ROS value converted to dialect value.

Definition at line 345 of file sqlbase.py.

◆ _convert_time_value()

def grepros.plugins.auto.sqlbase.SqlMixin._convert_time_value (   self,
  value,
  typename 
)
private
Returns ROS time/duration value converted to dialect value.

Definition at line 358 of file sqlbase.py.

◆ _get_dialect_option()

def grepros.plugins.auto.sqlbase.SqlMixin._get_dialect_option (   self,
  option 
)
private
Returns option for current SQL dialect, falling back to default dialect.

Definition at line 371 of file sqlbase.py.

◆ _make_column_names()

def grepros.plugins.auto.sqlbase.SqlMixin._make_column_names (   self,
  col_names 
)
private
Returns valid unique names for table columns.

Definition at line 286 of file sqlbase.py.

◆ _make_column_type()

def grepros.plugins.auto.sqlbase.SqlMixin._make_column_type (   self,
  typename,
  fallback = None 
)
private
Returns column type for SQL.

@param  fallback  fallback typename to use for lookup if no mapping for typename

Definition at line 317 of file sqlbase.py.

◆ _make_column_value()

def grepros.plugins.auto.sqlbase.SqlMixin._make_column_value (   self,
  value,
  typename = None 
)
private
Returns column value suitable for inserting to database.

Reimplemented in grepros.plugins.auto.postgres.PostgresSink.

Definition at line 294 of file sqlbase.py.

◆ _make_entity_name()

def grepros.plugins.auto.sqlbase.SqlMixin._make_entity_name (   self,
  category,
  args 
)
private
Returns valid unique name for table/view.

@param   args  format arguments for table/view name template

Definition at line 250 of file sqlbase.py.

◆ _make_message_insert_sql()

def grepros.plugins.auto.sqlbase.SqlMixin._make_message_insert_sql (   self,
  topic,
  msg,
  extra_cols = () 
)
private
Returns ("INSERT ..", [args]) for inserting into message type table.

@param   extra_cols  list of additional table columns, as [(name, value)]

Definition at line 211 of file sqlbase.py.

◆ _make_name()

def grepros.plugins.auto.sqlbase.SqlMixin._make_name (   self,
  category,
  name,
  existing = () 
)
private
Returns a valid unique name for table/view/column.

Replaces invalid characters and constrains length.
If name already exists, appends counter like " (2)".

Definition at line 263 of file sqlbase.py.

◆ _make_topic_data()

def grepros.plugins.auto.sqlbase.SqlMixin._make_topic_data (   self,
  topic,
  msg,
  exclude_cols = () 
)
private
Returns full data dictionary for topic, including view name and SQL.

@param   exclude_cols  list of column names to exclude from view SELECT, if any
@return                {"name": topic name, "type": message type name as "pkg/Cls",
                "table_name": message type table name, "view_name": topic view name,
                "md5": message type definition MD5 hash, "sql": "CREATE VIEW .."}

Definition at line 122 of file sqlbase.py.

◆ _make_topic_insert_sql()

def grepros.plugins.auto.sqlbase.SqlMixin._make_topic_insert_sql (   self,
  topic,
  msg 
)
private
Returns ("INSERT ..", [args]) for inserting into topics-table.

Definition at line 189 of file sqlbase.py.

◆ _make_type_data()

def grepros.plugins.auto.sqlbase.SqlMixin._make_type_data (   self,
  msg,
  extra_cols = (),
  rootmsg = None 
)
private
Returns full data dictionary for message type, including table name and SQL.

@param   rootmsg     top message this message is nested under, if any
@param   extra_cols  additional table columns, as [(column name, column def)]
@return              {"type": message type name as "pkg/Cls",
              "table_name": message type table name,
              "definition": message type definition,
              "cols": [(column name, column type)],
              "md5": message type definition MD5 hash, "sql": "CREATE TABLE .."}

Definition at line 152 of file sqlbase.py.

◆ _make_type_insert_sql()

def grepros.plugins.auto.sqlbase.SqlMixin._make_type_insert_sql (   self,
  msg 
)
private
Returns ("INSERT ..", [args]) for inserting into types-table.

Definition at line 200 of file sqlbase.py.

◆ _make_update_sql()

def grepros.plugins.auto.sqlbase.SqlMixin._make_update_sql (   self,
  table,
  values,
  where = () 
)
private
Returns ("UPDATE ..", [args]).

Definition at line 238 of file sqlbase.py.

◆ _validate_dialect()

def grepros.plugins.auto.sqlbase.SqlMixin._validate_dialect (   self)
private
Returns whether "dialect" is valid in args.WRITE_OPTIONS.

Definition at line 101 of file sqlbase.py.

◆ _validate_dialect_file()

def grepros.plugins.auto.sqlbase.SqlMixin._validate_dialect_file (   self)
private
Returns whether "dialect-file" is valid in args.WRITE_OPTIONS.

Definition at line 67 of file sqlbase.py.

◆ close()

def grepros.plugins.auto.sqlbase.SqlMixin.close (   self)
Clears data structures.

Reimplemented in grepros.plugins.auto.dbbase.BaseDataSink, and grepros.plugins.sql.SqlSink.

Definition at line 114 of file sqlbase.py.

◆ validate()

def grepros.plugins.auto.sqlbase.SqlMixin.validate (   self)
Returns whether arguments are valid.

Verifies that "dialect-file" is valid and "dialect" contains supported value, if any.

Reimplemented in grepros.plugins.auto.dbbase.BaseDataSink, grepros.plugins.auto.postgres.PostgresSink, grepros.plugins.auto.sqlite.SqliteSink, and grepros.plugins.sql.SqlSink.

Definition at line 58 of file sqlbase.py.

Member Data Documentation

◆ _args

grepros.plugins.auto.sqlbase.SqlMixin._args
private

Definition at line 49 of file sqlbase.py.

◆ _dialect

grepros.plugins.auto.sqlbase.SqlMixin._dialect
private

Definition at line 54 of file sqlbase.py.

◆ _nesting

grepros.plugins.auto.sqlbase.SqlMixin._nesting
private

Definition at line 55 of file sqlbase.py.

◆ _schema

grepros.plugins.auto.sqlbase.SqlMixin._schema
private

Definition at line 52 of file sqlbase.py.

◆ _sql_cache

grepros.plugins.auto.sqlbase.SqlMixin._sql_cache
private

Definition at line 53 of file sqlbase.py.

◆ _topics

grepros.plugins.auto.sqlbase.SqlMixin._topics
private

Definition at line 50 of file sqlbase.py.

◆ _types

grepros.plugins.auto.sqlbase.SqlMixin._types
private

Definition at line 51 of file sqlbase.py.

◆ DEFAULT_ARGS

grepros.plugins.auto.sqlbase.SqlMixin.DEFAULT_ARGS = dict(META=False, WRITE_OPTIONS={}, MATCH_WRAPPER=None, VERBOSE=False)
static

Constructor argument defaults.

Definition at line 37 of file sqlbase.py.

◆ DEFAULT_DIALECT

string grepros.plugins.auto.sqlbase.SqlMixin.DEFAULT_DIALECT = "sqlite"
static

Default SQL dialect used if dialect not specified.

Definition at line 34 of file sqlbase.py.

◆ DIALECTS

dictionary grepros.plugins.auto.sqlbase.SqlMixin.DIALECTS
static

Supported SQL dialects and options.

Definition at line 377 of file sqlbase.py.

◆ KEYWORDS

list grepros.plugins.auto.sqlbase.SqlMixin.KEYWORDS
static

Words that need quoting if in name context, like table name.

Combined from reserved words for Postgres, SQLite, MSSQL, Oracle et al.

Definition at line 513 of file sqlbase.py.


The documentation for this class was generated from the following file:


grepros
Author(s): Erki Suurjaak
autogenerated on Sat Jan 6 2024 03:11:30