brianc / node-sql

SQL generation for node.js
MIT License
1.05k stars 191 forks source link

Can't double alias subquery column #331

Open kevinolorenzo opened 8 years ago

kevinolorenzo commented 8 years ago

As of version 0.67.0, I was able to double alias a sub query column. For example, I would have a shared subquery function like

public getServiceTypeCategories(alias?: string) { var orderServices = this.orderServices; var os = orderServices; var osqt = orderServices.subQuery(alias || "osqt") .select(os.ServiceID, os.Description, os.Description.case([os.Description.equals("billable"), os.Description.equals("contract"), os.Description.equals("installation"), os.Description.equals("warranty")], [ServiceTypeCategory.billable, ServiceTypeCategory.contract, ServiceTypeCategory.installation, ServiceTypeCategory.warranty], ServiceTypeCategory.none).as("Category") ) .from(os); return osqt; } And then call this function when I wanted to join to it, alias the Category to a different name

var serviceTypes = this._dataContext.serviceTypes; var locations = this._dataContext.locations; var orderTypes = this._dataContext.orderTypes; var ost = serviceTypes.as("ost"); var cl = locations.as("cl"); var oot = orderTypes.as("oot"); var os = this._dataContext.getServiceTypeCategories("os"); let mquery = serviceTypes.select(cl.Id.as("branchId"), os.Category.as("categoryType"), ost.Description.as("description"), ost.Id.as("id"), ost.DefaultType.as("isDefault"), ost.Active.as("isActive"), ost.IsDeleted.as("isDeleted"), oot.Id.as("serviceOrderTypeId") ) .from(ost.join(cl).on(ost.LocationID.equals(cl.LocationID)) .join(os).on(os.ServiceID.equals(ost.ServiceID)) .leftJoin(oot).on(ost.OrderTypeID.equals(oot.OrderTypeID)) )

Since version 0.67.0, I receive a type not recongized error. I suspect it has to do with the change:

from commit eba2de6dc7a6b272ee94a7ad56eb6434a5a50305.

I was looking to see if there was different way of doing this in the test samples but they seem to only alias once for subqueries.