Migrate to current Roc syntax#13
Merged
Merged
Conversation
- No backpassing
- New record builders
- PNC
- snake_case
The API changes from:
```roc
|> Pg.Cmd.expectN (
Pg.Result.succeed {
name: <- Pg.Result.str "name" |> Pg.Result.apply,
price: <- Pg.Result.dec "price" |> Pg.Result.apply
}
)
```
To:
```roc
|> Pg.Cmd.expect_n(
{ Pg.Result.record_builder <-
name: Pg.Result.str("name"),
price: Pg.Result.dec("price"),
},
)
```
Note `Pg.Result.record_builder` above. `Pg.Cmd.succeed` can still be
used to return non-records like so:
```roc
|> Pg.Cmd.expect_n(
Pg.Result.succeed(
|name|
|age|
age_str = Num.to_str(age)
"${name}: ${age_str}",
)
|> Pg.Result.with(Pg.Result.str("name"))
|> Pg.Result.with(Pg.Result.u8("age")),
)
```
It's unclear to me whether this is desirable. However, given that the
name `Pg.Result.succeed` is taken, I opted for
`Pg.Result.record_builder` for the records to make it discoverable and
understandable.
This is a partial migration as I ran out of steam part-way through
`sql-cli` and `examples/store`.
niclas-ahden
added a commit
to growthagent/roc-pg
that referenced
this pull request
Apr 19, 2025
Owner
|
@niclas-ahden Thank you so much for all the effort you put into this. I'm going to clean up a few other things and make a release! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The API changes from:
To:
Note
Pg.Result.record_builderabove.Pg.Cmd.succeedcan still be used to return non-records like so:It's unclear to me whether this is desirable. However, given that the name
Pg.Result.succeedis taken, I opted forPg.Result.record_builderfor the records to make it discoverable and understandable.This PR also includes the changes from #10 and #11.
This is a partial migration as I ran out of steam part-way through
sql-cliandexamples/store. I stopped when faced with the query builder and its use of the old record builders. There were no brain cells left over to start pondering that design. Hopefully this offering can still be helpful as a stepping stone toward current Roc!