mirror of
https://github.com/creyD/creyPY.git
synced 2026-04-13 11:50:31 +02:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 807af12fa1 | |||
|
|
dce897c247 | ||
|
|
89997372ef | ||
| c8c5977978 | |||
| 974bc591d6 | |||
| eb895398ab | |||
| 867abd7054 | |||
| 26e18f6b31 | |||
| 8a3a60dbb0 | |||
| e52a5f421b | |||
| a6ded91185 | |||
| eb64874c47 | |||
| b7200852a4 | |||
| 3d18205205 | |||
| 99c84b676c | |||
| 6806de23b3 | |||
| 6a93ab05a3 | |||
|
|
c5b2ab9932 | ||
| 5a32a5908b | |||
| b7df0bfdcd | |||
| 378d1d60f1 |
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
@@ -12,7 +12,6 @@ on:
|
|||||||
- "**/CHANGELOG.md"
|
- "**/CHANGELOG.md"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- master
|
|
||||||
- dev
|
- dev
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ jobs:
|
|||||||
|
|
||||||
tag_and_publish:
|
tag_and_publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.head_ref == 'master' || github.head_ref == 'dev'
|
if: github.ref_name == 'master' || github.ref_name == 'dev'
|
||||||
needs: test
|
needs: test
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
||||||
@@ -56,7 +55,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-tags: true
|
fetch-tags: true
|
||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.ref_name }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: setup git
|
- name: setup git
|
||||||
@@ -64,6 +63,15 @@ jobs:
|
|||||||
git config --local user.email "15138480+creyD@users.noreply.github.com"
|
git config --local user.email "15138480+creyD@users.noreply.github.com"
|
||||||
git config --local user.name "creyD"
|
git config --local user.name "creyD"
|
||||||
|
|
||||||
|
- name: set version format
|
||||||
|
id: version_format
|
||||||
|
run: |
|
||||||
|
if [[ ${{ github.ref_name }} == 'master' ]]; then
|
||||||
|
echo "version_format=\${major}.\${minor}.\${patch}" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "version_format=\${major}.\${minor}.\${patch}rc\${increment}" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Git Version
|
- name: Git Version
|
||||||
uses: PaulHatch/semantic-version@v5.4.0
|
uses: PaulHatch/semantic-version@v5.4.0
|
||||||
id: git_version
|
id: git_version
|
||||||
@@ -72,10 +80,9 @@ jobs:
|
|||||||
major_pattern: "breaking:"
|
major_pattern: "breaking:"
|
||||||
minor_pattern: "feat:"
|
minor_pattern: "feat:"
|
||||||
enable_prerelease_mode: false
|
enable_prerelease_mode: false
|
||||||
version_format: "${major}.${minor}.${patch}rc${increment}"
|
version_format: ${{ steps.version_format.outputs.version_format }}
|
||||||
|
|
||||||
- name: Create & Push Tag
|
- name: Create & Push Tag
|
||||||
if: github.head_ref == 'master' || github.head_ref == 'dev'
|
|
||||||
run: |
|
run: |
|
||||||
git tag ${{ steps.git_version.outputs.version }}
|
git tag ${{ steps.git_version.outputs.version }}
|
||||||
git push origin ${{ steps.git_version.outputs.version }}
|
git push origin ${{ steps.git_version.outputs.version }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from math import ceil
|
from math import ceil
|
||||||
from typing import Any, Generic, Optional, Self, Sequence, TypeVar, Union
|
from typing import Any, Generic, Optional, Self, Sequence, TypeVar, Union
|
||||||
|
from pydantic import BaseModel
|
||||||
from fastapi_pagination import Params
|
from fastapi_pagination import Params
|
||||||
from fastapi_pagination.bases import AbstractPage, AbstractParams
|
from fastapi_pagination.bases import AbstractPage, AbstractParams
|
||||||
from fastapi_pagination.types import (
|
from fastapi_pagination.types import (
|
||||||
@@ -12,14 +12,28 @@ from fastapi_pagination.types import (
|
|||||||
from fastapi_pagination.api import create_page, apply_items_transformer
|
from fastapi_pagination.api import create_page, apply_items_transformer
|
||||||
from fastapi_pagination.utils import verify_params
|
from fastapi_pagination.utils import verify_params
|
||||||
from fastapi_pagination.ext.sqlalchemy import create_paginate_query
|
from fastapi_pagination.ext.sqlalchemy import create_paginate_query
|
||||||
|
from fastapi_pagination.bases import AbstractParams, RawParams
|
||||||
from pydantic.json_schema import SkipJsonSchema
|
from pydantic.json_schema import SkipJsonSchema
|
||||||
from sqlalchemy.sql.selectable import Select
|
from sqlalchemy.sql.selectable import Select
|
||||||
from sqlalchemy.orm.session import Session
|
from sqlalchemy.orm.session import Session
|
||||||
from sqlalchemy import select, func
|
from sqlalchemy import select, func
|
||||||
|
from fastapi import Query
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
|
class PaginationParams(BaseModel, AbstractParams):
|
||||||
|
page: int = Query(1, ge=1, description="Page number")
|
||||||
|
size: int = Query(50, ge=1, le=100, description="Page size")
|
||||||
|
pagination: bool = Query(True, description="Toggle pagination")
|
||||||
|
|
||||||
|
def to_raw_params(self) -> RawParams:
|
||||||
|
if not self.pagination:
|
||||||
|
return RawParams(limit=None, offset=None)
|
||||||
|
|
||||||
|
return RawParams(limit=self.size, offset=(self.page - 1) * self.size)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Add complete fastapi-pagination proxy here
|
# TODO: Add complete fastapi-pagination proxy here
|
||||||
# TODO: Add pagination off functionality
|
# TODO: Add pagination off functionality
|
||||||
# SkipJsonSchema is used to avoid generating invalid JSON schema in FastAPI
|
# SkipJsonSchema is used to avoid generating invalid JSON schema in FastAPI
|
||||||
@@ -32,7 +46,7 @@ class Page(AbstractPage[T], Generic[T]):
|
|||||||
has_next: bool | SkipJsonSchema[None] = None
|
has_next: bool | SkipJsonSchema[None] = None
|
||||||
has_prev: bool | SkipJsonSchema[None] = None
|
has_prev: bool | SkipJsonSchema[None] = None
|
||||||
|
|
||||||
__params_type__ = Params
|
__params_type__ = PaginationParams
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
@@ -97,18 +111,19 @@ def unwrap_scalars(
|
|||||||
def paginate(
|
def paginate(
|
||||||
connection: Session,
|
connection: Session,
|
||||||
query: Select,
|
query: Select,
|
||||||
paginationFlag: bool = True,
|
|
||||||
params: Optional[AbstractParams] = None,
|
params: Optional[AbstractParams] = None,
|
||||||
transformer: Optional[SyncItemsTransformer] = None,
|
transformer: Optional[SyncItemsTransformer] = None,
|
||||||
additional_data: Optional[AdditionalData] = None,
|
additional_data: Optional[AdditionalData] = None,
|
||||||
):
|
):
|
||||||
params, _ = verify_params(params, "limit-offset", "cursor")
|
|
||||||
|
|
||||||
|
params, raw_params = verify_params(params, "limit-offset", "cursor")
|
||||||
count_query = create_count_query(query)
|
count_query = create_count_query(query)
|
||||||
total = connection.scalar(count_query)
|
total = connection.scalar(count_query)
|
||||||
|
|
||||||
if paginationFlag is False:
|
if params.pagination is False and total > 0:
|
||||||
params = Params(page=1, size=total)
|
params = Params(page=1, size=total)
|
||||||
|
else:
|
||||||
|
params = Params(page=params.page, size=params.size)
|
||||||
|
|
||||||
query = create_paginate_query(query, params)
|
query = create_paginate_query(query, params)
|
||||||
items = connection.execute(query).all()
|
items = connection.execute(query).all()
|
||||||
|
|||||||
Reference in New Issue
Block a user