rockdai / sql-bricks

Transparent, Schemaless SQL Generation
http://csnw.github.io/sql-bricks
MIT License
213 stars 25 forks source link

Wrong number of params with sub query? #79

Closed barbogast closed 8 years ago

barbogast commented 8 years ago

First of all, great library, thanks a lot :)

When using sub queries and joining them to tables toParams() seems to return parameters in the sub query twice:

sql
    .select()
    .from(sql.select().from('a').where('x', 'y').as('b'))
    .join('c', {'c.id': 'b.id'})
    .toParams()

prints this:

{ 
   text: 'SELECT * FROM (SELECT * FROM a WHERE x = $1) b INNER JOIN c ON c.id = b.id',
   values: [ 'y', 'y' ] 
}

Expected:

{ 
   text: 'SELECT * FROM (SELECT * FROM a WHERE x = $1) b INNER JOIN c ON c.id = b.id',
   values: [ 'y'] 
}
prust commented 8 years ago

@Koblaid: thank you for reporting this! I fixed it in #80 (though it is possible that there may be lingering deeper issues) and published to npm as v1.2.3.

Thanks also for the detailed code and actual vs expected output, I was able to easily convert that into a failing test and add it to our test suite, which makes life easier for me & makes me happy :-)

barbogast commented 8 years ago

Wow, that was quick, thanks a lot. I also enjoyed a lot reading your answer :-)