Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
FastAPI y GINO no pueden obtener todas las filas de la tabla en db

Estoy atrapado en un problema con GINO. Puedo obtener una fila de mi tabla llamada plantillas, por lo que en la otra ruta quiero obtener todas las filas de la tabla. Aquí puede ver mi vista para obtener un registro de db ant, funciona perfectamente.

 @router.get("/templates/{uid}") async def get_template(uid: str): temp = await Template.get_or_404(uid) return temp.to_dict()

A continuación, puede ver mi vista para agregar un registro a la base de datos y también funciona bien:

 @router.post("/templates") async def add_template(template: TemplateModel): rv = await Template.create(name=template.name, text=template.text) return rv.to_dict()

Entonces, la causa principal en esta vista, no funciona:

 @router.get("/templates/all") async def get_all_templates(): temp = await Template.all() return temp.to_dict()

Mire abajo para mi modelo de plantilla:

 class Template(db.Model): __tablename__ = "templates" UUID = db.Column( str(UUID(as_uuid=True)), db.String, primary_key=True, default=str(uuid.uuid4()), unique=True, nullable=False, ) name = db.Column("name", db.String, nullable=False) text = db.Column("text", db.String, nullable=False) created_at = db.Column("created_at", db.DateTime, nullable=False, server_default=db.func.now())

Y finalmente mi motor db GINO:

 from gino_starlette import Gino from .. import config db = Gino( dsn=config.DB_DSN, pool_min_size=config.DB_POOL_MIN_SIZE, pool_max_size=config.DB_POOL_MAX_SIZE, echo=config.DB_ECHO, )

REGISTRO DE ERRORES:

 2020-08-08 12:07:57,698 INFO gino.engine._SAEngine SELECT templates."UUID", templates.name, templates.text, templates.created_at FROM templates WHERE templates."UUID" = $1 2020-08-08 12:07:57,699 INFO gino.engine._SAEngine ('all',) INFO: 172.23.0.1:40676 - "GET /templates/all HTTP/1.1" 404 Not Found

Por favor, dígame qué está mal, pasé mucho tiempo para resolver este problema. Siéntase libre de responder, gracias.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sin embargo, no sé sobre eso. Y la documentación de GINO no dice que las operaciones con db que usan modelos GINO, como obtener todos los registros de db, deben solicitarse en POST. Entonces, la respuesta correcta es reemplazar router.get to router.post:

 @router.post("/templates/all") async def get_all_templates(): temp = await Template.all() return temp.to_dict()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!