Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Type annotation of a variadic function

$
0
0

Will this work?

module SQLQuery = {
  type t<'a> = promise<'a>
}

@unboxed
type rec param = Boolean(bool)

type t
type t_query = (array<string>, array<param>) => SQLQuery.t<param>

@module("bun") @new
external make: string => t = "SQL"
external toQuery: t => t_query = "%identity"

@send
external begin: (t, t_query => 'a) => 'a = "begin"

let run = async () => {
  let sqlite = make("sqlite://myapp.db")

  let query_sqlite = toQuery(sqlite)
  let sqliteResults =
    await query_sqlite`
  SELECT * FROM users 
  WHERE active = ${Boolean(true)}
`

  let begin_results = begin(sqlite, async tx =>
    await tx`
  SELECT * FROM users 
  WHERE active = ${Boolean(true)}
`
  )

  Js.log((sqliteResults, begin_results))
}

Playground link


Viewing all articles
Browse latest Browse all 2592

Trending Articles