Skip to content

Instantly share code, notes, and snippets.

@Norbert515
Created February 20, 2018 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Norbert515/6bcde9aba98e76fa4cecce8588d42999 to your computer and use it in GitHub Desktop.
Save Norbert515/6bcde9aba98e76fa4cecce8588d42999 to your computer and use it in GitHub Desktop.
BookDatabase init
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