本文整理汇总了TypeScript中db/db.execute函数的典型用法代码示例。如果您正苦于以下问题:TypeScript execute函数的具体用法?TypeScript execute怎么用?TypeScript execute使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
api.post('/countries', async (req: Request, res: Response) => {
const countries = req.body.countries
const mapOwidNameToId: any = {}
let owidRows = []
// find owid ID
const owidNames = Object.keys(countries).map(key => countries[key])
owidRows = await db.query(
`SELECT id, owid_name
FROM country_name_tool_countrydata
WHERE owid_name in (?)
`, [owidNames])
for (const row of owidRows) {
mapOwidNameToId[row.owid_name] = row.id
}
// insert one by one (ideally do a bulk insert)
for (const country of Object.keys(countries)) {
const owidName = countries[country]
console.log(`adding ${country}, ${mapOwidNameToId[owidName]}, ${owidName}`)
await db.execute(
`INSERT INTO country_name_tool_countryname (country_name, owid_country)
VALUES (?, ?)`, [country, mapOwidNameToId[owidName]])
}
return { success: true }
})