Skip to content

Commit dbd94bb

Browse files
Merge pull request #36 from fastapi-startkit/docs/fix-misc-issues
docs: fix database examples, models gaps, remove queue stub, minor fixes
2 parents f8f2ffe + 41a0bfa commit dbd94bb

9 files changed

Lines changed: 69 additions & 44 deletions

File tree

.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export default defineConfig({
155155
items: [
156156
{ text: 'Getting Started', link: '/docs/getting-started' },
157157
{ text: 'Configuration', link: '/docs/configuration' },
158+
{ text: 'Config Component', link: '/docs/config' },
158159
{ text: 'FastAPI', link: '/docs/fastapi' },
159160
{ text: 'Exception Handling', link: '/docs/exception-handling' },
160161
{ text: 'Logging', link: '/docs/logging' },

docs/ai/agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Apply decorators directly to the class to configure it declaratively:
142142

143143
| Decorator | Default | Description |
144144
|---|---|---|
145-
| `@provider(name)` | `"anthropic"` | LLM provider: `"anthropic"`, `"openai"`, or `"google"` |
145+
| `@provider(name)` | `AI_PROVIDER` env var (default: `google`) | LLM provider: `"anthropic"`, `"openai"`, or `"google"` |
146146
| `@model(name)` | provider default | Model identifier (e.g. `"claude-sonnet-4-6"`, `"gpt-4o"`) |
147147
| `@max_tokens(n)` | `4096` | Maximum output tokens per response |
148148
| `@max_steps(n)` | `10` | Maximum agentic loop iterations before stopping |

docs/database/casts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Casts automatically transform model attribute values when reading from or writin
2020
| `dict` | JSON | `'{"key":"val"}'``{"key": "val"}` |
2121
| `list` | JSON | `'["a","b"]'``["a", "b"]` |
2222
| `datetime` | DateTime | `"2024-01-01 08:00:00"``datetime.datetime` |
23-
| `date` | DateTime | `"2024-01-01"``datetiem.date` |
23+
| `date` | DateTime | `"2024-01-01"``datetime.date` |
2424
| `Carbon` | DateTime | `"2024-01-01 00:00:00"``Carbon` |
2525
| `time` | Time | `"09:00:00"``datetime.time` |
2626
| `timedelta` | TimeDelta | `3600.0``datetime.timedelta(seconds=3600)` |

docs/database/index.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ This will create a `config/database.py` file in your project. Alternatively, you
7878

7979
```python
8080
# config/database.py
81-
from dataclasses import field
82-
from pydantic.dataclasses import dataclass
81+
from dataclasses import dataclass, field
8382
from fastapi_startkit.environment import env
8483
from fastapi_startkit.masoniteorm import MySQLConfig, SQLiteConfig
8584

@@ -88,20 +87,17 @@ class DatabaseConfig:
8887
default: str = field(default_factory=lambda: env("DB_CONNECTION", "sqlite"))
8988

9089
connections: dict = field(default_factory=lambda: {
91-
"sqlite": DatabaseConnection(
90+
"sqlite": SQLiteConfig(
9291
driver="sqlite",
9392
database=env("DB_DATABASE", "database.sqlite"),
9493
),
95-
"mysql": DatabaseConnection(
94+
"mysql": MySQLConfig(
9695
driver="mysql",
9796
host=env("DB_HOST", "127.0.0.1"),
9897
database=env("DB_DATABASE", "app"),
9998
username=env("DB_USERNAME", "root"),
10099
password=env("DB_PASSWORD", ""),
101100
port=env("DB_PORT", "3306"),
102-
options={
103-
"charset": "utf8mb4"
104-
}
105101
),
106102
})
107103

docs/database/models.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,66 @@ user = await User.where("email", "admin@example.com").first()
7777
posts = await Post.where("user_id", 1).get()
7878
```
7979

80+
### `find_or_fail(id)` — find or raise
81+
82+
Fetch a record by primary key, raising `ModelNotFoundException` if nothing is found:
83+
84+
```python
85+
user = await User.find_or_fail(1)
86+
```
87+
88+
### `first_or_fail()` — first or raise
89+
90+
Execute the current query and raise `ModelNotFoundException` if no record matches:
91+
92+
```python
93+
user = await User.where("email", "admin@example.com").first_or_fail()
94+
```
95+
96+
### `exists()` — check existence
97+
98+
Return `True` if any record matches the current query, `False` otherwise:
99+
100+
```python
101+
active = await User.where("is_active", True).exists()
102+
```
103+
104+
### `count()` — row count
105+
106+
Return the number of rows matching the current query:
107+
108+
```python
109+
total = await User.count()
110+
active_count = await User.where("is_active", True).count()
111+
```
112+
113+
### `paginate(per_page, page)` — paginate results
114+
115+
Return a `LengthAwarePaginator` containing the requested slice of records plus total-count metadata:
116+
117+
```python
118+
page = await User.paginate(per_page=15, page=1)
119+
# page.items → list of User instances
120+
# page.total → total number of matching rows
121+
# page.last_page → last available page number
122+
```
123+
124+
### `or_where` / `where_raw` / `or_where_raw` / `or_where_null` — raw & OR variants
125+
126+
```python
127+
# OR condition
128+
users = await User.where("role", "admin").or_where("role", "moderator").get()
129+
130+
# Raw SQL predicate
131+
users = await User.where_raw("created_at > NOW() - INTERVAL '7 days'").get()
132+
133+
# Raw SQL with OR
134+
users = await User.where("is_active", True).or_where_raw("role = 'superadmin'").get()
135+
136+
# OR IS NULL
137+
users = await User.where("name", "Alice").or_where_null("deleted_at").get()
138+
```
139+
80140
## Creating Records
81141

82142
### `create`

docs/exception-handling.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: Exception Handling
44
description: Robust exception handling and custom error responses in Fastapi Startkit.
55
keywords: error handling, exceptions, fastapi, debugging
66
---
7+
78
# Exception Handling
89

910
The framework provides a centralized `ExceptionHandler` that handles reporting (logging) and rendering (HTTP responses) for exceptions across both web and CLI contexts.

docs/frontend/inertia.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: Inertia
44
description: Build modern single-page applications without the complexity of a separate API using Inertia.js and Fastapi Startkit.
55
keywords: inertia, spa, frontend, fastapi, monolithic
66
---
7+
78
# Inertia
89

910
[Inertia.js](https://inertiajs.com) is a protocol that bridges your server and frontend, letting you build full-stack single-page applications without building a separate API. Instead of writing REST endpoints and consuming them with `fetch()`, you write controllers that return component names and props — Inertia takes care of the rest.

docs/jsonapi.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
outline: deep
23
title: JSON:API Resources
34
description: Build JSON:API-compliant responses with JsonResource — automatic serialization, hidden fields, pagination meta, fluent chain API for fields and includes.
45
---

docs/queue.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)