Skip to content

Commit

Permalink
docs: add usage example for Appointment model in README
Browse files Browse the repository at this point in the history
Generated-by: aiautocommit
  • Loading branch information
iloveitaly committed Dec 13, 2024
1 parent d3e6173 commit 7d9ac70
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ This package provides a thin wrapper around SQLModel that provides a more Active
* Timestamp column mixins
* Lifecycle hooks

## Usage

### TypeID

```python
import uuid

from activemodel import BaseModel
from activemodel.mixins import TimestampsMixin, TypeIDMixin
from sqlmodel import Field, Relationship

from .patient import Patient

class Appointment(BaseModel, TimestampsMixin, TypeIDMixin("appointment"), table=True):
# NOTE uuid.UUID and not types.Uuid is used here
patient_id: uuid.UUID = Field(foreign_key="patient.id", nullable=False)
patient: Patient = Relationship()

location: str
```

## Limitations

### Validation
Expand Down
45 changes: 44 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,47 @@ Docs are bad:
TODO

- [ ] snake case for attributes https://github.com/sqlalchemy/sqlalchemy/issues/7149
- [ ] foreign key names https://github.com/fastapi/sqlmodel/discussions/1213
- [ ] foreign key names https://github.com/fastapi/sqlmodel/discussions/1213


find_or_create

```
@staticmethod
def find_or_create_from_scrape(scrape: "Scrape", normalized_scrape_data: StoreScrape):
if menu := Menu.get(
digital_channel=normalized_scrape_data.digital_channel, channel_id=normalized_scrape_data.channel_id
):
return menu

assert scrape.id
assert normalized_scrape_data.normalized_url
assert normalized_scrape_data.channel_id

menu = Menu(
originating_scrape_id=scrape.id,
name=normalized_scrape_data.name,
channel_id=normalized_scrape_data.channel_id,
url=normalized_scrape_data.normalized_url,
).save()

return menu

```

clear engine

```
# def clear_engine():
# global _engine, _connection

# if _engine:
# _engine.dispose()
# _engine = None
# _connection = None
```

TODO

https://github.com/fastapi/sqlmodel/issues/492#issuecomment-2489858633 comments on models, table and field comments
https://github.com/zhanymkanov/fastapi-best-practices?tab=readme-ov-file#set-db-keys-naming-conventions there was another error around this as well

0 comments on commit 7d9ac70

Please sign in to comment.