From da5c0a3204028f6036fc45d360a841fead6799d2 Mon Sep 17 00:00:00 2001 From: Vitus Ortner Date: Sun, 17 Feb 2019 00:06:26 +0100 Subject: [PATCH] Cleanup example app --- example/lib/database.dart | 90 +++++++++++---------------------------- example/lib/main.dart | 2 +- 2 files changed, 27 insertions(+), 65 deletions(-) diff --git a/example/lib/database.dart b/example/lib/database.dart index a1b488d4..ab4fc43e 100644 --- a/example/lib/database.dart +++ b/example/lib/database.dart @@ -4,31 +4,40 @@ import 'package:sqflite/sqflite.dart' as sqflite; part 'database.g.dart'; -@entity -class Person { - @PrimaryKey() - final int id; - final String name; - final int age; - final bool isHungry; +@Database() +abstract class MyDatabase extends FloorDatabase { + static Future openDatabase() async => _$open(); - Person(this.id, this.name, this.age, this.isHungry); -} + @Query('SELECT * FROM task WHERE id = :id') + Future findTaskById(int id); -@entity -class Car { - @PrimaryKey(autoGenerate: false) - final int id; - final String manufacturer; - final int wheels; + @Query('SELECT * FROM task') + Future> findAllTasks(); + + @insert + Future insertTask(Task task); + + @insert + Future insertTasks(List tasks); + + @update + Future updateTask(Task task); + + @update + Future updateTasks(List task); - Car(this.id, this.manufacturer, this.wheels); + @delete + Future deleteTask(Task task); + + @delete + Future deleteTasks(List tasks); } -@entity +@Entity(tableName: 'task') class Task { @PrimaryKey(autoGenerate: true) final int id; + final String message; Task(this.id, this.message); @@ -49,50 +58,3 @@ class Task { return 'Task{id: $id, message: $message}'; } } - -@entity -class Bar { - final int id; - final String foo; - - Bar(this.id, this.foo); -} - -@Database() -abstract class MyDatabase extends FloorDatabase { - static Future openDatabase() async => _$open(); - - @Query('SELECT * FROM Person') - Future> findAllPersons(); - - @Query('SELECT * FROM Person WHERE id = :id') - Future findPersonById(int id); - - @Query('SELECT * FROM Car WHERE id = :id') - Future findCarById(int id); - - @insert - Future insertPerson(Person person); - - @insert - Future insertCar(Car car); - - @Query('SELECT * FROM Task') - Future> findAllTasks(); - - @insert - Future insertTask(Task task); - - @update - Future updateTask(Task task); - - @update - Future updatePerson(Person person); - - @delete - Future deletePerson(Person person); -} - -Future main() async { - final database = await MyDatabase.openDatabase(); -} diff --git a/example/lib/main.dart b/example/lib/main.dart index 61e114a5..ac5077a0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -54,7 +54,7 @@ class TasksWidgetState extends State { await database.insertTask(task); _tasks = await database.findAllTasks(); - setState(() {}); // trigger rebuild + setState(() {}); // trigger rebuild to show inserted task } @override