databaseserve
v1.0.7
Published
indexdb普通操作的类 自己使用以防忘记对于indexdb的操作 懒得看文档
Downloads
11
Readme
个人使用的indexDB的基本操作的类
邮箱 [email protected] 这是本人的邮箱 又不懂的 可以发邮箱给我(This is my email address and do not understand can send email to me)
let tableList = [
{
tableName:'student',
option:{
keyPath:'id'
}
}
]
let indexList = [
{
name:'id',
keyPath:'id'
},
{
name:'name',
keyPath:'name'
},
{
name:'age',
keyPath:['page','nianling']
}
]
let dataBaseServe = new DataBaseServe('test',1,tableList,indexList,()=>{
// 增加
dataBaseServe.add('test','student',[{id:1,name:'测试1',age:11},{id:2,name:'测试2',age:22},{id:3,name:'测试3',age:33}])
.then((list)=>{
console.log('成功数组',list)
})
.catch((list,errStr)=>{
console.log('失败数组',list)
console.log('失败原因',errStr)
})
// 主键查询
dataBaseServe.getKey('test','student',1)
.then((obj)=>{
console.log('查询的结果',obj);
})
.catch((str)=>{
console.log('查询失败',str);
})
// 游标查询
dataBaseServe.getCursor('test','student',(res)=>{
console.log('查询的结果',res);
}).then(list=>{
console.log('所有',list)
})
// 索引查询
dataBaseServe.getIndex('test','student','name')
.then((list)=>{
console.log('查询的结果',list);
})
.catch((str)=>{
console.log('查询失败',str);
})
// 自定义操作
dataBaseServe.getDivFun('test','student',(res)=>{
console.log(res)
})
// 更新
dataBaseServe.update('test','student',[{id:1,name:'测试111s',age:11},{id:3,name:'测试3336',age:111},{id:5,name:'测试555',age:555}])
.then((list)=>{
console.log('成功数组',list)
})
.catch((list,errStr)=>{
console.log('==失败数组',list,'失败原因',errStr)
})
// 删除
dataBaseServe.del('test','student',[])
.then((list)=>{
console.log('成功数组',list)
})
.catch((list,errStr)=>{
console.log('==失败数组',list,'失败原因',errStr)
})
})
1.0.3 更新文件上传和下载
let tableList = [
{
tableName:'fileTable',
option:{
keyPath:'id'
}
}
]
let indexTable = [
{
name:'name',
keyPath:['name','png','jpg'],
option:{
unique:true
}
}
]
const dataBaseServe = new DataBaseServe('fileBase',1,tableList,indexTable,()=>{
dataBaseServe.downloadFile('fileBase','fileTable',1);
});
this.$refs.fileRef.addEventListener("change",e=>{
const file = e.target.files[0];
dataBaseServe.uploadFile('fileBase','fileTable','id',2,'测试文件',file,'.png');
})