db.crud module

Create Retrieve Update and Delete (CRUD) functions for database tables

Rather than litter the code with raw database queries the vast majority should be turned into reusable functions that are defined in this file.

async db.crud.count_matching_questions(name: str) int

Count the number of Question entries that match the given name.

Parameters:

name – str, the name (div_id) of the question

Returns:

int, the number of matching questions

async db.crud.count_useinfo_for(div_id: str, course_name: str, start_date: datetime) List[tuple]

return a list of tuples that include the [(act, count), (act, count)] act is a freeform field in the useinfo table that varies from event type to event type.

Parameters:
  • div_id (str) – Unique identifier of a Runestone component

  • course_name (str) – The current course

  • start_date (datetime.datetime) –

Returns:

A list of tuples [(act, count), (act), count)]

Return type:

List[tuple]

async db.crud.create_answer_table_entry(log_entry: LogItemIncoming, event: str) LogItemIncoming

Populate the xxx_answers table with the incoming data

Parameters:
  • log_entry (schemas.LogItemIncoming) –

  • event (str) – Will be something like “mchoice”, “parsons”, etc.

Returns:

Returns the newly created item

Return type:

schemas.LogItemIncoming

async db.crud.create_book_author(author: str, document_id: str) None

Creates a new BookAuthor object using the provided parameters and saves it in the database.

Parameters:
  • author – str, the name of the author

  • document_id – str, the unique identifier of the book

Returns:

None

async db.crud.create_code_entry(data: code) code

Create a new code entry with the given data (data)

Parameters:

data – CodeValidator, the CodeValidator object representing the code entry data

Returns:

CodeValidator, the newly created CodeValidator object

async db.crud.create_course(course_info: courses) None

Creates a new course in the database.

Parameters:

course_info (CoursesValidator) – A CoursesValidator instance representing the course to be created.

Returns:

None

async db.crud.create_course_attribute(course_id: int, attr: str, value: str)

Create a new course attribute for a given course (course_id)

Parameters:
  • course_id – int, the id of the course

  • attr – str, the attribute name

  • value – str, the attribute value

async db.crud.create_editor_for_basecourse(user_id: int, bc_name: str) EditorBasecourse

Creates a new editor for a given basecourse.

Parameters:
  • user_id (int) – The ID of the user creating the editor.

  • bc_name (str) – The name of the basecourse for which the editor is being created.

Returns:

The newly created editor for the basecourse.

Return type:

EditorBasecourse

async db.crud.create_group(group_name)

Create a new group with the given name (group_name)

Parameters:

group_name – str, the name of the group to be created

Returns:

AuthGroup, the newly created AuthGroup object

async db.crud.create_initial_courses_users()

This function populates the database with the common base courses and creates a test user.

async db.crud.create_instructor_course_entry(iid: int, cid: int) CourseInstructor

Create a new CourseInstructor entry with the given instructor id (iid) and course id (cid)

Parameters:
  • iid – int, the id of the instructor

  • cid – int, the id of the course

Returns:

CourseInstructor, the newly created CourseInstructor object

async db.crud.create_library_book(bookid: str, vals: Dict[str, Any]) None

Creates a new Library object using the provided parameters and saves it in the database.

Parameters:
  • bookid – str, the unique identifier of the book

  • vals – Dict[str, Any], the dictionary containing the properties of the book

Returns:

None

async db.crud.create_membership(group_id, user_id)

Create a new membership record with the given group id (group_id) and user id (user_id)

Parameters:
  • group_id – int, the id of the group

  • user_id – int, the id of the user

Returns:

AuthMembership, the newly created AuthMembership object

async db.crud.create_question(question: questions) questions

Add a row to the question table.

Parameters:

question (QuestionValidator) – A question object

Returns:

A representation of the row inserted.

Return type:

QuestionValidator

async db.crud.create_selected_question(sid: str, selector_id: str, selected_id: str, points: Optional[int] = None, competency: Optional[str] = None) selected_questions

Create a new SelectedQuestion entry with the given sid, selector_id, selected_id, points, and competency.

Parameters:
  • sid – str, the student id

  • selector_id – str, the id of the question selector

  • selected_id – str, the id of the selected question

  • points – int, the points earned (optional)

  • competency – str, the competency (optional)

Returns:

SelectedQuestionValidator, the newly created SelectedQuestionValidator object

