~cytrogen/fluent-reader-mobile

ref: 4a21d3259885f835d064df292029e7fe164db960 fluent-reader-mobile/lib/utils/db.dart -rw-r--r-- 1.3 KiB
4a21d325 — Bruce Liu add google reader api support 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import 'dart:async';

import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

abstract class DatabaseHelper {
  static final _dbName = "frlite.db";
  static final _dbVersion = 1;

  static Database _database;

  static Future<Database> getDatabase() async {
    if (_database != null) return _database;
    String path = join(await getDatabasesPath(), _dbName);
    _database = await openDatabase(path, version:_dbVersion, onCreate: _onCreate);
    return _database;
  }

  static Future<void> _onCreate(Database db, int version) async {
    await db.execute('''
      CREATE TABLE sources (
        sid TEXT PRIMARY KEY,
        url TEXT NOT NULL,
        iconUrl TEXT,
        name TEXT NOT NULL,
        openTarget INTEGER NOT NULL,
        latest INTEGER NOT NULL,
        lastTitle INTEGER NOT NULL
      );
    ''');
    await db.execute('''
    CREATE TABLE items (
        iid TEXT PRIMARY KEY,
        source TEXT NOT NULL,
        title TEXT NOT NULL,
        link TEXT NOT NULL,
        date INTEGER NOT NULL,
        content TEXT NOT NULL,
        snippet TEXT NOT NULL,
        hasRead INTEGER NOT NULL,
        starred INTEGER NOT NULL,
        creator TEXT,
        thumb TEXT
      );
    ''');
    await db.execute("CREATE INDEX itemsDate ON items (date DESC);");
  }
}