Constraint factory¶
Factory producing a class for defining a table-level constraint on the database table, permit to support a composite primary key. Contains the Field class for defining column-level constraints.
xlsx2sqlite.constraint_factory module¶
-
class
xlsx2sqlite.constraint_factory.Field(field_name=None, field_type=None, definition=None)¶ Bases:
objectRepresents a database field.
- Parameters
type_of (str) –
The type to assign to the database table column, choose between:
Field: generic field without a column level constraint
Unique: field with a UNIQUE clause
PrimaryKey: field with PRIMARY KEY column level constraint
NotNullField: set a NOT NULL column constraint on the database column
field_name (str) – Label for the column of the database table.
field_type (str) – Column type as a string defined in sqlite column types.
definition (str) – Type of column-level constraint to declare.
- Returns
An instance of a Field object with a to_sql() method that returns an appropriate SQL string.
- Return type
object
-
DEFINITIONS= {'Field': None, 'Unique': 'UNIQUE', 'PrimaryKey': 'NOT NULL PRIMARY KEY', 'NotNull': 'NOT NULL', None: None}¶
-
SPACE_DELIM= ' '¶ This dictionary represents the column-level constraints as SQL strings.
-
label()¶ A form of the string with the leading and trailing characters removed.
- Returns
A form of the string with the leading and trailing characters removed.
- Return type
str
-
to_sql()¶ Return a suitable string for using in the database.
- Returns
A capitalized form of the string with the leading and trailing characters removed.
- Return type
str
-
xlsx2sqlite.constraint_factory.create_table_constraint(clause: str, columns: list) → object¶ Table-level constraint class factory, valid clauses are:
“Unique”
“PrimaryKey”
- Returns
An instance of TableConstraint, a class that represents a SQL table level constraint
- Return type
object