Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
#31. Completing dbOpenEntity generation.
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
matei-tm committed May 16, 2019
1 parent a7e580d commit ef08b33
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Supported orm-m8 features:
| CompositeConstraint. | primaryKey | CompositeConstraint | v0.4.0 | |
| CompositeConstraint. | foreignKey | CompositeConstraint | - | Planned for v0.7.0 |
| CompositeConstraint. | indexed | CompositeConstraint | - | Planned for v0.7.0 |
| implements | DbOpenEntity | entity helper | - | Planned for v0.7.0 |
| implements | DbOpenEntity | entity helper | v0.6.3 | |
| implements | DbEntity | entity helper | v0.1.0 | |
| implements | DbAccountEntity | entity helper | v0.1.0 | |
| implements | DbAccountRelatedEntity | entity helper | v0.1.0 | |
Expand Down Expand Up @@ -94,7 +94,7 @@ Supported orm-m8 features:

dev_dependencies:
build_runner: ^1.0.0
f_orm_m8_sqlite: ^0.6.2
f_orm_m8_sqlite: ^0.6.3
flutter_test:
sdk: flutter

Expand Down
7 changes: 7 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

## [Unreleased]

## [0.6.3] - 2019-05-16

### Added

* Implementation for mapping Duration fields. Currently handled in milliseconds and saved to database as INTEGER
* Implementation for mapping BigInt fields. Saved to database as TEXT to keep precision
* Implementation for DbOpenEntity scaffolding

### Changed

* If the Model class does not implement allowed interfaces (DbEntity or DbOpenEntity) the parser will handle as validation error (not Exception)

## [0.6.2+1] - 2019-05-15

Expand Down
4 changes: 2 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Supported orm-m8 features:
| CompositeConstraint. | primaryKey | CompositeConstraint | v0.4.0 | |
| CompositeConstraint. | foreignKey | CompositeConstraint | - | Planned for v0.7.0 |
| CompositeConstraint. | indexed | CompositeConstraint | - | Planned for v0.7.0 |
| implements | DbOpenEntity | entity helper | - | Planned for v0.7.0 |
| implements | DbOpenEntity | entity helper | v0.6.3 | |
| implements | DbEntity | entity helper | v0.1.0 | |
| implements | DbAccountEntity | entity helper | v0.1.0 | |
| implements | DbAccountRelatedEntity | entity helper | v0.1.0 | |
Expand Down Expand Up @@ -94,7 +94,7 @@ Supported orm-m8 features:

dev_dependencies:
build_runner: ^1.0.0
f_orm_m8_sqlite: ^0.6.2
f_orm_m8_sqlite: ^0.6.3
flutter_test:
sdk: flutter

Expand Down
17 changes: 11 additions & 6 deletions src/lib/generator/model_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ class ModelParser {
}

void _extractEntityMeta() {
validatePreExtractionConditions();
if (!validatePreExtractionConditions()) {
validationIssues.add(ValidationIssue(
isError: true,
message:
"Model ${modelName} does not implement `DbEntity` or `DbOpenEntity` interface!"));
return;
}

final ElementAnnotation elementAnnotationMetadata =
modelClassElement.metadata.firstWhere(
Expand Down Expand Up @@ -80,17 +86,16 @@ class ModelParser {
}
}

void validatePreExtractionConditions() {
bool validatePreExtractionConditions() {
if (isDbEntity.isAssignableFromType(modelClassElement.type)) {
return;
return true;
}

if (isDbOpenEntity.isAssignableFromType(modelClassElement.type)) {
return;
return true;
}

throw Exception(
"Database models must implement `DbEntity` or `DbOpenEntity` interface!");
return false;
}

void _extractEntityAttributes() {
Expand Down
2 changes: 1 addition & 1 deletion src/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: f_orm_m8_sqlite
description: Flutter package to generate SQLite fixture in conjuction with the package f_orm_m8.
version: 0.7.0-pre1
version: 0.6.3
author: Mircea-Tiberiu MATEI<[email protected]>
homepage: https://github.com/matei-tm/f-orm-m8-sqlite

Expand Down
13 changes: 0 additions & 13 deletions src/test/exceptions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,16 @@ import 'utils/test_file_utils.dart';
import 'package:source_gen_test/source_gen_test.dart';

void main() {
LibraryReader library_1;
LibraryReader library_2;
final path = testFilePath('test', 'src', 'model');

setUp(() async {
library_1 = await initializeLibraryReaderForDirectory(
path, "bad_nondbentity_probe.dart");
library_2 = await initializeLibraryReaderForDirectory(
path, "bad_no_datatable_annotation_probe.dart");
});

group('Exceptions tests', () {
final generator = OrmM8GeneratorForAnnotation();

test('Test Database models must implement DbEntity or DbOpenEntity', () async {
String v = await generator.generate(library_1, null);

expect(
v.contains(
'''/*\nException: Database models must implement `DbEntity` or `DbOpenEntity` interface!'''),
true);
});

test(
'Test the DbEntity implementations must be annotated with `@DataTable`!',
() async {
Expand Down
5 changes: 5 additions & 0 deletions src/test/out/non_dbentity_or_dbopenentity.0.caliber
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
Not all the models have passed the validation process. Review the following issues, fix them and rerun the builder:

Error: Model BadNonDbEntityProbe does not implement `DbEntity` or `DbOpenEntity` interface!
*/
14 changes: 14 additions & 0 deletions src/test/validation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void main() {
LibraryReader library_2;
LibraryReader library_3;
LibraryReader library_4;
LibraryReader library_5;

final path = testFilePath('test', 'src', 'model');
final caliber1Path =
Expand All @@ -20,6 +21,8 @@ void main() {
final caliber3Path = testFilePath('test', 'out', 'no_fields.0.caliber');
final caliber4Path =
testFilePath('test', 'out', 'custom_type_field.0.caliber');
final caliber5Path =
testFilePath('test', 'out', 'non_dbentity_or_dbopenentity.0.caliber');

setUp(() async {
library_1 = await initializeLibraryReaderForDirectory(
Expand All @@ -30,6 +33,8 @@ void main() {
await initializeLibraryReaderForDirectory(path, "no_fields_probe.dart");
library_4 = await initializeLibraryReaderForDirectory(
path, "custom_type_field_probe.dart");
library_5 = await initializeLibraryReaderForDirectory(
path, "not_allowed_entity_probe.dart");
});

group('Validation tests', () {
Expand Down Expand Up @@ -63,5 +68,14 @@ void main() {
final expected = await File(caliber4Path).readAsString();
expect(output, expected);
});

test(
'Test validation Database models must implement DbEntity or DbOpenEntity',
() async {
String output = await generator.generate(library_5, null);

final expected = await File(caliber5Path).readAsString();
expect(output, expected);
});
});
}

0 comments on commit ef08b33

Please sign in to comment.