fastapi-repository 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl

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.
@@ -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
- # in句
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
- クエリに対して order_by を適用するヘルパー。
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
- # keyに "__" が含まれていれば、フィールド名と演算子を分割する
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
- # 単純カラム: foo__icontains=bar
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
- # 1ホップのリレーション: rel__field__op=value
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
- # "__"が含まれていない場合は eq (=) 比較とみなす
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.1
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 Takeda <takedaseiya@gmail.com>
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
- ## Usage
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,6 @@
1
+ fastapi_repository/__init__.py,sha256=ymIcIyfYlbv-TudpI3UOU1f2y57tEnRIFIYQMjnw0bI,87
2
+ fastapi_repository/base.py,sha256=K_rD_pu9t530od-4zJL2dmEJU_bSuuEyK11bi0UCZYM,12250
3
+ fastapi_repository-0.0.2.dist-info/METADATA,sha256=q_HdAJ9siKarj6aYZImgX6WpOjZj3kQ4PFQJq_NJOHs,1958
4
+ fastapi_repository-0.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ fastapi_repository-0.0.2.dist-info/top_level.txt,sha256=SSUZqBKCDo6XNjAhSFvpv4tmiPW1COl86ZR5B4ucBkU,19
6
+ fastapi_repository-0.0.2.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- fastapi_repository/__init__.py,sha256=ymIcIyfYlbv-TudpI3UOU1f2y57tEnRIFIYQMjnw0bI,87
2
- fastapi_repository/base.py,sha256=5RpkNKXnl3cozCiHkWhU7sGY0QIY_36BmT8AoGge0kM,12325
3
- fastapi_repository-0.0.1.dist-info/METADATA,sha256=X-xa_Q5eCVrC4IPlenM8dl6LwEhFrp5RrnRoWleUkBc,1089
4
- fastapi_repository-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- fastapi_repository-0.0.1.dist-info/top_level.txt,sha256=SSUZqBKCDo6XNjAhSFvpv4tmiPW1COl86ZR5B4ucBkU,19
6
- fastapi_repository-0.0.1.dist-info/RECORD,,