async db.crud.create_timed_exam_entry(sid: str, exam_id: str, course_name: str, start_time: <module 'datetime' from '/home/docs/.asdf/installs/python/3.10.13/lib/python3.10/datetime.py'>) timed_exam

Create a new TimedExam entry with the given sid, exam_id, course_name, and start_time.

Parameters:
  • sid – str, the student id

  • exam_id – str, the id of the timed exam

  • course_name – str, the name of the course

  • start_time – datetime, the start time of the exam

Returns:

TimedExamValidator, the TimedExamValidator object

async db.crud.create_traceback(exc: Exception, request: Request, host: str)

Create a new TraceBack entry with the given Exception, Request, and host.

Parameters:
  • exc – Exception, the exception that occurred

  • request – Request, the request object

  • host – str, the hostname

async db.crud.create_useinfo_entry(log_entry: useinfo) useinfo

Add a row to the useinfo table.

Parameters:

log_entry (UseinfoValidation) – Log entries contain a timestamp, an event, details about the event, a student id, and the identifier of the book element that was interacted with.

Returns:

A representation of the row inserted.

Return type:

UseinfoValidation

async db.crud.create_user(user: AuthUserValidator) Optional[AuthUserValidator]

The given user will have the password in plain text. First we will hash the password then add this user to the database.

Parameters:

user – AuthUserValidator, the AuthUserValidator object representing the user to be created

Returns:

Optional[AuthUserValidator], the newly created AuthUserValidator object if successful, None otherwise

async db.crud.create_user_chapter_progress_entry(user, last_page_chapter, status) user_chapter_progress

Create a new UserChapterProgress entry with the given user (user), chapter label (last_page_chapter), and status (status)

Parameters:
  • user – AuthUserValidator, the AuthUserValidator object representing the user

  • last_page_chapter – str, the chapter label of the last page accessed

  • status – int, the completion status

Returns:

UserChapterProgressValidator, the newly created UserChapterProgressValidator object

async db.crud.create_user_course_entry(user_id: int, course_id: int) UserCourse

Create a new user course entry for a given user (user_id) and course (course_id)

Parameters:
  • user_id – int, the user id

  • course_id – int, the course id

Returns:

UserCourse, the newly created UserCourse object

async db.crud.create_user_experiment_entry(sid: str, ab: str, group: int) user_experiment

Create a new UserExperiment entry with the given sid, ab, and group.

Parameters:
  • sid – str, the student id

  • ab – str, the name of the AB experiment

  • group – int, the experiment group number

Returns:

UserExperimentValidator, the UserExperimentValidator object

async db.crud.create_user_state_entry(user_id: int, course_name: str) user_state

Create a new UserState entry with the given user id (user_id) and course name (course_name)

Parameters:
  • user_id – int, the id of the user

  • course_name – str, the name of the course

Returns:

UserStateValidator, the newly created UserStateValidator object

async db.crud.create_user_sub_chapter_progress_entry(user, last_page_chapter, last_page_subchapter, status=-1) user_sub_chapter_progress

Create a new UserSubChapterProgress entry with the given user (user), chapter label (last_page_chapter), subchapter label (last_page_subchapter), and status (status)

Parameters:
  • user – AuthUserValidator, the AuthUserValidator object representing the user

  • last_page_chapter – str, the chapter label of the last page accessed

  • last_page_subchapter – str, the subchapter label of the last page accessed

  • status – int, the completion status (default is -1)

Returns:

UserSubChapterProgressValidator, the newly created UserSubChapterProgressValidator object

async db.crud.create_user_topic_practice(user: AuthUserValidator, last_page_chapter: str, last_page_subchapter: str, qname: str, now_local: datetime, now: datetime, tz_offset: float)

Add a new UserTopicPractice entry for the given user, chapter, subchapter, and question.

Parameters:
  • user – AuthUserValidator, the AuthUserValidator object

  • last_page_chapter – str, the label of the chapter

  • last_page_subchapter – str, the label of the subchapter

  • qname – str, the name of the question to be assigned first when the topic is presented; will be rotated

  • now_local – datetime.datetime, the current local datetime

  • now – datetime.datetime, the current utc datetime

  • tz_offset – float, the timezone offset

Returns:

None

async db.crud.delete_one_user_topic_practice(dbid: int) None

Delete a single UserTopicPractice entry for the given id.

Used by self-paced topic selection. If a student un-marks a page as completed then if there is a card from the page it will be removed from the set of possible flashcards a student can see.

