I'm writing a simple stock trading site with Flask while learning how to use SQLite database. When a logged in user makes a transaction (buy/sell), I insert it into the transactions
database with this command:
db.execute("INSERT INTO transactions (user_id, symbol, shares, price) VALUES (:user_id, :symbol, :shares, :price)",
user_id=session["user_id"], symbol=symbol, shares=shares, price=price)
If the user wants to check what stocks they currently have, I just query it from the database:
trades = db.execute("SELECT * FROM transactions WHERE user_id = :user_id ORDER BY transaction_id ASC",
user_id=session["user_id"])
But this gives me back all of the transactions for both buy and sell. The way I set it up is that when a user sells a stock, the shares column will be a negative number. At this point it became pretty messy for me to organize the data in my code. But I'm not sure if I should add another database since I will also have to insert and query that database separately in my code.
Is there a command that allows me to split buy and sell transactions into two separate tables?
Edit: Typo in command