Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
creates a binding dictionary explicitly on JS, zipping the arguments with their index and binding str(idx+1) to the argument
  • Loading branch information
s5bug committed Mar 23, 2024
1 parent 44337cd commit 8ce752b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 12 additions & 2 deletions core/js/src/main/scala/porcupine/dbplatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ private abstract class DatabasePlatform:
def cursor(args: A): Resource[F, Cursor[F, B]] = mutex.lock *>
Resource
.eval {
F.delay(statement.iterate(bind(args)*)).map { iterator =>
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 =>
new:
def fetch(maxRows: Int): F[(List[B], Boolean)] =
F.delay {
Expand Down Expand Up @@ -90,7 +95,12 @@ private abstract class DatabasePlatform:
new AbstractStatement[F, A, B]:
def cursor(args: A): Resource[F, Cursor[F, B]] =
mutex.lock *> Resource.eval {
F.delay(statement.run(bind(args)*)).as(_ => F.pure(Nil, false))
val argsList = bind(args)
val argsDict: js.Dictionary[Any] =
js.Dictionary(argsList.zipWithIndex.map { case (v, idx) =>
(s"${idx + 1}", v)
}*)
F.delay(statement.run(argsDict)).as(_ => F.pure(Nil, false))
}

}
Expand Down
5 changes: 3 additions & 2 deletions core/js/src/main/scala/porcupine/facade.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private[porcupine] trait Statement extends js.Object:

def raw(toggleState: Boolean): Statement = js.native

def iterate(bindParameters: Any*): js.Iterator[js.UndefOr[js.Array[Any]]] = js.native
def iterate(bindParameters: js.Dictionary[Any]): js.Iterator[js.UndefOr[js.Array[Any]]] =
js.native

def run(bindParameters: Any*): js.Object = js.native
def run(bindParameters: js.Dictionary[Any]): js.Object = js.native

0 comments on commit 8ce752b

Please sign in to comment.