Parameters:

qid – int, the id of the UserTopicPractice entry

Returns:

None

async db.crud.delete_user(username)

Delete a user by their username (username)

Parameters:

username – str, the username of the user to be deleted

async db.crud.fetch_all_assignment_stats(course_name: str, userid: int) list[pydantic.main.grades]

Fetch the Grade information for all assignments for a given student in a given course.

Parameters:
  • course_name (str) – The name of the current course

  • userid (int) – the users numeric id

Return list[AssignmentValidator]:

a list of AssignmentValidator objects

async db.crud.fetch_all_course_attributes(course_id: int) dict

Retrieve all attributes and their values for a given course (course_id)

Parameters:

course_id – int, the id of the course

Returns:

dict, a dictionary containing all course attributes and their values

async db.crud.fetch_assignment_question(assignment_name: str, question_name: str) assignment_questions

Retrieve the AssignmentQuestion entry for the given assignment_name and question_name.

Parameters:
  • assignment_name – str, the name of the assignment

  • question_name – str, the name (div_id) of the question

Returns:

AssignmentQuestionValidator, the AssignmentQuestionValidator object

async db.crud.fetch_assignment_questions(assignment_id: int) List[Tuple[Question, AssignmentQuestion]]

Retrieve the AssignmentQuestion entry for the given assignment_name and question_name.

Parameters:
  • assignment_name – str, the name of the assignment

  • question_name – str, the name (div_id) of the question

Returns:

AssignmentQuestionValidator, the AssignmentQuestionValidator object

async db.crud.fetch_assignments(course_name: str, is_peer: Optional[bool] = False, is_visible: Optional[bool] = False) List[assignments]

Fetch all Assignment objects for the given course name. If is_peer is True then only select asssigments for peer isntruction. If is_visible is True then only fetch visible assignments.

Parameters:
  • course_name – str, the course name

  • is_peer – bool, whether or not the assignment is a peer assignment

Returns:

List[AssignmentValidator], a list of AssignmentValidator objects

async db.crud.fetch_base_course(base_course: str) courses

Fetches a base course by its name.

Parameters:

base_course (str) – The name of the base course to be fetched.

Returns:

A CoursesValidator instance representing the fetched base course.

Return type:

CoursesValidator

async db.crud.fetch_books_by_author(author: str) List[Tuple[Library, BookAuthor]]

Fetches all books written by a given author.

Parameters:

author (str) – The name of the author.

Returns:

A list of tuples, each containing a Library and a BookAuthor object.

Return type:

list[tuple[Library, BookAuthor]]

async db.crud.fetch_chapter_for_subchapter(subchapter: str, base_course: str) str

Used for pretext books where the subchapter is unique across the book due to the flat structure produced by pretext build. In this case the old RST structure where we get the chapter and subchapter from the URL /book/chapter/subchapter.html gives us the wrong answer of the book.

async db.crud.fetch_code(sid: str, acid: str, course_id: int) List[code]

Retrieve a list of code entries for the given student id (sid), assignment id (acid), and course id (course_id).

Parameters:
  • sid – str, the id of the student

  • acid – str, the id of the assignment

  • course_id – int, the id of the course

Returns:

List[CodeValidator], a list of CodeValidator objects representing the code entries

async db.crud.fetch_course(course_name: str) courses

Fetches a course by its name.

Parameters:

course_name (str) – The name of the course to be fetched.

Returns:

A CoursesValidator instance representing the fetched course.

Return type:

CoursesValidator

async db.crud.fetch_course_by_id(course_id: int) courses

Fetches a course by its id.

Parameters:

course_name (int) – The id of the course to be fetched.

Returns:

A CoursesValidator instance representing the fetched course.

Return type:

CoursesValidator

async db.crud.fetch_course_instructors(course_name: Optional[str] = None) List[AuthUserValidator]

Retrieve a list of instructors for the given course name (course_name). If course_name is not provided, return a list of all instructors.

Parameters:

course_name – Optional[str], the name of the course (if provided)

Returns:

List[AuthUserValidator], a list of AuthUserValidator objects representing the instructors

async db.crud.fetch_course_practice(course_name: str) Optional[CoursePractice]

Fetches the course practice row for a given course.

Parameters:

course_name (str) – The name of the course.

Returns:

The CoursePractice object containing the configuration of the practice feature for the given course.

Return type:

Optional[CoursePractice]

