brianc/node-sql

Calling `.cast()` on a column defined with `property` yields invalid SQL

Closed this issue · 0 comments

If we define a table using property:

var myTable = sql.define({
    name: 'my_table',
    columns: [
        { name: 'some_column_name', property: 'someColumnName' }
    ]
});

and then cast that column to a data type in a query:

var q = myTable.select(myTable.someColumnName.cast('text'))
.from(myTable)
.toQuery();

we get invalid SQL back; console.log(q.text) prints:

SELECT CAST("my_table"."some_column_name" AS "someColumnName" AS text) FROM "my_table"

Depending on whether or not we want the property attribute to affect the column name resulting from the CAST() call, we'd either expect to get:

SELECT CAST("my_table"."some_column_name" AS text) AS "someColumnName" FROM "my_table"

or:

SELECT CAST("my_table"."some_column_name" AS text) FROM "my_table"