opencode/packages/console/core/script/lookup-user.ts

27 lines
831 B
TypeScript
Raw Normal View History

2025-10-31 02:12:49 +08:00
import { Database, eq } from "../src/drizzle/index.js"
import { AuthTable } from "../src/schema/auth.sql"
// get input from command line
const email = process.argv[2]
if (!email) {
console.error("Usage: bun lookup-user.ts <email>")
process.exit(1)
}
2025-11-08 09:59:02 +08:00
const authData = await printTable("Auth", (tx) => tx.select().from(AuthTable).where(eq(AuthTable.subject, email)))
2025-10-31 02:12:49 +08:00
if (authData.length === 0) {
console.error("User not found")
process.exit(1)
}
2025-11-08 09:59:02 +08:00
await printTable("Auth", (tx) => tx.select().from(AuthTable).where(eq(AuthTable.accountID, authData[0].accountID)))
2025-10-31 02:12:49 +08:00
2025-11-08 09:59:02 +08:00
function printTable(title: string, callback: (tx: Database.TxOrDb) => Promise<any[]>): Promise<any[]> {
2025-10-31 02:12:49 +08:00
return Database.use(async (tx) => {
const data = await callback(tx)
console.log(`== ${title} ==`)
console.table(data)
return data
})
}