sqlquerybuilder
Advanced tools
Comparing version 0.0.55 to 0.0.56
@@ -56,31 +56,37 @@ var _ = require('lodash'); | ||
var alias; | ||
if (element.indexOf('.') !== -1 && element.indexOf('(') !== 0) { | ||
var parts = element.split('.'); | ||
var table = parts[0]; | ||
if (self._options.enumerationSuffixes.indexOf(parts[1]) !== -1) { | ||
element = parts[0] + parts[1]; | ||
} else { | ||
if (self._options.entityToTableMap[table]) { | ||
element = self._options.entityToTableMap[table] + '.' + parts[1]; | ||
if (element[0] != '(') { | ||
var alias; | ||
if (element.indexOf('.') !== -1) { | ||
var parts = element.split('.'); | ||
var table = parts[0]; | ||
if (self._options.enumerationSuffixes.indexOf(parts[1]) !== -1) { | ||
element = parts[0] + parts[1]; | ||
} else { | ||
alias = _.find(self._selectAliases, function (alias) { | ||
return alias.alias == element; | ||
}); | ||
if (self._options.entityToTableMap[table]) { | ||
element = self._options.entityToTableMap[table] + '.' + parts[1]; | ||
} else { | ||
alias = _.find(self._selectAliases, function (alias) { | ||
return alias.alias == element; | ||
}); | ||
if (alias) | ||
element = alias.selectProp; | ||
else | ||
element = self._checkTableName(table) + '.' + parts[1]; | ||
if (alias) | ||
element = alias.selectProp; | ||
else | ||
element = self._checkTableName(table) + '.' + parts[1]; | ||
} | ||
} | ||
} else if (!skipAlias) { | ||
alias = _.find(self._selectAliases, function (alias) { | ||
return alias.alias == element; | ||
}); | ||
if (alias) | ||
element = alias.selectProp; | ||
else | ||
element = self._sqlObject.fromAlias + "." + element; | ||
} | ||
} else if (!skipAlias && element.indexOf('(') !== 0) { | ||
alias = _.find(self._selectAliases, function (alias) { | ||
return alias.alias == element; | ||
}); | ||
if (alias) | ||
element = alias.selectProp; | ||
else | ||
element = self._sqlObject.fromAlias + "." + element; | ||
if (self._isDateTimeField(element) && element.indexOf('CONVERT(DATETIMEOFFSET') == -1) { | ||
element = "CONVERT(DATETIMEOFFSET," + element + ")"; | ||
} | ||
} | ||
@@ -87,0 +93,0 @@ |
{ | ||
"name": "sqlquerybuilder", | ||
"version": "0.0.55", | ||
"version": "0.0.56", | ||
"description": "Highly opinionated Sql Server Query Writer, mostly for internal use.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index", |
@@ -556,3 +556,3 @@ var sqlQueryBuilder = require('../../../lib/index'), | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT f.Id, AssetNumber, ShortDescription, glc.Name AS 'GLCategory.Name', ac.Number AS 'AccountCode', oc.Name AS 'OperationalCategory.Name', f.InitialCost, SUBSTRING(f.AcquiredDate,6,2) + '/' + SUBSTRING(f.AcquiredDate,9,2) + '/' + SUBSTRING(f.AcquiredDate,1,4) + SUBSTRING(f.AcquiredDate,11,LEN(f.AcquiredDate)-10) AcquiredDate, y.Name AS 'Yard.Name', dep.Name AS 'Department.Name', f.FixedAssetTypeDisplayName AS 'FixedAssetType.DisplayName', f.VIN, po.Number AS 'PONumber', ROW_NUMBER() OVER (ORDER BY f.AcquiredDate DESC) AS Position FROM FixedAssets f JOIN AccountingProcessTypes glc ON glc.Id = f.GLCategory_id JOIN AccountCodes ac ON ac.Id = glc.AccountCode_id JOIN EquipmentTypes oc ON oc.Id = f.OperationalCategory_id JOIN Yards y ON f.Yard_id = y.Id JOIN Departments dep ON f.Department_id = dep.Id LEFT JOIN Receivers r ON f.Receiver_id = r.Id LEFT JOIN PurchaseOrders po ON po.Id = r.PurchaseOrder_id WHERE y.Name LIKE '%Okla%' AND f.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
.equal("WITH SelectedItems AS (SELECT f.Id, AssetNumber, ShortDescription, glc.Name AS 'GLCategory.Name', ac.Number AS 'AccountCode', oc.Name AS 'OperationalCategory.Name', f.InitialCost, SUBSTRING(f.AcquiredDate,6,2) + '/' + SUBSTRING(f.AcquiredDate,9,2) + '/' + SUBSTRING(f.AcquiredDate,1,4) + SUBSTRING(f.AcquiredDate,11,LEN(f.AcquiredDate)-10) AcquiredDate, y.Name AS 'Yard.Name', dep.Name AS 'Department.Name', f.FixedAssetTypeDisplayName AS 'FixedAssetType.DisplayName', f.VIN, po.Number AS 'PONumber', ROW_NUMBER() OVER (ORDER BY CONVERT(DATETIMEOFFSET,f.AcquiredDate) DESC) AS Position FROM FixedAssets f JOIN AccountingProcessTypes glc ON glc.Id = f.GLCategory_id JOIN AccountCodes ac ON ac.Id = glc.AccountCode_id JOIN EquipmentTypes oc ON oc.Id = f.OperationalCategory_id JOIN Yards y ON f.Yard_id = y.Id JOIN Departments dep ON f.Department_id = dep.Id LEFT JOIN Receivers r ON f.Receiver_id = r.Id LEFT JOIN PurchaseOrders po ON po.Id = r.PurchaseOrder_id WHERE y.Name LIKE '%Okla%' AND f.IsActive = 1) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
@@ -681,3 +681,3 @@ | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', SUBSTRING(Created,6,2) + '/' + SUBSTRING(Created,9,2) + '/' + SUBSTRING(Created,1,4) + SUBSTRING(Created,11,LEN(Created)-10) AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY Created ASC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId IS null)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
.equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', SUBSTRING(Created,6,2) + '/' + SUBSTRING(Created,9,2) + '/' + SUBSTRING(Created,1,4) + SUBSTRING(Created,11,LEN(Created)-10) AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY CONVERT(DATETIMEOFFSET,Created) ASC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId IS null)) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
@@ -722,3 +722,3 @@ | ||
query.should | ||
.equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', SUBSTRING(Created,6,2) + '/' + SUBSTRING(Created,9,2) + '/' + SUBSTRING(Created,1,4) + SUBSTRING(Created,11,LEN(Created)-10) AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY Created DESC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId = 'A1139D28-CE9E-4EF9-A595-A31401026A65')) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
.equal("WITH SelectedItems AS (SELECT Status, Description AS 'Description', CreatorFirstName AS 'CreatorFirstName', TerritoryId AS 'TerritoryId', ServiceTicketId AS 'ServiceTicketId', ServiceTicketNumber AS 'ServiceTicketNumber', YardId AS 'YardId', Yard AS 'Yard', Equipment AS 'Equipment', JobInstructions AS 'JobInstructions', Categories AS 'Categories', SUBSTRING(Created,6,2) + '/' + SUBSTRING(Created,9,2) + '/' + SUBSTRING(Created,1,4) + SUBSTRING(Created,11,LEN(Created)-10) AS 'Created', Id AS 'Id', (CreatorFirstName + ' ' + CreatorLastName) AS 'CreatorName', (CASE WHEN Status = 'Rejected' Then 1 else 1 END) AS 'IsRejected', ROW_NUMBER() OVER (ORDER BY CONVERT(DATETIMEOFFSET,Created) DESC) AS Position FROM MaintenanceAssignmentView WHERE MaintenanceAssignmentView.Status = 'Complete' AND MaintenanceAssignmentView.IsActive = 1 AND (TerritoryId = 'A1139D28-CE9E-4EF9-A595-A31401026A65')) SELECT *, (Select MAX(Position) From SelectedItems) as 'TotalRows' FROM SelectedItems WHERE Position > 0 AND Position <= 100 ") | ||
@@ -725,0 +725,0 @@ |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
236458
4756