Database Model Classes
Decks
- class flashcards_core.database.models.decks.Deck(**kwargs)
Bases:
sqlalchemy.orm.decl_api.Base
,flashcards_core.database.crud.CrudOperations
- algorithm
The SRS algorithm to use to review the cards in this deck. See flashcards_core.schedulers.SCHEDULERS for valid keys.
- assign_tag(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Assign the given Tag to this Deck and refreshes the Deck object.
- Parameters
tag_id – the name of the Tag to assign to the Deck.
session – the session (see flashcards_core.database:init_db()).
- async assign_tag_async(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Assign the given Tag to this Deck and refreshes the Deck object (asyncio friendly).
- Parameters
tag_id – the name of the Tag to assign to the Deck.
session – the session (see flashcards_core.database:init_db()).
- cards
All the cards that belong to this deck
- description
Description of the deck
- classmethod get_by_name(session: sqlalchemy.orm.session.Session, name: str) Optional[Any]
Returns the deck corresponding to the given name.
- Parameters
session – the session (see flashcards_core.database:init_db()).
name – the name of the model object to return.
- Returns
the matching model object.
- async classmethod get_by_name_async(session: sqlalchemy.orm.session.Session, name: str) Optional[Any]
Returns the deck corresponding to the given name (asyncio friendly).
- Parameters
session – the session (see flashcards_core.database:init_db()).
name – the name of the model object to return.
- Returns
the matching model object.
- id
Primary key
- name
Name of the deck (short)
- parameters
A JSON field containing the SRS parameters of the deck. Several SRS algorothms can be configured, and this field is designed to store those configuration values.
- remove_tag(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Remove the given Tag from this Deck.
- Parameters
tag_id – the ID of the tag to remove from this deck
session – the session (see flashcards_core.database:init_db()).
- Returns
None.
- async remove_tag_async(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Remove the given Tag from this Deck.
- Parameters
tag_id – the ID of the tag to remove from this deck
session – the session (see flashcards_core.database:init_db()).
- Returns
None.
- state
A JSON field containing the SRS state of the deck. Some SRS algorithms are stateful, and this field is designed to store that state.
- tags
All the tags assigned to this deck
- unseen_cards_list() List[Any]
Return a list of all the cards belonging to this deck that have no Reviews, which means they have never been seen/reviewed.
- async unseen_cards_list_async() List[Any]
Return a list of all the cards belonging to this deck that have no Reviews, which means they have never been seen/reviewed.
- unseen_cards_number() int
Return the number of cards belonging to this deck that have no Reviews, which means they have never been seen/reviewed.
- async unseen_cards_number_async() int
Return the number of cards belonging to this deck that have no Reviews, which means they have never been seen/reviewed.
- flashcards_core.database.models.decks.DeckTag = Table('decktags', MetaData(), Column('deck_id', GUID(), ForeignKey('decks.id'), table=<decktags>, primary_key=True, nullable=False), Column('tag_id', GUID(), ForeignKey('tags.id'), table=<decktags>, primary_key=True, nullable=False), schema=None)
Associative table for Decks and Tags
Cards
- class flashcards_core.database.models.cards.Card(**kwargs)
Bases:
sqlalchemy.orm.decl_api.Base
,flashcards_core.database.crud.CrudOperations
- answer
The fact containing the answer of this card.
- answer_context_facts
All the facts containing some context for the answer. You can add as many facts as you wish for cards answers.
- answer_id
ID of the fact containing the answer of this card.
- assign_answer_context(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Assign the given Fact as context to the Answer to this Card.
- Parameters
fact_id – the name of the Fact to assign as context to the answer of this card.
session – the session (see flashcards_core.database:init_db()).
- async assign_answer_context_async(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Assign the given Fact as context to the Answer to this Card (asyncio friendly).
- Parameters
fact_id – the name of the Fact to assign as context to the answer of this card.
session – the session (see flashcards_core.database:init_db()).
- assign_question_context(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Assign the given Fact as context to the Question to this Card.
- Parameters
fact_id – the name of the Fact to assign as context to the question of this card.
session – the session (see flashcards_core.database:init_db()).
- async assign_question_context_async(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Assign the given Fact as context to the Question to this Card (asyncio friendly).
- Parameters
fact_id – the name of the Fact to assign as context to the question of this card.
session – the session (see flashcards_core.database:init_db()).
Create a relationship between these two Cards.
- Parameters
card_id – the name of the other Card.
relationship – the type of relationship between these Cards
session – the session (see flashcards_core.database:init_db()).
Create a relationship between these two Cards (asyncio friendly).
- Parameters
card_id – the name of the other Card.
relationship – the type of relationship between these Cards
session – the session (see flashcards_core.database:init_db()).
- assign_tag(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Assign the given Tag to this Card.
- Parameters
tag_id – the name of the Tag to assign to the Card.
session – the session (see flashcards_core.database:init_db())
- async assign_tag_async(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Assign the given Tag to this Card (asyncio friendly).
- Parameters
tag_id – the name of the Tag to assign to the Card.
session – the session (see flashcards_core.database:init_db())
- deck
The deck this card belongs to. Note that this is a one-to-many repationship because it should be easy to copy cards. Cards hold no actual data: it’s just an associative table
- deck_id
ID to the deck this card belongs to. Note that this is a one-to-many repationship because it should be easy to copy cards. Cards hold no actual data: it’s just an associative table
- id
Primary key
- question
The fact containing the question of this card.
- question_context_facts
All the facts containing some context for the question. You can add as many facts as you wish for cards questions.
- question_id
ID of the fact containing the question of this card.
All the cards that are somehow related to the current one Relationships are named (to help discoverability), see RelatedCards
Returns all the related cards pairs in an asyncio friendly way.
- Returns
a list of Card with a “relationship” attribute, which
contains the name of the relationship as it was stored in the RelatedCard associative table
- remove_answer_context(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Remove the given Fact as a context for the Answer from this Card.
- Parameters
fact_id – the ID of the fact to remove from the answer’s context
session – the session (see flashcards_core.database:init_db()).
- async remove_answer_context_async(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Remove the given Fact as a context for the Answer from this Card (asyncio friendly).
- Parameters
fact_id – the ID of the fact to remove from the answer’s context
session – the session (see flashcards_core.database:init_db()).
- remove_question_context(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Remove the given Fact as a context for the Question from this Card.
- Parameters
fact_id – the ID of the fact to remove from the answer’s context
session – the session (see flashcards_core.database:init_db()).
- async remove_question_context_async(session: sqlalchemy.orm.session.Session, fact_id: uuid.UUID) None
Remove the given Fact as a context for the Question from this Card (asyncio friendly).
- Parameters
fact_id – the ID of the fact to remove from the answer’s context
session – the session (see flashcards_core.database:init_db()).
Remove the relationship between these two Cards
- Parameters
card_id – the ID of the relationship between these two Cards
session – the session (see flashcards_core.database:init_db()).
Remove the relationship between these two Cards (asyncio friendly)
- Parameters
card_id – the ID of the relationship between these two Cards
session – the session (see flashcards_core.database:init_db()).
- remove_tag(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Remove the given Tag from this Card.
- Parameters
tag_id – the ID of the connection between a tag and a card.
session – the session (see flashcards_core.database:init_db()).
- async remove_tag_async(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Remove the given Tag from this Card (asyncio friendly).
- Parameters
tag_id – the ID of the connection between a tag and a card.
session – the session (see flashcards_core.database:init_db()).
- reviews
All the reviews done on this card.
- tags
All the tags assigned to this card
- flashcards_core.database.models.cards.CardAnswerContext = Table('card_answer_contextes', MetaData(), Column('card_id', GUID(), ForeignKey('cards.id'), table=<card_answer_contextes>, primary_key=True, nullable=False), Column('fact_id', GUID(), ForeignKey('facts.id'), table=<card_answer_contextes>, primary_key=True, nullable=False), schema=None)
Associative table for Cards and answer context Facts
- flashcards_core.database.models.cards.CardQuestionContext = Table('card_question_contextes', MetaData(), Column('card_id', GUID(), ForeignKey('cards.id'), table=<card_question_contextes>, primary_key=True, nullable=False), Column('fact_id', GUID(), ForeignKey('facts.id'), table=<card_question_contextes>, primary_key=True, nullable=False), schema=None)
Associative table for Cards and question context Facts
- flashcards_core.database.models.cards.CardTag = Table('cardtags', MetaData(), Column('card_id', GUID(), ForeignKey('cards.id'), table=<cardtags>, primary_key=True, nullable=False), Column('tag_id', GUID(), ForeignKey('tags.id'), table=<cardtags>, primary_key=True, nullable=False), schema=None)
Associative table for Cards and Tags
- flashcards_core.database.models.cards.RelatedCard = Table('related_cards', MetaData(), Column('original_card_id', GUID(), ForeignKey('cards.id'), table=<related_cards>, primary_key=True, nullable=False), Column('related_card_id', GUID(), ForeignKey('cards.id'), table=<related_cards>, primary_key=True, nullable=False), Column('relationship', String(), table=<related_cards>, primary_key=True, nullable=False), schema=None)
Associative table for Cards relationships
Facts
- class flashcards_core.database.models.facts.Fact(**kwargs)
Bases:
sqlalchemy.orm.decl_api.Base
,flashcards_core.database.crud.CrudOperations
Create a relationship between these two Facts.
- Parameters
fact_id – the name of the other Fact.
relationship – the type of relationship between these facts
session – the session (see flashcards_core.database:init_db()).
Create a relationship between these two Facts (asyncio friendly).
- Parameters
fact_id – the name of the other Fact.
relationship – the type of relationship between these facts
session – the session (see flashcards_core.database:init_db()).
- assign_tag(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Assign the given Tag to this Fact.
- Parameters
tag_id – the name of the Tag to assign to the Fact.
session – the session (see flashcards_core.database:init_db()).
- async assign_tag_async(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Assign the given Tag to this Fact (asyncio friendly).
- Parameters
tag_id – the name of the Tag to assign to the Fact.
session – the session (see flashcards_core.database:init_db()).
- format
How to interpret the content of Fact.value. It’s up to the frontend application to decide how to represent the card, but this field should give a good hint. For example, it can have values like ‘plaintext’, ‘markdown’, ‘image’, ‘url’, etc.
- id
Primary key
All the facts that are somehow related to the current one Relationships are named (to help discoverability), see RelatedFacts
Returns all the related facts pairs in an asyncio friently way.
- Returns
a list of Fact with a “relationship” attribute, which
contains the name of the relationship as it was stored in the RelatedFacts associative table
Remove the relationship between these two Facts
- Parameters
fact_id – the ID of the relationship between these two Facts
session – the session (see flashcards_core.database:init_db()).
Remove the relationship between these two Facts (asyncio friendly)
- Parameters
fact_id – the ID of the relationship between these two Facts
session – the session (see flashcards_core.database:init_db()).
- remove_tag(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Remove the given Tag from this Fact.
- Parameters
facttag_id – the ID of the connection between a tag and a fact.
session – the session (see flashcards_core.database:init_db()).
- async remove_tag_async(session: sqlalchemy.orm.session.Session, tag_id: uuid.UUID) None
Remove the given Tag from this Fact (asyncio friendly).
- Parameters
facttag_id – the ID of the connection between a tag and a fact.
session – the session (see flashcards_core.database:init_db()).
- tags
All the tags assigned to this fact
- value
The content of this fact. Can be plaintext, html, markdown, a URL, a path to a file… Use the content of Fact.format to understando how to decode this field.
- flashcards_core.database.models.facts.RelatedFact = Table('related_facts', MetaData(), Column('original_fact_id', GUID(), ForeignKey('facts.id'), table=<related_facts>, primary_key=True, nullable=False), Column('related_fact_id', GUID(), ForeignKey('facts.id'), table=<related_facts>, primary_key=True, nullable=False), Column('relationship', String(), table=<related_facts>, primary_key=True, nullable=False), schema=None)
Associative table for Facts relationships
Reviews
- class flashcards_core.database.models.reviews.Review(**kwargs)
Bases:
sqlalchemy.orm.decl_api.Base
,flashcards_core.database.crud.CrudOperations
- algorithm
The algorithm used to do this review. See flashcards_core.schedulers.SCHEDULERS for valid keys.
- card
The card that was reviewed
- card_id
ID of the card that was reviewed
- datetime
Date and time of the review. Note: using the lambda for compatibility with freezegun (see the tests), but might drop in favour of func.now() if I observe serious performance issues (unlikely for now)
- id
Primary key
- result
The result of the review. It depends a lot on the SRS algorithm used for the review, so use the content of Review.algorithm to understand what this field contains.