lookup-user.ts 831 B

1234567891011121314151617181920212223242526
  1. import { Database, eq } from "../src/drizzle/index.js"
  2. import { AuthTable } from "../src/schema/auth.sql"
  3. // get input from command line
  4. const email = process.argv[2]
  5. if (!email) {
  6. console.error("Usage: bun lookup-user.ts <email>")
  7. process.exit(1)
  8. }
  9. const authData = await printTable("Auth", (tx) => tx.select().from(AuthTable).where(eq(AuthTable.subject, email)))
  10. if (authData.length === 0) {
  11. console.error("User not found")
  12. process.exit(1)
  13. }
  14. await printTable("Auth", (tx) => tx.select().from(AuthTable).where(eq(AuthTable.accountID, authData[0].accountID)))
  15. function printTable(title: string, callback: (tx: Database.TxOrDb) => Promise<any[]>): Promise<any[]> {
  16. return Database.use(async (tx) => {
  17. const data = await callback(tx)
  18. console.log(`== ${title} ==`)
  19. console.table(data)
  20. return data
  21. })
  22. }