Skip to content

Commit

Permalink
Cleanup example app (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitusortner authored Feb 16, 2019
1 parent 0390991 commit d946e8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 65 deletions.
90 changes: 26 additions & 64 deletions example/lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyDatabase> openDatabase() async => _$open();

Person(this.id, this.name, this.age, this.isHungry);
}
@Query('SELECT * FROM task WHERE id = :id')
Future<Task> findTaskById(int id);

@entity
class Car {
@PrimaryKey(autoGenerate: false)
final int id;
final String manufacturer;
final int wheels;
@Query('SELECT * FROM task')
Future<List<Task>> findAllTasks();

@insert
Future<void> insertTask(Task task);

@insert
Future<void> insertTasks(List<Task> tasks);

@update
Future<void> updateTask(Task task);

@update
Future<void> updateTasks(List<Task> task);

Car(this.id, this.manufacturer, this.wheels);
@delete
Future<void> deleteTask(Task task);

@delete
Future<void> deleteTasks(List<Task> tasks);
}

@entity
@Entity(tableName: 'task')
class Task {
@PrimaryKey(autoGenerate: true)
final int id;

final String message;

Task(this.id, this.message);
Expand All @@ -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<MyDatabase> openDatabase() async => _$open();

@Query('SELECT * FROM Person')
Future<List<Person>> findAllPersons();

@Query('SELECT * FROM Person WHERE id = :id')
Future<Person> findPersonById(int id);

@Query('SELECT * FROM Car WHERE id = :id')
Future<Car> findCarById(int id);

@insert
Future<void> insertPerson(Person person);

@insert
Future<void> insertCar(Car car);

@Query('SELECT * FROM Task')
Future<List<Task>> findAllTasks();

@insert
Future<void> insertTask(Task task);

@update
Future<void> updateTask(Task task);

@update
Future<void> updatePerson(Person person);

@delete
Future<void> deletePerson(Person person);
}

Future<void> main() async {
final database = await MyDatabase.openDatabase();
}
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TasksWidgetState extends State<TasksWidget> {
await database.insertTask(task);
_tasks = await database.findAllTasks();

setState(() {}); // trigger rebuild
setState(() {}); // trigger rebuild to show inserted task
}

@override
Expand Down

0 comments on commit d946e8f

Please sign in to comment.