async db.crud.fetch_courses_for_user(user_id: int, course_id: Optional[int] = None) UserCourse

Retrieve a list of courses for a given user (user_id)

Parameters:
  • user_id – int, the user id

  • course_id – Optional[int], the id of the course (optional)

Returns:

List[UserCourse], a list of UserCourse objects representing the courses

async db.crud.fetch_grade(userid: int, assignmentid: int) Optional[grades]

Fetch the Grade object for the given user and assignment.

Parameters:
  • userid – int, the user id

  • assignmentid – int, the assignment id

Returns:

Optional[GradeValidator], the GradeValidator object

async db.crud.fetch_group(group_name)

Retrieve a group by its name (group_name)

Parameters:

group_name – str, the name of the group

Returns:

AuthGroup, the AuthGroup object representing the group

async db.crud.fetch_instructor_courses(instructor_id: int, course_id: Optional[int] = None) List[course_instructor]

Retrieve a list of courses for which the given instructor id (instructor_id) is an instructor. If the optional course_id value is included then return the row for that course to verify that instructor_id is an instructor for course_id

Parameters:
  • instructor_id – int, the id of the instructor

  • course_id – Optional[int], the id of the course (if provided)

Returns:

List[CourseInstructorValidator], a list of CourseInstructorValidator objects representing the courses

async db.crud.fetch_last_answer_table_entry(query_data: AssessmentRequest) LogItemIncoming

The xxx_answers table contains ALL of the answers a student has made for this question. but most often all we want is the most recent answer

Parameters:

query_data (schemas.AssessmentRequest) –

Returns:

The most recent answer

Return type:

schemas.LogItemIncoming

async db.crud.fetch_last_page(user: AuthUserValidator, course_name: str)

Retrieve the last page accessed by the given user (user) for the given course name (course_name)

Parameters:
  • user – AuthUserValidator, the AuthUserValidator object representing the user

  • course_name – str, the name of the course

Returns:

Tuple[str, str, str, str, str], a tuple representing the last page accessed

async db.crud.fetch_last_poll_response(sid: str, course_name: str, poll_id: str) str

Return a student’s (sid) last response to a given poll (poll_id)

Parameters:
  • sid – str, the student id

  • course_name – str, the name of the course

  • poll_id – str, the id of the poll

Returns:

str, the last response of the student for the given poll

async db.crud.fetch_library_book(book)

Retrieve the Library entry for the given book.

Parameters:

book – str, the name of the book

Returns:

Library, the Library object

async db.crud.fetch_library_books()

Retrieve a list of visible library books ordered by shelf section and title.

Returns:

List[LibraryValidator], a list of LibraryValidator objects

async db.crud.fetch_matching_questions(request_data: SelectQRequest) List[str]

Return a list of question names (div_ids) that match the criteria for a particular question. This is used by select questions and in particular get_question_source

async db.crud.fetch_membership(group_id, user_id)

Retrieve a membership record by the group id (group_id) and user id (user_id)

Parameters:
  • group_id – int, the id of the group

  • user_id – int, the id of the user

Returns:

AuthMembership, the AuthMembership object representing the membership record

async db.crud.fetch_one_assignment(assignment_id: int) assignments

Fetch one Assignment object

Parameters:

assignment_id – int, the assignment id

Returns:

AssignmentValidator

async db.crud.fetch_one_course_attribute()

Fetch a single course attribute (not implemented)

Raises:

NotImplementedError

async db.crud.fetch_one_user_topic_practice(user: AuthUserValidator, last_page_chapter: str, last_page_subchapter: str) user_topic_practice

The user_topic_practice table contains information about each topic (flashcard) that a student is eligible to see for a given topic in a course. A particular topic should ony be in the table once per student. This row also contains information about scheduling and correctness to help the practice algorithm select the best question to show a student.

Retrieve a single UserTopicPractice entry for the given user, chapter, and subchapter (i.e., topic).

Parameters:
  • user – AuthUserValidator, the AuthUserValidator object

  • last_page_chapter – str, the label of the chapter

  • last_page_subchapter – str, the label of the subchapter

  • qname – str, the name of the question

Returns:

UserTopicPracticeValidator, the UserTopicPracticeValidator object

async db.crud.fetch_page_activity_counts(chapter: str, subchapter: str, base_course: str, course_name: str, username: str) Dict[str, int]

