Skip to content

Instantly share code, notes, and snippets.

@wumanho
Created July 11, 2021 14:35
Show Gist options
  • Save wumanho/60498d5a5aaf188bda9ea7d7f70baed9 to your computer and use it in GitHub Desktop.
Save wumanho/60498d5a5aaf188bda9ea7d7f70baed9 to your computer and use it in GitHub Desktop.
api.js
const db = require('./db')
//添加任务
module.exports.add = (title) => {
db.write({title: title, done: false}).then(() => {
console.log('添加成功')
db.close()
}).catch(err => {
console.log('添加失败' + err)
db.close()
})
}
//清空任务
module.exports.clear = () => {
db.clear().then(() => {
console.log('清除成功')
db.close()
}).catch((err) => {
console.log('清除成功失败' + err)
db.close()
})
}
//展示所有
module.exports.listAll = async () => {
return await db.read()
}
//更新标题
module.exports.updateTitle = (id, newTitle) => {
db.update('title', id, newTitle).then(() => {
console.log('更新标题成功')
db.close()
}).catch((err) => {
console.log('更新标题失败' + err)
db.close()
})
}
//更新状态
module.exports.updateStatus = (id, newStatus) => {
db.update('done', id, newStatus).then(() => {
console.log('更新成功')
db.close()
}).catch((err) => {
console.log('更新失败' + err)
db.close()
})
}
//删除任务
module.exports.delete = (id) => {
db.delete(id).then(() => {
console.log('删除成功')
db.close()
}).catch(err => {
console.log('删除失败' + err)
db.close()
})
}
//断开连接
module.exports.close = () => {
db.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment