39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import sqlite3
|
|
|
|
class Ledger():
|
|
def __init__(self) -> None:
|
|
self.db = sqlite3.connect("ledger.db")
|
|
self.data = self.db.cursor()
|
|
self.data.execute(""" CREATE TABLE IF NOT EXISTS ledger (
|
|
ID integer PRIMARY KEY,
|
|
USERID integer,
|
|
MONEY integer DEFAULT 100,
|
|
WINS integer DEFAULT 0,
|
|
LOSSES integer DEFAULT 0
|
|
); """)
|
|
|
|
def read(self, ID):
|
|
self.data.execute("""SELECT USERID, MONEY, WINS, LOSSES FROM ledger WHERE USERID = ?""", (ID,))
|
|
data = self.data.fetchone()
|
|
return data
|
|
|
|
def write(self, ID):
|
|
query = """ INSERT INTO ledger(USERID)
|
|
VALUES(?) """
|
|
self.data.execute(query, (ID,))
|
|
self.db.commit()
|
|
|
|
def update(self, data, newData):
|
|
query = """ UPDATE ledger
|
|
SET MONEY = ?,
|
|
WINS = ?,
|
|
LOSSES = ?,
|
|
WHERE USERID = ?"""
|
|
data = [data[i] + newData[i] for i in range(len(data))]
|
|
self.data.execute(query, data)
|
|
|
|
def main():
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main() |