zepben.ewb 1.0.0b4__py3-none-any.whl → 1.0.0b5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zepben/ewb/__init__.py +1 -1
- zepben/ewb/database/sql/__init__.py +4 -0
- zepben/ewb/database/{sqlite/tables → sql}/column.py +1 -1
- zepben/ewb/database/sql/sql_table.py +142 -0
- zepben/ewb/database/sqlite/tables/associations/table_asset_organisation_roles_assets.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_assets_power_system_resources.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_battery_units_battery_controls.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_circuits_substations.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_circuits_terminals.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_customer_agreements_pricing_structures.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_end_devices_end_device_functions.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_equipment_equipment_containers.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_equipment_operational_restrictions.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_equipment_usage_points.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_loops_substations.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_pricing_structures_tariffs.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_protection_relay_functions_protected_switches.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_protection_relay_functions_sensors.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_protection_relay_schemes_protection_relay_functions.py +1 -1
- zepben/ewb/database/sqlite/tables/associations/table_usage_points_end_devices.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61968/assetinfo/table_reclose_delays.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61968/assetinfo/table_relay_info.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61968/metering/table_pan_demand_response_functions.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/feeder/table_lv_feeders.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_distance_relays.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_function_thresholds.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_function_time_limits.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_functions.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_schemes.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_systems.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/wires/table_battery_controls.py +1 -1
- zepben/ewb/database/sqlite/tables/extensions/iec61970/base/wires/table_power_transformer_end_ratings.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_no_load_tests.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_open_circuit_tests.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_short_circuit_tests.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_shunt_compensator_info.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_switch_info.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_transformer_end_info.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_transformer_tank_info.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_transformer_test.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_wire_info.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assets/table_assets.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/assets/table_streetlights.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/common/table_documents.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/common/table_location_street_addresses.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/common/table_organisation_roles.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/common/table_position_points.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/common/table_street_addresses.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/common/table_town_details.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/customers/table_customer_agreements.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/customers/table_customers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/infiec61968/infassetinfo/table_current_transformer_info.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/infiec61968/infassetinfo/table_potential_transformer_info.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/infiec61968/infassets/table_poles.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/metering/table_end_device_functions.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/metering/table_end_devices.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61968/metering/table_usage_points.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/auxiliaryequipment/table_auxiliary_equipment.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/auxiliaryequipment/table_current_transformers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/auxiliaryequipment/table_potential_transformers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_base_voltages.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_conducting_equipment.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_curve_data.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_equipment.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_feeders.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_identified_objects.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_name_types.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_names.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_power_system_resources.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_sub_geographical_regions.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_substations.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/core/table_terminals.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/diagramlayout/table_diagram_object_points.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/diagramlayout/table_diagram_objects.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/diagramlayout/table_diagrams.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/equivalents/table_equivalent_branches.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/generation/production/table_battery_units.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/generation/production/table_power_electronics_units.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/meas/table_analogs.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/meas/table_controls.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/meas/table_measurements.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/protection/table_current_relays.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/scada/table_remote_controls.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/scada/table_remote_sources.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_ac_line_segments.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_breakers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_clamps.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_conductors.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_cuts.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_earth_fault_compensators.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_consumer_phases.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_consumers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_source_phases.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_sources.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_fuses.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_grounding_impedances.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_linear_shunt_compensators.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_per_length_sequence_impedances.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_petersen_coils.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_phase_impedance_data.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_electronics_connection_phases.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_electronics_connections.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_transformer_ends.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_transformers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_protected_switches.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_ratio_tap_changers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_regulating_cond_eq.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_regulating_controls.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_rotating_machines.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_series_compensators.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_shunt_compensators.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_static_var_compensator.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_switches.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_synchronous_machines.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_tap_changer_controls.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_tap_changers.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_transformer_ends.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_transformer_star_impedances.py +1 -1
- zepben/ewb/database/sqlite/tables/iec61970/infiec61970/feeder/table_circuits.py +1 -1
- zepben/ewb/database/sqlite/tables/sqlite_table.py +21 -118
- zepben/ewb/database/sqlite/tables/table_metadata_data_sources.py +1 -1
- zepben/ewb/database/sqlite/tables/table_version.py +2 -1
- {zepben_ewb-1.0.0b4.dist-info → zepben_ewb-1.0.0b5.dist-info}/METADATA +1 -1
- {zepben_ewb-1.0.0b4.dist-info → zepben_ewb-1.0.0b5.dist-info}/RECORD +127 -125
- {zepben_ewb-1.0.0b4.dist-info → zepben_ewb-1.0.0b5.dist-info}/WHEEL +0 -0
- {zepben_ewb-1.0.0b4.dist-info → zepben_ewb-1.0.0b5.dist-info}/licenses/LICENSE +0 -0
- {zepben_ewb-1.0.0b4.dist-info → zepben_ewb-1.0.0b5.dist-info}/top_level.txt +0 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
__all__ = ["TableStaticVarCompensators"]
|
|
7
7
|
|
|
8
8
|
from zepben.ewb import TableRegulatingCondEq
|
|
9
|
-
from zepben.ewb.database.
|
|
9
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class TableStaticVarCompensators(TableRegulatingCondEq):
|
|
@@ -7,7 +7,7 @@ __all__ = ["TableSwitches"]
|
|
|
7
7
|
|
|
8
8
|
from abc import ABC
|
|
9
9
|
|
|
10
|
-
from zepben.ewb.database.
|
|
10
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
11
11
|
from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_conducting_equipment import TableConductingEquipment
|
|
12
12
|
|
|
13
13
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
__all__ = ["TableSynchronousMachines"]
|
|
7
7
|
|
|
8
|
-
from zepben.ewb.database.
|
|
8
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
9
9
|
from zepben.ewb.database.sqlite.tables.iec61970.base.wires.table_rotating_machines import TableRotatingMachines
|
|
10
10
|
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
__all__ = ["TableTapChangerControls"]
|
|
7
7
|
|
|
8
|
-
from zepben.ewb.database.
|
|
8
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
9
9
|
from zepben.ewb.database.sqlite.tables.iec61970.base.wires.table_regulating_controls import TableRegulatingControls
|
|
10
10
|
|
|
11
11
|
|
|
@@ -7,7 +7,7 @@ __all__ = ["TableTapChangers"]
|
|
|
7
7
|
|
|
8
8
|
from abc import ABC
|
|
9
9
|
|
|
10
|
-
from zepben.ewb.database.
|
|
10
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
11
11
|
from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_power_system_resources import TablePowerSystemResources
|
|
12
12
|
|
|
13
13
|
|
|
@@ -8,7 +8,7 @@ __all__ = ["TableTransformerEnds"]
|
|
|
8
8
|
from abc import ABC
|
|
9
9
|
from typing import List, Generator
|
|
10
10
|
|
|
11
|
-
from zepben.ewb.database.
|
|
11
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
12
12
|
from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_identified_objects import TableIdentifiedObjects
|
|
13
13
|
|
|
14
14
|
|
|
@@ -7,7 +7,7 @@ __all__ = ["TableTransformerStarImpedances"]
|
|
|
7
7
|
|
|
8
8
|
from typing import List, Generator
|
|
9
9
|
|
|
10
|
-
from zepben.ewb.database.
|
|
10
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
11
11
|
from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_identified_objects import TableIdentifiedObjects
|
|
12
12
|
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ __all__ = ["TableCircuits"]
|
|
|
7
7
|
|
|
8
8
|
from typing import List, Generator
|
|
9
9
|
|
|
10
|
-
from zepben.ewb.database.
|
|
10
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
11
11
|
from zepben.ewb.database.sqlite.tables.iec61970.base.wires.table_lines import TableLines
|
|
12
12
|
|
|
13
13
|
|
|
@@ -7,136 +7,39 @@ from __future__ import annotations
|
|
|
7
7
|
|
|
8
8
|
__all__ = ["SqliteTable"]
|
|
9
9
|
|
|
10
|
-
from abc import
|
|
11
|
-
from typing import List,
|
|
10
|
+
from abc import ABC
|
|
11
|
+
from typing import List, Generator
|
|
12
12
|
|
|
13
|
-
from zepben.ewb.database.
|
|
13
|
+
from zepben.ewb.database.sql.column import Column
|
|
14
|
+
from zepben.ewb.database.sql.sql_table import SqlTable
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
class SqliteTable(object):
|
|
17
|
+
class SqliteTable(SqlTable, ABC):
|
|
18
18
|
"""
|
|
19
|
-
Represents a table in an Sqlite Database.
|
|
20
|
-
Methods that need to be overridden are those marked @abstractmethod.
|
|
21
|
-
Methods that can be optionally overridden are unique_index_columns() and non_unique_index_columns().
|
|
22
|
-
Columns must be assigned in __init__ and column_index must be incremented for each Column created.
|
|
23
|
-
See existing implementations such as TableVersion for examples.
|
|
19
|
+
Represents a table in an Sqlite Database.
|
|
24
20
|
"""
|
|
25
21
|
|
|
26
|
-
column_index: int = 0
|
|
27
|
-
"""Used to specify index of the column in the table during initialisation. Always increment BEFORE creating a Column. Indices start from 1."""
|
|
28
|
-
|
|
29
|
-
_column_set: Optional[List[Column]] = None
|
|
30
|
-
_create_table_sql: Optional[str] = None
|
|
31
|
-
_prepared_insert_sql: Optional[str] = None
|
|
32
|
-
_prepared_update_sql: Optional[str] = None
|
|
33
|
-
_create_indexes_sql: Optional[List[str]] = None
|
|
34
|
-
_select_sql: Optional[str] = None
|
|
35
|
-
|
|
36
|
-
@property
|
|
37
|
-
@abstractmethod
|
|
38
|
-
def name(self) -> str:
|
|
39
|
-
pass
|
|
40
|
-
|
|
41
|
-
#
|
|
42
|
-
# NOTE: This function is called `description` in teh JVM SDK, but in the python SDK this
|
|
43
|
-
# conflicts with the `description` column of `TableIdentifiedObjects`.
|
|
44
|
-
#
|
|
45
|
-
def describe(self) -> str:
|
|
46
|
-
return self.name.replace("_", " ")
|
|
47
|
-
|
|
48
22
|
@property
|
|
49
23
|
def create_table_sql(self):
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def prepared_insert_sql(self):
|
|
54
|
-
return self._prepared_insert_sql if self._prepared_insert_sql else self._build_prepared_insert_sql()
|
|
24
|
+
if self._create_table_sql is None:
|
|
25
|
+
self._create_table_sql = self._build_create_table_sql()
|
|
26
|
+
return self._create_table_sql
|
|
55
27
|
|
|
56
28
|
@property
|
|
57
29
|
def create_indexes_sql(self):
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
def select_sql(self):
|
|
62
|
-
return self._select_sql if self._select_sql else self._build_select_sql()
|
|
63
|
-
|
|
64
|
-
@property
|
|
65
|
-
def prepared_update_sql(self):
|
|
66
|
-
return self._prepared_update_sql if self._prepared_update_sql else self._build_prepared_update_sql()
|
|
67
|
-
|
|
68
|
-
@property
|
|
69
|
-
def unique_index_columns(self) -> Generator[List[Column], None, None]:
|
|
70
|
-
# To make this a generator we need to `yield`, but we have nothing to yield by default, so trick it by yielding from an empty for-loop.
|
|
71
|
-
for it in []:
|
|
72
|
-
yield it
|
|
73
|
-
|
|
74
|
-
@property
|
|
75
|
-
def non_unique_index_columns(self) -> Generator[List[Column], None, None]:
|
|
76
|
-
# To make this a generator we need to `yield`, but we have nothing to yield by default, so trick it by yielding from an empty for-loop.
|
|
77
|
-
for it in []:
|
|
78
|
-
yield it
|
|
79
|
-
|
|
80
|
-
@property
|
|
81
|
-
def column_set(self) -> List[Column]:
|
|
82
|
-
return self._column_set if self._column_set else self._build_column_set(self.__class__, self)
|
|
83
|
-
|
|
84
|
-
def _build_column_set(self, clazz: Type[Any], instance: SqliteTable) -> List[Column]:
|
|
85
|
-
"""
|
|
86
|
-
Builds the list of columns for use in DDL statements for this table.
|
|
87
|
-
|
|
88
|
-
:param clazz: The class of this table.
|
|
89
|
-
:param instance:
|
|
90
|
-
:return:
|
|
91
|
-
"""
|
|
92
|
-
cols = list()
|
|
93
|
-
for field, x in instance.__dict__.items():
|
|
94
|
-
if isinstance(x, Column):
|
|
95
|
-
if x.query_index != len(cols) + 1:
|
|
96
|
-
raise ValueError(
|
|
97
|
-
f"Field {field} in SQL Table class {clazz.__name__} is using an invalid column index. "
|
|
98
|
-
f"Did you forget to increment column_index, or did you skip one?"
|
|
99
|
-
)
|
|
100
|
-
cols.append(x)
|
|
101
|
-
|
|
102
|
-
if len(set([c.name for c in cols])) != len(cols):
|
|
103
|
-
raise ValueError("You have a duplicate column names, go fix that.")
|
|
104
|
-
|
|
105
|
-
self._column_set = sorted(cols, key=lambda it: it.query_index)
|
|
106
|
-
return self._column_set
|
|
107
|
-
|
|
108
|
-
def _build_create_table_sql(self) -> str:
|
|
109
|
-
self._create_table_sql = f"CREATE TABLE {self.name} ({', '.join([str(c) for c in self.column_set])})"
|
|
110
|
-
return self._create_table_sql
|
|
111
|
-
|
|
112
|
-
def _build_prepared_insert_sql(self) -> str:
|
|
113
|
-
self._prepared_insert_sql = f"INSERT INTO {self.name} ({', '.join([c.name for c in self.column_set])}) " \
|
|
114
|
-
f"VALUES ({', '.join(['?' for _ in self.column_set])})"
|
|
115
|
-
return self._prepared_insert_sql
|
|
116
|
-
|
|
117
|
-
def _build_indexes_sql(self) -> List[str]:
|
|
118
|
-
statements = []
|
|
119
|
-
for index_col in self.unique_index_columns:
|
|
120
|
-
statements.append(self._build_index_sql(index_col, True))
|
|
121
|
-
for index_col in self.non_unique_index_columns:
|
|
122
|
-
statements.append(self._build_index_sql(index_col, False))
|
|
123
|
-
self._create_indexes_sql = statements
|
|
30
|
+
if self._create_indexes_sql is None:
|
|
31
|
+
self._create_indexes_sql = list(self._build_indexes_sql())
|
|
124
32
|
return self._create_indexes_sql
|
|
125
33
|
|
|
126
|
-
def
|
|
127
|
-
|
|
128
|
-
col_string = ', '.join(map(lambda c: c.name, index_col))
|
|
129
|
-
return f"CREATE {'UNIQUE ' if is_unique else ''}INDEX {id_string} ON {self.name} ({col_string})"
|
|
130
|
-
|
|
131
|
-
def _build_select_sql(self) -> str:
|
|
132
|
-
self._select_sql = f"SELECT {', '.join([c.name for c in self.column_set])} FROM {self.name}"
|
|
133
|
-
return self._select_sql
|
|
34
|
+
def _build_create_table_sql(self) -> str:
|
|
35
|
+
return f"CREATE TABLE {self.name} ({', '.join(str(c) for c in self.column_set)})"
|
|
134
36
|
|
|
135
|
-
def
|
|
136
|
-
|
|
137
|
-
|
|
37
|
+
def _build_indexes_sql(self) -> Generator[str, None, None]:
|
|
38
|
+
yield from (self._build_index_sql(index_col, True) for index_col in self.unique_index_columns)
|
|
39
|
+
yield from (self._build_index_sql(index_col, False) for index_col in self.non_unique_index_columns)
|
|
138
40
|
|
|
139
|
-
def
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
41
|
+
def _build_index_sql(self, index_col: List[Column], is_unique: bool) -> str:
|
|
42
|
+
index_col_names = [c.name for c in index_col]
|
|
43
|
+
return (f"CREATE {'UNIQUE ' if is_unique else ''}INDEX "
|
|
44
|
+
f"{self.name}_{'_'.join(index_col_names)}" # id string
|
|
45
|
+
f" ON {self.name} ({', '.join(index_col_names)})") # col string
|
|
@@ -9,7 +9,7 @@ import sqlite3
|
|
|
9
9
|
from sqlite3 import Cursor
|
|
10
10
|
from typing import Optional
|
|
11
11
|
|
|
12
|
-
from zepben.ewb.database.
|
|
12
|
+
from zepben.ewb.database.sql.column import Column, Nullable
|
|
13
13
|
from zepben.ewb.database.sqlite.tables.sqlite_table import SqliteTable
|
|
14
14
|
|
|
15
15
|
|
|
@@ -17,6 +17,7 @@ class TableVersion(SqliteTable):
|
|
|
17
17
|
SUPPORTED_VERSION = 59
|
|
18
18
|
|
|
19
19
|
def __init__(self):
|
|
20
|
+
super().__init__()
|
|
20
21
|
self.version: Column = self._create_column("version", "TEXT", Nullable.NOT_NULL)
|
|
21
22
|
|
|
22
23
|
@property
|