Skip to content

Commit dfe04bf

Browse files
authored
Merge pull request #3 from wherobots/cursor-add-close
Add close and exit method for cursor
2 parents d806b38 + 4ad5fe6 commit dfe04bf

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

wherobots/db/constants.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import auto
2-
from strenum import StrEnum
2+
from strenum import LowercaseStrEnum
33

44
from .region import Region
55
from .runtime import Runtime
@@ -14,7 +14,7 @@
1414
MAX_MESSAGE_SIZE: int = 100 * 2**20 # 100MiB
1515

1616

17-
class ExecutionState(StrEnum):
17+
class ExecutionState(LowercaseStrEnum):
1818
IDLE = auto()
1919
"Not executing any operation."
2020

@@ -40,21 +40,21 @@ def is_terminal_state(self):
4040
return self in (ExecutionState.COMPLETED, ExecutionState.FAILED)
4141

4242

43-
class RequestKind(StrEnum):
43+
class RequestKind(LowercaseStrEnum):
4444
EXECUTE_SQL = auto()
4545
RETRIEVE_RESULTS = auto()
4646

4747

48-
class EventKind(StrEnum):
48+
class EventKind(LowercaseStrEnum):
4949
STATE_UPDATED = auto()
5050
EXECUTION_RESULT = auto()
5151
ERROR = auto()
5252

5353

54-
class ResultsFormat(StrEnum):
54+
class ResultsFormat(LowercaseStrEnum):
5555
JSON = auto()
5656
ARROW = auto()
5757

5858

59-
class DataCompression(StrEnum):
59+
class DataCompression(LowercaseStrEnum):
6060
BROTLI = auto()

wherobots/db/cursor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,18 @@ def fetchmany(self, size: int = None):
7777
def fetchall(self):
7878
return self.__get_results()[self.__current_row :]
7979

80+
def close(self):
81+
"""Close the cursor."""
82+
pass
83+
8084
def __iter__(self):
8185
return self
8286

8387
def __next__(self):
8488
raise StopIteration
89+
90+
def __enter__(self):
91+
return self
92+
93+
def __exit__(self, exc_type, exc_val, exc_tb):
94+
self.close()

0 commit comments

Comments
 (0)