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

Commit ed7ef8c

Browse files
committed
delete method
1 parent 970e3d6 commit ed7ef8c

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

fyCursor/__main__.py

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

33
cursor = connect("database.db")
4-
'''
54

65
# --------------------------------------------------------------------------------------//
76
# CREATING A TABLE
@@ -35,6 +34,7 @@
3534
# Now there are two versions of creating table,
3635
# but they are working totally same:
3736
AnotherTable.create(if_not_exist=True)
37+
'''
3838
cursor.create_table(AnotherTable, if_not_exist=True)
3939
4040
# --------------------------------------------------------------------------------------//
@@ -50,6 +50,13 @@
5050
5151
# add 5 to money to all users
5252
cursor.update("myTable").add(money=5).commit()
53-
'''
5453
cursor.execute("INSERT INTO myTable(money) VALUES (2)").commit()
55-
print(cursor.execute("SELECT * FROM myTable WHERE money=2").fetch())
54+
55+
b = AnotherTable << {
56+
"money": 2
57+
}
58+
input()
59+
a = AnotherTable >> {
60+
"money": 2
61+
}
62+
'''

fyCursor/core/core.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,29 @@ def __lshift__(self, __b: dict[str, Any]) -> "Table":
106106
self.insert(**__b)
107107
return self
108108

109+
def delete(self, **kwargs: Any) -> "Table":
110+
"""
111+
Same as `DELETE FROM {table.name} WHERE kwargs.keys=kwargs.values`
112+
"""
113+
names_ = list(kwargs.keys())
114+
values_ = list(kwargs.values())
115+
116+
where = str()
117+
is_first = True
118+
for name, value in zip(names_, values_):
119+
if not is_first:
120+
where += "AND"
121+
where += f"{name} = \"{value}\""
122+
is_first = False
123+
124+
self.cursor.execute(f"DELETE FROM {self.name} WHERE {where}").commit()
125+
return self
126+
109127
def __rshift__(self, __b: dict[str, Any]) -> "Table":
110-
"""Insert dict using right shift (>>) operator"""
128+
"""Delete dict using right shift (>>) operator"""
111129
if not isinstance(__b, dict): # type: ignore
112130
raise TableError("Wrong arguments")
113-
self.insert(**__b)
131+
self.delete(**__b)
114132
return self
115133

116134
def get_values(self) -> dict[str, Field]:

0 commit comments

Comments
 (0)