Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
JoshYuJump opened this issue Sep 20, 2023 · 3 comments
Open

Comments

@JoshYuJump
Copy link
Contributor

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"
}
@sinisaos
Copy link
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.

@JoshYuJump
Copy link
Contributor Author

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

or it's a good practice right now?

@sinisaos
Copy link
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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants