gensaschema package¶
Submodules¶
- gensaschema._column module
- gensaschema._config module
- gensaschema._constraint module
- gensaschema._exceptions module
- gensaschema._meta module
- gensaschema._schema module
- gensaschema._symbols module
- gensaschema._table module
- gensaschema._template module
- gensaschema._type module
- gensaschema._util module
- gensaschema.constraints module
Module contents¶
- Copyright:
Copyright 2014 - 2023 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)[source]¶
Schema config container
- tables¶
Table list
- Type:
list
- schemas¶
Alien schema mapping
- Type:
dict
- _lines¶
Original config lines (or
None
)- Type:
list
- _CONFIG_TPL = <gensaschema._template.Template object>¶
Template for empty config file
- Type:
Template
- __dict__ = mappingproxy({'__module__': 'gensaschema._config', '__doc__': '\n Schema config container\n\n Attributes:\n tables (list):\n Table list\n\n schemas (dict):\n Alien schema mapping\n\n _lines (list):\n Original config lines (or ``None``)\n ', '_CONFIG_TPL': <gensaschema._template.Template object>, '__init__': <function Config.__init__>, 'from_file': <classmethod(<function Config.from_file>)>, 'from_lines': <classmethod(<function Config.from_lines>)>, 'from_parser': <classmethod(<function Config.from_parser>)>, 'dump': <function Config.dump>, '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__annotations__': {}})¶
- __init__(tables, schemas, lines=None)[source]¶
Initialization
- Parameters:
tables (
list
) – Table listschemas (
dict
) – (Alien) Schema mappinglines (
iterable
) – Original config lines. If omitted orNone
, the config lines are not available.
- __module__ = 'gensaschema._config'¶
- __weakref__¶
list of weak references to the object (if defined)
- classmethod from_file(name_or_file)[source]¶
Construct from config file
- Parameters:
name_or_file (
str or file
) – Config filename or file pointer- Returns:
New Config instance
- Return type:
- Raises:
IOError – Error reading the file (except for ENOENT, which treats the file as empty)
- exception gensaschema.Error[source]¶
Base exception for this package
- __module__ = 'gensaschema._exceptions'¶
- __weakref__¶
list of weak references to the object (if defined)
- class gensaschema.Schema(conn, tables, schemas, symbols, dbname=None, types=None)[source]¶
Schema container
- _dialect¶
Dialect name
- Type:
str
- _tables¶
Table collection
- Type:
TableCollection
- _schemas¶
Schema -> module mapping
- Type:
dict
- _symbols¶
Symbol table
- Type:
- _dbname¶
DB identifier
- Type:
str or None
- _MODULE_TPL = <gensaschema._template.Template object>¶
Template for the module
- Type:
Template
- __dict__ = mappingproxy({'__module__': 'gensaschema._schema', '__doc__': '\n Schema container\n\n Attributes:\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 ', '_MODULE_TPL': <gensaschema._template.Template object>, '__init__': <function Schema.__init__>, 'dump': <function Schema.dump>, '__dict__': <attribute '__dict__' of 'Schema' objects>, '__weakref__': <attribute '__weakref__' of 'Schema' objects>, '__annotations__': {}})¶
- __init__(conn, tables, schemas, symbols, dbname=None, types=None)[source]¶
Initialization
- Parameters:
conn (
Connection or Engine
) – SQLAlchemy connection or enginetables (
list
) – List of tables to reflect, (local name, table name) pairsschemas (
dict
) – schema -> module mappingsymbols (gensaschema.Symbols) – Symbol table
dbname (
str
) – Optional db identifier. Used for informational purposes. If omitted orNone
, 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’sischema_names
. If omitted orNone
, the reflector will always fail on unknown types.
- __module__ = 'gensaschema._schema'¶
- __weakref__¶
list of weak references to the object (if defined)
- exception gensaschema.SymbolException[source]¶
Symbol error
- __annotations__ = {}¶
- __module__ = 'gensaschema._symbols'¶
- class gensaschema.Symbols(symbols=None, imports=None)[source]¶
Symbol table
- _symbols¶
Symbols
- Type:
dict
- imports¶
Import container
- Type:
_Imports
- types¶
Type container
- Type:
_Types
- __contains__(name)[source]¶
Check symbol table entry
- Parameters:
name (
str
) – Symbol identifier- Returns:
Does the symbol entry exist?
- Return type:
bool
- __delitem__(name)[source]¶
Remove symbol entry if available
- Parameters:
name (
str
) – Symbol identifier
- __dict__ = mappingproxy({'__module__': 'gensaschema._symbols', '__doc__': '\n Symbol table\n\n Attributes:\n _symbols (dict):\n Symbols\n\n imports (_Imports):\n Import container\n\n types (_Types):\n Type container\n ', '__init__': <function Symbols.__init__>, '__delitem__': <function Symbols.__delitem__>, '__setitem__': <function Symbols.__setitem__>, '__getitem__': <function Symbols.__getitem__>, '__contains__': <function Symbols.__contains__>, '__iter__': <function Symbols.__iter__>, '__dict__': <attribute '__dict__' of 'Symbols' objects>, '__weakref__': <attribute '__weakref__' of 'Symbols' objects>, '__annotations__': {}})¶
- __getitem__(name)[source]¶
Get symbol table entry
- Parameters:
name (
str
) – Symbol identifier- Returns:
The symbol
- Return type:
str
- Raises:
KeyError – Symbol not found
- __init__(symbols=None, imports=None)[source]¶
Initialization
- Parameters:
symbols (
dict
) – Initial symbolsimports (
iterable
) – List of initial (id, import statement) tuples. If omitted orNone
, it’s empty.
- __module__ = 'gensaschema._symbols'¶
- __setitem__(name, symbol)[source]¶
Set symbol table entry
- Parameters:
name (
str
) – Symbol identifiersymbol (
str
) – Symbol
- Raises:
SymbolException – Symbol could not be set because of some conflict
- __weakref__¶
list of weak references to the object (if defined)
- class gensaschema.Type(ctype, dialect_name, symbols)[source]¶
Type container
- _ctype¶
Column type
- Type:
SA type
- _dialect¶
Dialect name
- Type:
str
- _symbols¶
Symbol table
- Type:
- __dict__ = mappingproxy({'__module__': 'gensaschema._type', '__doc__': '\n Type container\n\n Attributes:\n _ctype (SA type):\n Column type\n\n _dialect (str):\n Dialect name\n\n _symbols (Symbols):\n Symbol table\n ', '__init__': <function Type.__init__>, 'by_column': <classmethod(<function Type.by_column>)>, '__repr__': <function Type.__repr__>, '__dict__': <attribute '__dict__' of 'Type' objects>, '__weakref__': <attribute '__weakref__' of 'Type' objects>, '__annotations__': {}})¶
- __init__(ctype, dialect_name, symbols)[source]¶
Initialization
- Parameters:
ctype (
SA type
) – Column typedialect_name (
str
) – Dialect namesymbols (gensaschema.Symbols) – Symbol table
- __module__ = 'gensaschema._type'¶
- __weakref__¶
list of weak references to the object (if defined)
- exception gensaschema.Warning[source]¶
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)[source]¶
Emit a warning of this very category
This method is pure convenience. It saves you the unfriendly
warnings.warn
syntax (and thewarnings
import).- Parameters:
- messageany
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.