Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from typing import Optional
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlmodel import SQLModel, Field
from fastapi_amis_admin.crud import SQLModelCrud
from fastapi_sqlmodel_crud import SQLModelCrud


# 1. Create SQLModel model
Expand Down
2 changes: 1 addition & 1 deletion fastapi_sqlmodel_crud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from typing import Optional
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlmodel import SQLModel, Field
from fastapi_amis_admin.crud import SQLModelCrud
from fastapi_sqlmodel_crud import SQLModelCrud


# 1. Create SQLModel model
Expand Down
9 changes: 8 additions & 1 deletion fastapi_sqlmodel_crud/_sqlmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ async def route(
):
if not await self.has_list_permission(request, paginator, filters):
return self.error_no_router_permission(request)
using_custom_model = self.schema_list != self.schema_model
if using_custom_model:
stmt = select(self.schema_model)
data = ItemListSchema(items=[])
page, perPage = paginator.page, paginator.perPage
filters_data = await self.on_filter_pre(request, filters)
Expand All @@ -443,7 +446,11 @@ async def route(
stmt = stmt.order_by(*orderBy)
stmt = stmt.limit(perPage).offset((page - 1) * perPage)
result = await self.db.async_execute(stmt)
data.items = self.parser.conv_row_to_dict(result.all())
result = result.all()
if using_custom_model:
data.items = [item[0] for item in result]
else:
data.items = self.parser.conv_row_to_dict(result)
data.items = [self.list_item(item) for item in data.items] if data.items else []
data.query = request.query_params
data.filters = filters_data
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ maintainers = [
]
description = "fastapi-sqlmodel-crud is a program which is based on fastapi+sqlmodel and used to quickly build the Create, Read, Update, Delete generic API interface."
readme = "README.md"
requires-python = ">=3.6.1"
requires-python = ">=3.7"
dynamic = ["version"]
keywords = [
"sqlmodel",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_crud/test_Mapper_Events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel
from sqlalchemy import event

from fastapi_amis_admin.crud import SQLModelCrud
from fastapi_sqlmodel_crud import SQLModelCrud
from tests.conftest import async_db as db
from tests.models import User
from tests.test_crud.test_SQLModelCrud_routes_async import (
Expand Down
8 changes: 5 additions & 3 deletions tests/test_crud/test_SQLModelCrud_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from starlette.requests import Request
from starlette.routing import NoMatchFound

from fastapi_amis_admin.crud import SQLModelCrud
from fastapi_amis_admin.crud.parser import LabelField, PropertyField
from fastapi_amis_admin.models import Field
from fastapi_sqlmodel_crud import SQLModelCrud
from fastapi_sqlmodel_crud.parser import LabelField, PropertyField
# from fastapi_amis_admin.models import Field # what should I do here?
Copy link
Author

@udiNur udiNur Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should I do here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should I do here?

from sqlmodel import Field

from tests.conftest import async_db as db
from tests.models import Article, ArticleContent, Category, Tag, User

Expand Down Expand Up @@ -140,6 +140,7 @@ class UserCrud(SQLModelCrud):
assert data["password"] == ""


@pytest.mark.skip(reason="no way of currently testing this without `from fastapi_amis_admin.models import Field`")
async def test_list_filter_relationship(app: FastAPI, async_client: AsyncClient, fake_articles):
class ArticleCrud(SQLModelCrud):
router_prefix = "/article"
Expand Down Expand Up @@ -197,6 +198,7 @@ async def get_select(self, request: Request) -> Select:
assert items[0]["id"] == 2


@pytest.mark.skip(reason="no way of currently testing this without `from fastapi_amis_admin.models import Field`")
async def test_fields(app: FastAPI, async_client: AsyncClient, fake_articles):
class ArticleCrud(SQLModelCrud):
router_prefix = "/article"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_crud/test_SQLModelCrud_routes_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from httpx import AsyncClient
from sqlalchemy import func, select

from fastapi_amis_admin.crud import SQLModelCrud
from fastapi_sqlmodel_crud import SQLModelCrud
from tests.conftest import async_db as db
from tests.models import Tag, User

Expand Down
2 changes: 1 addition & 1 deletion tests/test_crud/test_SQLModelCrud_routes_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.testclient import TestClient

from fastapi_amis_admin.crud import SQLModelCrud
from fastapi_sqlmodel_crud import SQLModelCrud
from tests.conftest import sync_db as db
from tests.models import Tag, User

Expand Down
2 changes: 1 addition & 1 deletion tests/test_crud/test_SQLModelCrud_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel
from sqlmodel import SQLModel

from fastapi_amis_admin.crud import SQLModelCrud
from fastapi_sqlmodel_crud import SQLModelCrud
from tests.conftest import async_db as db
from tests.models import Article, ArticleContent, Category, Tag, User

Expand Down
2 changes: 1 addition & 1 deletion tests/test_crud/test_SQLModelSelector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi_amis_admin.crud import SQLModelSelector
from fastapi_sqlmodel_crud import SQLModelSelector
from tests.models import Article, User


Expand Down