def edit_tread(id, name, board_id): with db.cursor() as cursor: db.autocommit = True cursor.execute( 'UPDATE tread SET name = %s, board_id = %s WHERE id = %s', (name, board_id, id)) print("Edit tread with id %s", id)
def create_board(name): with db.cursor() as cursor: db.autocommit = True values = [(name)] insert = sql.SQL('INSERT INTO board (name) VALUES ({})').format( sql.SQL(',').join(map(sql.Literal, values))) cursor.execute(insert) print("create")
def get_board(id): ret = {} with db.cursor() as cursor: db.autocommit = True cursor.execute('SELECT * FROM board WHERE board.id = %s;', id) for row in cursor: ret[row[0]] = {'name': row[1]} return ret
def get_all_boards(): ret = {} with db.cursor() as cursor: db.autocommit = True cursor.execute('SELECT * FROM board;') for row in cursor: ret[row[0]] = {'name': row[1]} return ret
def get_tread(id): ret = {} with db.cursor() as cursor: db.autocommit = True cursor.execute('SELECT * FROM tread WHERE tread.id = %s;', id) for row in cursor: ret[row[0]] = {'name': row[1], 'board_id': row[2]} return ret
def create_message(author, text, tread_id): with db.cursor() as cursor: db.autocommit = True values = [(author, text, tread_id)] insert = sql.SQL( 'INSERT INTO message (author, text, tread_id) VALUES {}' ).format(sql.SQL(',').join(map(sql.Literal, values))) cursor.execute(insert) print("create")
def get_message(id): ret = {} with db.cursor() as cursor: db.autocommit = True cursor.execute('SELECT * FROM message WHERE message.id = %s;', id) for row in cursor: ret[row[0]] = { 'name': row[1], 'text': row[2], 'tread_id': row[3] } return ret
def edit_board(id, name): with db.cursor() as cursor: db.autocommit = True cursor.execute('UPDATE board SET name = %s WHERE id = %s', (name, id)) print("edit board with id %s", id)
def delete_message(id): ret = {} with db.cursor() as cursor: db.autocommit = True cursor.execute('DELETE FROM message WHERE message.id = %s;', id) return ret