Used for the progress bar at the bottom of each page. This function finds all of the components for a particular page (chaper/subchapter) and then finds out which of those elements the student has interacted with. It returns a dictionary of {divid: 0/1}

async db.crud.fetch_poll_summary(div_id: str, course_name: str) List[tuple]

Find the last answer for each student and then aggregate those answers to provide a summary of poll responses for the given question. For a poll, the value of act is a response number 0–N where N is the number of different choices.

Parameters:
  • div_id (str) – The div_id of the poll

  • course_name (str) – The name of the course

Returns:

A list of tuples where the first element is the response number and the second element is the count of students who chose that response.

Return type:

List[tuple]

async db.crud.fetch_previous_selections(sid) List[str]

Retrieve a list of selected question ids for the given student id (sid).

Parameters:

sid – str, the student id

Returns:

List[str], a list of selected question ids

async db.crud.fetch_qualified_questions(base_course: str, chapter_label: str, sub_chapter_label: str) list[pydantic.main.questions]

Retrieve a list of qualified questions for a given chapter and subchapter.

Parameters:
  • base_course – str, the base course

  • chapter_label – str, the label of the chapter

  • sub_chapter_label – str, the label of the subchapter

Returns:

list[QuestionValidator], a list of QuestionValidator objects

async db.crud.fetch_question(name: str, basecourse: Optional[str] = None, assignment: Optional[str] = None) questions

Fetch a single matching question row from the database that matches the name (div_id) of the question. If the base course is provided make sure the question comes from that basecourse. basecourse,name pairs are guaranteed to be unique in the questions table

More and more questions have globally unique names in the runestone database and that is definitely a direction to keep pushing. But it is possible that there are duplicates but we are not going to worry about that we are just going to return the first one we find.

Parameters:
  • name – str, the name (div_id) of the question

  • basecourse – str, the base course (optional)

  • assignment – str, the assignment (optional)

Returns:

QuestionValidator, the QuestionValidator object

async db.crud.fetch_question_grade(sid: str, course_name: str, qid: str)

Retrieve the QuestionGrade entry for the given sid, course_name, and qid.

Parameters:
  • sid – str, the student id

  • course_name – str, the course name

  • qid – str, the question id (div_id)

Returns:

QuestionGradeValidator, the QuestionGradeValidator object

async db.crud.fetch_selected_question(sid: str, selector_id: str) selected_questions

Retrieve the SelectedQuestion entry for the given sid and selector_id.

Parameters:
  • sid – str, the student id

  • selector_id – str, the id of the question selector

Returns:

SelectedQuestionValidator, the SelectedQuestionValidator object

async db.crud.fetch_subchapters(course, chap)

Retrieve all subchapters for a given chapter.

Parameters:
  • course – str, the name of the course

  • chap – str, the label of the chapter

Returns:

ResultProxy, the result of the query

async db.crud.fetch_timed_exam(sid: str, exam_id: str, course_name: str) timed_exam

Retrieve the TimedExam entry for the given sid, exam_id, and course_name.

Parameters:
  • sid – str, the student id

  • exam_id – str, the id of the timed exam

  • course_name – str, the name of the course

Returns:

TimedExamValidator, the TimedExamValidator object

async db.crud.fetch_top10_fitb(dbcourse: courses, div_id: str) List[tuple]

Return the top 10 answers to a fill in the blank question.

Parameters:
  • dbcourse (CoursesValidator) – The course for which to retrieve the top answers.

  • div_id (str) – The div_id of the fill in the blank question.

Returns:

A list of tuples where the first element is the answer and the second element is the count of times that answer was given.

Return type:

List[tuple]

async db.crud.fetch_user(user_name: str) AuthUserValidator

Retrieve a user by their username (user_name)

Parameters:

user_name – str, the username of the user

Returns:

AuthUserValidator, the AuthUserValidator object representing the user

async db.crud.fetch_user_chapter_progress(user, last_page_chapter: str) user_chapter_progress

Retrieve the UserChapterProgress entry for the given user (user) and chapter label (last_page_chapter).

Parameters:
  • user – AuthUserValidator, the AuthUserValidator object representing the user

  • last_page_chapter – str, the chapter label of the last page accessed

Returns:

UserChapterProgressValidator, the UserChapterProgressValidator object

async db.crud.fetch_user_experiment(sid: str, ab_name: str) int

When a question is part of an AB experiement (ab_name) get the experiment group for a particular student (sid). The group number will have been randomly assigned by the initial question selection.

