Alasql query is not able to filter the array of objects

44 Views Asked by At

I have an array of objects and I want to fetch something from it using alasql but my query is not working properly

I have array of objects like

const formattedObjects = [
{
    asOfDate: ISODate('Mon Jul 31 2023 05:30:00 GMT+0530 (India 
    Standard Time)'),
    CategoryId: 'Covenants',
    covenant: 'Interest Coverage Ratio',
    EntityID: 'd4a1d3b3-42d0-4d46-bca0-bf9a4286d7ae',
    EntityName: 'OMS Test Deal 2',
    Formula: null,
    id: '85af80e5-64d8-4853-98e0-e0ad34aad913',
    modifiedAt: new Date('Wed Nov 15 2023 15:57:13 GMT+0530 (India Standard Time)'),
    modifiedBy: 'mvashistha',
    period: 'Jul 2023',
    periodDisplayName: 'Jul 2023',
    periodType: 'Monthly',
    SubCategoryId: 'System_Covenants',
    type: 'Reported',
    value: 5
},
// Add more objects as needed
];

I want to fetch maximum asOfDate from this array where type is reported and value not in [NULL,""] I have written the following query for the same but it's not working

//AlaSQL query to fetch maximum asOfDate

const result = alasql('SELECT MAX(asOfDate) AS maxAsOfDate FROM ? WHERE 
type = ? AND value IS NOT NULL AND value <> ""', 
[formattedObjects,'Reported']);

console.log(result[0].maxAsOfDate); //output is undefined
0

There are 0 best solutions below