Skip to content

Commit 8ce752b

Browse files
committed
creates a binding dictionary explicitly on JS, zipping the arguments with their index and binding str(idx+1) to the argument
1 parent 44337cd commit 8ce752b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

core/js/src/main/scala/porcupine/dbplatform.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ private abstract class DatabasePlatform:
5252
def cursor(args: A): Resource[F, Cursor[F, B]] = mutex.lock *>
5353
Resource
5454
.eval {
55-
F.delay(statement.iterate(bind(args)*)).map { iterator =>
55+
val argsList = bind(args)
56+
val argsDict: js.Dictionary[Any] =
57+
js.Dictionary(argsList.zipWithIndex.map { case (v, idx) =>
58+
(s"${idx + 1}", v)
59+
}*)
60+
F.delay(statement.iterate(argsDict)).map { iterator =>
5661
new:
5762
def fetch(maxRows: Int): F[(List[B], Boolean)] =
5863
F.delay {
@@ -90,7 +95,12 @@ private abstract class DatabasePlatform:
9095
new AbstractStatement[F, A, B]:
9196
def cursor(args: A): Resource[F, Cursor[F, B]] =
9297
mutex.lock *> Resource.eval {
93-
F.delay(statement.run(bind(args)*)).as(_ => F.pure(Nil, false))
98+
val argsList = bind(args)
99+
val argsDict: js.Dictionary[Any] =
100+
js.Dictionary(argsList.zipWithIndex.map { case (v, idx) =>
101+
(s"${idx + 1}", v)
102+
}*)
103+
F.delay(statement.run(argsDict)).as(_ => F.pure(Nil, false))
94104
}
95105

96106
}

core/js/src/main/scala/porcupine/facade.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private[porcupine] trait Statement extends js.Object:
3737

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

40-
def iterate(bindParameters: Any*): js.Iterator[js.UndefOr[js.Array[Any]]] = js.native
40+
def iterate(bindParameters: js.Dictionary[Any]): js.Iterator[js.UndefOr[js.Array[Any]]] =
41+
js.native
4142

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

0 commit comments

Comments
 (0)