I am trying do POC on using ReScript with NodeJS. So far I was able to connect to backend MySQL database and return simple “hello from database”. But code to access DB is in commonjs format.
Now I am trying ti write a module for Database connectivity, query etc. Just wanted to know if anyone done this or is this make sense.
Next you might like to try improve the types on your callbacks.
For example, for your connect() function:
type connectCallback = Js.Nullable.t<Js.Exn.t> => unit
@send external connect: (connection, connectCallback) => unit = "connect"
And your query() function:
type row
type fields
type queryCallback = (
Js.Nullable.t<Js.Exn.t>,
Js.Nullable.t<array<row>>,
Js.Nullable.t<fields>,
) => unit
@send external query: (connection, string, queryCallback) => unit = "query"
You can convert the Nullable values into option values using Js.Nullable.toOption() so you can then use switch on the result.