def get_target_id(reply_id): sql = select([t3_reply.c.target_id]).where(t3_reply.c.reply_id == reply_id) with engine.connect() as conn: results = conn.execute(sql) row = results.first() if row is None: return None return row[t3_reply.c.target_id]
def addCodeSnippet(n, c, p): connection = engine.connect() ins = codesnippet.insert( values=dict(name=n, code=c, pub_date=p) ) result = connection.execute(ins) connection.close() return result.inserted_primary_key
def generate(): field_mappings = reviews_report_mappings() columns = [field[0].label(field[1]) for field in field_mappings] conn = engine.connect() result = conn.execute(select(columns)) rows = (dict(row) for row in result) for blob in write_report(rows, field_mappings): yield blob result.close()
def is_deletable(reply_id): sql = select([t3_reply.c.is_deletable ]).where(t3_reply.c.reply_id == reply_id) with engine.connect() as conn: results = conn.execute(sql) row = results.first() if row is None: return True return bool(row[t3_reply.c.is_deletable])
def record_submission_reply(submission, comment_reply, topic_flags=0, extra_flags=0): target_id = submission.id reply_id = comment_reply.id target_created = submission.created_utc author_name = submission.author.name with engine.connect() as conn: result = conn.execute(sql_lines.target_id_exists, b_target_id=target_id) row = result.first() if row[0]: # The target id is already in the database. # This shouldn't happen, but update the fields just in case. with engine.connect() as conn: conn.execute(sql_lines.record_submission_reply_update, b_author_name=author_name, b_reply_id=reply_id, b_target_created=target_created, b_topic_flags=topic_flags, b_previous_topic_flags=None, b_extra_flags=extra_flags, b_is_set=True, b_is_ignored=False, b_is_deletable=True, b_target_id=target_id) else: with engine.connect() as conn: conn.execute(sql_lines.record_submission_reply_insert, b_target_id=target_id, b_author_name=author_name, b_reply_id=reply_id, b_target_created=target_created, b_topic_flags=topic_flags, b_previous_topic_flags=None, b_extra_flags=extra_flags, b_is_set=True, b_is_ignored=False, b_is_deletable=True)
def review(review_id): if request.method == 'GET': conn = engine.connect() return jsonify(get_review(conn, review_id)) elif request.method == 'PUT': review = request.get_json() with engine.begin() as conn: save_review(conn, review_id, review) return jsonify(review['id']) else: return 'error'
def generate(): field_mappings = effect_sizes_report_mappings() columns = [field[0].label(field[1]) for field in field_mappings] conn = engine.connect() query = select(columns).where( (exposures_table.c.id == effect_sizes_table.c.exposure_id) & (outcomes_table.c.id == effect_sizes_table.c.outcome_id) & (moderators_table.c.id == effect_sizes_table.c.moderator_id)) result = conn.execute(query) rows = (dict(row) for row in result) for blob in write_report(rows, field_mappings): yield blob result.close()
def getCodeSinppet(i): connection = engine.connect() ins = codesnippet.select(codesnippet.c.id == i) result = connection.execute(ins) row = result.fetchone() cs = None if row is not None: cs = {} cs["id"] = row['id'] cs["name"] = row['name'] cs["code"] = row['code'] cs["pub_date"] = unicode(row['pub_date']) connection.close() return cs
def getCodeSinppets(): connection = engine.connect() ins = codesnippet.select() result = connection.execute(ins) rows = result.fetchall() cslist = [] for row in rows: cs = {} cs["id"] = row['id'] cs["name"] = row['name'] cs["code"] = row['code'] cs["pub_date"] = unicode(row['pub_date']) cslist.append(cs) connection.close() return cslist
def reviews(): if request.method == 'GET': conn = engine.connect() return jsonify(list_reviews(conn)) else: return 'error'
def assign_extra_flags(extra_flags, target_id): with engine.connect() as conn: conn.execute(sql_lines.extra_flags, b_extra_flags=extra_flags, b_target_id=target_id)
def assign_previous_topic_flags(topic_flags, target_id): with engine.connect() as conn: conn.execute(sql_lines.previous_topic_flags, b_previous_topic_flags=topic_flags, b_target_id=target_id)
def assign_is_deletable_0(target_id): with engine.connect() as conn: conn.execute(sql_lines.is_deletable_0, b_target_id=target_id)
def assign_is_ignored_1(target_id): with engine.connect() as conn: conn.execute(sql_lines.is_ignored_1, b_target_id=target_id)
def revisit(): with engine.connect() as conn: results = conn.execute(sql_lines.revisit, b_current_epoch=time.time()) for row in results: yield row
def updateCodeSnippet(i, n, c): connection = engine.connect() ins = update(codesnippet).where(codesnippet.c.id == i).values(name=n, code=c) connection.execute(ins) connection.close() return