Code Monkey home page Code Monkey logo

Comments (5)

wu-clan avatar wu-clan commented on June 12, 2024

我在本地测试中没有遇到此错误:

curl -X 'GET' \
  'http://127.0.0.1:8000/api/v1/depts/1' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDQ5NzkwMjUsInN1YiI6IjIifQ.0ciKz_asssLjZw7B-F7q-ZCT_OPtlW2JuLy1XvoKRwg'
{
  "code": 200,
  "msg": "请求成功",
  "data": {
    "name": "test",
    "parent_id": null,
    "sort": 0,
    "leader": null,
    "phone": null,
    "email": null,
    "status": 1,
    "id": 1,
    "del_flag": false,
    "created_time": "2023-06-26T17:13:45",
    "updated_time": "2023-08-11T15:18:33"
  }
}

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on June 12, 2024

我们有一个关于 CRUDBase 的讨论:#267

如果你有兴趣,欢迎提供建议

from fastapi_best_architecture.

jundaychan avatar jundaychan commented on June 12, 2024

这是我的 model,

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime

from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column

from backend.app.models.base import DataClassBase, id_key

from backend.app.utils.timezone import timezone


class Knowledge(DataClassBase):
    """
    知识库表
    """

    __tablename__ = 'knowledge'

    dept_id: Mapped[int | None] = mapped_column(comment='部门ID')
    id: Mapped[id_key] = mapped_column(init=False)
    name: Mapped[str] =  mapped_column(String(52),default=None,comment='知识库名称')
    description: Mapped[str | None] = mapped_column(String(255),default=None,comment='描述')
    model: Mapped[str | None] = mapped_column(String(32),default=None,comment='模型')
    index_name: Mapped[str | None] = mapped_column(String(32),default=None,comment='索引名称')
    collection_name: Mapped[str | None] = mapped_column(String(32),default=None,comment='集合名称')
    is_partition: bool = True
    created_time: Mapped[datetime] = mapped_column(init=False, default_factory=timezone.now, comment='创建时间')
    updated_time: Mapped[datetime] = mapped_column(init=False, default_factory=timezone.now, comment='更新时间')

目前卡在了result = await db.execute(select(self.model).where(and_(*where_list)))

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on June 12, 2024

is_partition: bool = True?

Why not is_partition: Mapped[bool] = mapped_column(default=True)?

你尝试过使用await db.execute(select(self.model).where(self.model.id == pk))是否能正确返回码?

另外,你完全可以继承 Base,从而省略手动编写的 created_time 和 updated_time

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on June 12, 2024

If there is no feedback, I will close this problem.

from fastapi_best_architecture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.