modulitiz-micro 2.45.1__py311-none-any.whl → 2.46.0__py311-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.
Files changed (64) hide show
  1. modulitiz_micro/ModuloSeriale.py +70 -70
  2. modulitiz_micro/ModuloTarghe.py +47 -47
  3. modulitiz_micro/database/AbstractDatabaseService.py +13 -13
  4. modulitiz_micro/database/AbstractSql.py +69 -69
  5. modulitiz_micro/database/ModuloSqlOracle.py +19 -19
  6. modulitiz_micro/database/ModuloSqlServer.py +43 -43
  7. modulitiz_micro/database/eccezioni/EccezioneDbNoData.py +6 -6
  8. modulitiz_micro/database/mysql/AbstractBasicMysql.py +114 -114
  9. modulitiz_micro/database/mysql/ModuloMysql.py +163 -163
  10. modulitiz_micro/database/mysql/MysqlCommonConverter.py +47 -47
  11. modulitiz_micro/database/mysql/eccezioni/EccezioneMysqlOffline.py +6 -6
  12. modulitiz_micro/database/sqlite/AbstractBasicSQLite.py +114 -114
  13. modulitiz_micro/database/sqlite/ModuloSQLite.py +82 -82
  14. modulitiz_micro/eccezioni/EccezioneCtrlC.py +7 -7
  15. modulitiz_micro/eccezioni/EccezioneScheduler.py +7 -7
  16. modulitiz_micro/eccezioni/http/EccezioneHttp.py +8 -8
  17. modulitiz_micro/eccezioni/http/EccezioneHttp404.py +7 -7
  18. modulitiz_micro/eccezioni/http/EccezioneHttpGeneric.py +7 -7
  19. modulitiz_micro/files/cache/DatabaseCache.py +91 -91
  20. modulitiz_micro/files/cache/decorators/cacheRam.py +26 -26
  21. modulitiz_micro/files/git/ModuloGit.py +28 -28
  22. modulitiz_micro/files/git/decorators/catchAndRaiseGitExceptions.py +19 -19
  23. modulitiz_micro/files/git/exceptions/EccezioneGit.py +7 -7
  24. modulitiz_micro/gestionedom/GestioneDom.py +44 -44
  25. modulitiz_micro/iot/ModuleIotDevice.py +62 -62
  26. modulitiz_micro/keylogger/EccezioneKeyLogger.py +7 -7
  27. modulitiz_micro/keylogger/ModuloKeylogger.py +73 -73
  28. modulitiz_micro/rete/ModuleAndroidTVRemote.py +107 -0
  29. modulitiz_micro/rete/ModuloNetworking.py +67 -72
  30. modulitiz_micro/rete/ModuloOpenVpn.py +15 -15
  31. modulitiz_micro/rete/email/EmailBean.py +5 -5
  32. modulitiz_micro/rete/email/ModuloEmail.py +90 -90
  33. modulitiz_micro/rete/http/ModuloHttp.py +119 -119
  34. modulitiz_micro/rete/http/ModuloHttpConnectionSafe.py +91 -91
  35. modulitiz_micro/rete/http/ModuloHttpUtils.py +69 -69
  36. modulitiz_micro/rete/http/beans/HttpResponseBean.py +5 -5
  37. modulitiz_micro/rete/http/decorators/catchAndRaiseHttpExceptions.py +22 -22
  38. modulitiz_micro/rete/http/huawei/fusionsolar/ModuleHuaweiFusionSolar.py +84 -84
  39. modulitiz_micro/rete/http/huawei/fusionsolar/beans/TokenBean.py +28 -28
  40. modulitiz_micro/rete/http/huawei/fusionsolar/beans/device/DeviceBean.py +6 -6
  41. modulitiz_micro/rete/http/huawei/fusionsolar/beans/device/DeviceDataBattery.py +22 -22
  42. modulitiz_micro/rete/http/huawei/fusionsolar/beans/device/DeviceDataPowerSensor.py +49 -49
  43. modulitiz_micro/rete/http/huawei/fusionsolar/enums/DevTypeIdEnum.py +21 -21
  44. modulitiz_micro/rete/http/huawei/fusionsolar/exceptions/ExceptionTooManyLogins.py +7 -7
  45. modulitiz_micro/rete/http/huawei/fusionsolar/service/AbstractHuaweiFusionSolar.py +72 -72
  46. modulitiz_micro/rete/ntp/AbstractModuloNtp.py +73 -73
  47. modulitiz_micro/rete/ntp/ModuloNtpIt.py +8 -8
  48. modulitiz_micro/rete/socketserver/AbstractBasicGetSocketServer.py +35 -35
  49. modulitiz_micro/rete/socketserver/AbstractSocketServer.py +267 -267
  50. modulitiz_micro/rete/ssl/ModuloSsl.py +56 -56
  51. modulitiz_micro/sistema/ModuloEnvVars.py +34 -34
  52. modulitiz_micro/sistema/ModuloSystemPipe.py +67 -67
  53. modulitiz_micro/social/telegram/AbstractModuloTelegram.py +53 -53
  54. modulitiz_micro/social/telegram/ModuloTelegramSimple.py +26 -26
  55. modulitiz_micro/util/beans/globalvar/AbstractBasicGlobalVarBean.py +15 -15
  56. modulitiz_micro/util/scheduler/ModuleScheduler.py +26 -26
  57. modulitiz_micro/weather/AbstractModuleWeather.py +31 -31
  58. modulitiz_micro/weather/ModuleWeather.py +62 -62
  59. {modulitiz_micro-2.45.1.dist-info → modulitiz_micro-2.46.0.dist-info}/METADATA +59 -59
  60. modulitiz_micro-2.46.0.dist-info/RECORD +67 -0
  61. {modulitiz_micro-2.45.1.dist-info → modulitiz_micro-2.46.0.dist-info}/licenses/LICENSE +21 -21
  62. modulitiz_micro-2.45.1.dist-info/RECORD +0 -66
  63. {modulitiz_micro-2.45.1.dist-info → modulitiz_micro-2.46.0.dist-info}/WHEEL +0 -0
  64. {modulitiz_micro-2.45.1.dist-info → modulitiz_micro-2.46.0.dist-info}/top_level.txt +0 -0
