v2.0.0
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { getDB } from '../../db'
|
||||
import {
|
||||
createMusicInfoQueryStatement,
|
||||
createMusicInfoInsertStatement,
|
||||
createMusicInfoDeleteStatement,
|
||||
createMusicInfoClearStatement,
|
||||
createCountStatement,
|
||||
} from './statements'
|
||||
|
||||
|
||||
/**
|
||||
* 查询歌曲信息
|
||||
* @param id 歌曲id
|
||||
* @returns 歌曲信息
|
||||
*/
|
||||
export const queryMusicInfo = (id: string): LX.DBService.MusicInfoOtherSource[] => {
|
||||
const musicInfoQueryStatement = createMusicInfoQueryStatement()
|
||||
return musicInfoQueryStatement.all(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入歌曲信息
|
||||
* @param musicInfos 列表
|
||||
*/
|
||||
export const inertMusicInfo = (musicInfos: LX.DBService.MusicInfoOtherSource[]) => {
|
||||
const db = getDB()
|
||||
const musicInfoInsertStatement = createMusicInfoInsertStatement()
|
||||
db.transaction((musicInfos: LX.DBService.MusicInfoOtherSource[]) => {
|
||||
for (const info of musicInfos) musicInfoInsertStatement.run(info)
|
||||
})(musicInfos)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除歌曲信息
|
||||
* @param ids 列表
|
||||
*/
|
||||
export const deleteMusicInfo = (ids: string[]) => {
|
||||
const db = getDB()
|
||||
const musicInfoDeleteStatement = createMusicInfoDeleteStatement()
|
||||
db.transaction((ids: string[]) => {
|
||||
for (const id of ids) musicInfoDeleteStatement.run(id)
|
||||
})(ids)
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空歌曲信息
|
||||
*/
|
||||
export const clearMusicInfo = () => {
|
||||
const musicInfoClearStatement = createMusicInfoClearStatement()
|
||||
musicInfoClearStatement.run()
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计歌曲信息数量
|
||||
*/
|
||||
export const countMusicInfo = () => {
|
||||
const countStatement = createCountStatement()
|
||||
return countStatement.get().count
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
queryMusicInfo,
|
||||
inertMusicInfo,
|
||||
deleteMusicInfo,
|
||||
clearMusicInfo,
|
||||
countMusicInfo,
|
||||
} from './dbHelper'
|
||||
|
||||
|
||||
const toDBMusicInfo = (id: string, musicInfos: LX.Music.MusicInfo[]): LX.DBService.MusicInfoOtherSource[] => {
|
||||
return musicInfos.map((info, index) => {
|
||||
return {
|
||||
...info,
|
||||
meta: JSON.stringify(info.meta),
|
||||
source_id: id,
|
||||
order: index,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取歌曲信息
|
||||
* @param id 歌曲id
|
||||
* @returns 歌词信息
|
||||
*/
|
||||
export const getMusicInfoOtherSource = (id: string): LX.Music.MusicInfoOnline[] => {
|
||||
const list = queryMusicInfo(id).map(info => {
|
||||
return {
|
||||
id: info.id,
|
||||
name: info.name,
|
||||
singer: info.singer,
|
||||
source: info.source,
|
||||
interval: info.interval,
|
||||
meta: JSON.parse(info.meta),
|
||||
}
|
||||
})
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存歌曲信息信息
|
||||
* @param id 歌曲id
|
||||
* @param musicInfos 歌词信息
|
||||
*/
|
||||
export const musicInfoOtherSourceAdd = (id: string, musicInfos: LX.Music.MusicInfoOnline[]) => {
|
||||
inertMusicInfo(toDBMusicInfo(id, musicInfos))
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除歌曲信息信息
|
||||
* @param ids 歌曲id
|
||||
*/
|
||||
export const musicInfoOtherSourceRemove = (ids: string[]) => {
|
||||
deleteMusicInfo(ids)
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空歌曲信息信息
|
||||
*/
|
||||
export const musicInfoOtherSourceClear = () => {
|
||||
clearMusicInfo()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 统计歌曲信息信息数量
|
||||
*/
|
||||
export const musicInfoOtherSourceCount = () => {
|
||||
return countMusicInfo()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { getDB } from '../../db'
|
||||
|
||||
|
||||
/**
|
||||
* 创建歌曲信息查询语句
|
||||
* @returns 查询语句
|
||||
*/
|
||||
export const createMusicInfoQueryStatement = () => {
|
||||
const db = getDB()
|
||||
return db.prepare<[string]>(`
|
||||
SELECT "id", "name", "singer", "source", "meta"
|
||||
FROM "main"."music_info_other_source"
|
||||
WHERE source_id=?
|
||||
ORDER BY "order" ASC
|
||||
`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建歌曲信息插入语句
|
||||
* @returns 插入语句
|
||||
*/
|
||||
export const createMusicInfoInsertStatement = () => {
|
||||
const db = getDB()
|
||||
return db.prepare<[LX.DBService.MusicInfoOtherSource]>(`
|
||||
INSERT INTO "main"."music_info_other_source" ("id", "name", "singer", "source", "meta", "source_id", "order")
|
||||
VALUES (@id, @name, @singer, @source, @meta, @source_id, @order)
|
||||
`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建歌曲信息清空语句
|
||||
* @returns 清空语句
|
||||
*/
|
||||
export const createMusicInfoClearStatement = () => {
|
||||
const db = getDB()
|
||||
return db.prepare(`
|
||||
DELETE FROM "main"."music_info_other_source"
|
||||
`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建歌曲信息删除语句
|
||||
* @returns 删除语句
|
||||
*/
|
||||
export const createMusicInfoDeleteStatement = () => {
|
||||
const db = getDB()
|
||||
return db.prepare<[string]>(`
|
||||
DELETE FROM "main"."music_info_other_source"
|
||||
WHERE "source_id"=?
|
||||
`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数量统计语句
|
||||
* @returns 统计语句
|
||||
*/
|
||||
export const createCountStatement = () => {
|
||||
const db = getDB()
|
||||
return db.prepare('SELECT COUNT(*) as count FROM "main"."music_info_other_source"')
|
||||
}
|
||||
Reference in New Issue
Block a user