Skip to content

Commit 280acc1

Browse files
committed
proofread and fix the docs, part 1
1 parent 27a981c commit 280acc1

File tree

5 files changed

+42
-45
lines changed

5 files changed

+42
-45
lines changed

docs/index.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
### Overview
2323

24-
The `ormar` package is an async mini ORM for Python, with support for **Postgres,
24+
The `ormar` package is an async ORM for Python, with support for **Postgres,
2525
MySQL**, and **SQLite**.
2626

2727
The main benefits of using `ormar` are:
@@ -53,13 +53,7 @@ Yet remember that those are - well - tests and not all solutions are suitable to
5353

5454
### Part of the `fastapi` ecosystem
5555

56-
As part of the fastapi ecosystem `ormar` is supported in libraries that somehow work with databases.
57-
58-
As of now `ormar` is supported by:
59-
60-
* [`fastapi-users`](https://github.com/frankie567/fastapi-users)
61-
* [`fastapi-crudrouter`](https://github.com/awtkns/fastapi-crudrouter)
62-
* [`fastapi-pagination`](https://github.com/uriyyo/fastapi-pagination)
56+
As part of the fastapi ecosystem `ormar` is supported in selected libraries that somehow work with databases.
6357

6458
Ormar remains sql dialect agnostic - so only columns working in all supported backends are implemented.
6559

@@ -76,7 +70,6 @@ Ormar is built with:
7670
* [`sqlalchemy core`][sqlalchemy-core] for query building.
7771
* [`databases`][databases] for cross-database async support.
7872
* [`pydantic`][pydantic] for data validation.
79-
* `typing_extensions` for python 3.6 - 3.7
8073

8174
### License
8275

@@ -658,7 +651,6 @@ The following keyword arguments are supported on all field types.
658651
* `server_default: Any`
659652
* `index: bool`
660653
* `unique: bool`
661-
* `choices: typing.Sequence`
662654
* `name: str`
663655

664656
All fields are required unless one of the following is set:

docs/install.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,33 @@ Ormar uses `databases` for connectivity issues, `pydantic` for validation and `s
1313
All three should install along the installation of ormar if not present at your system before.
1414

1515
* databases
16-
* pydantic>=1.5
16+
* pydantic
1717
* sqlalchemy
1818

19+
The required versions are pinned in the pyproject.toml file.
1920

2021
## Optional dependencies
2122

2223
*ormar* has three optional dependencies based on database backend you use:
2324

24-
### Postgresql
25+
### Database backend
26+
27+
#### Postgresql
2528

2629
```py
2730
pip install ormar[postgresql]
2831
```
2932
Will install also `asyncpg` and `psycopg2`.
3033

31-
### Mysql
34+
#### Mysql
3235

3336
```py
3437
pip install ormar[mysql]
3538
```
3639

3740
Will install also `aiomysql` and `pymysql`.
3841

39-
### Sqlite
42+
#### Sqlite
4043

4144
```py
4245
pip install ormar[sqlite]

docs/models/index.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ you should get back exactly same value in `response`.).
6767
If you set pydantic field with `default` parameter and do not pass actual value in request you will always get default value.
6868
Since it can be a function you can set `default=datetime.datetime.now` and get current timestamp each time you call an endpoint etc.
6969

70+
#### Non Database Fields in Fastapi
71+
7072
!!!note
7173
Note, that both pydantic and calculated_fields decorated field can be included/excluded in both `model_dump()` and `fastapi`
7274
response with `include`/`exclude` and `response_model_include`/`response_model_exclude` accordingly.
7375

7476
```python
75-
# <==related of code removed for clarity==>
77+
# <==part of related code removed for clarity==>
7678
base_ormar_config = ormar.OrmarConfig(
7779
database=databases.Database(DATABASE_URL),
7880
metadata=sqlalchemy.MetaData(),
@@ -93,14 +95,14 @@ class User(ormar.Model):
9395
default=datetime.datetime.now
9496
)
9597

96-
# <==related of code removed for clarity==>
98+
# <==part of related code removed for clarity==>
9799
app = FastAPI()
98100

99101
@app.post("/users/")
100102
async def create_user(user: User):
101103
return await user.save()
102104

103-
# <==related of code removed for clarity==>
105+
# <==part of related code removed for clarity==>
104106

105107
def test_excluding_fields_in_endpoints():
106108
client = TestClient(app)
@@ -127,7 +129,7 @@ def test_excluding_fields_in_endpoints():
127129
assert response.json().get("timestamp") == str(timestamp).replace(" ", "T")
128130

129131

130-
# <==related of code removed for clarity==>
132+
# <==part of related code removed for clarity==>
131133
```
132134

133135
#### Fields names vs Column names
@@ -152,7 +154,7 @@ But for now you cannot change the ManyToMany column names as they go through oth
152154
--8<-- "../docs_src/models/docs010.py"
153155
```
154156

155-
## Overwriting the default QuerySet
157+
### Overwriting the default QuerySet
156158

157159
If you want to customize the queries run by ormar you can define your own queryset class (that extends the ormar `QuerySet`) in your model class, default one is simply the `QuerySet`
158160

@@ -188,9 +190,9 @@ book = await Book.objects.first_or_404(name="123")
188190

189191
```
190192

191-
### Type Hints & Legacy
193+
### Type Hints
192194

193-
From version >=0.4.0 `ormar` switched to new notation.
195+
Note that for better IDE support and mypy checks you can provide type hints.
194196

195197
```Python hl_lines="15-17"
196198
--8<-- "../docs_src/models/docs001.py"
@@ -245,20 +247,20 @@ Created instance needs to be passed to every `Model` with `ormar_config` object
245247

246248
#### Best practice
247249

248-
Only thing that `ormar` expects is a field with name `ormar_config`.
249-
250+
Note that `ormar` expects the field with name `ormar_config` that is an instance of `OrmarConfig` class.
251+
To ease the config management, the `OrmarConfig` class provide `copy` method.
250252
So instead of providing the same parameters over and over again for all models
251-
you should creat an object and use its copy in all models.
253+
you should create a base object and use its copy in all models.
252254

253-
```Python hl_lines="9-11 18 27"
255+
```Python hl_lines="9-12 19 28"
254256
--8<-- "../docs_src/models/docs013.py"
255257
```
256258

257259
### Table Names
258260

259261
By default table name is created from Model class name as lowercase name plus 's'.
260262

261-
You can overwrite this parameter by providing `ormar_config` object `tablename` argument.
263+
You can overwrite this parameter by providing `ormar_config` object's `tablename` argument.
262264

263265
```Python hl_lines="14-16"
264266
--8<-- "../docs_src/models/docs002.py"
@@ -268,10 +270,10 @@ You can overwrite this parameter by providing `ormar_config` object `tablename`
268270

269271
On a model level you can also set model-wise constraints on sql columns.
270272

271-
Right now only `IndexColumns` and `UniqueColumns` constraints are supported.
273+
Right now only `IndexColumns`, `UniqueColumns` and `CheckColumns` constraints are supported.
272274

273275
!!!note
274-
Note that both constraints should be used only if you want to set a name on constraint or want to set the index on multiple columns, otherwise `index` and `unique` properties on ormar fields are preferred.
276+
Note that both constraints should be used only if you want to set a name on constraint or want to set the index on multiple columns, otherwise `index` and `unique` properties on ormar fields are preferred.
275277

276278
!!!tip
277279
To read more about columns constraints like `primary_key`, `unique`, `ForeignKey` etc. visit [fields][fields].
@@ -285,9 +287,9 @@ You can set this parameter by providing `ormar_config` object `constraints` argu
285287
```
286288

287289
!!!note
288-
Note that constraints are meant for combination of columns that should be unique.
289-
To set one column as unique use [`unique`](../fields/common-parameters.md#unique) common parameter.
290-
Of course you can set many columns as unique with this param but each of them will be checked separately.
290+
Note that constraints are meant for combination of columns that should be unique.
291+
To set one column as unique use [`unique`](../fields/common-parameters.md#unique) common parameter.
292+
Of course you can set many columns as unique with this param but each of them will be checked separately.
291293

292294
#### IndexColumns
293295

@@ -298,9 +300,9 @@ You can set this parameter by providing `ormar_config` object `constraints` argu
298300
```
299301

300302
!!!note
301-
Note that constraints are meant for combination of columns that should be in the index.
302-
To set one column index use [`unique`](../fields/common-parameters.md#index) common parameter.
303-
Of course, you can set many columns as indexes with this param but each of them will be a separate index.
303+
Note that constraints are meant for combination of columns that should be in the index.
304+
To set one column index use [`unique`](../fields/common-parameters.md#index) common parameter.
305+
Of course, you can set many columns as indexes with this param but each of them will be a separate index.
304306

305307
#### CheckColumns
306308

@@ -311,7 +313,7 @@ You can set this parameter by providing `ormar_config` object `constraints` argu
311313
```
312314

313315
!!!note
314-
Note that some databases do not actively support check constraints such as MySQL.
316+
Note that some databases do not actively support check constraints (such as MySQL).
315317

316318

317319
### Pydantic configuration
@@ -323,13 +325,13 @@ The way to do this in pydantic is to adjust the settings on the `model_config` d
323325
So in order to set your own preferences you need to provide not only the `ormar_config` class but also the `model_config = ConfigDict()` class to your model.
324326

325327
!!!note
326-
To read more about available settings visit the [pydantic](https://pydantic-docs.helpmanual.io/usage/model_config/) config page.
328+
To read more about available settings visit the [pydantic](https://pydantic-docs.helpmanual.io/usage/model_config/) config page.
327329

328330
Note that if you do not provide your own configuration, ormar will do it for you.
329331
The default config provided is as follows:
330332

331333
```python
332-
model_config = ConfigDict(validate_assignment=True)
334+
model_config = ConfigDict(validate_assignment=True, ser_json_bytes="base64")
333335
```
334336

335337
So to overwrite setting or provide your own a sample model can look like following:
@@ -373,7 +375,7 @@ When querying the database with given model by default the Model is ordered by t
373375
column ascending. If you wish to change the default behaviour you can do it by providing `orders_by`
374376
parameter to model `ormar_config` object.
375377

376-
Sample default ordering:
378+
Sample default ordering (not specified - so by primary key):
377379
```python
378380
base_ormar_config = ormar.OrmarConfig(
379381
database=databases.Database(DATABASE_URL),
@@ -383,13 +385,15 @@ base_ormar_config = ormar.OrmarConfig(
383385

384386
# default sort by column id ascending
385387
class Author(ormar.Model):
386-
ormar_config = base_ormar_config.copy()
388+
ormar_config = base_ormar_config.copy(
389+
tablename="authors",
390+
)
387391

388392
id: int = ormar.Integer(primary_key=True)
389393
name: str = ormar.String(max_length=100)
390394
```
391395
Modified
392-
```python
396+
```python hl_lines="9"
393397
base_ormar_config = ormar.OrmarConfig(
394398
database=databases.Database(DATABASE_URL),
395399
metadata=sqlalchemy.MetaData(),
@@ -410,9 +414,6 @@ class Author(ormar.Model):
410414

411415
There are two ways to create and persist the `Model` instance in the database.
412416

413-
!!!tip
414-
Use `ipython` to try this from the console, since it supports `await`.
415-
416417
If you plan to modify the instance in the later execution of your program you can initiate your `Model` as a normal class and later await a `save()` call.
417418

418419
```Python hl_lines="25-26"

docs/models/inheritance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class Truck2(Car2):
372372

373373

374374
class Bus2(Car2):
375-
ormar_config = base_ormar_config.copy(tablename="busses2")
375+
ormar_config = base_ormar_config.copy(tablename="buses2")
376376

377377
max_persons: int = ormar.Integer()
378378
```

docs_src/models/docs013.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
DATABASE_URL = "sqlite:///test.db"
88

99
ormar_base_config = ormar.OrmarConfig(
10-
database=databases.Database(DATABASE_URL), metadata=sqlalchemy.MetaData()
10+
database=databases.Database(DATABASE_URL),
11+
metadata=sqlalchemy.MetaData(),
1112
)
1213

1314

0 commit comments

Comments
 (0)