Kirill Simonov avatar Kirill Simonov committed 1482318

tweak.override: added description.

Comments (0)

Files changed (2)

src/htsql_tweak/override/__init__.py

 class TweakOverrideAddon(Addon):
 
     name = 'tweak.override'
+    hint = """adjust database metadata"""
+    help = """
+    This addon provides several ways to adjust database metadata.
+    It allows you to restrict access to specific tables and columns,
+    specify additional database constraints, change the names of
+    tables, columns and links, and define calculated attributes.
+
+    Parameter `included-tables` is a list of tables allowed to be used
+    by HTSQL.  Any table not in this list is completely hidden from
+    the HTSQL processor.  Each table in the list must have the form
+    `<table>` or `<schema>.<table>` and may include `*` symbol to
+    indicate any number of characters.
+
+    Parameter `excluded-tables` is a list of tables which are not
+    allowed to be used by HTSQL.  When both `included-tables` and
+    `excluded-tables` are specified, the only tables available
+    are those which are in the `included-tables` list, but not in
+    the `excluded-tables` list.
+
+    Parameter `included-columns` is a list of columns allowed to be
+    used by HTSQL.  Any column not in this list is completely hidden
+    from the HTSQL processor.  The column must have the form
+    `<column>`, `<table>.<column>` or `<schema>.<table>.<column>`
+    and may include `*` symbol to indicate any number of characters.
+
+    Parameter `excluded-columns` is a list of columns not allowed to
+    be used by HTSQL.
+
+    Parameter `not-nulls` is a list of columns with a `NOT NULL`
+    constraint.
+
+    Parameter `unique-keys` is a list of `UNIQUE` and `PRIMARY KEY`
+    constraints.  Each constraint definition must have a form:
+    `<table>(<column>, ...)`, optionally followed by `!` symbol.
+    The `!` symbol indicates a `PRIMARY KEY` constraint.
+
+    Parameter `foreign-keys` is a list of `FOREIGN KEY` constraints.
+    Each constraint definition must have the form:
+    `<table>(<column>,...) -> <table>(<column>,...)`,
+
+    Parameter `class-labels` is a mapping of labels to class
+    definitions.  Each class definition is either a table name
+    or an HTSQL expression wrapped in parentheses.
+
+    Parameter `field-labels` is a mapping of qualified labels to
+    field definitions.  Each field definition is either a column name,
+    a comma-separated list of `FOREIGN KEY` and reverse `FOREIGN KEY`
+    constraints, or an HTSQL expression.
+
+    Parameter `field-orders` is a mapping of table labels to lists
+    of fields to be displayed when an explicit selector is not
+    provided.
+
+    Parameter `unlabeled-tables` is a list of tables hidden from
+    the user.  The tables could still be used in SQL generated by
+    the HTSQL translator.
+
+    Parameter `unlabeled-columns` is a list of columns hidden from
+    the user.  The columns could still be used in SQL generated by
+    the HTSQL translator.
+    """
 
     parameters = [
-            Parameter('include_tables', SeqVal(TablePatternVal()),
-                      default=[]),
-            Parameter('exclude_tables', SeqVal(TablePatternVal()),
-                      default=[]),
-            Parameter('include_columns', SeqVal(ColumnPatternVal()),
-                      default=[]),
-            Parameter('exclude_columns', SeqVal(ColumnPatternVal()),
-                      default=[]),
+            Parameter('included_tables', SeqVal(TablePatternVal()),
+                      default=[],
+                      value_name="TABLES",
+                      hint="""permitted tables"""),
+            Parameter('excluded_tables', SeqVal(TablePatternVal()),
+                      default=[],
+                      value_name="TABLES",
+                      hint="""forbidden tables"""),
+            Parameter('included_columns', SeqVal(ColumnPatternVal()),
+                      default=[],
+                      value_name="COLUMNS",
+                      hint="""permitted columns"""),
+            Parameter('excluded_columns', SeqVal(ColumnPatternVal()),
+                      default=[],
+                      value_name="COLUMNS",
+                      hint="""forbidden columns"""),
             Parameter('not_nulls', SeqVal(ColumnPatternVal()),
-                      default=[]),
+                      default=[],
+                      value_name="COLUMNS",
+                      hint="""`NOT NULL` constraints"""),
             Parameter('unique_keys', SeqVal(UniqueKeyPatternVal()),
-                      default=[]),
+                      default=[],
+                      value_name="KEYS",
+                      hint="""`UNIQUE` and `PRIMARY KEY` constraints"""),
             Parameter('foreign_keys', SeqVal(ForeignKeyPatternVal()),
-                      default=[]),
+                      default=[],
+                      value_name="KEYS",
+                      hint="""`FOREIGN KEY` constraints`"""),
             Parameter('class_labels', MapVal(LabelVal(), ClassPatternVal()),
-                      default={}),
+                      default={},
+                      value_name="LABELS",
+                      hint="""labels for tables and calculations"""),
             Parameter('field_labels', MapVal(QLabelVal(), FieldPatternVal()),
-                      default={}),
+                      default={},
+                      value_name="LABELS",
+                      hint="""labels for table fields"""),
             Parameter('field_orders', MapVal(LabelVal(), SeqVal(LabelVal())),
-                      default={}),
+                      default={},
+                      value_name="LABELS",
+                      hint="""default table fields"""),
             Parameter('unlabeled_tables', SeqVal(TablePatternVal()),
-                      default=[]),
+                      default=[],
+                      value_name="TABLES",
+                      hint="""ignored tables"""),
             Parameter('unlabeled_columns', SeqVal(ColumnPatternVal()),
-                      default=[]),
+                      default=[],
+                      value_name="COLUMNS",
+                      hint="""ignored columns"""),
     ]
 
     def __init__(self, app, attributes):

src/htsql_tweak/override/introspect.py

         catalog = super(OverrideIntrospect, self).__call__()
         unused = set()
 
-        if addon.include_tables or addon.exclude_tables:
-            include = addon.include_tables
-            exclude = addon.exclude_tables
+        if addon.included_tables or addon.excluded_tables:
+            include = addon.included_tables
+            exclude = addon.excluded_tables
             unused.update(include)
             unused.update(exclude)
             for schema in catalog.schemas:
                     unused.difference_update(include_matches)
                     unused.difference_update(exclude_matches)
 
-        if addon.include_columns or addon.exclude_columns:
-            include = addon.include_columns
-            exclude = addon.exclude_columns
+        if addon.included_columns or addon.excluded_columns:
+            include = addon.included_columns
+            exclude = addon.excluded_columns
             unused.update(include)
             unused.update(exclude)
             for schema in catalog.schemas:
                                    if pattern.matches(column)]
                         unused.difference_update(matches)
 
-        for pattern in (addon.include_tables + addon.exclude_tables +
-                        addon.include_columns + addon.exclude_columns +
+        for pattern in (addon.included_tables + addon.excluded_tables +
+                        addon.included_columns + addon.excluded_columns +
                         addon.not_nulls + addon.unique_keys +
                         addon.foreign_keys +
                         addon.unlabeled_tables + addon.unlabeled_columns):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.