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

How to use @taggedTemplate generate js with tagged template literals

$
0
0

@tsnobip Thank for you reply, I’m trying to solve this problem with other way these days, but it doesn’t work well

First I patch the code (compile to PostgresqlPatch.js)

%%raw(`
import Postgres from "postgres"

export default myPostgres;

function myPostgres(a, b) {

    var sql = Postgres(a, b);
    Object.assign(sql, {safeSql: sql})
    return sql;
}

`)

Then bind the path code use the object function

type t
@module("./PostgresqlPatch.js") external make: (~url: string, ~config: config=?) => t = "default"

@taggedTemplate @send
external safeSql: (t, array<string>, array<'sqlParam>) => promise<result<'data>> = "safeSql"

Then call object function:

let abc = "name"
    let result: Postgresql.result<userInfo> = await sql->Postgresql.safeSql`select name, sigup_date from user_tbl where name=${ abc }`

output:

var result = await sql.safeSql([
              "select name, sigup_date from user_tbl where name=",
              ""
            ], "name");

Is it possible to consider ways to support object functions in the future?
Thanks.


Viewing all articles
Browse latest Browse all 2592

Trending Articles