-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from CrispenGari/delete
Delete
- Loading branch information
Showing
10 changed files
with
235 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
push = True | ||
push = False | ||
|
||
|
||
if push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
class TestDeletingOnPG: | ||
def test_delete_by_pk_single_fn(self): | ||
from orm.db import Database | ||
from orm.model.column import Column | ||
from orm.model.model import Model, PrimaryKeyColumn | ||
from orm.keys import password, database, user | ||
|
||
db = Database(database, password=password, user=user) | ||
conn = db.connect() | ||
|
||
class User(Model): | ||
__tablename__ = "users" | ||
id = PrimaryKeyColumn(type="bigint", auto_increment=True) | ||
username = Column(type="text", nullable=False, default="Hello there!!") | ||
name = Column(type="varchar", unique=True, length=255) | ||
|
||
db.sync([User], drop=True, force=True) | ||
|
||
user = User(name="Crispen", username="heyy") | ||
userId = db.commit(user) | ||
affected_rows_1 = db.delete_by_pk(User, userId) | ||
affected_rows_2 = db.delete_by_pk(User, 89) | ||
assert affected_rows_1 == 1 | ||
assert affected_rows_2 == 0 | ||
conn.close() | ||
|
||
def test_delete_one_fn(self): | ||
from orm.db import Database | ||
from orm.model.column import Column | ||
from orm.model.model import Model, PrimaryKeyColumn | ||
from orm.keys import password, database, user | ||
|
||
db = Database(database, password=password, user=user) | ||
conn = db.connect() | ||
|
||
class User(Model): | ||
__tablename__ = "users" | ||
id = PrimaryKeyColumn(type="bigint", auto_increment=True) | ||
username = Column(type="text", nullable=False, default="Hello there!!") | ||
name = Column(type="varchar", unique=False, length=255) | ||
|
||
db.sync([User], drop=True, force=True) | ||
|
||
db.commit_bulk( | ||
[ | ||
User(name="Crispen", username="heyy"), | ||
User(name="Crispen", username="heyy"), | ||
User(name="Crispen", username="heyy"), | ||
] | ||
) | ||
db.delete_one(User, {"name": "Crispen"}) | ||
rows_1 = db.find_many(User, {"name": "Crispen"}) | ||
db.delete_one(User, {"name": "Crispen", "id": 9}) | ||
rows_2 = db.find_many(User, {"name": "Crispen"}) | ||
db.delete_one(User, {"name": "Crispen", "id": 2}) | ||
rows_3 = db.find_many(User, {"name": "Crispen"}) | ||
assert len(rows_1) == 2 | ||
assert len(rows_2) == 2 | ||
assert len(rows_3) == 1 | ||
conn.close() | ||
|
||
def test_delete_bulk_fn(self): | ||
from orm.db import Database | ||
from orm.model.column import Column | ||
from orm.model.model import Model, PrimaryKeyColumn | ||
from orm.keys import password, database, user | ||
|
||
db = Database(database, password=password, user=user) | ||
conn = db.connect() | ||
|
||
class User(Model): | ||
__tablename__ = "users" | ||
id = PrimaryKeyColumn(type="bigint", auto_increment=True) | ||
username = Column(type="text", nullable=False, default="Hello there!!") | ||
name = Column(type="varchar", unique=False, length=255) | ||
|
||
db.sync([User], drop=True, force=True) | ||
|
||
db.commit_bulk( | ||
[ | ||
User(name="Crispen", username="heyy"), | ||
User(name="Crispen", username="heyy"), | ||
User(name="Crispen", username="heyy"), | ||
] | ||
) | ||
db.delete_bulk(User, {"name": "Crispen"}) | ||
rows_1 = db.find_many(User, {"name": "Crispen"}) | ||
db.commit_bulk( | ||
[ | ||
User(name="Crispen", username="heyy"), | ||
User(name="Crispen", username="heyy"), | ||
User(name="Crispen", username="heyy"), | ||
] | ||
) | ||
db.delete_bulk(User, {"name": "Crispen", "id": 99}) | ||
rows_2 = db.find_many(User, {"name": "Crispen"}) | ||
db.delete_bulk(User, {"name": "Crispen", "id": 5}) | ||
rows_3 = db.find_many(User, {"name": "Crispen"}) | ||
assert len(rows_1) == 0 | ||
assert len(rows_2) == 3 | ||
assert len(rows_3) == 2 | ||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.