check-my-audio-books.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function checkBooks() {
  4. console.log('\n📊 检查书籍列表:\n');
  5. const books = await prisma.book.findMany({
  6. orderBy: { id: 'desc' },
  7. take: 20,
  8. select: {
  9. id: true,
  10. title: true,
  11. description: true,
  12. userId: true,
  13. isPublished: true,
  14. createdAt: true,
  15. _count: {
  16. select: { chapters: true }
  17. }
  18. }
  19. });
  20. console.log(`最近20本书籍:\n`);
  21. books.forEach((book, index) => {
  22. console.log(`${index + 1}. ID: ${book.id}`);
  23. console.log(` 标题: ${book.title}`);
  24. console.log(` 描述: ${book.description}`);
  25. console.log(` 用户: ${book.userId}`);
  26. console.log(` 公开: ${book.isPublished}`);
  27. console.log(` 章节数: ${book._count.chapters}`);
  28. console.log(` 创建时间: ${book.createdAt}\n`);
  29. });
  30. // 统计标题为"我的音频"的书籍
  31. const myAudioBooks = await prisma.book.count({
  32. where: {
  33. title: '我的音频'
  34. }
  35. });
  36. console.log(`\n📈 标题为"我的音频"的书籍数量: ${myAudioBooks}\n`);
  37. await prisma.$disconnect();
  38. }
  39. checkBooks().catch(console.error);