def get_query_list_threads(data, has_forum): query = Query() columns = "t.*" if has_forum: columns += ", f.id, f.name, f.short_name, f.user" query.add_select("thread as t", columns) if has_forum: query.add_left_join("forum as f", "t.forum = f.short_name") if data.get("forum"): query.add_where_condition("t.forum = \"{}\"".format(data["forum"])) else: query.add_where_condition("t.user = \"{}\"".format(data["user"])) if "since" in data: query.add_more_where_condition("t.date > \"{}\"".format(data["since"])) query.add_order_by("t.date", data["order"]) if "limit" in data: query.add_limit(data["limit"]) return query
def get_query_list_posts_by_forum(data, has_forum, has_thread): query = Query() columns = "p.id, p.message, p.date, p.isApproved, p.isHighlighted, p.isEdited, p.isSpam, " \ "p.isDeleted, p.forum, p.thread, p.user, p.dislikes, p.likes, p.points, p.parent" if has_forum: columns += ", f.id, f.name, f.short_name, f.user" if has_thread: columns += ", t.id, t.title, t.slug, t.message, t.date, " \ "t.posts, t.likes, t.dislikes, t.points, " \ "t.isClosed, t.isDeleted, t.forum, t.user" query.add_select("post as p", columns) if has_forum: query.add_left_join("forum as f", "p.forum = f.short_name") if has_thread: query.add_left_join("thread as t", "p.thread = t.id") if data.get("forum"): query.add_where_condition("p.forum = \"{}\"".format(data["forum"])) else: query.add_where_condition("p.thread = \"{}\"".format(data["thread"])) if "since" in data: query.add_more_where_condition("p.date > \"{}\"".format(data["since"])) query.add_order_by("p.date", data["order"]) if "limit" in data: query.add_limit(data["limit"]) return query
def get_query_users_by_followers(data, follower=None): query = Query() columns = 'u.*, group_concat(distinct f.following),' \ 'group_concat(distinct f1.follower),' \ 'group_concat(distinct s.thread)' query.add_select("user as u", columns) query.add_left_join("follow as f", "u.email = f.follower") query.add_left_join("follow as f1", "u.email = f1.following") query.add_left_join("subscribe as s", "u.email= s.user") query.add_left_join("post as p", "p.user = u.email") if follower: query.add_where_condition("f.following = \"{}\"".format(data["user"])) else: query.add_where_condition("f.follower = \"{}\"".format(data["user"])) if "since_id" in data: query.add_more_where_condition(" u.id >= {}".format(data["since_id"])) if follower: query.add_group_by("f.follower") else: query.add_group_by("f.following") query.add_order_by("u.name", data["order"]) if "limit" in data: query.add_limit(data["limit"]) return query
def get_query_list_child_posts(data, id_parent, do_limit=None): query = Query() columns = "id, message, date, isApproved, isHighlighted, isEdited, isSpam, " \ "isDeleted, forum, thread, user, dislikes, likes, points, parent" query.add_select("post", columns) query.add_where_condition("parent = {}".format(id_parent)) if "since" in data: query.add_more_where_condition("date > \"{}\"".format(data["since"])) if do_limit: query.add_limit(data["limit"]) query.add_order_by("date", "asc") return query
def get_query_list_root_posts(data): query = Query() columns = "id, message, date, isApproved, isHighlighted, isEdited, isSpam, " \ "isDeleted, forum, thread, user, dislikes, likes, points, parent" query.add_select("post", columns) query.add_where_condition("parent is NULL ") query.add_more_where_condition(" thread = {}".format(data["thread"])) if "since" in data: query.add_more_where_condition("date > \"{}\"".format(data["since"])) query.add_order_by("date", data["order"]) if "limit" in data: query.add_limit(data["limit"]) return query
def get_query_list_posts_by_thread(data): query = Query() columns = "p.id, p.message, p.date, p.isApproved, p.isHighlighted, p.isEdited, p.isSpam," \ "p.isDeleted, p.forum, p.thread, p.user, p.dislikes, p.likes, p.points, p.parent" query.add_select("post as p", columns) query.add_where_condition("p.thread = \"{}\"".format(data["thread"])) if "since" in data: query.add_more_where_condition("p.date > \"{}\"".format(data["since"])) query.add_order_by("p.date", data["order"]) if "limit" in data: query.add_limit(data["limit"]) return query