gensaschema._table module

Table inspection and representation

Table inspection and representation

Copyright:

Copyright 2010 - 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.

class gensaschema._table.Table(varname, table, schemas, symbols)[source]

Reflected table

varname

Variable name

Type:

str

sa_table

Table

Type:

sqlalchemy.Table

constraints

Constraint list

Type:

list

_symbols

Symbol table

Type:

gensaschema.Symbols

__dict__ = mappingproxy({'__module__': 'gensaschema._table', '__doc__': '\n    Reflected table\n\n\n    Attributes:\n      varname (str):\n        Variable name\n\n      sa_table (sqlalchemy.Table):\n        Table\n\n      constraints (list):\n        Constraint list\n\n      _symbols (Symbols):\n        Symbol table\n    ', 'is_reference': False, '__new__': <staticmethod(<function Table.__new__>)>, '__init__': <function Table.__init__>, 'by_name': <classmethod(<function Table.by_name>)>, '__repr__': <function Table.__repr__>, '__dict__': <attribute '__dict__' of 'Table' objects>, '__weakref__': <attribute '__weakref__' of 'Table' objects>, '__annotations__': {}})
__init__(varname, table, schemas, symbols)[source]

Initialization

Parameters:
  • varname (str) – Variable name

  • table (sqlalchemy.Table) – Table

  • schemas (dict) – Schema -> module mapping

  • symbols (gensaschema.Symbols) – Symbol table

__module__ = 'gensaschema._table'
static __new__(cls, varname, table, schemas, symbols)[source]

Construct

This might actually return a table reference

Parameters:
  • varname (str) – Variable name

  • table (sqlalchemy.Table) – Table

  • schemas (dict) – Schema -> module mapping

  • symbols (gensaschema.Symbols) – Symbol table

Returns:

New instance

Return type:

Table or TableReference

__repr__()[source]

Make string representation

Returns:

The string representation

Return type:

str

__weakref__

list of weak references to the object (if defined)

classmethod by_name(name, varname, metadata, schemas, symbols, types=None)[source]

Construct by name

Parameters:
  • name (str) – Table name (possibly qualified)

  • varname (str) – Variable name of the table

  • metadata (SA (bound) metadata) – Metadata container

  • schemas (dict) – Schema -> module mapping

  • symbols (gensaschema.Symbols) – Symbol table

  • 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 or None, the reflector will always fail on unknown types.

Returns:

new Table instance

Return type:

Table

is_reference = False

Is it a table reference (vs. a table)?

Type:

bool

class gensaschema._table.TableCollection(iterable=(), /)[source]

Table collection

__dict__ = mappingproxy({'__module__': 'gensaschema._table', '__doc__': 'Table collection', 'by_names': <classmethod(<function TableCollection.by_names>)>, '__dict__': <attribute '__dict__' of 'TableCollection' objects>, '__annotations__': {}})
__module__ = 'gensaschema._table'
classmethod by_names(metadata, names, schemas, symbols, types=None)[source]

Construct by table names

Parameters:
  • metadata (sqlalchemy.MetaData) – Metadata

  • names (iterable) – Name list (list of tuples (varname, name))

  • symbols (gensaschema.Symbols) – Symbol table

  • 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 or None, the reflector will always fail on unknown types.

Returns:

New table collection instance

Return type:

TableCollection

class gensaschema._table.TableReference(varname, table, schema, symbols)[source]

Referenced table

varname

Variable name

Type:

str

sa_table

Table

Type:

sqlalchemy.Table

constraints

Constraint list

Type:

list

__dict__ = mappingproxy({'__module__': 'gensaschema._table', '__doc__': '\n    Referenced table\n\n    Attributes:\n      varname (str):\n        Variable name\n\n      sa_table (sqlalchemy.Table):\n        Table\n\n      constraints (list):\n        Constraint list\n    ', 'is_reference': True, '__init__': <function TableReference.__init__>, '__dict__': <attribute '__dict__' of 'TableReference' objects>, '__weakref__': <attribute '__weakref__' of 'TableReference' objects>, '__annotations__': {}})
__init__(varname, table, schema, symbols)[source]

Initialization

Parameters:
  • varname (str) – Variable name

  • table (sqlalchemy.Table) – Table

  • symbols (gensaschema.Symbols) – Symbol table

__module__ = 'gensaschema._table'
__weakref__

list of weak references to the object (if defined)

is_reference = True

Is it a table reference (vs. a table)?

Type:

bool

gensaschema._table._break_cycles(metadata)[source]

Find foreign key cycles and break them apart

Parameters:

metadata (sqlalchemy.MetaData) – Metadata