本文整理匯總了Python中API.tools.DBconnect.exist方法的典型用法代碼示例。如果您正苦於以下問題:Python DBconnect.exist方法的具體用法?Python DBconnect.exist怎麽用?Python DBconnect.exist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類API.tools.DBconnect
的用法示例。
在下文中一共展示了DBconnect.exist方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: vote
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def vote(vote_id, vote_type):
DBconnect.exist(entity="Posts", identifier="id", value=vote_id)
if vote_type == -1:
DBconnect.update_query("UPDATE Posts SET dislikes=dislikes+1, points=points-1 where id = %s", (vote_id,))
else:
DBconnect.update_query("UPDATE Posts SET likes=likes+1, points=points+1 where id = %s", (vote_id,))
return details(details_id=vote_id, related=[])
示例2: followers_list
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def followers_list(email, type, params):
DBconnect.exist(entity="Users", identifier="email", value=email)
if type == "follower":
where = "followee"
if type == "followee":
where = "follower"
query = "SELECT " + type + " FROM Followers JOIN Users ON Users.email = Followers." + type + \
" WHERE " + where + " = %s "
if "since_id" in params:
query += " AND Users.id >= " + str(params["since_id"])
if "order" in params:
query += " ORDER BY Users.name " + params["order"]
else:
query += " ORDER BY Users.name DESC "
if "limit" in params:
query += " LIMIT " + str(params["limit"])
followers_ids_tuple = DBconnect.select_query(query=query, params=(email, ))
f_list = []
for id in followers_ids_tuple:
id = id[0]
f_list.append(users.details(email=id))
return f_list
示例3: threads_list
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def threads_list(entity, identifier, related, params):
if entity == "forum":
DBconnect.exist(entity="Forums", identifier="short_name", value=identifier)
if entity == "user":
DBconnect.exist(entity="Users", identifier="email", value=identifier)
query = "SELECT id FROM Threads WHERE " + entity + " = %s "
parameters = [identifier]
if "since" in params:
query += " AND date >= %s"
parameters.append(params["since"])
if "order" in params:
query += " ORDER BY date " + params["order"]
else:
query += " ORDER BY date DESC "
if "limit" in params:
query += " LIMIT " + str(params["limit"])
thread_ids_tuple = DBconnect.select_query(query=query, params=parameters)
thread_list = []
for id in thread_ids_tuple:
id = id[0]
thread_list.append(details(id=id, related=related))
return thread_list
示例4: remove_restore
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def remove_restore(thread_id, status):
DBconnect.exist(entity="Threads", identifier="id", value=thread_id)
DBconnect.update_query("UPDATE Threads SET isDeleted = %s WHERE id = %s", (status, thread_id, ))
response = {
"thread": thread_id
}
return response
示例5: open_close_thread
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def open_close_thread(id, isClosed):
DBconnect.exist(entity="Threads", identifier="id", value=id)
DBconnect.update_query("UPDATE Threads SET isClosed = %s WHERE id = %s", (isClosed, id, ))
response = {
"thread": id
}
return response
示例6: vote
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def vote(id, vote):
DBconnect.exist(entity="Threads", identifier="id", value=id)
if vote == -1:
DBconnect.update_query("UPDATE Threads SET dislikes=dislikes+1, points=points-1 where id = %s", (id, ))
else:
DBconnect.update_query("UPDATE Threads SET likes=likes+1, points=points+1 where id = %s", (id, ))
return details(id=id, related=[])
示例7: save_forum
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def save_forum(name, short_name, user):
DBconnect.exist(entity="Users", identifier="email", value=user)
forum = DBconnect.select_query(
'select id, name, short_name, user FROM Forums WHERE short_name = %s', (short_name, )
)
if len(forum) == 0:
DBconnect.update_query('INSERT INTO Forums (name, short_name, user) VALUES (%s, %s, %s)',
(name, short_name, user, ))
forum = DBconnect.select_query(
'select id, name, short_name, user FROM Forums WHERE short_name = %s', (short_name, )
)
return forum_description(forum)
示例8: remove_subscription
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def remove_subscription(email, thread_id):
DBconnect.exist(entity="Threads", identifier="id", value=thread_id)
DBconnect.exist(entity="Users", identifier="email", value=email)
subscription = DBconnect.select_query(
'select thread, user FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, )
)
if len(subscription) == 0:
raise Exception("user " + email + " does not subscribe thread #" + str(thread_id))
DBconnect.update_query('DELETE FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, ))
response = {
"thread": subscription[0][0],
"user": subscription[0][1]
}
return response
示例9: add_follow
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def add_follow(email1, email2):
DBconnect.exist(entity="Users", identifier="email", value=email1)
DBconnect.exist(entity="Users", identifier="email", value=email2)
if email1 == email2:
raise Exception("User with email=" + email1 + " can't follow himself")
follows = DBconnect.select_query(
'SELECT id FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, )
)
if len(follows) == 0:
DBconnect.update_query('INSERT INTO Followers (follower, followee) VALUES (%s, %s)', (email1, email2, ))
user = users.details(email1)
return user
示例10: save_subscription
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def save_subscription(email, thread_id):
DBconnect.exist(entity="Threads", identifier="id", value=thread_id)
DBconnect.exist(entity="Users", identifier="email", value=email)
subscription = DBconnect.select_query(
'select thread, user FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, )
)
if len(subscription) == 0:
DBconnect.update_query('INSERT INTO Subscriptions (thread, user) VALUES (%s, %s)', (thread_id, email, ))
subscription = DBconnect.select_query(
'select thread, user FROM Subscriptions WHERE user = %s AND thread = %s', (email, thread_id, )
)
response = {
"thread": subscription[0][0],
"user": subscription[0][1]
}
return response
示例11: list_users
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def list_users(short_name, optional):
DBconnect.exist(entity="Forums", identifier="short_name", value=short_name)
query = "SELECT distinct email FROM Users JOIN Posts ON Posts.user = Users.email " \
" JOIN Forums on Forums.short_name = Posts.forum WHERE Posts.forum = %s "
if "since_id" in optional:
query += " AND Users.id >= " + str(optional["since_id"])
if "order" in optional:
query += " ORDER BY Users.id " + optional["order"]
if "limit" in optional:
query += " LIMIT " + str(optional["limit"])
users_tuple = DBconnect.select_query(query, (short_name, ))
list_u = []
for user in users_tuple:
user = user[0]
list_u.append(users.details(user))
return list_u
示例12: save_thread
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def save_thread(forum, title, isClosed, user, date, message, slug, optional):
DBconnect.exist(entity="Users", identifier="email", value=user)
DBconnect.exist(entity="Forums", identifier="short_name", value=forum)
isDeleted = 0
if "isDeleted" in optional:
isDeleted = optional["isDeleted"]
thread = DBconnect.select_query(
'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
'FROM Threads WHERE slug = %s', (slug, )
)
if len(thread) == 0:
DBconnect.update_query('INSERT INTO Threads (forum, title, isClosed, user, date, message, slug, isDeleted) '
'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
(forum, title, isClosed, user, date, message, slug, isDeleted, ))
thread = DBconnect.select_query(
'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
'FROM Threads WHERE slug = %s', (slug, )
)
thread = thread[0]
response = {
'date': str(thread[0]),
'forum': thread[1],
'id': thread[2],
'isClosed': bool(thread[3]),
'isDeleted': bool(thread[4]),
'message': thread[5],
'slug': thread[6],
'title': thread[7],
'user': thread[8],
'dislikes': thread[9],
'likes': thread[10],
'points': thread[11],
'posts': thread[12],
}
# Delete few extra elements
del response["dislikes"]
del response["likes"]
del response["points"]
del response["posts"]
return response
示例13: create
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def create(date, thread, message, user, forum, optional):
DBconnect.exist(entity="Threads", identifier="id", value=thread)
DBconnect.exist(entity="Forums", identifier="short_name", value=forum)
DBconnect.exist(entity="Users", identifier="email", value=user)
if len(DBconnect.select_query("SELECT Threads.id FROM Threads JOIN Forums ON Threads.forum = Forums.short_name "
"WHERE Threads.forum = %s AND Threads.id = %s", (forum, thread, ))) == 0:
raise Exception("no thread with id = " + str(thread) + " in forum " + forum)
if "parent" in optional:
if len(DBconnect.select_query("SELECT Posts.id FROM Posts JOIN Threads ON Threads.id = Posts.thread "
"WHERE Posts.id = %s AND Threads.id = %s", (optional["parent"], thread, ))) == 0:
raise Exception("No post with id = " + optional["parent"])
query = "INSERT INTO Posts (message, user, forum, thread, date"
values = "(%s, %s, %s, %s, %s"
parameters = [message, user, forum, thread, date]
for param in optional:
query += ", " + param
values += ", %s"
parameters.append(optional[param])
query += ") VALUES " + values + ")"
update_thread_posts = "UPDATE Threads SET posts = posts + 1 WHERE id = %s"
con = DBConnection()
con = con.connect()
con.autocommit(False)
with con:
cursor = con.cursor()
try:
con.begin()
cursor.execute(update_thread_posts, (thread, ))
cursor.execute(query, parameters)
con.commit()
except Exception as e:
con.rollback()
raise Exception("Database error: " + e.message)
post_id = cursor.lastrowid
cursor.close()
con.close()
post = post_query(post_id)
del post["dislikes"]
del post["likes"]
del post["parent"]
del post["points"]
return post
示例14: remove_restore
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def remove_restore(post_id, status):
DBconnect.exist(entity="Posts", identifier="id", value=post_id)
DBconnect.update_query("UPDATE Posts SET isDeleted = %s WHERE Posts.id = %s", (status, post_id))
return {"post": post_id}
示例15: update
# 需要導入模塊: from API.tools import DBconnect [as 別名]
# 或者: from API.tools.DBconnect import exist [as 別名]
def update(update_id, message):
DBconnect.exist(entity="Posts", identifier="id", value=update_id)
DBconnect.update_query("UPDATE Posts SET message = %s WHERE id = %s", (message, update_id))
return details(details_id=update_id, related=[])