插入数据方法抽离为 dataManager.js
This commit is contained in:
103
netease_music/src/dataManager.js
Normal file
103
netease_music/src/dataManager.js
Normal file
@@ -0,0 +1,103 @@
|
||||
const dbUtils = global.dbUtils;
|
||||
|
||||
module.exports = {
|
||||
song: {
|
||||
insertCollection: async (songInfoList) => {
|
||||
if (songInfoList.length == 0) return;
|
||||
// image 因为接口没有返回,所以不更新
|
||||
return 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
|
||||
])]);
|
||||
},
|
||||
},
|
||||
|
||||
album: {
|
||||
insert: async (albumInfo) => {
|
||||
return await dbUtils.query('INSERT IGNORE INTO album SET ?', albumInfo);
|
||||
},
|
||||
|
||||
update: async (albumId, albumInfo) => {
|
||||
return await dbUtils.query(`UPDATE album SET ? WHERE album_id = ${albumId}`, albumInfo);
|
||||
}
|
||||
},
|
||||
|
||||
artist: {
|
||||
insert: async (artistInfo) => {
|
||||
return await dbUtils.query('INSERT IGNORE INTO artist SET ?', artistInfo);
|
||||
},
|
||||
},
|
||||
|
||||
lyric: {
|
||||
insert: async (lyricInfo) => {
|
||||
return await dbUtils.query('INSERT IGNORE INTO lyric SET ?', lyricInfo);
|
||||
}
|
||||
},
|
||||
|
||||
comment: {
|
||||
insertCollection: async (commentInfoList) => {
|
||||
if (commentInfoList.length == 0) return;
|
||||
return await dbUtils.query(`
|
||||
INSERT INTO comment ( comment_id, parent_comment_id, user_id, song_id, content, time, like_count, comment_type ) VALUES ?
|
||||
ON DUPLICATE KEY UPDATE content = VALUES(content), like_count = VALUES(like_count), comment_type = GREATEST(comment_type, VALUES(comment_type)), modify_time = CURRENT_TIMESTAMP
|
||||
`, [commentInfoList]);
|
||||
}
|
||||
},
|
||||
|
||||
comment_progress: {
|
||||
update: async (commentProgressInfo, songId) => {
|
||||
return await dbUtils.query('UPDATE comment_progress SET ? WHERE song_id = ? LIMIT 1', [commentProgressInfo, songId]);
|
||||
},
|
||||
},
|
||||
|
||||
playlist: {
|
||||
insertCollection: async (playlistInfo) => {
|
||||
if (playlistInfo.length == 0) return;
|
||||
return await dbUtils.query(`
|
||||
INSERT INTO playlist ( ${Object.keys(playlistInfo).map(field => `\`${field}\``).join(",")} ) VALUES ?
|
||||
ON DUPLICATE KEY UPDATE ${Object.keys(playlistInfo).map(field => `${field}=VALUES(${field})`).join(", ")}
|
||||
`, [[Object.values(playlistInfo)]]);
|
||||
}
|
||||
},
|
||||
|
||||
user: {
|
||||
insertCollection: async (userInfoList) => {
|
||||
if (userInfoList.length == 0) return;
|
||||
return await dbUtils.query(`
|
||||
INSERT INTO user ( user_id, user_type, nickname, avatar_url ) VALUES ?
|
||||
ON DUPLICATE KEY UPDATE user_type = VALUES(user_type), nickname = VALUES(nickname), avatar_url = VALUES(avatar_url), modify_time = CURRENT_TIMESTAMP
|
||||
`, [userInfoList]);
|
||||
}
|
||||
},
|
||||
|
||||
song_album: {
|
||||
insertCollection: async (songAlbumRel) => {
|
||||
if (songAlbumRel.length == 0) return;
|
||||
return await dbUtils.query('INSERT IGNORE INTO song_album_relation (song_id, album_id) VALUES ?', [songAlbumRel]);
|
||||
}
|
||||
},
|
||||
|
||||
song_artist: {
|
||||
insertCollection: async (songArtistRel) => {
|
||||
if (songArtistRel.length == 0) return;
|
||||
return await dbUtils.query('INSERT IGNORE INTO song_artist_relation (song_id, artist_id) VALUES ?', [songArtistRel]);
|
||||
}
|
||||
},
|
||||
|
||||
song_playlist: {
|
||||
insertCollection: async (trackIds) => {
|
||||
if (trackIds.length == 0) return;
|
||||
return await dbUtils.query('INSERT IGNORE INTO song_playlist_relation (song_id, playlist_id, alg, rcmd_reason) VALUES ?', [trackIds]);
|
||||
}
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user