29 lines
893 B
TypeScript
29 lines
893 B
TypeScript
import { execute, selectArray, pool, queryCount } from './../service/service/mysql'
|
|
|
|
// 使用execute执行更新数据
|
|
describe('Database', () => {
|
|
it('excute update', () => {
|
|
execute('update user set name = ? where id = ?', ['张三', '1']).then(ret => {
|
|
console.log(ret)
|
|
})
|
|
})
|
|
it('excute insert', () => {
|
|
execute('insert into user set ?', {
|
|
name: '张三111'
|
|
}).then(ret => {
|
|
console.log(ret)
|
|
})
|
|
})
|
|
it('query array', async () => {
|
|
const ret = await selectArray<{ id: number; name: string }>('select * from user')
|
|
ret.forEach(it => {
|
|
console.log(it.id, '=>', it.name)
|
|
})
|
|
// console.log(ret)
|
|
})
|
|
it('query count', async () => {
|
|
const count = await queryCount('select count(*) from user');
|
|
console.log('total:', count);
|
|
})
|
|
})
|