gensaschema package¶
Module contents¶
Copyright: | Copyright 2014 - 2018 André Malo or his licensors, as applicable |
---|---|
License: | Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
GenSASchema - Static SQLAlchemy Schema Generator¶
GenSASchema generates static schema definitions using SQLAlchemy’s inspection capabilities.
-
class
gensaschema.
Config
(tables, schemas, lines=None)¶ Schema config container
IVariables: - tables :
list
Table list
- _lines : sequence
Original config lines (or
None
)
-
__dict__
= dict_proxy({'from_file': <classmethod object>, '__module__': 'gensaschema._config', 'dump': <function dump>, 'from_parser': <classmethod object>, '_CONFIG_TPL': <gensaschema._template.Template object>, 'from_lines': <classmethod object>, '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__doc__': '\n Schema config container\n\n :IVariables:\n `tables` : ``list``\n Table list\n\n `_lines` : sequence\n Original config lines (or ``None``)\n ', '__init__': <function __init__>})¶
-
__init__
(tables, schemas, lines=None)¶ Initialization
Parameters: - tables :
list
Table list
- schemas :
dict
(Alien) Schema mapping
- lines : sequence
Original config lines. If omitted or
None
, the config lines are not available.
- tables :
-
__module__
= 'gensaschema._config'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
dump
(fp)¶ Dump config to a file
Parameters: - fp :
file
Stream to dump to
- fp :
-
classmethod
from_file
(name_or_file)¶ Construct from config file
Parameters: - name_or_file :
str
orfile
Config filename or file pointer
Return: New Config instance
Rtype: Config
Exceptions: - IOError : Error reading the file (except for ENOENT, which treats the file as empty)
- name_or_file :
-
classmethod
from_lines
(lines)¶ Create from config lines
Parameters: - lines : sequence
List of config lines
Return: New Config instance
Rtype: Config
-
classmethod
from_parser
(parser, lines=None)¶ Construct from config parser
Parameters: - parser :
ConfigParser.RawConfigParser
Configparser instance
- lines : sequence
Original config lines
Return: New Config instance
Rtype: Config
- parser :
- tables :
-
class
gensaschema.
Schema
(conn, tables, schemas, symbols, dbname=None, types=None)¶ Schema container
CVariables: - _MODULE_TPL :
Template
Template for the module
IVariables: - _dialect :
str
Dialect name
- _tables : TableCollection
Table collection
- _schemas :
dict
Schema -> module mapping
- _symbols : Symbols
Symbol table
- _dbname :
str
orNone
DB identifier
-
__dict__
= dict_proxy({'__module__': 'gensaschema._schema', 'dump': <function dump>, '_MODULE_TPL': <gensaschema._template.Template object>, '__dict__': <attribute '__dict__' of 'Schema' objects>, '__weakref__': <attribute '__weakref__' of 'Schema' objects>, '__doc__': '\n Schema container\n\n :CVariables:\n `_MODULE_TPL` : ``Template``\n Template for the module\n\n :IVariables:\n `_dialect` : ``str``\n Dialect name\n\n `_tables` : `TableCollection`\n Table collection\n\n `_schemas` : ``dict``\n Schema -> module mapping\n\n `_symbols` : `Symbols`\n Symbol table\n\n `_dbname` : ``str`` or ``None``\n DB identifier\n ', '__init__': <function __init__>})¶
-
__init__
(conn, tables, schemas, symbols, dbname=None, types=None)¶ Initialization
Parameters: - conn :
Connection
orEngine
SQLAlchemy connection or engine
- tables :
list
List of tables to reflect, (local name, table name) pairs
- schemas :
dict
schema -> module mapping
- symbols : Symbols
Symbol table
- dbname :
str
Optional db identifier. Used for informational purposes. If omitted or
None
, the information just won’t be emitted.- types : callable
Extra type loader. If the type reflection fails, because SQLAlchemy cannot resolve it, the type loader will be called with the type name, (bound) metadata and the symbol table. It is responsible for modifying the symbols and imports and the dialect’s
ischema_names
. If omitted orNone
, the reflector will always fail on unknown types.
- conn :
-
__module__
= 'gensaschema._schema'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
dump
(fp)¶ Dump schema module to fp
Parameters: - fp :
file
File to write to
- fp :
- _MODULE_TPL :
-
exception
gensaschema.
SymbolException
¶ Symbol error
-
__module__
= 'gensaschema._symbols'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
gensaschema.
Type
(ctype, dialect_name, symbols)¶ Type container
IVariables: - _ctype : SA type
Column type
- _dialect :
str
Dialect name
- _symbols :
Symbols
Symbol table
-
__dict__
= dict_proxy({'__module__': 'gensaschema._type', '__doc__': '\n Type container\n\n :IVariables:\n `_ctype` : SA type\n Column type\n\n `_dialect` : ``str``\n Dialect name\n\n `_symbols` : ``Symbols``\n Symbol table\n ', '__repr__': <function __repr__>, '__dict__': <attribute '__dict__' of 'Type' objects>, '__weakref__': <attribute '__weakref__' of 'Type' objects>, 'by_column': <classmethod object>, '__init__': <function __init__>})¶
-
__init__
(ctype, dialect_name, symbols)¶ Initialization
Parameters: - ctype : SA type
Column type
- dialect_name :
str
Dialect name
- symbols :
Symbols
Symbol table
-
__module__
= 'gensaschema._type'¶
-
__repr__
()¶ Make string representation
Return: The string representation Rtype: str
-
__weakref__
¶ list of weak references to the object (if defined)
-
classmethod
by_column
(column, symbols)¶ Construct by SA column
Parameters: - column : SA column
SA column
Return: New Type instance
Rtype: Type
-
exception
gensaschema.
Error
¶ Base exception for this package
-
__module__
= 'gensaschema._exceptions'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
gensaschema.
Symbols
(symbols=None, imports=None)¶ Symbol table
IVariables: - _symbols :
dict
Symbols
- imports : _Imports
Import container
- types : _Types
Type container
-
__contains__
(name)¶ Check symbol table entry
Parameters: - name :
str
Symbol identifier
Return: The symbol
Rtype: str
Exceptions: - KeyError : Symbol not found
- name :
-
__delitem__
(name)¶ Remove symbol entry if available
-
__dict__
= dict_proxy({'__delitem__': <function __delitem__>, '__module__': 'gensaschema._symbols', '__getitem__': <function __getitem__>, '__contains__': <function __contains__>, '__setitem__': <function __setitem__>, '__iter__': <function __iter__>, '__dict__': <attribute '__dict__' of 'Symbols' objects>, '__weakref__': <attribute '__weakref__' of 'Symbols' objects>, '__doc__': '\n Symbol table\n\n :IVariables:\n `_symbols` : ``dict``\n Symbols\n\n `imports` : `_Imports`\n Import container\n\n `types` : `_Types`\n Type container\n ', '__init__': <function __init__>})¶
-
__getitem__
(name)¶ Get symbol table entry
Parameters: - name :
str
Symbol identifier
Return: The symbol
Rtype: str
Exceptions: - KeyError : Symbol not found
- name :
-
__init__
(symbols=None, imports=None)¶ Initialization
Parameters: - symbols :
dict
Initial symbols
- symbols :
-
__iter__
()¶ Make item iterator
Return: The iterator Rtype: iterable
-
__module__
= 'gensaschema._symbols'¶
-
__setitem__
(name, symbol)¶ Set symbol table entry
Parameters: - name :
str
Symbol identifier
- symbol :
str
Symbol
Exceptions: - SymbolException : Symbol could not be set because of some conflict
- name :
-
__weakref__
¶ list of weak references to the object (if defined)
- _symbols :
-
exception
gensaschema.
Warning
¶ Base warning for this package
>>> with _warnings.catch_warnings(record=True) as record: ... Warning.emit('my message') ... assert len(record) == 1 ... str(record[0].message) 'my message'
>>> _warnings.simplefilter('error') >>> Warning.emit('lalala') Traceback (most recent call last): ... Warning: lalala
-
__module__
= 'gensaschema._exceptions'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
classmethod
emit
(message, stacklevel=1)¶ Emit a warning of this very category
This method is pure convenience. It saves you the unfriendly
warnings.warn
syntax (and thewarnings
import).Parameters: - message : any
The warning message
- stacklevel :
int
Number of stackframes to go up in order to place the warning source. This is useful for generic warning-emitting helper functions. The stacklevel of this helper function is already taken into account.
-