Skip to content

PiccoloCRUD post_single return id of the inserted row instead of the row #255

Closed as duplicate

Description

@JoshYuJump

When I create a new item:

POST /items
{
    "name": "testing"
}

It response the id of the inserted row, in array format

[{"id": 1}]

How to get response of the row

{
    "id": 1,
    "name": "testing"
}

Activity

  1. sinisaos commented on Sep 20, 2023

    @sinisaos
    Member

    @JoshYuJump Right now you can't because of this line. If we change

    response = await row.save().run()
    json = dump_json(response)

    to this

    await row.save().run()
    json = dump_json(row.to_dict())

    we can get the response like this.

    {
        "id": 1,
        "name": "testing"
    }

    Another option is to not use PiccoloCRUD and write your own crud methods and use same to_dict() method.

  2. JoshYuJump commented on Sep 21, 2023

    @JoshYuJump
    ContributorAuthor

    @sinisaos
    I'm curious if you have any plans to do this in a future release.

    or it's a good practice right now?

  3. sinisaos commented on Sep 21, 2023

    @sinisaos
    Member

    @JoshYuJump I think dict is a much better response than list, since we are POST single item. I can make a PR with these changes, but I'm not a maintainer and @dantownsend has to approve changes, if he agrees with these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions