Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit d201a50

Browse files
committed
.execute() support for fyCursor .fetch() method
1 parent 6937f39 commit d201a50

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

fyCursor/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
'''from fyCursor import Table, Field, connect
1+
from . import connect
22

33
cursor = connect("database.db")
4+
'''
45
56
# --------------------------------------------------------------------------------------//
67
# CREATING A TABLE
@@ -50,3 +51,5 @@
5051
# add 5 to money to all users
5152
cursor.update("myTable").add(money=5).commit()
5253
'''
54+
cursor.execute("INSERT INTO myTable(money) VALUES (2)").commit()
55+
print(cursor.execute("SELECT * FROM myTable WHERE money=2").fetch())

fyCursor/core/core.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22
import logging
33

44
from sqlite3 import Cursor, Connection, ProgrammingError
5-
from sqlite3.dbapi2 import _Parameters
65

76
from .fields import Field
8-
from typing import Union, Any, Optional, Self
7+
from typing import Union, Any, Optional, Self, Protocol, TypeVar, Mapping
98

10-
NULL = None # python None is same as "NULL" here
9+
10+
NULL = None
11+
_T_co = TypeVar("_T_co", covariant=True)
12+
13+
14+
class SupportsLenAndGetItem(Protocol[_T_co]):
15+
def __len__(self) -> int: ...
16+
def __getitem__(self, __k: int) -> _T_co: ...
17+
18+
19+
_Parameters = type[
20+
SupportsLenAndGetItem[str | int | float | Any | None]] | type[
21+
Mapping[str, str | int | float | Any | None]
22+
]
1123

1224

1325
class TableError(BaseException):
@@ -218,15 +230,20 @@ def where(self, **kwargs: Any) -> Self:
218230
)
219231
return self
220232

221-
def execute(self, __sql: str, __parameters: _Parameters = ...) -> Self:
233+
def execute( # type: ignore
234+
self,
235+
__sql: str,
236+
*__parameters: _Parameters
237+
) -> Self:
222238
self._query = __sql
223239
if __parameters:
224-
for param in __parameters:
240+
for param in __parameters: # type: ignore
225241
self._query.replace("?", param, 1) # type: ignore
226-
return super().execute(__sql, __parameters)
242+
return super().execute(__sql, __parameters) # type: ignore
227243

228244
def fetch(
229-
self, one: bool = False
245+
self,
246+
one: bool = False
230247
) -> Optional[Union[tuple[Any], list[Any]] | Any]:
231248
"""
232249
fetch values from cursor query

0 commit comments

Comments
 (0)