https://github.com/jrycw/fasthtml-svcs-edgedb-mvp
MVP: EdgeDB and FastHTML Integration with svcs
https://github.com/jrycw/fasthtml-svcs-edgedb-mvp
database edgedb fasthtml python svcs
Last synced: about 1 month ago
JSON representation
MVP: EdgeDB and FastHTML Integration with svcs
- Host: GitHub
- URL: https://github.com/jrycw/fasthtml-svcs-edgedb-mvp
- Owner: jrycw
- License: mit
- Created: 2024-08-13T13:58:55.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-15T12:08:37.000Z (over 1 year ago)
- Last Synced: 2025-03-26T12:14:12.712Z (about 1 year ago)
- Topics: database, edgedb, fasthtml, python, svcs
- Language: Python
- Homepage:
- Size: 1.52 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fasthtml-svcs-edgedb-mvp

## Description
This repository is focused on building an MVP todo app using `EdgeDB`, `SVCS`, and `FastHTML`.
## EdgeDB schema
```elm
module default {
type Todo {
required title: str {
constraint exclusive;
constraint min_len_value(1);
constraint max_len_value(50);
};
}
function select_todo_by_id(tid: uuid) -> Todo
using (
select (assert_exists(assert_single((select Todo filter .id=tid))))
)
}
```
## Steps for this repo
1. Write EdgeQL queries and generate code using `edgedb-py` (stick with version 1.9.0, as v2 may have compatibility issues).
2. Set up the `db_client` in `lifespan.py`.
3. Define the `dataclass` models.
4. Implement the `__ft__()` method for the `Todo` dataclass.
5. Use `svcs.starlette.aget()` to obtain the `AsyncIOClient`.
6. Execute the generated queries to fetch results.
7. Convert the results into `Todo` instances, which FastHTML recognizes as a type of FT component, utilizing the `__ft__()` method we defined.
8. Return the output as FT components.
9. To get started, ensure `EdgeDB` is set up and then run `uvicorn app.main:app --port 8000 --reload`.
## Refs
* [FastHTML todo app](https://gallery.fastht.ml/start_simple/sqlite_todo/app/)
* [FastHTML todo app code](https://gallery.fastht.ml/start_simple/sqlite_todo/code)
* [SVCS Starlette](https://svcs.hynek.me/en/stable/integrations/starlette.html)
* [EdgeDB python query builder](https://docs.edgedb.com/guides/tutorials/rest_apis_with_fastapi)