Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup example app #56

Merged
merged 1 commit into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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