Generic `select`

trying to make generic selects. How can I do this? My attempt right now
// Fetch active quests from the database
export async function fetchActiveQuests<TSelection extends SelectedFields>(fields: TSelection) {
return Sentry.startSpan({ name: 'loadQuests' }, async () => {
// Get active escrow accounts from HoldCo
const activeEscrows = await holdco().accounts.getActiveEscrows();

// Get all quests that have holdcoIds matching the active escrows
if (!activeEscrows.accounts || activeEscrows.accounts.length === 0) {
return [];
}

// Extract the holdcoIds from the active escrows
const activeEscrowIds = activeEscrows.accounts.map((account) =>
account.main_account.id.toString()
);

// Query the database for quests with matching holdcoIds
return db
.select(fields)
.from(quest)
.where(eq(quest.isActive, true) && inArray(quest.holdcoId, activeEscrowIds))
});
}
// Fetch active quests from the database
export async function fetchActiveQuests<TSelection extends SelectedFields>(fields: TSelection) {
return Sentry.startSpan({ name: 'loadQuests' }, async () => {
// Get active escrow accounts from HoldCo
const activeEscrows = await holdco().accounts.getActiveEscrows();

// Get all quests that have holdcoIds matching the active escrows
if (!activeEscrows.accounts || activeEscrows.accounts.length === 0) {
return [];
}

// Extract the holdcoIds from the active escrows
const activeEscrowIds = activeEscrows.accounts.map((account) =>
account.main_account.id.toString()
);

// Query the database for quests with matching holdcoIds
return db
.select(fields)
.from(quest)
.where(eq(quest.isActive, true) && inArray(quest.holdcoId, activeEscrowIds))
});
}
However the type I am getting is
function fetchActiveQuests<TSelection extends SelectedFields>(fields: TSelection): Promise<any[]>
function fetchActiveQuests<TSelection extends SelectedFields>(fields: TSelection): Promise<any[]>
(return type should not be any[] ideally!
No description
2 Replies
andrew
andrewOP3w ago
ah it is there where statement which makes it any ah it changes types
andrew
andrewOP3w ago
there we go
No description

Did you find this page helpful?