Пример #1
0
def get_all_users():
    sql = ('SELECT * FROM blogger.users order by screen_name')
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(sql)
    row = cur.fetchone()
    while row:
        yield row
        row = cur.fetchone()
Пример #2
0
def store_passwd(user_id, hashed):
    sql = ('UPDATE blogger.users ' 'SET passwd=%s ' 'WHERE user_id=%s')
    cur = conn.cursor()
    try:
        cur.execute(sql, (hashed, user_id))
        conn.commit()
    except Exception as ex:
        conn.rollback()
        raise ex
Пример #3
0
def create_access_request(blog_id, user_id):
     sql = ('INSERT INTO blogger.blog_access '
             '(blog_id, user_id) values (%s, %s) '
              'RETURNING access_id') ' 
     cur = conn.cursor()
     try:
         cur.execute(sql, (blog_id, user_id))
	 return cur.fetchone()[0]
     except Exception as ex:
         conn.rollback()
         raise ex
Пример #4
0
def create_post(blog_id, title, post_text):
	sql = ('INSERT INTO blogger.posts (blog_id, title, post_text) '
                ' VALUES (%s, %s, %s) RETURNING post_id')
        cur = conn.cursor()
        try:
                cur.execute(sql, (blog_id, title, post_text))

        except Exception as ex:
                print "Ex: %s" % ex
                conn.rollback()
                raise ex

        conn.commit()
        blog_id = cur.fetchone()[0]
        return blog_id
Пример #5
0
def create_blog(title, blog_user_id):
    sql = ('INSERT INTO blogger.blogs (title, blog_user_id) '
           ' VALUES (%s, %s) RETURNING blog_id')
    cur = conn.cursor()
    try:
        cur.execute(sql, (title, blog_user_id))

    except Exception as ex:
        print "Ex: %s" % ex
        conn.rollback()
        raise ex

    conn.commit()
    blog_id = cur.fetchone()[0]
    return blog_id
Пример #6
0
def access_list(user_id):
    sql = ('SELECT * FROM blogger.blog_access')
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(sql)
    return cur.fetchall()
Пример #7
0
def get_post_by_id(post_id):
    sql = ('SELECT * FROM blogger.posts '
           'WHERE post_id = %s ')
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(sql, (post_id,))
    return cur.fetchall()