Skip to content

Commit 0187997

Browse files
committed
renamed title to table name, added 3.13 to PR test matrix, updated README
1 parent 7c69e1d commit 0187997

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
"3.10",
1414
"3.11",
1515
"3.12",
16+
"3.13"
1617
]
1718
runs-on: ubuntu-latest
1819
env:

CHANGELOG.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11

22
# Change Log
3+
34
All notable changes to this project will be documented in this file.
4-
5+
56
The format is based on [Keep a Changelog](http://keepachangelog.com/)
67
and this project adheres to [Semantic Versioning](http://semver.org/).
7-
8+
89
## [1.0.0] - 2024-01-15
9-
10+
1011
Added support for Pydantic V2 (version - ^2.5).
11-
12+
1213
### Added
1314

1415
- Test coverage for Python versions `3.11` and `3.12`
1516

1617
### Changed
18+
1719
- Python base version from `3.7` to `3.8`.
1820
- Changed Pydantic version from `^1.8.2` to `^2.5`.
1921
- Updated Model validation function from `parse_obj` to `model_validate`.
2022
- Renamed backend initialization class from `Config` to `db_config` to follow pydantic's naming convention.
2123
- Updated method for generation of dictionary from `dict` to `model_dump`.
24+
- Renamed `db_config.title` to `db_config.table_name`.
2225

2326
## [0.4.2] - 2023-11-16
24-
27+
2528
Added count() for dynamo backend that returns integer count as total.

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ class User(BaseModel):
1515
id: int
1616
name: str
1717

18-
class Config:
19-
title = 'User'
18+
class db_config:
19+
table_name = 'User'
2020
backend = DynamoDbBackend
2121
hash_key = 'id'
2222
```
2323

2424
First, use the `BaseModel` from `pydanticrud` instead of `pydantic`.
2525

26-
Next add your backend to your model's `Config` class. PydantiCRUD is geared
26+
Next add your backend to your model's `db_config` class. PydantiCRUD is geared
2727
toward DynamoDB but provides SQLite for lighter-weight usage. You can provide
2828
your own if you like.
2929

30-
Finally, add appropriate members to the `Config` class for the chosen backend.
30+
Finally, add appropriate members to the `db_config` class for the chosen backend.
3131

3232
## Methods
3333

@@ -56,25 +56,26 @@ NOTE: Rule complexity is limited by the querying capabilities of the backend.
5656
### DynamoDB
5757

5858
`get(key: Union[Dict, Any])`
59-
- `key` can be any of 3 types:
60-
-
61-
- in the case of a single hash_key, a value of type that matches the hash_key
62-
- in the case of a hash and range key, a tuple specifying the respective values
63-
- a dictionary of the hash and range keys with their names and values. This method can pull for alternate indexes.
59+
60+
- `key` can be any of 3 types:
61+
- in the case of a single hash_key, a value of type that matches the hash_key
62+
- in the case of a hash and range key, a tuple specifying the respective values
63+
- a dictionary of the hash and range keys with their names and values. This method can pull for alternate indexes.
6464

6565
`query(query_expr: Optional[Rule], filter_expr: Optional[Rule], limit: Optional[str], exclusive_start_key: Optional[tuple[Any]], order: str = 'asc'`
66-
- Providing a `query_expr` parameter will try to apply the keys of the expression to an
66+
67+
- Providing a `query_expr` parameter will try to apply the keys of the expression to an
6768
existing index.
68-
- Providing a `filter_expr` parameter will filter the results of
69+
- Providing a `filter_expr` parameter will filter the results of
6970
a passed `query_expr` or run a dynamodb `scan` if no `query_expr` is passed.
70-
- An empty call to `query()` will return the scan results (and be resource
71+
- An empty call to `query()` will return the scan results (and be resource
7172
intensive).
72-
- Providing a `limit` parameter will limit the number of results. If more results remain, the returned dataset will have an `last_evaluated_key` property that can be passed to `exclusive_start_key` to continue with the next page.
73-
- Providing `order='desc'` will return the result set in descending order. This is not available for query calls that "scan" dynamodb.
73+
- Providing a `limit` parameter will limit the number of results. If more results remain, the returned dataset will have an `last_evaluated_key` property that can be passed to `exclusive_start_key` to continue with the next page.
74+
- Providing `order='desc'` will return the result set in descending order. This is not available for query calls that "scan" dynamodb.
7475

7576
`count(query_expr: Optional[Rule], exclusive_start_key: Optional[tuple[Any]], order: str = 'asc'`
76-
- Same as `query` but returns an integer count as total. (When calling `query` with a limit, the count dynamodb returns is <= the limit you provide)
7777

78+
- Same as `query` but returns an integer count as total. (When calling `query` with a limit, the count dynamodb returns is <= the limit you provide)
7879

7980
## Backend Configuration Members
8081

pydanticrud/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from warnings import warn
12
from pydantic import BaseModel as PydanticBaseModel
23
from pydantic._internal._model_construction import ModelMetaclass
34

@@ -43,7 +44,12 @@ def initialize(cls):
4344

4445
@classmethod
4546
def get_table_name(cls) -> str:
46-
return cls.db_config.title.lower()
47+
warn("'title' has been renamed to 'table_name'.", DeprecationWarning)
48+
return (
49+
cls.db_config.table_name.lower()
50+
if cls.db_config.table_name.lower()
51+
else cls.db_config.title.lower() # Will be deprecated
52+
)
4753

4854
@classmethod
4955
def exists(cls) -> bool:

tests/test_dynamodb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SimpleKeyModel(BaseModel):
3535
hash: UUID
3636

3737
class db_config:
38-
title = "ModelTitle123"
38+
table_name = "ModelTitle123"
3939
hash_key = "name"
4040
ttl = "expires"
4141
backend = DynamoDbBackend
@@ -57,7 +57,7 @@ def type_from_typ(cls, values):
5757
return values
5858

5959
class db_config:
60-
title = "AliasTitle123"
60+
table_name = "AliasTitle123"
6161
hash_key = "name"
6262
backend = DynamoDbBackend
6363
endpoint = "http://localhost:18002"
@@ -73,7 +73,7 @@ class ComplexKeyModel(BaseModel):
7373
body: str = "some random string"
7474

7575
class db_config:
76-
title = "ComplexModelTitle123"
76+
table_name = "ComplexModelTitle123"
7777
hash_key = "account"
7878
range_key = "sort_date_key"
7979
backend = DynamoDbBackend
@@ -103,7 +103,7 @@ class NestedModel(BaseModel):
103103
other: Union[Ticket, SomethingElse]
104104

105105
class db_config:
106-
title = "NestedModelTitle123"
106+
table_name = "NestedModelTitle123"
107107
hash_key = "account"
108108
range_key = "sort_date_key"
109109
backend = DynamoDbBackend

tests/test_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Model(BaseModel):
2222
total: float
2323

2424
class db_config:
25-
title = "ModelTitle123"
25+
table_name = "ModelTitle123"
2626
backend = FalseBackend
2727

2828

@@ -57,4 +57,4 @@ def test_model_backend_query():
5757

5858

5959
def test_model_table_name_from_title():
60-
assert Model.get_table_name() == Model.db_config.title.lower()
60+
assert Model.get_table_name() == Model.db_config.table_name.lower()

tests/test_sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Model(BaseModel):
2020
items: List[int]
2121

2222
class db_config:
23-
title = "ModelTitle123"
23+
table_name = "ModelTitle123"
2424
hash_key = "id"
2525
backend = SqliteBackend
2626
database = ":memory:"

0 commit comments

Comments
 (0)