def get():
     query = """
   SELECT *
   FROM users
   WHERE id = %(id)s
   LIMIT 1;
 """
     result = get_row(db_conn, query, params)
     return result
def test_get_row(db_conn, session):
    query = """
    SELECT *
    FROM users
    WHERE id = %(id)s
    LIMIT 1;
  """
    params = {
        'id': convert_slug_to_uuid(user_id),
    }
    result = get_row(db_conn, query, params)
    assert result['id'] == convert_slug_to_uuid(user_id)
Beispiel #3
0
def get_subject_version(db_conn, version_id):
  """
  Get a subject version.
  """

  query = """
    SELECT *
    FROM subjects
    WHERE version_id = %(version_id)s
    ORDER BY created DESC;
    /* TODO LIMIT OFFSET */
  """
  params = {'version_id': convert_slug_to_uuid(version_id)}
  return get_row(db_conn, query, params)
def get_card_parameters(db_conn, params):
    """
  Get Card Parameters
  """
    query = """
    SELECT *
    FROM cards_parameters
    WHERE entity_id = %(entity_id)s
    LIMIT 1;
  """
    params = {
        'entity_id': convert_slug_to_uuid(params['entity_id']),
    }
    return get_row(db_conn, query, params)
Beispiel #5
0
def get_notice(db_conn, params):
    """
  Get the user matching the parameters.
  """

    query = """
    SELECT *
    FROM notices
    WHERE id = %(id)s
    LIMIT 1;
  """
    params = {
        'id': convert_slug_to_uuid(params['id']),
    }
    return get_row(db_conn, query, params)
Beispiel #6
0
def does_subject_exist(db_conn, entity_id):
  """
  Just... is this a valid subject entity_id.
  """

  query = """
    SELECT entity_id
    FROM subjects_entity_id
    WHERE entity_id = %(entity_id)s
    LIMIT 1;
  """
  params = {
    'entity_id': convert_slug_to_uuid(entity_id),
  }
  return get_row(db_conn, query, params)
Beispiel #7
0
def get_user_by_name(db_conn, params):
    """
  Get the user by name.
  """

    query = """
    SELECT *
    FROM users
    WHERE name = %(name)s
    LIMIT 1;
  """
    params = {
        'name': params['name'],
    }
    return get_row(db_conn, query, params)
Beispiel #8
0
def get_user_by_email(db_conn, params):
    """
  Get the user by email.
  """

    query = """
    SELECT *
    FROM users
    WHERE email = %(email)s
    LIMIT 1;
  """
    params = {
        'email': params['email'],
    }
    return get_row(db_conn, query, params)
Beispiel #9
0
def get_user_by_id(db_conn, params):
    """
  Get the user by ID.
  """

    query = """
    SELECT *
    FROM users
    WHERE id = %(id)s
    LIMIT 1;
  """
    params = {
        'id': convert_slug_to_uuid(params['id']),
    }
    return get_row(db_conn, query, params)
Beispiel #10
0
def get_follow_by_id(db_conn, follow_id):
    """
  Find a specific follow (entity <-> user).
  """

    query = """
    SELECT *
    FROM follows
    WHERE id = %(id)s
    LIMIT 1;
  """
    params = {
        'id': convert_slug_to_uuid(follow_id),
    }
    return get_row(db_conn, query, params)
Beispiel #11
0
def get_latest_accepted_subject(db_conn, entity_id):
  """
  Get Latest Accepted Subject Version by EID
  """

  query = """
    SELECT DISTINCT ON (entity_id) *
    FROM subjects
    WHERE status = 'accepted' AND entity_id = %(entity_id)s
    ORDER BY entity_id, created DESC;
    /* TODO LIMIT */
  """
  params = {
    'entity_id': convert_slug_to_uuid(entity_id),
  }
  return get_row(db_conn, query, params)
Beispiel #12
0
def get_follow(db_conn, user_id, entity_id):
    """
  Find a specific follow (entity <-> user).
  """

    query = """
    SELECT *
    FROM follows
    WHERE user_id = %(user_id)s AND entity_id = %(entity_id)s
    LIMIT 1;
  """
    params = {
        'user_id': convert_slug_to_uuid(user_id),
        'entity_id': convert_slug_to_uuid(entity_id),
    }
    return get_row(db_conn, query, params)
Beispiel #13
0
def get_latest_response(db_conn, user_id, unit_id):
    """
  Get the latest response given a user ID and a unit ID.
  """

    query = """
    SELECT *
    FROM responses
    WHERE user_id = %(user_id)s AND unit_id = %(unit_id)s
    ORDER BY created DESC
    LIMIT 1;
  """
    params = {
        'user_id': convert_slug_to_uuid(user_id),
        'unit_id': convert_slug_to_uuid(unit_id),
    }
    return get_row(db_conn, query, params)
def test_get_row_error(db_conn):
    query = "a;"
    params = {}
    result = get_row(db_conn, query, params)
    assert result is None