Created
February 20, 2018 16:53
-
-
Save Norbert515/6bcde9aba98e76fa4cecce8588d42999 to your computer and use it in GitHub Desktop.
BookDatabase init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookDatabase { | |
static final BookDatabase _bookDatabase = new BookDatabase._internal(); | |
final String tableName = "Books"; | |
Database db; | |
static BookDatabase get() { | |
return _bookDatabase; | |
} | |
BookDatabase._internal(); | |
Future init() async { | |
// Get a location using path_provider | |
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |
String path = join(documentsDirectory.path, "demo.db"); | |
db = await openDatabase(path, version: 1, | |
onCreate: (Database db, int version) async { | |
// When creating the db, create the table | |
await db.execute( | |
"CREATE TABLE $tableName (" | |
"${Book.db_id} STRING PRIMARY KEY," | |
"${Book.db_title} TEXT," | |
"${Book.db_url} TEXT," | |
"${Book.db_star} BIT," | |
"${Book.db_notes} TEXT" | |
")"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment