Created
June 16, 2020 13:27
-
-
Save CoutinhoElias/1246abd46c62125de980e44528cd0bbc to your computer and use it in GitHub Desktop.
Moor
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
//********************************************************************* | |
//Conteúdo de ProdutoDAO.dart | |
//********************************************************************* | |
import 'package:moor_flutter/moor_flutter.dart'; | |
import 'package:listadecompras/src/db/my_database.dart'; | |
part 'ProdutoDAO.g.dart'; | |
@UseDao(tables: [Produtos, Categorias]) | |
class ProdutoDAO extends DatabaseAccessor<MyDatabase> with _$ProdutoDAOMixin { | |
ProdutoDAO(MyDatabase db) : super(db); | |
} | |
//********************************************************************* | |
//Conteúdo de my_database.dart | |
//********************************************************************* | |
import 'package:moor_flutter/moor_flutter.dart'; | |
import 'package:listadecompras/src/db/dao/ProdutoDAO.dart'; | |
part 'my_database.g.dart'; | |
class Produtos extends Table { | |
IntColumn get id => integer().autoIncrement()(); | |
TextColumn get title => text()(); | |
TextColumn get description => text()(); | |
IntColumn get qtd => integer()(); | |
IntColumn get price => integer()(); | |
IntColumn get id_categoria => integer()(); | |
} | |
class Categorias extends Table { | |
IntColumn get id => integer().autoIncrement()(); | |
TextColumn get name => text()(); | |
} | |
@UseMoor(tables: [Produtos, Categorias]) | |
class MyDatabase extends _$MyDatabase { | |
static MyDatabase instance = MyDatabase._internal(); | |
ProdutoDAO produtoDAO = ProdutoDAO(); | |
MyDatabase._internal() | |
: super(FlutterQueryExecutor.inDatabaseFolder(path: 'db.sqlite')); | |
@override | |
int get schemaVersion => throw UnimplementedError(); | |
} | |
mixin ProdutoDAO {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment