Compare commits

...

9 Commits

Author SHA1 Message Date
Neil Parikh 89977d3c57 Merge branch 'main' into william/setup-db 2021-03-11 07:19:46 -05:00
William Tran 288de5a45b Merge remote-tracking branch 'refs/remotes/origin/william/setup-db' into william/setup-db 2021-03-10 22:45:31 -05:00
William Tran 9e5bb54eab Raise exception if links tables already exists 2021-03-10 22:43:25 -05:00
William Tran 3035b138f9 Remove active column 2021-03-10 22:30:22 -05:00
William Tran 676442ac07 Apply 1 suggestion(s) to 1 file(s) 2021-03-10 00:21:50 -05:00
William 98dacb78a3 Add check to see if links table already exists 2021-03-09 19:56:02 -05:00
William 28f1c680e7 Add constraints to links table columns 2021-03-09 19:09:21 -05:00
William b4a996023a Add position column to links table 2021-03-08 21:16:11 -05:00
William 2e1344d49a Adds python file to setup database 2021-03-07 22:51:35 -05:00
2 changed files with 37 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
venv venv
links.db

35
backend/setup_db.py Normal file
View File

@ -0,0 +1,35 @@
import sqlite3
import os
DB_PATH = os.path.join(os.path.dirname(__file__), 'links.db')
con = sqlite3.connect(DB_PATH)
# array of links to store
links = [
('http://csclub.uwaterloo.ca/','CS Club Website',3,0),
('https://www.instagram.com/uwcsclub/','Instagram',4,1),
('https://www.facebook.com/uw.computerscienceclub','Facebook',5,2),
('http://twitch.tv/uwcsclub','Twitch',6,3),
('http://bit.ly/uwcsclub-yt','YouTube',7,4),
]
# 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():
raise Exception('Links table already exists.')
else:
cur.execute('''CREATE TABLE links (
url text NOT NULL,
name text NOT NULL,
clicks int NOT NULL,
position int NOT NULL UNIQUE,
UNIQUE(url, name)
)''')
cur.executemany('INSERT INTO links VALUES (?,?,?,?)', links)
con.commit()
con.close()