`.orderBy` influence `sql` output
With the following code:
I get the following output:
Why would the
const exchanges = await db
.select({
...getTableColumns(stockExchanges),
isUsed:
sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`.mapWith(
(value) => value === "1",
),
})
.from(stockExchanges)
.leftJoin(usedExchanges, eq(usedExchanges.data, stockExchanges.code));
console.log(exchanges.find((exch) => exch.code === "BR"));
const orderedExchanges = await db
.select({
...getTableColumns(stockExchanges),
isUsed:
sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`.mapWith(
(value) => value === "1",
),
})
.from(stockExchanges)
.leftJoin(usedExchanges, eq(usedExchanges.data, stockExchanges.code))
.orderBy(asc(stockExchanges.name));
console.log(orderedExchanges.find((exch) => exch.code === "BR")); const exchanges = await db
.select({
...getTableColumns(stockExchanges),
isUsed:
sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`.mapWith(
(value) => value === "1",
),
})
.from(stockExchanges)
.leftJoin(usedExchanges, eq(usedExchanges.data, stockExchanges.code));
console.log(exchanges.find((exch) => exch.code === "BR"));
const orderedExchanges = await db
.select({
...getTableColumns(stockExchanges),
isUsed:
sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`.mapWith(
(value) => value === "1",
),
})
.from(stockExchanges)
.leftJoin(usedExchanges, eq(usedExchanges.data, stockExchanges.code))
.orderBy(asc(stockExchanges.name));
console.log(orderedExchanges.find((exch) => exch.code === "BR"));I get the following output:
{
name: 'Euronext Brussels',
code: 'BR',
operatingMIC: 'XBRU',
country: 'Belgium',
currency: 'EUR',
countryISO2: 'BE',
countryISO3: 'BEL',
isUsed: true
}
{
name: 'Euronext Brussels',
code: 'BR',
operatingMIC: 'XBRU',
country: 'Belgium',
currency: 'EUR',
countryISO2: 'BE',
countryISO3: 'BEL',
isUsed: false
}{
name: 'Euronext Brussels',
code: 'BR',
operatingMIC: 'XBRU',
country: 'Belgium',
currency: 'EUR',
countryISO2: 'BE',
countryISO3: 'BEL',
isUsed: true
}
{
name: 'Euronext Brussels',
code: 'BR',
operatingMIC: 'XBRU',
country: 'Belgium',
currency: 'EUR',
countryISO2: 'BE',
countryISO3: 'BEL',
isUsed: false
}Why would the
orderByorderBy influence the computed column isUsedisUsed (the expected result is truetrue)?