forked from CodecoolBase/proman-javascript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnection.py
106 lines (85 loc) · 2.75 KB
/
connection.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import database_common
from psycopg2 import sql
@database_common.connection_handler
def select_boards(cursor):
query = """SELECT * FROM boards"""
cursor.execute(query)
boards = cursor.fetchall()
return boards
@database_common.connection_handler
def select_cards(cursor):
query = """SELECT * FROM cards"""
cursor.execute(query)
cards = cursor.fetchall()
return cards
@database_common.connection_handler
def select_statuses(cursor):
query = """SELECT * FROM statuses"""
cursor.execute(query)
statuses = cursor.fetchall()
return statuses
@database_common.connection_handler
def select_users(cursor):
query = """SELECT * FROM users"""
cursor.execute(query)
users = cursor.fetchall()
return users
@database_common.connection_handler
def delete_from(cursor,table):
query = sql.SQL("""DELETE FROM {}""").format(sql.Identifier(table))
cursor.execute(query)
@database_common.connection_handler
def insert_to_boards(cursor,params):
query = """
INSERT INTO boards(id, title, is_active, user_id)
VALUES(%(id)s,%(title)s,%(is_active)s,%(user_id)s)
"""
cursor.execute(query,params)
@database_common.connection_handler
def insert_to_cards(cursor,params):
query = """
INSERT INTO cards(id, title, board_id, status_id, card_order)
VALUES(%(id)s,%(title)s,%(board_id)s,%(status_id)s,%(card_order)s)
"""
cursor.execute(query,params)
@database_common.connection_handler
def insert_new_user(cursor,username,hashed_password):
query= """
INSERT INTO users(nick_name,hashed_password)
VALUES(%(username)s,%(hashed_password)s)
"""
params={
'username':username,
'hashed_password':hashed_password
}
cursor.execute(query,params)
@database_common.connection_handler
def get_hashed_password_by_username(cursor,username):
query="""
SELECT hashed_password FROM users
WHERE nick_name = %(username)s
"""
params = {'username':username}
cursor.execute(query,params)
hashed_pwd = cursor.fetchone()
if hashed_pwd is not None:
return hashed_pwd['hashed_password']
else:
return ''
@database_common.connection_handler
def get_all_usernames(cursor):
query = """
SELECT nick_name FROM users
"""
cursor.execute(query)
return cursor.fetchall()
@database_common.connection_handler
def get_user_id_by_username(cursor,username):
query = """
SELECT id FROM users
WHERE nick_name = %(username)s
"""
params = {'username':username}
cursor.execute(query,params)
id = cursor.fetchone()
return id['id']