插入数据方法抽离为 dataManager.js
This commit is contained in:
@@ -2,6 +2,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const sleepUtils = require('../../../utils/sleepUtils');
|
||||
const dataManager = require('../dataManager');
|
||||
|
||||
const dbUtils = global.dbUtils;
|
||||
|
||||
@@ -106,24 +107,9 @@ async function fetch({ songIdArray, debug = false }) {
|
||||
if (songInfoList.length == 0) return;
|
||||
|
||||
console.log("插入数据库");
|
||||
if (songAlbumRel.length > 0)
|
||||
await dbUtils.query('INSERT IGNORE INTO song_album_relation (song_id, album_id) VALUES ?', [songAlbumRel]);
|
||||
await dbUtils.query('INSERT IGNORE INTO song_artist_relation (song_id, artist_id) VALUES ?', [songArtistRel]);
|
||||
await dbUtils.query(`
|
||||
INSERT INTO song (
|
||||
song_id, title, type, alias, pop, fee, quality, cd,
|
||||
no, dj_id, s_id, origin_cover_type, pub_time,
|
||||
no_copyright_rcmd, mv, single, version, data_version
|
||||
) VALUES ? ON DUPLICATE KEY UPDATE
|
||||
title = VALUES(title), type = VALUES(type), alias = VALUES(alias), pop = VALUES(pop), fee = VALUES(fee), quality = VALUES(quality), cd = VALUES(cd),
|
||||
no = VALUES(no), dj_id = VALUES(dj_id), s_id = VALUES(s_id), origin_cover_type = VALUES(origin_cover_type), pub_time = VALUES(pub_time),
|
||||
no_copyright_rcmd = VALUES(no_copyright_rcmd), mv = VALUES(mv), single = VALUES(single), version = VALUES(version), data_version = VALUES(data_version)
|
||||
`, [songInfoList.map(songInfo => [
|
||||
songInfo.id, songInfo.title, songInfo.type, songInfo.alias, songInfo.pop, songInfo.fee, songInfo.quality, songInfo.cd,
|
||||
songInfo.no, songInfo.djId, songInfo.sId, songInfo.originCoverType, songInfo.pubTime,
|
||||
songInfo.noCopyrightRcmd, songInfo.mv, songInfo.single, songInfo.version, 2
|
||||
])]);
|
||||
// image 因为接口没有返回,所以不更新
|
||||
await dataManager.song_album.insertCollection(songAlbumRel);
|
||||
await dataManager.song_artist.insertCollection(songArtistRel);
|
||||
await dataManager.song.insertCollection(songInfoList); // image 因为接口没有返回,所以不更新
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Reference in New Issue
Block a user