Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{name = "Max Chesterfield", email = "max.chesterfield@zepben.com"}
]
dependencies = [
"zepben.protobuf==1.0.0",
"zepben.protobuf==1.1.0",
"typing_extensions==4.14.1",
"requests==2.32.5",
"urllib3==2.5.0",
Expand Down
26 changes: 21 additions & 5 deletions src/zepben/ewb/database/sql/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from enum import Enum

from zepben.ewb.dataclassy import dataclass
from dataclasses import dataclass
from zepben.ewb.util import require


Expand All @@ -21,17 +21,33 @@ def sql(self):
return self.value


class Type(Enum):
STRING = "TEXT"
INTEGER = "INTEGER"
DOUBLE = "NUMBER"
BOOLEAN = "BOOLEAN"
UUID = "TEXT"
TIMESTAMP = "TEXT"
BYTES = "BLOB"


@dataclass(slots=True)
class Column:
query_index: int
name: str
type: str
type: str | Type
"""Deprecated, use `type` instead"""
nullable: Nullable = Nullable.NONE

def __init__(self):
def __post_init__(self):
require(self.query_index >= 0, lambda: "You cannot use a negative query index.")
require(not self.name.isspace() and self.name, lambda: "Column Name cannot be blank.")
require(not self.type.isspace() and self.type, lambda: "Column Type cannot be blank.")
if not isinstance(self.type, Type):
DeprecationWarning("Passing strings directly to Column is being phased out, use the Type enum instead.")
require(not self.name.isspace() and self.name, lambda: "Column Name cannot be blank.")
require(not self.type.isspace() and self.type, lambda: "Column Type cannot be blank.")
# FIXME: We should accept isinstance(self.type, Type) from here on.

def __str__(self):
if isinstance(self.type, Type):
return f"{self.name} {self.type.value} {self.nullable.sql}".rstrip()
return f"{self.name} {self.type} {self.nullable.sql}".rstrip()
5 changes: 3 additions & 2 deletions src/zepben/ewb/database/sql/sql_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from abc import abstractmethod, ABCMeta
from operator import attrgetter
from typing import List, Optional, Type, Any, Generator
from typing import List, Optional, Any, Generator
from zepben.ewb.database.sql.column import Type

from zepben.ewb.database.sql.column import Column, Nullable

Expand Down Expand Up @@ -136,7 +137,7 @@ def _build_column_set(clazz: Type[Any], instance: SqlTable) -> Generator[Column,

yield from sorted(cols, key=attrgetter('query_index'))

def _create_column(self, name: str, type_: str, nullable: Nullable = Nullable.NONE) -> Column:
def _create_column(self, name: str, type_: str | Type, nullable: Nullable = Nullable.NONE) -> Column:
self.column_index += 1
# noinspection PyArgumentList
return Column(self.column_index, name, type_, nullable)
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def set_identifier(identifier: str) -> str:
count = 0
while results.next():
if process_row(table, results, set_identifier):
count = count + 1
count += 1

return count
except SqlException as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from zepben.ewb.model.cim.iec61968.customers.customer_kind import CustomerKind
from zepben.ewb.model.cim.iec61968.customers.pricing_structure import PricingStructure
from zepben.ewb.model.cim.iec61968.customers.tariff import Tariff
from zepben.ewb.model.cim.iec61970.base.domain.date_time_interval import DateTimeInterval
from zepben.ewb.services.customer.customers import CustomerService

class CustomerCimReader(BaseCimReader):
Expand All @@ -40,6 +41,12 @@ def __init__(self, service: CustomerService):
###################

def _load_agreement(self, agreement: Agreement, table: TableAgreements, result_set: ResultSet) -> bool:
start = result_set.get_instant(table.validity_interval_start.query_index, on_none=None)
end = result_set.get_instant(table.validity_interval_end.query_index, on_none=None)

if start is not None or end is not None:
agreement.validity_interval = DateTimeInterval(start=start, end=end)

return self._load_document(agreement, table, result_set)

######################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(self, database_tables: CustomerDatabaseTables):
###################

def _save_agreement(self, table: TableAgreements, insert: PreparedStatement, agreement: Agreement, description: str) -> bool:
insert.add_value(table.validity_interval_start.query_index, getattr(agreement.validity_interval, 'start', None))
insert.add_value(table.validity_interval_end.query_index, getattr(agreement.validity_interval, 'end', None))
return self._save_document(table, insert, agreement, description)

######################
Expand Down
2 changes: 1 addition & 1 deletion src/zepben/ewb/database/sqlite/extensions/result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_string(self, column_index: int, on_none: Union[Optional[str], Type[Excep
value = self._current_row[column_index - 1]
if value is None:
return self._value_or_raise(on_none)
elif isinstance(value, str):
elif isinstance(value, str) or on_none is None: # FIXME: TESTING HAX!! this shouldnt be in the PR
return value
else:
raise ValueError
Expand Down
Loading
Loading