logic change

This commit is contained in:
lda committed 2025-05-01 23:28:49 +07:00
1 parent 20412d225e
commit 22647dce11
1 file changed
+18 -12
+18 -12
View File
@@ -105,7 +105,7 @@ def better_connection_actuallyworking(connectionSettings: dict, conn_name="conn"
return decorator
fn: TypeAlias = Literal["one", "many", "all", "warnings"]
fetch_many_t: TypeAlias = Literal["one", "many", "all", "warnings"]
# i have to use my own tech
@@ -113,14 +113,14 @@ fn: TypeAlias = Literal["one", "many", "all", "warnings"]
def query_once_fetch_lda(
execute_settings: tuple,
cursor_settings: dict,
fetch_many: fn | Collection[fn] = "one",
fetch_many: fetch_many_t | Collection[fetch_many_t] = "one",
*,
conn=None,
):
"every thing passes to execute, return fetchone. lda test"
# print("i seqeralr", conn)
with conn.cursor(**cursor_settings) as r:
rf: dict[fn, Callable] = {
rf: dict[fetch_many_t, Callable] = {
"one": r.fetchone,
"all": r.fetchall,
"many": r.fetchmany,
@@ -128,15 +128,21 @@ def query_once_fetch_lda(
}
r.execute(*execute_settings)
if isinstance(fetch_many, str):
return rf[fetch_many]()
if isinstance(fetch_many, Collection):
return tuple(rf[i]() for i in fetch_many)
raise AttributeError(
f"please put one of the one, many, all, warnings in ty (you put {fetch_many})",
name=fetch_many,
obj=r,
)
try:
if isinstance(fetch_many, str):
ef = rf[fetch_many]()
elif isinstance(fetch_many, Collection): # not a string hahahahah
ef = tuple(rf[i]() for i in fetch_many)
else:
raise AttributeError(
f"please put one of the one, many, all, warnings in ty (you put {fetch_many})",
name=fetch_many,
obj=r,
)
except (TypeError, KeyError): # calling None exception
pass
else:
return ef
@better_connection_actuallyworking(connectionSettings)