Last active
March 29, 2018 21:20
-
-
Save Zwork101/24e0c7eb6af8ab4a04319400aadd3d9b to your computer and use it in GitHub Desktop.
Cool, can't wait for release!, comparing my lib vs sqlite.
This file contains hidden or 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
from sqlite3 import connect | |
db = connect("item.sqlite") | |
cursor = db.cursor() | |
cursor.execute("CREATE TABLE IF NOT EXISTS Weapon(NAME text, DAMAGE integer DEFAULT 10)") | |
cursor.execute("DELETE FROM Weapon") # Clear everything | |
cursor.execute("INSERT INTO Weapon (NAME) VALUES (\"Sword\")") | |
cursor.execute("INSERT INTO Weapon (NAME, DAMAGE) VALUES (\"Dead Ringer\", 5)") | |
cursor.execute("INSERT INTO Weapon (NAME) VALUES (\"Mace\")") # sqlite gets made if you enter an invalid value | |
db.commit() | |
cursor.execute("SELECT * FROM Weapon") | |
for row in cursor.fetchall(): | |
print("Get ALL", row) | |
cursor.execute("SELECT * FROM Weapon WHERE DAMAGE=10") | |
for row in cursor.fetchall(): | |
print("Get Only DAMAGE=10:", row) | |
cursor.execute("DELETE FROM Weapon WHERE DAMAGE=10") | |
print("Delete Only DAMAGE=10") | |
db.commit() | |
cursor.execute("SELECT * FROM Weapon") | |
for row in cursor.fetchall(): | |
print("Get ALL:", row) |
This file contains hidden or 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
from superbase import StrRow, IntRow, SuperBase | |
class Weapon(SuperBase): | |
file_dir = './items.db' | |
NAME = StrRow | |
DAMAGE = IntRow("10") | |
if __name__ == "__main__": | |
Weapon.delete_all() # Clear the DB | |
ws = Weapon.add_all([ | |
{"NAME": "Sword"}, | |
{"DAMAGE": 5, "NAME": "Dead Ringer"}, | |
{"NAME": "Mace", "CHANCE": 54.22} | |
]) | |
print("Returned:", ws) | |
print("Get ALL:", Weapon.get_all()) | |
print("Get Only DAMAGE=10:", Weapon.get({"DAMAGE": 10})) | |
print("Delete Only DAMAGE=10:", Weapon.delete({"DAMAGE": 10})) | |
print("Get ALL:", Weapon.get_all()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment