-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
49 lines (45 loc) · 1.37 KB
/
model.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
from schema import engine, codesnippet
from sqlalchemy import update, select
def addCodeSnippet(n, c, p):
connection = engine.connect()
ins = codesnippet.insert(
values=dict(name=n, code=c, pub_date=p)
)
result = connection.execute(ins)
connection.close()
return result.inserted_primary_key
def updateCodeSnippet(i, n, c):
connection = engine.connect()
ins = update(codesnippet).where(codesnippet.c.id == i).values(name=n, code=c)
connection.execute(ins)
connection.close()
return
def getCodeSinppet(i):
connection = engine.connect()
ins = codesnippet.select(codesnippet.c.id == i)
result = connection.execute(ins)
row = result.fetchone()
cs = None
if row is not None:
cs = {}
cs["id"] = row['id']
cs["name"] = row['name']
cs["code"] = row['code']
cs["pub_date"] = unicode(row['pub_date'])
connection.close()
return cs
def getCodeSinppets():
connection = engine.connect()
ins = codesnippet.select()
result = connection.execute(ins)
rows = result.fetchall()
cslist = []
for row in rows:
cs = {}
cs["id"] = row['id']
cs["name"] = row['name']
cs["code"] = row['code']
cs["pub_date"] = unicode(row['pub_date'])
cslist.append(cs)
connection.close()
return cslist