LinkList/backend/setup_db.py

32 lines
887 B
Python
Raw Normal View History

2021-03-07 22:51:35 -05:00
import sqlite3
con = sqlite3.connect('links.db')
# array of links to store
links = [
2021-03-08 21:16:11 -05:00
('http://csclub.uwaterloo.ca/','CS Club Website',3,1,0),
('https://www.instagram.com/uwcsclub/','Instagram',4,1,1),
('https://www.facebook.com/uw.computerscienceclub','Facebook',5,0,2),
('http://twitch.tv/uwcsclub','Twitch',6,0,3),
('http://bit.ly/uwcsclub-yt','YouTube',7,1,4),
2021-03-07 22:51:35 -05:00
]
# SQLite setup
cur = con.cursor()
# test if table already exists
cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='links'")
if cur.fetchone():
print('Links table already exists.')
else:
cur.execute('''CREATE TABLE links (
url text NOT NULL,
name text NOT NULL,
clicks int NOT NULL,
active int NOT NULL,
position int NOT NULL UNIQUE,
UNIQUE(url, name)
)''')
cur.executemany('INSERT INTO links VALUES (?,?,?,?,?)', links)
con.commit()
2021-03-07 22:51:35 -05:00
con.close()