Module Schema
source code
Provides access to the database schema. As described in the collection
of *.sql
files in the sql
directory. This
allows CUs to become schema driven.
Usage
Case 1 - Retrieving table schema details
Call the parseTables() function to retrieve a dictionary of
table schemas from a supplied .sql schema file, e.g. :
import wsatools.DbConnect.Schema as schema
tableSchema = schema.parseTables("WSA_MultiframeSchema.sql")
print(tableSchema[0].name)
for column in tableSchema[0].columns:
print(column.name, column.dataType)
Read documentation for Table and Attribute classes to see what data is available and
how to access it.
Case 2 - Retrieving table index details
Call the parseIndices() function to retrieve a dictionary of
table indices, e.g. :
import wsatools.DbConnect.Schema as schema
from wsatools.SystemConstants import WsaConstants
idxInfo = schema.parseIndices(WsaConstants.indexScript)
db.addIndex(idxInfo["lasSource"][0])
# to apply just the first or to all indices to lasSource:
db.createObjects(idxInfo["lasSource"])
Read documentation for Index class to see what data is available and how to
access it.
Case 3 - Retrieving view schema details
Call the parseViews() function to retrieve an ordered list of
view schemas, e.g. :
import wsatools.DbConnect.Schema as schema
db.createObjects(schema.parseViews())
Schema Objects
|
Class Hierarchy for _Schema
|
Author:
R.S. Collins
Organization:
WFAU, IfA, University of Edinburgh
To Do:
-
Reduce code replication in all parse*() objects
-
Better exception handling on parsing - return file and line number, as
well as line where problem occurred. Also handling missing files
better?
-
Rename Attribute Column?
-
Give Attributes create/dropSQL() methods so that add/drop column can
work like createObject/dropObject.
list(Procedure)
|
|
defaultdict(str: list(Index))
|
parseIndices(schemaFileName=' WSA_Indices.sql ' )
Parses the supplied .sql schema, returning a dictionary of Index objects referenced by table name representing
the indices defined that schema script for that table. |
source code
|
|
list(Table)
|
parseTables(schemaFileName,
tableList=[ ] ,
reqAllTables=True)
Parses the supplied .sql schema file, returning Table objects for every table described in the file. |
source code
|
|
list(View)
|
|
Attribute
|
|
|
__package__ = ' wsatools.DbConnect '
|
Parses the supplied .sql schema, returning an ordered list of Procedure and Function objects.
- Parameters:
schemaFileName (str) - Name of .sql schema file to parse.
- Returns: list(Procedure)
- A list of Procedure and Function objects ordered as supplied in the
script file.
|
parseIndices(schemaFileName=' WSA_Indices.sql ' )
| source code
|
Parses the supplied .sql schema, returning a dictionary of Index
objects referenced by table name representing the indices defined that
schema script for that table.
- Parameters:
schemaFileName (str) - Name of .sql schema file to parse.
- Returns: defaultdict(str: list(Index))
- Dictionary of Index object lists for every table, referenced
by table name.
|
parseTables(schemaFileName,
tableList=[ ] ,
reqAllTables=True)
| source code
|
Parses the supplied .sql schema file, returning Table
objects for every table described in the file. (Unless a subset is
requested).
- Parameters:
schemaFileName (str) - Name of .sql schema file to parse.
tableList (list(str)) - Optional list of tables to be extracted, by default all tables
are extracted.
reqAllTables (bool) - If True, an exception is thrown if any tables in the supplied
list are missing from the schema.
- Returns: list(Table)
- A list of Table objects in the order given by the schema
file.
|
Parses the supplied .sql schema, returning an ordered list of View
objects.
- Parameters:
schemaFileName (str) - Name of .sql schema file to parse.
- Returns: list(View)
- A list of View objects ordered as supplied in the script
file.
|
Parse the list of properties for this attribute supplied by parseTables() from the .sql schema file. This consists
of both SQL attribute and user-defined tag properties.
- Parameters:
detailsList (list(str)) - The unprocessed attribute line from the .sql file split on
whitespace.
- Returns: Attribute
- The attribute object containing the full schema for this
attribute.
|