File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,14 @@ var unaryMethod = function(name, operator) {
3434 }
3535}
3636
37+ var contextify = function ( base ) {
38+ var context = Object . create ( Column . prototype ) ;
39+ Object . keys ( base ) . forEach ( function ( key ) {
40+ context [ key ] = base [ key ] ;
41+ } )
42+ return context ;
43+ }
44+
3745Column . prototype . value = function ( value ) {
3846 this . _value = value ;
3947 return this ;
@@ -45,12 +53,13 @@ Column.prototype.getValue = function() {
4553
4654Column . prototype . toNode = function ( ) {
4755 //creates a query node from this column
48- return new ColumnNode ( this ) ;
56+ return new ColumnNode ( contextify ( this ) ) ;
4957}
5058
5159Column . prototype . as = function ( alias ) {
52- this . alias = alias ;
53- return new ColumnNode ( this ) ;
60+ var context = contextify ( this ) ;
61+ context . alias = alias ;
62+ return new ColumnNode ( context ) ;
5463}
5564
5665binaryMethod ( 'equals' , '=' ) ;
Original file line number Diff line number Diff line change @@ -102,6 +102,12 @@ test({
102102 pg : 'SELECT "user"."name" as "user name" FROM "user" WHERE ("user"."name" = $1)'
103103} ) ;
104104
105+ //Fix #10: prevent column state mutation
106+ test ( {
107+ query : user . select ( user . name ) . from ( user ) . where ( user . name . equals ( 'brian' ) ) ,
108+ pg : 'SELECT "user"."name" FROM "user" WHERE ("user"."name" = $1)'
109+ } ) ;
110+
105111var u = user . as ( 'u' ) ;
106112test ( {
107113 query : u . select ( u . name ) . from ( u ) ,
You can’t perform that action at this time.
0 commit comments