Skip to content

Allow Codec#product to behave correctly with parameter count - #94

Open
s5bug wants to merge 5 commits into
armanbilge:mainfrom
s5bug:indexed-parameters
Open

s5bug wants to merge 5 commits into
armanbilge:mainfrom
s5bug:indexed-parameters

Conversation

@s5bug

@s5bug s5bug commented Feb 21, 2024 •

Copy link
Copy Markdown

The way this is implemented is via a parameters: Int on Encoder.

Notes:

  • The State[Int, String] solution from Skunk was attempted, but there was no way to prevent the bad behavior of (someNonUnit, Codec.unit).tupled from generating (?, ?, ?,) rather than (?, ?, ?). A possible solution to this issue is State[Int, List[Either[String, Int]]], where the transitions Left→Left, Left→Right, Right→Left are directly concatenated, but transitions Right→Right are joined with , .
  • For some reason the string interpolator doesn't like ${ a *: b *: nil }, and I don't know why.
  • It's not exactly clear how to handle Encoder#either in this case.
  • I refactored the base types into a common superclass so I wouldn't have to write def parameters = 1 6 times.

@s5bug

s5bug commented Feb 21, 2024

Copy link
Copy Markdown
Author

The latest commit addresses point 1, with the Fragment.Part ADT.

@armanbilge armanbilge closed this Feb 21, 2024
@armanbilge armanbilge reopened this Feb 21, 2024
@s5bug

s5bug commented Feb 21, 2024

Copy link
Copy Markdown
Author

JS support blocked by WiseLibs/better-sqlite3#1032

creates a binding dictionary explicitly on JS, zipping the arguments with their index and binding str(idx+1) to the argument
Comment on lines +55 to +60
val argsList = bind(args)
val argsDict: js.Dictionary[Any] =
js.Dictionary(argsList.zipWithIndex.map { case (v, idx) =>
(s"${idx + 1}", v)
}*)
F.delay(statement.iterate(argsDict)).map { iterator =>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this all in the delay block, and I think we can build the JS object more efficiently without all the intermediate datastructures form zipWithIndex and map. Instead, we can just create a new js.Object and set its keys with js.Dynamic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants