mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 18:03:31 +01:00
64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
import abc
|
||
|
|
|
||
|
|
from jwutils.log import *
|
||
|
|
from jwutils.misc import load_classes
|
||
|
|
from jwutils.Cmds import Cmds
|
||
|
|
from jwutils.db.DataBase import DataBase
|
||
|
|
from jwutils.db.query.QueryResult import QueryResult
|
||
|
|
#from jwutils.db.query.Queries import Queries
|
||
|
|
|
||
|
|
class Query(abc.ABC): # export
|
||
|
|
|
||
|
|
def __init__(self, parent: Any) -> None:
|
||
|
|
self.__parent = parent
|
||
|
|
|
||
|
|
# -- pure virtuals
|
||
|
|
|
||
|
|
@abc.abstractmethod
|
||
|
|
def _run(self, *args, **kwargs) -> QueryResult:
|
||
|
|
raise Exception('Called pure virtual _run()')
|
||
|
|
|
||
|
|
@abc.abstractmethod
|
||
|
|
def _register(self):
|
||
|
|
raise Exception('Called pure virtual _register()')
|
||
|
|
|
||
|
|
@abc.abstractmethod
|
||
|
|
def _column_names(self) -> list[str]:
|
||
|
|
raise Exception('Called pure virtual _column()')
|
||
|
|
|
||
|
|
# -- used by Queries class
|
||
|
|
|
||
|
|
def register(self):
|
||
|
|
return self._register()
|
||
|
|
|
||
|
|
# -- to be used
|
||
|
|
|
||
|
|
def _add(self, query_name: str, location: str, func: Any):
|
||
|
|
return self.__parent.add(self, query_name, location, func)
|
||
|
|
|
||
|
|
def run(self, *args, **kwargs) -> QueryResult:
|
||
|
|
return self._run(*args, **kwargs)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def parent(self):
|
||
|
|
return self.__parent
|
||
|
|
|
||
|
|
@property
|
||
|
|
def db(self) -> DataBase:
|
||
|
|
return self.__parent.db
|
||
|
|
|
||
|
|
@property
|
||
|
|
def schema(self):
|
||
|
|
return self.__parent.db.schema
|
||
|
|
|
||
|
|
@property
|
||
|
|
def app(self) -> Cmds:
|
||
|
|
return self.__parent.app
|
||
|
|
|
||
|
|
@property
|
||
|
|
def column_names(self) -> list[str]:
|
||
|
|
return self._column_names()
|