本文整理匯總了Python中API.tools.DBconnect類的典型用法代碼示例。如果您正苦於以下問題:Python DBconnect類的具體用法?Python DBconnect怎麽用?Python DBconnect使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DBconnect類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: followers_list
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
示例2: threads_list
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
示例3: remove_restore
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
示例4: open_close_thread
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
示例5: remove_follow
def remove_follow(email1, email2):
follows = DBconnect.select_query(
'SELECT id FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, )
)
if len(follows) != 0:
DBconnect.update_query('DELETE FROM Followers WHERE follower = %s AND followee = %s', (email1, email2, ))
else:
raise Exception("No such following")
return users.details(email1)
示例6: details
def details(id, related):
thread = DBconnect.select_query(
'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
'FROM Threads WHERE id = %s', (id, )
)
if len(thread) == 0:
raise Exception('No thread exists with id=' + str(id))
thread = thread[0]
thread = {
'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],
}
if "user" in related:
thread["user"] = users.details(thread["user"])
if "forum" in related:
thread["forum"] = forums.details(short_name=thread["forum"], related=[])
return thread
示例7: post_query
def post_query(id):
post = DBconnect.select_query('select date, dislikes, forum, id, isApproved, isDeleted, isEdited, '
'isHighlighted, isSpam, likes, message, parent, points, thread, user '
'FROM Posts WHERE id = %s', (id, ))
if len(post) == 0:
return None
return post_formated(post)
示例8: save_user
def save_user(email, username, about, name, optional):
isAnonymous = 0
if "isAnonymous" in optional:
isAnonymous = optional["isAnonymous"]
try:
user = DBconnect.select_query('select email, about, isAnonymous, id, name, username FROM Users WHERE email = %s',
(email, ))
if len(user) == 0:
DBconnect.update_query(
'INSERT INTO Users (email, about, name, username, isAnonymous) VALUES (%s, %s, %s, %s, %s)',
(email, about, name, username, isAnonymous, ))
user = DBconnect.select_query('select email, about, isAnonymous, id, name, username FROM Users WHERE email = %s',
(email, ))
except Exception as e:
raise Exception(e.message)
return user_format(user)
示例9: list_users
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
示例10: details
def details(email):
user = DBconnect.select_query('select email, about, isAnonymous, id, name, username FROM Users WHERE email = %s', (email, ))
user = user_format(user)
if user is None:
raise Exception("No user with email " + email)
user["followers"] = followers(email, "follower")
user["following"] = followers(email, "followee")
user["subscriptions"] = user_subscriptions(email)
return user
示例11: select_query
def select_query(query, params):
try:
con = DBconnect.connect()
cursor = con.cursor()
cursor.execute(query, params)
result = cursor.fetchall()
cursor.close()
con.close()
except db.Error as e:
raise Exception(e.message)
return result
示例12: followers
def followers(email, type):
where = "followee"
if type == "follower":
where = "followee"
if type == "followee":
where = "follower"
f_list = DBconnect.select_query(
"SELECT " + type + " FROM Followers JOIN Users ON Users.email = Followers." + type +
" WHERE " + where + " = %s ", (email, )
)
return tuple2list(f_list)
示例13: details
def details(short_name, related):
forum = DBconnect.select_query(
'select id, name, short_name, user FROM Forums WHERE short_name = %s', (short_name, )
)
if len(forum) == 0:
raise ("No forum with exists short_name=" + short_name)
forum = forum_description(forum)
if "user" in related:
forum["user"] = users.details(forum["user"])
return forum
示例14: vote
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=[])
示例15: update_query
def update_query(query, params):
try:
con = DBconnect.connect()
cursor = con.cursor()
cursor.execute(query, params)
con.commit()
inserted_id = cursor.lastrowid
cursor.close()
con.close()
except db.Error as e:
raise Exception(e.message)
return inserted_id