Closed
Description
Hi!
my userTable
has
userTable :: Table ( bio ∷ Maybe LongString , email ∷ ShortString , id ∷ Auto Int , image ∷ Maybe LongString , password ∷ LongString , username ∷ ShortString )
I have tried to do an update
update :: Pool -> Raw -> UserId -> Aff (Either InputError User)
update pool raw id =
withConnection pool
( \conn ->
runSelda conn do
S.update userTable
(\r -> r.id .== litPG id)
( \r ->
r
{ bio = litPG raw.bio
, email = litPG raw.email
, image = litPG raw.image
, password = litPG raw.password
, username = litPG raw.username
}
)
S.query $ selectById id
)
>>= validate
And I get
Error: (ProgrammingError { code: "428C9", column: "", constraint: "", dataType: "", detail: "Column \"id\" is an identity column defined as GENERATED ALWAYS.", file: "rewriteHandler.c", hint: "", internalPosition: "", internalQuery: "", line: "827", message: "column \"id\" can only be updated to DEFAULT", position: "", routine: "rewriteTargetListIU", schema: "", severity: "ERROR", table: "", where_: "" })
logUpdate
shows:
UPDATE "user" SET username = $2, password = $3, image = $4, id = id, email = $5, bio = $6 WHERE (id = $1)
[3,"jim","$2a$06$cfxV0SUgZU60hPdu9sSptOHDkG7VT2VjCxSKnhM0ivRb6abHepnDe",null,"jim@jjim.jim","I work at statefarm"]
logUpdate ∷
forall t s r m.
TableToColsWithoutAlias s t r =>
GetCols r =>
MonadEffect m =>
Table t → ({ | r } → Col s Boolean) → ({ | r } → { | r }) → m Unit
logUpdate table pred up = do
let
{ strQuery, params } = showPG $ showUpdate table pred up
log strQuery
log $ unsafeStringify params
log ""
I don't know the full functionality. Please correct me if I am doing things awfully complicated. It would be nice to have:
- Easier generic logging of the update, insert ..., not me replicating every param for every command.
- Update returning like insert returning.
Thanks.