application.py 1.22 KB
Newer Older
Vladislav Rykov's avatar
Vladislav Rykov committed
1
from misc import with_psql
Vladislav Rykov's avatar
Vladislav Rykov committed
2

Vladislav Rykov's avatar
Vladislav Rykov committed
3
4
5
6
7
8
9
10
11
12
13
@with_psql
def create(cur, name, appkey, username, desc):
    query = """
    INSERT INTO
        applications
    VALUES
        (%s, %s, %s, %s)
    """
    cur.execute(query, (name, appkey, username, desc))
       
    return (True,)
Vladislav Rykov's avatar
Vladislav Rykov committed
14

Vladislav Rykov's avatar
Vladislav Rykov committed
15
16
17
18
19
20
21
22
23
@with_psql
def delete(cur, appkey):
    query = """
    DELETE FROM
        applications
    WHERE
        app_key = %s
    """
    cur.execute(query, (appkey,))
Vladislav Rykov's avatar
Vladislav Rykov committed
24
        
Vladislav Rykov's avatar
Vladislav Rykov committed
25
    return (True,)
Vladislav Rykov's avatar
Vladislav Rykov committed
26

Vladislav Rykov's avatar
Vladislav Rykov committed
27
28
29
30
31
32
33
34
35
36
@with_psql
def get(cur, appkey):
    query = """
    SELECT * FROM
        applications
    WHERE
        app_key = %s
    """
    cur.execute(query, (appkey,))
    app = cur.fetchone()
Vladislav Rykov's avatar
Vladislav Rykov committed
37

Vladislav Rykov's avatar
Vladislav Rykov committed
38
39
40
41
    if app is None:
        return (False, 'Application with key {} does not exist'.format(appkey))
    else:
        return (True, app)
Vladislav Rykov's avatar
Vladislav Rykov committed
42
43

    
Vladislav Rykov's avatar
Vladislav Rykov committed
44
45
46
47
48
49
50
51
52
@with_psql
def get_list(cur, username):
    query = """
    SELECT * FROM
        applications
    WHERE
        username = %s
    """
    cur.execute(query, (username,))
Vladislav Rykov's avatar
Vladislav Rykov committed
53

Vladislav Rykov's avatar
Vladislav Rykov committed
54
    return (True, cur.fetchall())
Vladislav Rykov's avatar
Vladislav Rykov committed
55

Vladislav Rykov's avatar
Vladislav Rykov committed
56
57
58
59
60
61
62
63
64
65
66
67
@with_psql
def update(cur, appkey, name, desc):
    query = """
    UPDATE
        applications
    SET
        name = %s,
        description = %s,
    WHERE
        app_key = %s
    """
    cur.execute(query, (name, desc, appkey))
Vladislav Rykov's avatar
Vladislav Rykov committed
68

Vladislav Rykov's avatar
Vladislav Rykov committed
69
    return (True,)
Vladislav Rykov's avatar
Vladislav Rykov committed
70
71