Allow to set custom attribute on query object
It could be great to allow user to add custom attribute to the returned query.
My use-case is the usage of a custom Postgres client which enables some debuging utilities :
client.query({
text: `SELECT * FROM table WHERE column = $1`,
values: [value],
explain: true
}
In this example, my client will also log the query plan of the request.
Today, I have to write it like this using your module, and it's not very handy:
const query = SQL`SELECT * FROM table WHERE column = ${value}`;
query.explain = true;
client.query(query);
I have tried with some destructuring but it doesn't play nicely with classes...
client.query({
...SQL`SELECT * FROM table WHERE column = ${value}`, // This doesn't work since the prototype is lost
explain: true
});
My proposition is to allow the addition of custom attributes in the same way we add a name:
client.query(
SQL`SELECT * FROM table WHERE column = ${value}`.set("explain", true)
);
This way it is really simple for me to add/remove my little debugging trick !
What do you think about this ?
Any reason this wouldn't work?
client.query(Object.assign(sql`select ...`, { explain: true }));
Yes it probably works but it's really difficult to read for me.
@felixfbecker Hey ! Do you thing this can have some interest or you want to close it ?