-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
29 lines (26 loc) · 809 Bytes
/
database.py
File metadata and controls
29 lines (26 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sqlite3
def init_db():
conn = sqlite3.connect('invoices.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS invoices (
id INTEGER PRIMARY KEY,
file_name TEXT,
content TEXT
)
''')
conn.commit()
conn.close()
def add_invoice(file_name, content):
conn = sqlite3.connect('invoices.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO invoices (file_name, content) VALUES (?, ?)', (file_name, content))
conn.commit()
conn.close()
def get_all_invoices():
conn = sqlite3.connect('invoices.db')
cursor = conn.cursor()
cursor.execute('SELECT file_name, content FROM invoices')
invoices = cursor.fetchall()
conn.close()
return invoices