diff options
author | Arun Isaac | 2022-10-18 16:24:37 +0530 |
---|---|---|
committer | Arun Isaac | 2022-10-18 17:45:26 +0530 |
commit | 30b8c86a8bb29451689735ba9cab95c6e104797c (patch) | |
tree | ad6b2bf45d1ee9a3594d1e5c7a78dbe449be1d7f /gn3 | |
parent | acc97e523ecdc6938b5744d4de4781e5d65f6d25 (diff) | |
download | genenetwork3-30b8c86a8bb29451689735ba9cab95c6e104797c.tar.gz |
Support server side SQL query retrieval.
* gn3/monads.py: Import SSDictCursor from MySQLdb.cursors.
(query_sql): Add server_side argument.
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/monads.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/gn3/monads.py b/gn3/monads.py index 964dce2..1fe4b33 100644 --- a/gn3/monads.py +++ b/gn3/monads.py @@ -12,7 +12,7 @@ from collections import UserDict from functools import partial from typing import Any, Hashable, Iterator -from MySQLdb.cursors import DictCursor +from MySQLdb.cursors import DictCursor, SSDictCursor from pymonad.maybe import Maybe, Just, Nothing @@ -124,9 +124,15 @@ class MonadicDict(UserDict): pass -def query_sql(conn, query: str) -> Iterator[MonadicDict]: - """Execute SQL query and return a generator of MonadicDict objects.""" - with conn.cursor(DictCursor) as cursor: +def query_sql(conn, query: str, server_side: bool=False) -> Iterator[MonadicDict]: + """Execute SQL query and return a generator of MonadicDict objects. + + If server_side is False, the result set is stored in the client. If + server_side is True, the result set is stored in the server. Therefore, + when server_side is True, this query must be completed before a new one + can be executed. + """ + with conn.cursor(SSDictCursor if server_side else DictCursor) as cursor: cursor.execute(query) while row := cursor.fetchone(): yield MonadicDict(row) |