//创建一个web 数据库functioncreateDataBase(){//参数1:数据库名称//参数2:数据库的版本//参数3:数据库的简介//参数4:数据库的大小,单位字节let db=openDatabase("blog","1.0","这是一个数据库",2*1024*1024);return db;}functiondataHandle(db,sql,arr=[]){returnnewPromise((resolve,reject)=>{
db.transaction((tx)=>{try{
tx.executeSql(sql,arr,(tx,result)=>{resolve(result);});}catch(error){reject(error);}})})}let db=createDataBase();functioncreateTable(db){let sqlUser="create table user1(username not null unique,password varchar(10))";dataHandle(db,sqlUser);}// createTable(db)//增加数据// let sqladd="insert into user(username,password) values('zxxxx','1001')";// dataHandle(db,sqladd).then(data=>{// console.log(data);// }).catch(err=>{// console.log(err);// })//查询// let sqlselect="select * from user";// dataHandle(db,sqlselect).then(data=>{// console.log(data.rows[0]);// })//修改// let sqlupdate="update user set username='21212121' where username='小红'";// dataHandle(db,sqlupdate).then(data=>{// console.log(data)// })//删除let sqldel="delete from user where username='小明' and password='1001'";dataHandle(db,sqldel).then(data=>{
console.log(data)})