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 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 # i have to use my own tech
@@ -113,14 +113,14 @@ fn: TypeAlias = Literal["one", "many", "all", "warnings"]
def query_once_fetch_lda( def query_once_fetch_lda(
execute_settings: tuple, execute_settings: tuple,
cursor_settings: dict, cursor_settings: dict,
fetch_many: fn | Collection[fn] = "one", fetch_many: fetch_many_t | Collection[fetch_many_t] = "one",
*, *,
conn=None, conn=None,
): ):
"every thing passes to execute, return fetchone. lda test" "every thing passes to execute, return fetchone. lda test"
# print("i seqeralr", conn) # print("i seqeralr", conn)
with conn.cursor(**cursor_settings) as r: with conn.cursor(**cursor_settings) as r:
rf: dict[fn, Callable] = { rf: dict[fetch_many_t, Callable] = {
"one": r.fetchone, "one": r.fetchone,
"all": r.fetchall, "all": r.fetchall,
"many": r.fetchmany, "many": r.fetchmany,
@@ -128,15 +128,21 @@ def query_once_fetch_lda(
} }
r.execute(*execute_settings) r.execute(*execute_settings)
if isinstance(fetch_many, str): try:
return rf[fetch_many]() if isinstance(fetch_many, str):
if isinstance(fetch_many, Collection): ef = rf[fetch_many]()
return tuple(rf[i]() for i in fetch_many) elif isinstance(fetch_many, Collection): # not a string hahahahah
raise AttributeError( ef = tuple(rf[i]() for i in fetch_many)
f"please put one of the one, many, all, warnings in ty (you put {fetch_many})", else:
name=fetch_many, raise AttributeError(
obj=r, 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) @better_connection_actuallyworking(connectionSettings)