NodeJS sqlite3如何仅从列中返回值而不是列数据

问题描述 投票:0回答:1
router.get('/play/:song_id', async ctx => {
    try {
        const sql = `SELECT location FROM songs WHERE song_id = ${ctx.params.song_id} LIMIT 1;`
        const db = await sqlite.open(dbName)
        const data = await db.get(sql)
        await db.close()
        const newdata = JSON.parse(JSON.stringify(data))
        console.log(newdata)
        ctx.response.type = 'mp3'
        ctx.response.body = fs.createReadStream(newdata)
    } catch (err) {
        ctx.body = err.message
    }
})

这是我得到的输出:

{ location: 'public/songs/Santeria.mp3' }

但是我只想要'public/songs/Santeria.mp3'部分(该列的值)。

node.js sqlite
1个回答
0
投票

您只需要更改行:

ctx.response.body = fs.createReadStream(newdata)

to

ctx.response.body = newdata.location
© www.soinside.com 2019 - 2024. All rights reserved.