Generic `select`
trying to make generic selects. How can I do this? My attempt right now
However the type I am getting is
(return type should not be
// 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))
});
}
function fetchActiveQuests<TSelection extends SelectedFields>(fields: TSelection): Promise<any[]>
function fetchActiveQuests<TSelection extends SelectedFields>(fields: TSelection): Promise<any[]>
any[]
ideally!
2 Replies