X Tutup
Skip to content

Commit d4c4265

Browse files
committed
增加本地数据库模块
增加动态event的数据库
1 parent 571d8c8 commit d4c4265

File tree

6 files changed

+1071
-150
lines changed

6 files changed

+1071
-150
lines changed

lib/common/ab/SqlManager.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'dart:async';
2+
3+
import 'package:sqflite/sqflite.dart';
4+
5+
/**
6+
* 数据库管理
7+
* Created by guoshuyu
8+
* Date: 2018-08-03
9+
*/
10+
11+
class SqlManager {
12+
static final _VERSION = 1;
13+
14+
static final _NAME = "gsy_github_app_flutter.db";
15+
16+
static Database _database;
17+
18+
///初始化
19+
static init() async {
20+
// open the database
21+
var databasesPath = await getDatabasesPath();
22+
String path = databasesPath + _NAME;
23+
_database = await openDatabase(path, version: _VERSION, onCreate: (Database db, int version) async {
24+
// When creating the db, create the table
25+
//await db.execute("CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER, num REAL)");
26+
});
27+
}
28+
29+
/**
30+
* 表是否存在
31+
*/
32+
static isTableExits(String tableName) async {
33+
await getCurrentDatabase();
34+
var res = await _database.rawQuery("select * from Sqlite_master where type = 'table' and name = '$tableName'");
35+
return res != null && res.length > 0;
36+
}
37+
38+
///获取当前数据库对象
39+
static Future<Database> getCurrentDatabase() async {
40+
if (_database == null) {
41+
await init();
42+
}
43+
return _database;
44+
}
45+
46+
///关闭
47+
static close() {
48+
if (_database != null) {
49+
_database.close();
50+
_database = null;
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)
X Tutup