book.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import connection from "./base.js";
  2. export async function book_mate_insert({
  3. book_name = "",
  4. book_id = "",
  5. book_md5 = "",
  6. language = "",
  7. date = null,
  8. creatorFileAs = "",
  9. UUID = "",
  10. ISBN = "",
  11. author_id = "",
  12. category_id = "",
  13. Introduction = "",
  14. }) {
  15. const sql = `
  16. INSERT INTO book (book_name, book_id, book_md5, language, date, creatorFileAs, UUID, ISBN, author_id, category_id, Introduction)
  17. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  18. ON DUPLICATE KEY UPDATE book_id = book_id;
  19. `;
  20. const values = [
  21. book_name,
  22. book_id,
  23. book_md5,
  24. language,
  25. date,
  26. creatorFileAs,
  27. UUID,
  28. ISBN,
  29. author_id,
  30. category_id,
  31. Introduction,
  32. ];
  33. return new Promise((resolve, reject) => {
  34. connection.execute(sql, values, (error, result) => {
  35. if (error) {
  36. console.error('Database error:', error);
  37. return reject(error); // 使用 reject 处理错误
  38. }
  39. resolve(result); // 返回查询结果
  40. });
  41. });
  42. }
  43. export async function getBookInfo(book_md5) {
  44. const sql = `select * from book where book_md5 = '${book_md5}';`;
  45. return new Promise((resolve, reject) => {
  46. connection.execute(sql, [], (error, result) => {
  47. if (error) {
  48. console.error('Database error:', error);
  49. return reject(error); // 使用 reject 处理错误
  50. }
  51. resolve(result.length ? result[0] : false); // 返回查询结果
  52. });
  53. });
  54. }