I am using Alasql to merge json objects.
I have this alasql query:
SELECT Employment.*,
EmploymentCore.CompanyCode AS EmploymentCore_CompanyCode,
Accumulator_DaysInAdvance.VacationYearValue AS Accumulator_DaysInAdvance_Value,
Accumulator_AgreementYearlyDays.VacationYearValue AS Accumulator_AgreementYearlyDays_Value,
Person.UserId AS Person_UserId,
FROM ? AS EmploymentCore
RIGHT JOIN ? AS Employment
ON Employment.Id = EmploymentCore.Id
LEFT JOIN ? AS Accumulator_DaysInAdvance
ON Accumulator_DaysInAdvance.WorkNumber = Employment.WorkNumber
AND Accumulator_DaysInAdvance.AccumulatorId = 'b82'
AND Accumulator_DaysInAdvance.AccumulatorType = 'd'
LEFT JOIN ? AS Accumulator_AgreementYearlyDays
ON Accumulator_AgreementYearlyDays.WorkNumber = Employment.WorkNumber
AND Accumulator_AgreementYearlyDays.AccumulatorId = 'b59'
AND Accumulator_AgreementYearlyDays.AccumulatorType = 'n'
JOIN ? AS Person
ON Person.Id = EmploymentCore.PersonId
And I have these objects:
- EmploymentCore
- Employment
- Accumulator
- Person
The Accumulator is redundant in the query though. So instead of passing the Accumulator object twice, Is there a way to use numbers instead?
Like:
SELECT Employment.*,
EmploymentCore.CompanyCode AS EmploymentCore_CompanyCode,
Accumulator_DaysInAdvance.VacationYearValue AS Accumulator_DaysInAdvance_Value,
Accumulator_AgreementYearlyDays.VacationYearValue AS Accumulator_AgreementYearlyDays_Value,
Person.UserId AS Person_UserId,
FROM $1 AS EmploymentCore
RIGHT JOIN $2 AS Employment
ON Employment.Id = EmploymentCore.Id
LEFT JOIN $3 AS Accumulator_DaysInAdvance
ON Accumulator_DaysInAdvance.WorkNumber = Employment.WorkNumber
AND Accumulator_DaysInAdvance.AccumulatorId = 'b82'
AND Accumulator_DaysInAdvance.AccumulatorType = 'd'
LEFT JOIN $3 AS Accumulator_AgreementYearlyDays
ON Accumulator_AgreementYearlyDays.WorkNumber = Employment.WorkNumber
AND Accumulator_AgreementYearlyDays.AccumulatorId = 'b59'
AND Accumulator_AgreementYearlyDays.AccumulatorType = 'n'
JOIN $4 AS Person
ON Person.Id = EmploymentCore.PersonId