Skip to content

Instantly share code, notes, and snippets.

@avinassh
Created November 9, 2024 11:35
Show Gist options
  • Save avinassh/0e7e4b0578136a338f1b9a03fba36ead to your computer and use it in GitHub Desktop.
Save avinassh/0e7e4b0578136a338f1b9a03fba36ead to your computer and use it in GitHub Desktop.
simple python script to create an SQLite database and add Alice $83k
import sqlite3
import os
def create_database(db_path, value):
if os.path.exists(db_path):
os.remove(db_path)
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS accounts(
id INTEGER PRIMARY KEY,
username TEXT,
amount_cents INTEGER
)
''')
amount_cents = int(value * 100)
cursor.execute('INSERT INTO accounts (username, amount_cents) VALUES (?, ?)',
('Alice', amount_cents))
conn.commit()
conn.close()
def main():
db_path = 'bank.db'
original_amount = 83886.08
create_database(db_path, original_amount)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment