Here is some example code for a basic SplitWise-style expense splitting app in Python using SQLite:
python
import sqlite3
# Connect to SQLite database
conn = sqlite3.connect('splitwise.db')
c = conn.cursor()
# Create users table
c.execute('''CREATE TABLE IF NOT EXISTS users
(id INTEGER PRIMARY KEY, name TEXT, email TEXT)''')
# Create groups table
c.execute('''CREATE TABLE IF NOT EXISTS groups
(id INTEGER PRIMARY KEY, name TEXT)''')
# Create expenses table
c.execute('''CREATE TABLE IF NOT EXISTS expenses
(id INTEGER PRIMARY KEY, payer_id INTEGER, group_id INTEGER,
amount FLOAT, description TEXT, FOREIGN KEY(payer_id) REFERENCES users(id),
FOREIGN KEY(group_id) REFERENCES groups(id))''')
# Create splits table
c.execute('''CREATE TABLE IF NOT EXISTS splits
(id INTEGER PRIMARY KEY, user_id INTEGER, expense_id INTEGER,
amount FLOAT, FOREIGN KEY(user_id) REFERENCES users(id),
FOREIGN KEY(expense_id) REFERENCES expenses(id))''')
# Sample data
c.execute('''INSERT INTO users VALUES
(1, 'Alice', 'alice@example.com'),
(2, 'Bob', 'bob@example.com'),
(3, 'Charlie', 'charlie@example.com')''')
c.execute('''INSERT INTO groups VALUES
(1, 'Roommates'),
(2, 'Classmates')''')
c.execute('''INSERT INTO expenses
VALUES (1, 1, 1, 30, 'Electricity bill')''')
c.execute('''INSERT INTO splits
VALUES (1, 2, 1, 10),
(2, 3, 1, 10),
(3, 1, 1, 10)''')
conn.commit()
conn.close()
This creates the basic tables and structure to store users, groups, expenses and splits. Additional logic would be needed for the actual app front-end, calculating balances, settling up expenses etc. But this is the SQLite database backend.