@@ -1,114 +1,114 @@
1
- from abc import abstractmethod
2
-
3
- from modulitiz_nano.ModuloStringhe import ModuloStringhe
4
- from modulitiz_micro.database.sqlite.ModuloSQLite import AbstractSqlite
5
-
6
-
7
- class AbstractBasicSqlite(AbstractSqlite):
8
-
9
- def __init__(self,*args,**kwargs):
10
- super().__init__(*args,**kwargs)
11
- if not self.isDbNew:
12
- return
13
- sql_str=ModuloStringhe.normalizzaEol(self.schemaBasicTables())
14
- with self.initCursor() as cursoreDb:
15
- with self.lock:
16
- cursoreDb.executescript(sql_str)
17
- sql_insertBasicTables=self.insertBasicTables()
18
- if not ModuloStringhe.isEmpty(sql_insertBasicTables):
19
- sql_insertBasicTables=ModuloStringhe.normalizzaEol(sql_insertBasicTables)
20
- with self.lock:
21
- cursoreDb.executescript(sql_insertBasicTables)
22
- self.commit()
23
-
24
- @abstractmethod
25
- def insertBasicTables(self):
26
- """
27
- Inserire le istruzioni sql che vanno eseguite alla fine di tutto
28
- """
29
-
30
- def schemaBasicTables(self):
31
- return """
32
-
33
- CREATE TABLE tb_params(
34
- id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
35
- type TEXT NOT NULL,
36
- key TEXT NULL,
37
- desc TEXT NOT NULL,
38
- enabled INTEGER NOT NULL,
39
- lang_code TEXT NULL,
40
- data_insert TIMESTAMP NOT NULL
41
- );
42
- CREATE UNIQUE INDEX PARAMS__UK1 ON tb_params(
43
- type,
44
- IFNULL(key, 0),
45
- IFNULL(lang_code, 0)
46
- );
47
-
48
- """
49
-
50
-
51
- #############################################################################################################################
52
- #############################################################################################################################
53
- #############################################################################################################################
54
- def selectParamDescByEntries(self,paramType,paramKey)->str|None:
55
- with self.selectParamByEntries(paramType, paramKey, None, True) as cursoreDb:
56
- results=cursoreDb.fetchall()
57
- if len(results)==0:
58
- return None
59
- return results[0]['desc']
60
-
61
- def selectParamByEntries(self,paramType,paramKey,langCode,enabled):
62
- addParamKey=ModuloStringhe.isEmpty(paramKey) is False
63
- addLangCode=ModuloStringhe.isEmpty(langCode) is False
64
- addEnabled=ModuloStringhe.isEmpty(enabled) is False
65
-
66
- sql="""
67
- SELECT *
68
- FROM tb_params
69
- WHERE type=:paramType
70
- """+("AND key=:paramKey" if addParamKey is True else "")+"""
71
- """+("AND langCode=:langCode" if addLangCode is True else "")+"""
72
- """+("AND enabled=:enabled" if addEnabled is True else "")+"""
73
- ;
74
- """
75
- params={'paramType':paramType}
76
- if addParamKey is True:
77
- params['paramKey']=paramKey
78
- if addLangCode is True:
79
- params['langCode']=langCode
80
- if addEnabled is True:
81
- params['enabled']=enabled
82
- cursoreDb=self.initCursor()
83
- with self.lock:
84
- cursoreDb.execute(sql,params)
85
- return cursoreDb
86
-
87
-
88
- def updateParamDesc(self,paramType,paramKey,newDesc):
89
- addParamKey=ModuloStringhe.isEmpty(paramKey) is False
90
- addNewDesc=ModuloStringhe.isEmpty(newDesc) is False
91
-
92
- sql_set=[]
93
- if addNewDesc is True:
94
- sql_set.append("desc=:newDesc")
95
- sql_set=", ".join(sql_set)
96
-
97
- sql="""
98
- UPDATE tb_params
99
- SET """+sql_set+"""
100
- WHERE type=:paramType
101
- """+("AND key=:paramKey" if addParamKey is True else "")+"""
102
- ;
103
- """
104
- params={}
105
- if addNewDesc is True:
106
- params['newDesc']=newDesc
107
- params['paramType']=paramType
108
- if addParamKey is True:
109
- params['paramKey']=paramKey
110
- cursoreDb=self.initCursor()
111
- with self.lock:
112
- cursoreDb.execute(sql,params)
113
- return cursoreDb
114
-
1
+ from abc import abstractmethod
2
+
3
+ from modulitiz_nano.ModuloStringhe import ModuloStringhe
4
+ from modulitiz_micro.database.sqlite.ModuloSQLite import AbstractSqlite
5
+
6
+
7
+ class AbstractBasicSqlite(AbstractSqlite):
8
+
9
+ def __init__(self,*args,**kwargs):
10
+ super().__init__(*args,**kwargs)
11
+ if not self.isDbNew:
12
+ return
13
+ sql_str=ModuloStringhe.normalizzaEol(self.schemaBasicTables())
14
+ with self.initCursor() as cursoreDb:
15
+ with self.lock:
16
+ cursoreDb.executescript(sql_str)
17
+ sql_insertBasicTables=self.insertBasicTables()
18
+ if not ModuloStringhe.isEmpty(sql_insertBasicTables):
19
+ sql_insertBasicTables=ModuloStringhe.normalizzaEol(sql_insertBasicTables)
20
+ with self.lock:
21
+ cursoreDb.executescript(sql_insertBasicTables)
22
+ self.commit()
23
+
24
+ @abstractmethod
25
+ def insertBasicTables(self):
26
+ """
27
+ Inserire le istruzioni sql che vanno eseguite alla fine di tutto
28
+ """
29
+
30
+ def schemaBasicTables(self):
31
+ return """
32
+
33
+ CREATE TABLE tb_params(
34
+ id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
35
+ type TEXT NOT NULL,
36
+ key TEXT NULL,
37
+ desc TEXT NOT NULL,
38
+ enabled INTEGER NOT NULL,
39
+ lang_code TEXT NULL,
40
+ data_insert TIMESTAMP NOT NULL
41
+ );
42
+ CREATE UNIQUE INDEX PARAMS__UK1 ON tb_params(
43
+ type,
44
+ IFNULL(key, 0),
45
+ IFNULL(lang_code, 0)
46
+ );
47
+
48
+ """
49
+
50
+
51
+ #############################################################################################################################
52
+ #############################################################################################################################
53
+ #############################################################################################################################
54
+ def selectParamDescByEntries(self,paramType,paramKey)->str|None:
55
+ with self.selectParamByEntries(paramType, paramKey, None, True) as cursoreDb:
56
+ results=cursoreDb.fetchall()
57
+ if len(results)==0:
58
+ return None
59
+ return results[0]['desc']
60
+
61
+ def selectParamByEntries(self,paramType,paramKey,langCode,enabled):
62
+ addParamKey=ModuloStringhe.isEmpty(paramKey) is False
63
+ addLangCode=ModuloStringhe.isEmpty(langCode) is False
64
+ addEnabled=ModuloStringhe.isEmpty(enabled) is False
65
+
66
+ sql="""
67
+ SELECT *
68
+ FROM tb_params
69
+ WHERE type=:paramType
70
+ """+("AND key=:paramKey" if addParamKey is True else "")+"""
71
+ """+("AND langCode=:langCode" if addLangCode is True else "")+"""
72
+ """+("AND enabled=:enabled" if addEnabled is True else "")+"""
73
+ ;
74
+ """
75
+ params={'paramType':paramType}
76
+ if addParamKey is True:
77
+ params['paramKey']=paramKey
78
+ if addLangCode is True:
79
+ params['langCode']=langCode
80
+ if addEnabled is True:
81
+ params['enabled']=enabled
82
+ cursoreDb=self.initCursor()
83
+ with self.lock:
84
+ cursoreDb.execute(sql,params)
85
+ return cursoreDb
86
+
87
+
88
+ def updateParamDesc(self,paramType,paramKey,newDesc):
89
+ addParamKey=ModuloStringhe.isEmpty(paramKey) is False
90
+ addNewDesc=ModuloStringhe.isEmpty(newDesc) is False
91
+
92
+ sql_set=[]
93
+ if addNewDesc is True:
94
+ sql_set.append("desc=:newDesc")
95
+ sql_set=", ".join(sql_set)
96
+
97
+ sql="""
98
+ UPDATE tb_params
99
+ SET """+sql_set+"""
100
+ WHERE type=:paramType
101
+ """+("AND key=:paramKey" if addParamKey is True else "")+"""
102
+ ;
103
+ """
104
+ params={}
105
+ if addNewDesc is True:
106
+ params['newDesc']=newDesc
107
+ params['paramType']=paramType
108
+ if addParamKey is True:
109
+ params['paramKey']=paramKey
110
+ cursoreDb=self.initCursor()
111
+ with self.lock:
112
+ cursoreDb.execute(sql,params)
113
+ return cursoreDb
114
+
@@ -1,82 +1,82 @@
1
- """
2
- esempio utilizzo per lista
3
-
4
- def __query_NOME_TABELLA(self,lista_status,is_count):
5
- paramsStatus=ModuloSQLite.add_param_list(lista_status, "status")
6
-
7
- sql='''
8
- SELECT '''+("COUNT(*)" if is_count is True else "*")+'''
9
- FROM NOME_TABELLA
10
- WHERE 1=1
11
- AND status IN (:'''+",:".join(paramsStatus.keys())+''')
12
- ;
13
- '''
14
- cursoreDb.execute(sql,paramsStatus)
15
- """
16
- import sqlite3
17
- from abc import abstractmethod
18
-
19
- from modulitiz_nano.ModuloStringhe import ModuloStringhe
20
- from modulitiz_micro.database.AbstractSql import AbstractSql
21
- from modulitiz_nano.files.ModuloFiles import ModuloFiles
22
-
23
-
24
- class AbstractSqlite(AbstractSql):
25
- """
26
- select
27
- count
28
- insert
29
- update
30
- delete
31
- """
32
-
33
- DATE_TIME_NOW="datetime('now','localtime')"
34
- DATE_TIME_NOW_MILLIS="strftime('%Y-%m-%d %H:%M:%f', 'now')"
35
-
36
- TIMEOUT_CONNECTION=10
37
-
38
- @abstractmethod
39
- def schema(self):
40
- """
41
- Insert here sql instructions containing table definitions (DDL)
42
- """
43
-
44
- def __init__(self,nomefile_db:str,show_sql:bool=False):
45
- super().__init__()
46
- self.isDbNew=ModuloFiles.getFileSize(nomefile_db)<=0
47
- #apro la connessione col db
48
- connDb=sqlite3.connect(nomefile_db, timeout=self.TIMEOUT_CONNECTION, detect_types=sqlite3.PARSE_DECLTYPES, check_same_thread=False)
49
- #modifica row factory per usare Row
50
- connDb.row_factory=sqlite3.Row
51
- self.connDb=connDb
52
- # creo il cursore, deve essere fatto dopo il row factory
53
- with self.initCursor() as cursoreDb:
54
- # setup iniziale
55
- with self.lock:
56
- # non puoi cancellare un record se e' referenziato da un'altra tabella
57
- cursoreDb.executescript('PRAGMA foreign_keys=ON;')
58
- self.commit()
59
- # mostra i comandi sql eseguiti
60
- if show_sql is True:
61
- self.connDb.set_trace_callback(print)
62
- # se il db non esisteva creo le tabelle
63
- if self.isDbNew:
64
- sql_str=ModuloStringhe.normalizzaEol(self.schema())
65
- with self.lock:
66
- cursoreDb.executescript(sql_str)
67
- self.commit()
68
-
69
- @staticmethod
70
- def getLastIdInserted(cursoreDb):
71
- return cursoreDb.lastrowid
72
-
73
- def paginazione(first_result:int,num_results:int)->str:
74
- sql=("LIMIT "+str(num_results) if num_results is not None else "")
75
- sql+=(" OFFSET "+str(first_result) if first_result is not None else "")
76
- return sql
77
-
78
- def add_param_list(lista,prefix):
79
- params={}
80
- for index,elem in enumerate(lista):
81
- params[prefix+str(index)]=elem
82
- return params
1
+ """
2
+ esempio utilizzo per lista
3
+
4
+ def __query_NOME_TABELLA(self,lista_status,is_count):
5
+ paramsStatus=ModuloSQLite.add_param_list(lista_status, "status")
6
+
7
+ sql='''
8
+ SELECT '''+("COUNT(*)" if is_count is True else "*")+'''
9
+ FROM NOME_TABELLA
10
+ WHERE 1=1
11
+ AND status IN (:'''+",:".join(paramsStatus.keys())+''')
12
+ ;
13
+ '''
14
+ cursoreDb.execute(sql,paramsStatus)
15
+ """
16
+ import sqlite3
17
+ from abc import abstractmethod
18
+
19
+ from modulitiz_nano.ModuloStringhe import ModuloStringhe
20
+ from modulitiz_micro.database.AbstractSql import AbstractSql
21
+ from modulitiz_nano.files.ModuloFiles import ModuloFiles
22
+
23
+
24
+ class AbstractSqlite(AbstractSql):
25
+ """
26
+ select
27
+ count
28
+ insert
29
+ update
30
+ delete
31
+ """
32
+
33
+ DATE_TIME_NOW="datetime('now','localtime')"
34
+ DATE_TIME_NOW_MILLIS="strftime('%Y-%m-%d %H:%M:%f', 'now')"
35
+
36
+ TIMEOUT_CONNECTION=10
37
+
38
+ @abstractmethod
39
+ def schema(self):
40
+ """
41
+ Insert here sql instructions containing table definitions (DDL)
42
+ """
43
+
44
+ def __init__(self,nomefile_db:str,show_sql:bool=False):
45
+ super().__init__()
46
+ self.isDbNew=ModuloFiles.getFileSize(nomefile_db)<=0
47
+ #apro la connessione col db
48
+ connDb=sqlite3.connect(nomefile_db, timeout=self.TIMEOUT_CONNECTION, detect_types=sqlite3.PARSE_DECLTYPES, check_same_thread=False)
49
+ #modifica row factory per usare Row
50
+ connDb.row_factory=sqlite3.Row
51
+ self.connDb=connDb
52
+ # creo il cursore, deve essere fatto dopo il row factory
53
+ with self.initCursor() as cursoreDb:
54
+ # setup iniziale
55
+ with self.lock:
56
+ # non puoi cancellare un record se e' referenziato da un'altra tabella
57
+ cursoreDb.executescript('PRAGMA foreign_keys=ON;')
58
+ self.commit()
59
+ # mostra i comandi sql eseguiti
60
+ if show_sql is True:
61
+ self.connDb.set_trace_callback(print)
62
+ # se il db non esisteva creo le tabelle
63
+ if self.isDbNew:
64
+ sql_str=ModuloStringhe.normalizzaEol(self.schema())
65
+ with self.lock:
66
+ cursoreDb.executescript(sql_str)
67
+ self.commit()
68
+
69
+ @staticmethod
70
+ def getLastIdInserted(cursoreDb):
71
+ return cursoreDb.lastrowid
72
+
73
+ def paginazione(first_result:int,num_results:int)->str:
74
+ sql=("LIMIT "+str(num_results) if num_results is not None else "")
75
+ sql+=(" OFFSET "+str(first_result) if first_result is not None else "")
76
+ return sql
77
+
78
+ def add_param_list(lista,prefix):
79
+ params={}
80
+ for index,elem in enumerate(lista):
81
+ params[prefix+str(index)]=elem
82
+ return params
@@ -1,7 +1,7 @@
1
- from modulitiz_nano.eccezioni.EccezioneBase import EccezioneBase
2
-
3
-
4
- class EccezioneCtrlC(EccezioneBase):
5
-
6
- def __init__(self,*args,**kwargs):
7
- super().__init__(*args,**kwargs)
1
+ from modulitiz_nano.eccezioni.EccezioneBase import EccezioneBase
2
+
3
+
4
+ class EccezioneCtrlC(EccezioneBase):
5
+
6
+ def __init__(self,*args,**kwargs):
7
+ super().__init__(*args,**kwargs)
@@ -1,7 +1,7 @@
1
- from modulitiz_nano.eccezioni.EccezioneBase import EccezioneBase
2
-
3
-
4
- class EccezioneScheduler(EccezioneBase):
5
-
6
- def __init__(self,*args,**kwargs):
7
- super().__init__(*args,**kwargs)
1
+ from modulitiz_nano.eccezioni.EccezioneBase import EccezioneBase
2
+
3
+
4
+ class EccezioneScheduler(EccezioneBase):
5
+
6
+ def __init__(self,*args,**kwargs):
7
+ super().__init__(*args,**kwargs)
@@ -1,8 +1,8 @@
1
- from modulitiz_nano.eccezioni.EccezioneBase import EccezioneBase
2
-
3
-
4
- class EccezioneHttp(EccezioneBase):
5
-
6
- def __init__(self,httpCode:int|None,*args,**kwargs):
7
- super().__init__(*args,**kwargs)
8
- self.httpCode=httpCode
1
+ from modulitiz_nano.eccezioni.EccezioneBase import EccezioneBase
2
+
3
+
4
+ class EccezioneHttp(EccezioneBase):
5
+
6
+ def __init__(self,httpCode:int|None,*args,**kwargs):
7
+ super().__init__(*args,**kwargs)
8
+ self.httpCode=httpCode
@@ -1,7 +1,7 @@
1
- from modulitiz_micro.eccezioni.http.EccezioneHttp import EccezioneHttp
2
-
3
-
4
- class EccezioneHttp404(EccezioneHttp):
5
-
6
- def __init__(self):
7
- super().__init__(404)
1
+ from modulitiz_micro.eccezioni.http.EccezioneHttp import EccezioneHttp
2
+
3
+
4
+ class EccezioneHttp404(EccezioneHttp):
5
+
6
+ def __init__(self):
7
+ super().__init__(404)
@@ -1,7 +1,7 @@
1
- from modulitiz_micro.eccezioni.http.EccezioneHttp import EccezioneHttp
2
-
3
-
4
- class EccezioneHttpGeneric(EccezioneHttp):
5
-
6
- def __init__(self):
7
- super().__init__(None)
1
+ from modulitiz_micro.eccezioni.http.EccezioneHttp import EccezioneHttp
2
+
3
+
4
+ class EccezioneHttpGeneric(EccezioneHttp):
5
+
6
+ def __init__(self):
7
+ super().__init__(None)
@@ -1,91 +1,91 @@
1
- from modulitiz_nano.ModuloStringhe import ModuloStringhe
2
- from modulitiz_micro.database.sqlite.ModuloSQLite import AbstractSqlite
3
-
4
-
5
- class DatabaseCache(AbstractSqlite):
6
-
7
- # costruttore
8
- def __init__(self,*args,**kwargs):
9
- super().__init__(*args,**kwargs)
10
-
11
- # metodi
12
- def schema(self):
13
- sql="""
14
- CREATE TABLE tb_cache(
15
- id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
16
- type TEXT NOT NULL,
17
- key TEXT NULL,
18
- valore TEXT NOT NULL,
19
- data_insert TIMESTAMP NOT NULL
20
- );
21
- CREATE UNIQUE INDEX IX_tb_cache__type_key ON tb_cache(type,key);
22
-
23
- """
24
-
25
- return sql
26
-
27
- def insertBasicTables(self):
28
- return
29
-
30
-
31
- #############################################################################################################################
32
- def select_cache_valore_by_entries(self,tipo,chiave):
33
- results=self.select_cache_by_entries(tipo, chiave)
34
- if results is None:
35
- return None
36
- return results[0]['valore']
37
-
38
- def select_cache_by_entries(self,tipo,chiave):
39
- with self.__query_cache_by_entries(tipo, chiave,False) as cursoreDb:
40
- results=cursoreDb.fetchall()
41
- if len(results)==0:
42
- return None
43
- return results
44
-
45
- def count_cache_by_entries(self,tipo,chiave)->int:
46
- cursoreDb=self.__query_cache_by_entries(tipo, chiave,True)
47
- return self.count(cursoreDb)
48
-
49
- def __query_cache_by_entries(self,tipo,chiave,isCount):
50
- add_chiave=ModuloStringhe.isEmpty(chiave) is False
51
- sql="SELECT "+("COUNT(*) AS conta" if isCount is True else "*")+"""
52
- FROM tb_cache
53
- WHERE type=:tipo
54
- """+("AND key=:chiave" if add_chiave is True else "")+"""
55
- ;
56
- """
57
- params={'tipo':tipo}
58
- if add_chiave is True:
59
- params['chiave']=chiave
60
-
61
- cursoreDb=self.initCursor()
62
- cursoreDb.execute(sql,params)
63
- return cursoreDb
64
-
65
- def insert_cache(self,tipo,chiave,valore):
66
- sql="""
67
- INSERT INTO tb_cache(
68
- type,key,valore,data_insert
69
- ) VALUES (
70
- :tipo,:chiave,:valore,"""+self.DATE_TIME_NOW+"""
71
- );
72
- """
73
- cursoreDb=self.initCursor()
74
- cursoreDb.execute(sql,{
75
- 'tipo':tipo,'chiave':chiave,'valore':valore
76
- })
77
- return cursoreDb
78
-
79
- def update_cache_valore(self,tipo,chiave,valore):
80
- sql="""
81
- UPDATE tb_cache
82
- SET valore=:valore,data_insert="""+self.DATE_TIME_NOW+"""
83
- WHERE type=:tipo AND key=:chiave
84
- ;
85
- """
86
- cursoreDb=self.initCursor()
87
- cursoreDb.execute(sql,{
88
- 'valore':valore,'tipo':tipo,'chiave':chiave
89
- })
90
- return cursoreDb
91
-
1
+ from modulitiz_nano.ModuloStringhe import ModuloStringhe
2
+ from modulitiz_micro.database.sqlite.ModuloSQLite import AbstractSqlite
3
+
4
+
5
+ class DatabaseCache(AbstractSqlite):
6
+
7
+ # costruttore
8
+ def __init__(self,*args,**kwargs):
9
+ super().__init__(*args,**kwargs)
10
+
11
+ # metodi
12
+ def schema(self):
13
+ sql="""
14
+ CREATE TABLE tb_cache(
15
+ id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
16
+ type TEXT NOT NULL,
17
+ key TEXT NULL,
18
+ valore TEXT NOT NULL,
19
+ data_insert TIMESTAMP NOT NULL
20
+ );
21
+ CREATE UNIQUE INDEX IX_tb_cache__type_key ON tb_cache(type,key);
22
+
23
+ """
24
+
25
+ return sql
26
+
27
+ def insertBasicTables(self):
28
+ return
29
+
30
+
31
+ #############################################################################################################################
32
+ def select_cache_valore_by_entries(self,tipo,chiave):
33
+ results=self.select_cache_by_entries(tipo, chiave)
34
+ if results is None:
35
+ return None
36
+ return results[0]['valore']
37
+
38
+ def select_cache_by_entries(self,tipo,chiave):
39
+ with self.__query_cache_by_entries(tipo, chiave,False) as cursoreDb:
40
+ results=cursoreDb.fetchall()
41
+ if len(results)==0:
42
+ return None
43
+ return results
44
+
45
+ def count_cache_by_entries(self,tipo,chiave)->int:
46
+ cursoreDb=self.__query_cache_by_entries(tipo, chiave,True)
47
+ return self.count(cursoreDb)
48
+
49
+ def __query_cache_by_entries(self,tipo,chiave,isCount):
50
+ add_chiave=ModuloStringhe.isEmpty(chiave) is False
51
+ sql="SELECT "+("COUNT(*) AS conta" if isCount is True else "*")+"""
52
+ FROM tb_cache
53
+ WHERE type=:tipo
54
+ """+("AND key=:chiave" if add_chiave is True else "")+"""
55
+ ;
56
+ """
57
+ params={'tipo':tipo}
58
+ if add_chiave is True:
59
+ params['chiave']=chiave
60
+
61
+ cursoreDb=self.initCursor()
62
+ cursoreDb.execute(sql,params)
63
+ return cursoreDb
64
+
65
+ def insert_cache(self,tipo,chiave,valore):
66
+ sql="""
67
+ INSERT INTO tb_cache(
68
+ type,key,valore,data_insert
69
+ ) VALUES (
70
+ :tipo,:chiave,:valore,"""+self.DATE_TIME_NOW+"""
71
+ );
72
+ """
73
+ cursoreDb=self.initCursor()
74
+ cursoreDb.execute(sql,{
75
+ 'tipo':tipo,'chiave':chiave,'valore':valore
76
+ })
77
+ return cursoreDb
78
+
79
+ def update_cache_valore(self,tipo,chiave,valore):
80
+ sql="""
81
+ UPDATE tb_cache
82
+ SET valore=:valore,data_insert="""+self.DATE_TIME_NOW+"""
83
+ WHERE type=:tipo AND key=:chiave
84
+ ;
85
+ """
86
+ cursoreDb=self.initCursor()
87
+ cursoreDb.execute(sql,{
88
+ 'valore':valore,'tipo':tipo,'chiave':chiave
89
+ })
90
+ return cursoreDb
91
+