nomicflux / servant-opaleye-blog

Tutorial on setting up a blog backend with Servant and Opaleye
Other
16 stars 2 forks source link

Bug? Not returning 'id' of newly created row #4

Closed saurabhnanda closed 8 years ago

saurabhnanda commented 8 years ago

What does this piece of code really return? Isn't it supposed to return the ID of the newly created blog post?

https://github.com/nomicflux/servant-opaleye-blog/blob/e4c1c6952cb3def9c5f573ad3321e4cce45148e8/src/Api/BlogPost.hs#L40-L41

tomjaguarpaw commented 8 years ago

I don't know what it's supposed to return, but it returns the number of rows inserted, presumably 1. If you want to return the ID of the newly created post you need to use runInsertManyReturning.

nomicflux commented 8 years ago

Right, it returns the number of rows inserted. I'll probably shovel in a new Lesson 2b in between the current Lessons 2 & 3 - I wanted Lesson 2 to just be about how to set up Opaleye, in the simplest way I could find, but there are a lot of features which a real system would want which aren't included.

nomicflux commented 8 years ago

I lied; it's implemented in Lesson 2 now. I had to update runInsert to runInsertMany anyhow, since runInsert is deprecated, so I just switched to returning keys.