You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a library which constructs SQL filters and I want to consume it in my main project.
Example
In library:
exportconstfilter=sql`WHERE year = 2018`;
In the main project:
const{filter}=require('library');sql`SELECT * FROM books ${filterThisYear ? filter : undefined}`
Expected behavior
I expect nested sql tags to merge and append the filter.
Actual behavior
Due to the object weirdness in JavaScript, class instances are compared by their prototype chain which depends on the way the class was imported. In this case, instanceof returns false. The SqlContainer class is the same, but imported from a different place. Finally this cause sql not to detect nested tag and treats is as an object parameter instead.
I created a fork which adds a tag method to allow comparison across modules. This is not the cleanest code ever, but is successfully used in Moment.js for instance.
The text was updated successfully, but these errors were encountered:
I have a library which constructs SQL filters and I want to consume it in my main project.
Example
In
library
:In the main project:
Expected behavior
I expect nested
sql
tags to merge and append the filter.Actual behavior
Due to the object weirdness in JavaScript, class instances are compared by their prototype chain which depends on the way the class was imported. In this case, instanceof returns
false
. TheSqlContainer
class is the same, but imported from a different place. Finally this causesql
not to detect nested tag and treats is as an object parameter instead.Suggested fix
I created a fork which adds a tag method to allow comparison across modules. This is not the cleanest code ever, but is successfully used in Moment.js for instance.
The text was updated successfully, but these errors were encountered: