]> git.mxchange.org Git - fba.git/blobdiff - fba/models/instances.py
Continued:
[fba.git] / fba / models / instances.py
index 0c39953a4e64f7b5d3202a39b79e67500dd0c377..3c8433de9de910e36afa6d35313c8b7d1ce1dfbd 100644 (file)
@@ -294,7 +294,7 @@ def is_recent(domain: str, column: str = "last_instance_fetch") -> bool:
 
     if not isinstance(column, str):
         raise ValueError(f"Parameter column[]='{type(column)}' is not of type 'str'")
-    elif column not in ["last_instance_fetch", "last_blocked"]:
+    elif column not in ["last_instance_fetch", "last_blocked", "last_nodeinfo"]:
         raise ValueError(f"Parameter column='{column}' is not expected")
     elif not is_registered(domain):
         logger.debug("domain='%s' is not registered, returning False - EXIT!", domain)
@@ -453,3 +453,24 @@ def set_software(domain: str, software: str):
     # Set timestamp
     _set_data("software", domain, software)
     logger.debug("EXIT!")
+
+def valid(value: str, column: str) -> bool:
+    logger.debug("value='%s' - CALLED!", value)
+    if not isinstance(value, str):
+        raise ValueError(f"Parameter value[]='{type(value)}' is not of type 'str'")
+    elif value == "":
+        raise ValueError("Parameter 'value' is empty")
+    elif not isinstance(column, str):
+        raise columnError(f"Parameter column[]='{type(column)}' is not of type 'str'")
+    elif column == "":
+        raise columnError("Parameter 'column' is empty")
+
+    # Query database
+    database.cursor.execute(
+        f"SELECT {column} FROM instances WHERE {column} = ? LIMIT 1", [value]
+    )
+
+    valid = database.cursor.fetchone() is not None
+
+    logger.debug("valid='%s' - EXIT!", valid)
+    return valid