This number indicates whether the student will see the 1st or 2nd question in the question list.

Parameters:
  • sid – str, the student id

  • ab_name – str, the name of the AB experiment

Returns:

int, the experiment group number

async db.crud.fetch_user_sub_chapter_progress(user, last_page_chapter=None, last_page_subchapter=None) List[user_sub_chapter_progress]

Retrieve the UserSubChapterProgress entries for the given user (user) and optional chapter and subchapter.

Parameters:
  • user – AuthUserValidator, the AuthUserValidator object representing the user

  • last_page_chapter – str, the chapter label of the last page accessed (optional)

  • last_page_subchapter – str, the subchapter label of the last page accessed (optional)

Returns:

List[UserSubChapterProgressValidator], a list of UserSubChapterProgressValidator objects

async db.crud.fetch_users_for_course(course_name: str) list[rsptx.db.models.AuthUserValidator]

Retrieve a list of users enrolled in a given course (course_name)

Parameters:

course_name – str, the name of the course

Returns:

list[AuthUserValidator], a list of AuthUserValidator objects representing the users

async db.crud.fetch_viewed_questions(sid: str, questionlist: List[str]) List[str]

Retrieve a list of questions from the given questionlist that a student (sid) has viewed before. Used for the selectquestion get_question_source to filter out questions that a student has seen before. One criteria of a select question is to make sure that a student has never seen a question before.

The best approximation we have for that is that they will have clicked on the run button for that question. Of course, they may have seen the question but not run it, but this is the best we can do.

Parameters:
  • sid – str, the student id

  • questionlist – List[str], a list of question ids (div_id)

Returns:

List[str], a list of question ids from the given questionlist that the student has viewed before

async db.crud.get_course_origin(base_course)

Retrieve the origin of a given course (base_course)

Parameters:

base_course – str, the name of the base course

Returns:

str, the origin of the course

async db.crud.get_courses_per_basecourse() dict

Gets the number of courses using a basecourse.

Returns:

A dictionary containing the base course name and the number of courses using it.

Return type:

Dict[str,int]

async db.crud.get_students_per_basecourse() dict

Gets the number of students using a book for each course.

Returns:

A dictionary containing the course name and the number of students using it.

Return type:

Dict[str,int]

async db.crud.is_author(userid: int) bool

Checks if a user is an author.

Parameters:

userid (int) – The ID of the user to check.

Returns:

True if the user is an author, False otherwise.

Return type:

bool

async db.crud.is_editor(userid: int) bool

Checks if a user is an editor.

Parameters:

userid (int) – The ID of the user to check.

Returns:

True if the user is an editor, False otherwise.

Return type:

bool

async db.crud.is_server_feedback(div_id: str, course: str) Optional[Dict[str, Any]]

Check if server feedback is available for the given div id (div_id) and course name (course). If server feedback is available and login is required, return the decoded feedback.

Parameters:
  • div_id – str, the id of the div element

  • course – str, the name of the course

Returns:

Optional[Dict[str, Any]], a dictionary representing the decoded feedback (if available)

async db.crud.update_library_book(bookid: int, vals: dict)

Update the Library entry with the given bookid and values.

Parameters:
  • bookid – int, the id of the book

  • vals – dict, a dictionary of values to update

async db.crud.update_selected_question(sid: str, selector_id: str, selected_id: str)

Update the selected_id of the SelectedQuestion entry for the given sid and selector_id.

Parameters:
  • sid – str, the student id

  • selector_id – str, the id of the question selector

  • selected_id – str, the id of the selected question

async db.crud.update_sub_chapter_progress(user_data: LastPageData)

Update the UserSubChapterProgress entry with the given user data (user_data)

Parameters:

user_data – LastPageData, the LastPageData object representing the user data

async db.crud.update_user(user_id: int, new_vals: dict)

Update a user’s information by their id (user_id)

Parameters:
  • user_id – int, the id of the user

  • new_vals – dict, a dictionary containing the new values to be updated

async db.crud.update_user_state(user_data: LastPageData)

Update the UserState entry with the given user data (user_data)

Parameters:

user_data – LastPageData, the LastPageData object representing the user data

async db.crud.upsert_grade(grade: grades) grades

Insert a new Grade object into the database or update an existing one.

Parameters:

grade – GradeValidator, the GradeValidator object

Returns:

GradeValidator, the GradeValidator object