import 'package:sqflite/sqflite.dart'; String sqName = 'walletDb'; class YSVideoTable{ Database? db; String? tabName = 'videoList'; YSVideoTable init() { final file = YSVideoTable(); open(); return file; } //判断表是否存在 isTableExits() async { db ??= await openDatabase('$sqName.db'); var sql ="SELECT * FROM sqlite_master WHERE TYPE = 'table' AND NAME = '$tabName'"; var res = await db!.rawQuery(sql); var returnRes = res.isNotEmpty; return returnRes; } open() async { if (await isTableExits()==false) { execute(); } } ///创建表 execute() async{ db ??= await openDatabase('$sqName.db'); await db!.execute( 'CREATE TABLE $tabName (id INTEGER PRIMARY KEY, name TEXT, path TEXT, time TEXT)' ); } ///插入数据 Future rawInsert({required String name,required String path,required String time}) async{ db ??= await openDatabase('$sqName.db'); int id = await db!.rawInsert( 'INSERT INTO $tabName(name,path,time) VALUES("$name","$path","$time")' ); return id; } ///查询数据 Future rawQuery() async{ try{ db ??= await openDatabase('$sqName.db'); List list = await db!.rawQuery('SELECT * FROM $tabName'); return list; }catch(e){ return []; } } ///更新数据 Future rawUpdate({required String id,required String name,required String path,required String time}) async{ db ??= await openDatabase('$sqName.db'); int count = await db!.rawUpdate( 'UPDATE $tabName SET name = ?,path = ?,time = ? ,to_token_addr = ?,amount = ? ,hash = ? WHERE id = $id', [name,path,time] ); return count; } ///删除数据 Future rawDelete(String id) async{ db ??= await openDatabase('$sqName.db'); int count = await db!.rawDelete('DELETE FROM $tabName WHERE id = ?', [id]); return count; } Future delete() async{ db ??= await openDatabase('$sqName.db'); final status = await db?.delete(tabName!)??0; return status; } }