selda icon indicating copy to clipboard operation
selda copied to clipboard

Is it possible to nest multiple SqlRows into one?

Open Eugleo opened this issue 5 years ago • 2 comments

I don't want to put IDs into my datatypes. I'd prefer to have a WithID wrapper type similar to the following:

data WithID a = WithID RowID a

and then do something like

instance SqlRow a => SqlRow (WithID a)

which would roughly mean "expand the a into a row and prepend the RowID from WithID. However, it seems to me that a here has to be an SqlType. Is there any way to do what I want?

Context: Let's say I have a type Comment. When the user makes a new Comment, I receive a Comment from the frontend. I store this Comment in the database, and only now it is given an ID. Now, whenever the user views all of his comments, I send WithID Comment to the frontend. As I'd like to avoid having two different datatypes (CommentWithoutID for frontend->db, and CommentWithID for db->frontend), I'm trying to do it with the wrapper instead.

Eugleo avatar May 07 '20 21:05 Eugleo

This is not currently possible, but it's a good idea and we really should support it. There's no technical reason not to, as far as I can see.

valderman avatar May 13 '20 00:05 valderman

Great to hear it’s going to be included! Is it impossible to do even with some of the internal types? It’d be nice if I could use some solution before 0.5.2, even if it’s not so nice.

Eugleo avatar May 13 '20 05:05 Eugleo