Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 5 additions & 37 deletions docs/intro/quickstart/inheritance/fastapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,15 @@ Adding shared properties

.. edb:split-section::

Since you don't have historical data for when these objects were actually created or modified, the migration will fall back to the default values set in the ``Timestamped`` type.

.. code-block:: sh

$ gel migration create
did you create object type 'default::Timestamped'? [y,n,l,c,b,s,q,?]
> y
did you alter object type 'default::Card'? [y,n,l,c,b,s,q,?]
> y
did you alter object type 'default::Deck'? [y,n,l,c,b,s,q,?]
> y
Created /home/strinh/projects/flashcards/dbschema/migrations/00004-m1d2m5n.edgeql, id: m1d2m5n5ajkalyijrxdliioyginonqbtfzihvwdfdmfwodunszstya

$ gel migrate
Applying m1d2m5n5ajkalyijrxdliioyginonqbtfzihvwdfdmfwodunszstya (00004-m1d2m5n.edgeql)
... parsed
... applied

.. edb:split-section::
If you have ``fastapi dev`` still running, the schema will automatically be updated, no manual migrations are needed. Once the schema is updated, the model generation tool will also be run, and you can see the changes in the ``models`` module. Since you don't have historical data for when these objects were actually created or modified, the migration will fall back to the default values set in the ``Timestamped`` type.

Update the ``get_decks`` query to sort the decks by ``updated_at`` in descending order.

.. code-block:: python-diff
:caption: main.py

@app.get("/decks", response_model=List[Deck])
@app.get("/decks")
async def get_decks():
decks = await client.query("""
select Deck {
id,
name,
description,
cards := (
select .cards {
id,
front,
back
}
order by .order
)
}
+ order by .updated_at desc
""")
return decks
db = g.client
- return await db.query(Deck.select("*", cards=True))
+ return await db.query(Deck.select("*", cards=True).order_by(updated_at="desc"))
6 changes: 3 additions & 3 deletions docs/intro/quickstart/modeling/fastapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Modeling the data

The flashcards application has a simple data model, but it's interesting enough to utilize many unique features of the |Gel| schema language.

Looking at the mock data in the example JSON file ``./deck-edgeql.json``, you can see this structure in the JSON. There is a ``Card`` class that describes a single flashcard, which contains two required string properties: ``front`` and ``back``. Each ``Deck`` object has zero or more ``Card`` objects in a list.
Looking at the mock data in the example JSON file ``./deck-edgeql.json``, you can see this structure in the JSON. There is a ``Card`` class that describes a single flashcard, which contains two required string properties: ``front`` and ``back``. Each ``Deck`` object has zero or more ``Card`` objects in a list. Here's what that data model looks like as Pydantic models.

.. code-block:: python

Expand All @@ -23,11 +23,11 @@ Modeling the data

class DeckBase(BaseModel):
name: str
description: Optional[str] = None
description: str | None = None

class Deck(DeckBase):
id: str
cards: List[Card]
cards: list[Card]

.. edb:split-section::

Expand Down
9 changes: 4 additions & 5 deletions docs/intro/quickstart/setup/fastapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ Setting up your environment
[email protected]:geldata/quickstart-fastapi.git \
flashcards
$ cd flashcards
$ python -m venv venv
$ source venv/bin/activate # or venv\Scripts\activate on Windows
$ pip install -r requirements.txt
$ uvx gel project init
$ uv venv
$ uv sync
$ uvx gel init

.. edb:split-section::

Expand Down Expand Up @@ -69,7 +68,7 @@ Setting up your environment
:caption: gel.toml

[instance]
server-version = 6.1
server-version = 6.9

[hooks]
schema.update.after = "uvx gel-py"
Expand Down
Loading