fastapi-repository 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/PKG-INFO +16 -4
- fastapi_repository-0.0.2/README.md +33 -0
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository/base.py +11 -13
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/PKG-INFO +16 -4
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/pyproject.toml +2 -2
- fastapi_repository-0.0.1/README.md +0 -21
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository/__init__.py +0 -0
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/SOURCES.txt +0 -0
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/dependency_links.txt +0 -0
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/requires.txt +0 -0
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/top_level.txt +0 -0
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/setup.cfg +0 -0
- {fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/tests/test_base_repository.py +0 -0
@@ -1,8 +1,8 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fastapi-repository
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.2
|
4
4
|
Summary: A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack.
|
5
|
-
Author-email: Seiya
|
5
|
+
Author-email: Peter Seiya Takahashi <seiya4@icloud.com>
|
6
6
|
Project-URL: Homepage, https://github.com/seiyat/fastapi-repository
|
7
7
|
Project-URL: Bug Tracker, https://github.com/seiyat/fastapi-repository/issues
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
@@ -15,7 +15,15 @@ Requires-Dist: fastapi>=0.70.0
|
|
15
15
|
|
16
16
|
# FastAPI Repository
|
17
17
|
|
18
|
-
A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack.
|
18
|
+
A base repository for FastAPI projects, inspired by Ruby on Rails' [Active Record](https://github.com/rails/rails/tree/main/activerecord) and [Ransack](https://github.com/activerecord-hackery/ransack). It provides a simple, intuitive interface for data access in asynchronous applications using SQLAlchemy.
|
19
|
+
|
20
|
+
## Features
|
21
|
+
|
22
|
+
- **Async-first:** Designed for modern asynchronous Python.
|
23
|
+
- **Simple CRUD:** `find`, `create`, `update`, `destroy` methods out of the box.
|
24
|
+
- **Powerful Filtering:** Use Ransack-style operators (`__icontains`, `__gt`, etc.) for complex queries.
|
25
|
+
- **Eager & Lazy Loading:** Control relationship loading with `joinedload` and `lazyload`.
|
26
|
+
- **Default Scoping:** Apply default conditions to all queries.
|
19
27
|
|
20
28
|
## Installation
|
21
29
|
|
@@ -23,7 +31,7 @@ A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record
|
|
23
31
|
pip install fastapi-repository
|
24
32
|
```
|
25
33
|
|
26
|
-
##
|
34
|
+
## Quick Start
|
27
35
|
|
28
36
|
```python
|
29
37
|
from fastapi_repository import BaseRepository
|
@@ -34,3 +42,7 @@ class UserRepository(BaseRepository):
|
|
34
42
|
def __init__(self, session: AsyncSession):
|
35
43
|
super().__init__(session, model=User)
|
36
44
|
```
|
45
|
+
|
46
|
+
## Documentation
|
47
|
+
|
48
|
+
For a complete guide, including all available methods, advanced filtering, and default scoping, please see the [full documentation](https://github.com/PeterTakahashi/fastapi-repository/blob/main/docs/index.md).
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# FastAPI Repository
|
2
|
+
|
3
|
+
A base repository for FastAPI projects, inspired by Ruby on Rails' [Active Record](https://github.com/rails/rails/tree/main/activerecord) and [Ransack](https://github.com/activerecord-hackery/ransack). It provides a simple, intuitive interface for data access in asynchronous applications using SQLAlchemy.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **Async-first:** Designed for modern asynchronous Python.
|
8
|
+
- **Simple CRUD:** `find`, `create`, `update`, `destroy` methods out of the box.
|
9
|
+
- **Powerful Filtering:** Use Ransack-style operators (`__icontains`, `__gt`, etc.) for complex queries.
|
10
|
+
- **Eager & Lazy Loading:** Control relationship loading with `joinedload` and `lazyload`.
|
11
|
+
- **Default Scoping:** Apply default conditions to all queries.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```bash
|
16
|
+
pip install fastapi-repository
|
17
|
+
```
|
18
|
+
|
19
|
+
## Quick Start
|
20
|
+
|
21
|
+
```python
|
22
|
+
from fastapi_repository import BaseRepository
|
23
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
24
|
+
from .models import User
|
25
|
+
|
26
|
+
class UserRepository(BaseRepository):
|
27
|
+
def __init__(self, session: AsyncSession):
|
28
|
+
super().__init__(session, model=User)
|
29
|
+
```
|
30
|
+
|
31
|
+
## Documentation
|
32
|
+
|
33
|
+
For a complete guide, including all available methods, advanced filtering, and default scoping, please see the [full documentation](https://github.com/PeterTakahashi/fastapi-repository/blob/main/docs/index.md).
|
@@ -7,20 +7,20 @@ from sqlalchemy import func, update, delete
|
|
7
7
|
from typing import Optional, List, Union, Dict, Any
|
8
8
|
|
9
9
|
OPERATORS = {
|
10
|
-
#
|
10
|
+
# Exact match
|
11
11
|
"exact": lambda col, val: col == val,
|
12
12
|
"iexact": lambda col, val: col.ilike(val),
|
13
|
-
#
|
13
|
+
# Partial match
|
14
14
|
"contains": lambda col, val: col.contains(val),
|
15
15
|
"icontains": lambda col, val: col.ilike(f"%{val}%"),
|
16
|
-
#
|
16
|
+
# IN clause
|
17
17
|
"in": lambda col, val: col.in_(val) if isinstance(val, list) else col.in_([val]),
|
18
|
-
#
|
18
|
+
# Comparison operators
|
19
19
|
"gt": lambda col, val: col > val,
|
20
20
|
"gte": lambda col, val: col >= val,
|
21
21
|
"lt": lambda col, val: col < val,
|
22
22
|
"lte": lambda col, val: col <= val,
|
23
|
-
#
|
23
|
+
# Starts/ends with
|
24
24
|
"startswith": lambda col, val: col.startswith(val),
|
25
25
|
"istartswith": lambda col, val: col.ilike(f"{val}%"),
|
26
26
|
"endswith": lambda col, val: col.endswith(val),
|
@@ -210,7 +210,7 @@ class BaseRepository:
|
|
210
210
|
|
211
211
|
def _apply_order_by(self, query, sorted_by: str, sorted_order: str):
|
212
212
|
"""
|
213
|
-
|
213
|
+
Helper to apply order_by to a query.
|
214
214
|
"""
|
215
215
|
column = getattr(self.model, sorted_by, None)
|
216
216
|
if not column:
|
@@ -231,14 +231,14 @@ class BaseRepository:
|
|
231
231
|
"""
|
232
232
|
conditions = []
|
233
233
|
for key, value in search_params.items():
|
234
|
-
#
|
234
|
+
# If "__" is included in the key, split into field name and operator
|
235
235
|
if "__" in key:
|
236
236
|
parts = key.split("__")
|
237
237
|
op = "exact"
|
238
|
-
if parts[-1] in OPERATORS: #
|
238
|
+
if parts[-1] in OPERATORS: # If the last part is an operator, remove it
|
239
239
|
op = parts.pop()
|
240
240
|
|
241
|
-
#
|
241
|
+
# Simple column: foo__icontains=bar
|
242
242
|
if len(parts) == 1:
|
243
243
|
column = getattr(self.model, parts[0], None)
|
244
244
|
if column is None:
|
@@ -248,7 +248,7 @@ class BaseRepository:
|
|
248
248
|
conditions.append(OPERATORS[op](column, value))
|
249
249
|
continue
|
250
250
|
|
251
|
-
#
|
251
|
+
# One-hop relationship: rel__field__op=value
|
252
252
|
rel_attr = getattr(self.model, parts[0], None)
|
253
253
|
if rel_attr is None or not hasattr(rel_attr, "property"):
|
254
254
|
raise AttributeError(
|
@@ -263,7 +263,7 @@ class BaseRepository:
|
|
263
263
|
conditions.append(rel_attr.any(OPERATORS[op](target_column, value)))
|
264
264
|
continue
|
265
265
|
else:
|
266
|
-
# "__"
|
266
|
+
# If "__" is not included, treat as simple eq (=) comparison
|
267
267
|
column = getattr(self.model, key, None)
|
268
268
|
if column is None:
|
269
269
|
raise AttributeError(
|
@@ -271,8 +271,6 @@ class BaseRepository:
|
|
271
271
|
)
|
272
272
|
conditions.append(column == value)
|
273
273
|
|
274
|
-
return conditions
|
275
|
-
|
276
274
|
async def create(self, **create_params):
|
277
275
|
"""
|
278
276
|
Generic create method that instantiates the model,
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fastapi-repository
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.2
|
4
4
|
Summary: A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack.
|
5
|
-
Author-email: Seiya
|
5
|
+
Author-email: Peter Seiya Takahashi <seiya4@icloud.com>
|
6
6
|
Project-URL: Homepage, https://github.com/seiyat/fastapi-repository
|
7
7
|
Project-URL: Bug Tracker, https://github.com/seiyat/fastapi-repository/issues
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
@@ -15,7 +15,15 @@ Requires-Dist: fastapi>=0.70.0
|
|
15
15
|
|
16
16
|
# FastAPI Repository
|
17
17
|
|
18
|
-
A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack.
|
18
|
+
A base repository for FastAPI projects, inspired by Ruby on Rails' [Active Record](https://github.com/rails/rails/tree/main/activerecord) and [Ransack](https://github.com/activerecord-hackery/ransack). It provides a simple, intuitive interface for data access in asynchronous applications using SQLAlchemy.
|
19
|
+
|
20
|
+
## Features
|
21
|
+
|
22
|
+
- **Async-first:** Designed for modern asynchronous Python.
|
23
|
+
- **Simple CRUD:** `find`, `create`, `update`, `destroy` methods out of the box.
|
24
|
+
- **Powerful Filtering:** Use Ransack-style operators (`__icontains`, `__gt`, etc.) for complex queries.
|
25
|
+
- **Eager & Lazy Loading:** Control relationship loading with `joinedload` and `lazyload`.
|
26
|
+
- **Default Scoping:** Apply default conditions to all queries.
|
19
27
|
|
20
28
|
## Installation
|
21
29
|
|
@@ -23,7 +31,7 @@ A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record
|
|
23
31
|
pip install fastapi-repository
|
24
32
|
```
|
25
33
|
|
26
|
-
##
|
34
|
+
## Quick Start
|
27
35
|
|
28
36
|
```python
|
29
37
|
from fastapi_repository import BaseRepository
|
@@ -34,3 +42,7 @@ class UserRepository(BaseRepository):
|
|
34
42
|
def __init__(self, session: AsyncSession):
|
35
43
|
super().__init__(session, model=User)
|
36
44
|
```
|
45
|
+
|
46
|
+
## Documentation
|
47
|
+
|
48
|
+
For a complete guide, including all available methods, advanced filtering, and default scoping, please see the [full documentation](https://github.com/PeterTakahashi/fastapi-repository/blob/main/docs/index.md).
|
@@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "fastapi-repository"
|
7
|
-
version = "0.0.
|
7
|
+
version = "0.0.2"
|
8
8
|
authors = [
|
9
|
-
{ name="Seiya
|
9
|
+
{ name="Peter Seiya Takahashi", email="seiya4@icloud.com" },
|
10
10
|
]
|
11
11
|
description = "A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack."
|
12
12
|
readme = "README.md"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# FastAPI Repository
|
2
|
-
|
3
|
-
A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
```bash
|
8
|
-
pip install fastapi-repository
|
9
|
-
```
|
10
|
-
|
11
|
-
## Usage
|
12
|
-
|
13
|
-
```python
|
14
|
-
from fastapi_repository import BaseRepository
|
15
|
-
from sqlalchemy.ext.asyncio import AsyncSession
|
16
|
-
from .models import User
|
17
|
-
|
18
|
-
class UserRepository(BaseRepository):
|
19
|
-
def __init__(self, session: AsyncSession):
|
20
|
-
super().__init__(session, model=User)
|
21
|
-
```
|
File without changes
|
{fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/SOURCES.txt
RENAMED
File without changes
|
File without changes
|
{fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/requires.txt
RENAMED
File without changes
|
{fastapi_repository-0.0.1 → fastapi_repository-0.0.2}/fastapi_repository.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|