-
-
Notifications
You must be signed in to change notification settings - Fork 6
Implement SQLite functions and aggregates, update SQLite encoder and decoder APIs #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robinheghan
merged 12 commits into
gren-lang:main
from
joeybright:implement-sqlite-functions
Sep 10, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bf0eaef
Initial, experimental, implementation of SQLite functions
joeybright b025e2f
Implement new SQLite decoder and encoder APIs
joeybright ff7dcee
New SQLite function implementation
joeybright 0109bf1
Merge branch 'main' into implement-sqlite-functions
joeybright 20420d2
Separate row encoders and decoders into their own modules
joeybright 18bf7c3
Initial aggregate function implementation
joeybright e9cbfb1
`succeed` -> `return` for SQLite functions
joeybright 9239a12
Construct proper error in kernel when encountering one in SQLite func…
joeybright 72b763b
Formatting updates, remove `String` error (given it doesn't matter gi…
joeybright 6e1384c
Comment guide for why `.a.a.a` is a selector for a returned function …
joeybright e264dcc
More tests for custom SQLite functions and aggregate functions
joeybright 51c9c99
Prettier formatting
joeybright File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| module Sqlite.Aggregate exposing ( .. ) | ||
|
|
||
| {-|-} | ||
|
|
||
| import Sqlite | ||
| import Sqlite.Decode as Decode | ||
| import Sqlite.Encode as Encode | ||
| import Json.Encode | ||
| import Json.Decode | ||
| import Task exposing ( Task ) | ||
|
|
||
|
|
||
| type Function state = | ||
| Function (Direction -> state -> Array Json.Encode.Value -> Result String state) | ||
|
|
||
|
|
||
| {-|-} | ||
| type Direction | ||
| = Entering | ||
| | Exiting | ||
|
|
||
|
|
||
| {-|-} | ||
| type Aggregate state | ||
| = Aggregate | ||
| { init : state | ||
| , function : Function state | ||
| , result : state -> Encode.Value | ||
| } | ||
|
|
||
|
|
||
| aggregate : { init : state, function: Function state, result : state -> Encode.Value } -> Aggregate state | ||
| aggregate { init, function, result } = | ||
| Aggregate | ||
| { init = init | ||
| , function = function | ||
| , result = result | ||
| } | ||
|
|
||
|
|
||
| {-|-} | ||
| start : (state -> Function state) -> Function state | ||
| start func = | ||
| Function <| \direction state args -> | ||
| when func state is | ||
| Function innerFunc -> | ||
| innerFunc direction state args | ||
|
|
||
|
|
||
| {-|-} | ||
| arg : Decode.Decoder a -> (a -> Function state) -> Function state | ||
| arg decoder func = | ||
| Function <| \direction state args -> | ||
| when Array.popFirst args is | ||
| Just { first = first, rest = rest } -> | ||
| when Json.Decode.decodeValue (Decode.unwrap decoder) first is | ||
| Ok val -> | ||
| when func val is | ||
| Function innerFunc -> | ||
| innerFunc direction state rest | ||
|
|
||
| Err _err -> | ||
| Err "decoding error" | ||
|
|
||
| Nothing -> | ||
| Err "not enough arguments passed" | ||
|
|
||
|
|
||
| {-|-} | ||
| return : (Direction -> state) -> Function state | ||
| return func = | ||
| Function <| \direction _state args -> | ||
| when args is | ||
| [] -> | ||
| Ok (func direction) | ||
|
|
||
| many -> | ||
| Err "too many arguments passed" | ||
|
|
||
|
|
||
| {-|-} | ||
| register : String -> Sqlite.Database -> Aggregate state -> Task x {} | ||
| register name db (Aggregate { init, function, result }) = | ||
| let | ||
| (Function unwrappedFunc) = | ||
| function | ||
| in | ||
| Gren.Kernel.Sqlite.aggregate name init unwrappedFunc result db |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to throw an exception here in order to return a detailed
Error? Would be helpful, I think, to see whyfunc(jsonArgs) !== OkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I was surprised to see any type of failure resulting in a
NoResultserror.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for when the encoding/decoding fails on the Gren side.