tables.BaseColumns
Base class for column enumeration-like access.
Usage
tables.BaseColumns(table)Provides dictionary-like access to table columns.
Attributes
| Name | Description |
|---|---|
| detached | Columns in the database that restore_user_defined can restore. |
| user_defined | Names of the user-defined columns currently shown in MIKE+. |
detached
Columns in the database that restore_user_defined can restore.
detached: list[str]
These are database columns of the table that are neither standard MIKE+ columns nor currently user-defined, for example after remove_user_defined.
user_defined
Names of the user-defined columns currently shown in MIKE+.
user_defined: list[str]
Methods
| Name | Description |
|---|---|
| __contains__() | Check for a column using case-insensitive matching. |
| __getitem__() | Resolve a column name to its canonical MIKE+ casing. |
| __init__() | Initialize with a reference to the parent table. |
| __iter__() | Make the columns iterable. |
| add_user_defined() | Add a user-defined column, like “Add user defined column” in MIKE+. |
| db_types() | Map casefolded column names to their database types. |
| remove_user_defined() | Remove a user-defined column, like “Remove column” in MIKE+. |
| restore_user_defined() | Restore a detached column with its existing data type and data. |
__contains__()
Check for a column using case-insensitive matching.
Usage
__contains__(item)Parameters
item: str- Column name in any casing.
Returns
bool- Whether a matching column exists.
__getitem__()
Resolve a column name to its canonical MIKE+ casing.
Usage
__getitem__(column_name)Parameters
column_name: str- Column name in any casing.
Returns
str- The canonical MIKE+ column name.
Raises
KeyError-
If no column matches
column_name.
__init__()
Initialize with a reference to the parent table.
Usage
__init__(table)Parameters
table: BaseTable- Reference to the parent BaseTable instance
__iter__()
Make the columns iterable.
Usage
__iter__()Returns
Iterator[str]- Iterator over column names
add_user_defined()
Add a user-defined column, like “Add user defined column” in MIKE+.
Usage
add_user_defined(name, data_type, header=None)Safe to call repeatedly: the column is created if it doesn’t exist, restored if it is in detached, and left unchanged if it is already user-defined.
Parameters
name: str-
Field name of the column. Case-insensitive: an existing or detached column matches regardless of casing. A new or restored column is stored with the casing given here.
data_type: str-
One of ‘integer’, ‘double’, ‘string’, ‘datetime’, in any casing. If the column already exists, it must match the existing type.
header: str or None = None- Header shown in the MIKE+ GUI. Defaults to name. Ignored if the column is already user-defined.
Returns
str-
MUID of the column’s record in
m_UserDefinedColumn, the same whether the column was created, restored or already there.
Raises
ValueError-
If name is a standard MIKE+ column, or if
data_typeis invalid or doesn’t match the existing column.
Examples
>>> pipes = db.tables.msm_Link
>>> pipes.columns.add_user_defined("install_year", "integer")‘udf_1’
db_types()
Map casefolded column names to their database types.
Usage
db_types()Read from the .NET table on each call, unlike the cached names, so user-defined columns added after construction are included.
Returns
dict[str, DbType]-
Casefolded column names mapped to their
DbType.
remove_user_defined()
Remove a user-defined column, like “Remove column” in MIKE+.
Usage
remove_user_defined(name)The column is no longer shown in MIKE+, but it stays in the database with its data and appears in detached. Restore it with restore_user_defined.
Parameters
name: str- Field name of the column. Case-insensitive.
Returns
str-
MUID of the removed
m_UserDefinedColumnrecord.
Raises
KeyError- If name isn’t a user-defined column of this table.
Examples
>>> pipes = db.tables.msm_Link
>>> pipes.columns.add_user_defined("install_year", "integer")‘udf_1’
>>> pipes.columns.remove_user_defined("install_year")‘udf_1’
>>> pipes.columns.detached[‘install_year’]
restore_user_defined()
Restore a detached column with its existing data type and data.
Usage
restore_user_defined(name)Parameters
name: str- Field name of a column in detached. Case-insensitive; the restored column is stored with the casing given here.
Returns
str-
MUID of the column’s new record in
m_UserDefinedColumn.
Raises
Examples
>>> pipes = db.tables.msm_Link
>>> pipes.columns.add_user_defined("install_year", "integer")‘udf_1’
>>> pipes.columns.remove_user_defined("install_year")‘udf_1’
>>> pipes.columns.restore_user_defined("install_year")‘udf_2’