def list(count): conn = connect() cur = conn.cursor() query = "SELECT id,title FROM %s ORDER BY id DESC LIMIT %d" query = query % (Config.DB_TABLE, count) cur.execute(query) result = Result() result.posts = [] for row in cur.fetchall(): post = Post() post.id = row[0] post.title = row[1] result.posts += [post] return result
def get(id): conn = connect() cur = conn.cursor() cur.execute("SELECT * FROM %s WHERE id='%d'" % (Config.DB_TABLE, id)) row = cur.fetchall() if len(row) == 0: return Result() row = row[0] result = Result() post = Post() post.id = row[0] post.title = row[1] post.content = row[2] post.date = str(row[3]) result.posts = [post] return result