sql-invite.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const pgp = require('pg-promise')();
  2. // 连接到数据库
  3. const db = pgp({
  4. user: 'web3',
  5. password: '666',
  6. host: 'web2023.fmode.cn',
  7. port: 25432,
  8. database: 'dev'
  9. });
  10. // 执行SELECT语句并返回结果的函数
  11. async function main() {
  12. try {
  13. // 查询:Member数量查询
  14. const data1 = await db.any(`SELECT COUNT(1) FROM "Member";`);
  15. console.log(`Member数量:`,data1)
  16. // 查询:InviteEvent数量查询
  17. const data2 = await db.any(`SELECT COUNT(1) FROM "InviteEvent";`);
  18. console.log(`InviteEvent数量:`,data2)
  19. // 查询:邀请关系会员列表查询
  20. let inviteId = "1"
  21. const data3 = await db.any(`SELECT * FROM "Member" WHERE ("invitePath" ?& $1 OR "invite"=$2)`,[[inviteId],inviteId]);
  22. console.log(`邀请关系会员列表:`,data3)
  23. return true;
  24. } catch (error) {
  25. console.error('Error executing SELECT query:', error);
  26. return null;
  27. }
  28. }
  29. // 调用函数并处理结果
  30. main()