Skip to content

Commit

Permalink
Move annotations to separate module to make the generator testable (#68
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vitusortner authored Mar 1, 2019
1 parent 9297188 commit fc60a51
Showing 20 changed files with 336 additions and 119 deletions.
2 changes: 1 addition & 1 deletion floor/lib/floor.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library floor;

export 'package:floor/src/annotations.dart';
export 'package:floor/src/database.dart';
export 'package:floor_annotation/floor_annotation.dart';
6 changes: 2 additions & 4 deletions floor/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -12,10 +12,8 @@ environment:
dependencies:
flutter:
sdk: flutter
meta: ^1.1.6
path: ^1.6.2
sqflite: ^1.1.1
floor_annotation:
path: ../floor_annotation/

dev_dependencies:
flutter_test:
sdk: flutter
27 changes: 27 additions & 0 deletions floor_annotation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Floor
**A supportive SQLite abstraction for your Flutter applications.**

This library holds all the annotations.

Run the generator with `flutter packages pub run build_runner build`.
To automatically run it, whenever a file changes, use `flutter packages pub run build_runner watch`.

*Floor - the bottom layer of a [Room](https://developer.android.com/topic/libraries/architecture/room).*

## Bugs and Feedback
For bugs, questions and discussions please use the [Github Issues](https://github.com/vitusortner/floor/issues).

## License
Copyright 2019 Vitus Ortner

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
13 changes: 13 additions & 0 deletions floor_annotation/lib/floor_annotation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library floor_annotation;

export 'src/column_info.dart';
export 'src/database.dart';
export 'src/delete.dart';
export 'src/entity.dart';
export 'src/foreign_key.dart';
export 'src/insert.dart';
export 'src/on_conflict_strategy.dart';
export 'src/primary_key.dart';
export 'src/query.dart';
export 'src/transaction.dart';
export 'src/update.dart';
10 changes: 10 additions & 0 deletions floor_annotation/lib/src/column_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// Allows customization of the column associated with this field.
class ColumnInfo {
/// The custom name of the column.
final String name;

/// Defines if the associated column is allowed to contain 'null'.
final bool nullable;

const ColumnInfo({this.name, this.nullable = true});
}
5 changes: 5 additions & 0 deletions floor_annotation/lib/src/database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// Marks a class as a FloorDatabase.
class Database {
/// Marks a class as a FloorDatabase.
const Database();
}
7 changes: 7 additions & 0 deletions floor_annotation/lib/src/delete.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Marks a method as a delete method.
class Delete {
const Delete();
}

/// Marks a method as a delete method.
const delete = Delete();
15 changes: 15 additions & 0 deletions floor_annotation/lib/src/entity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:floor_annotation/src/foreign_key.dart';

/// Marks a class as a database entity (table).
class Entity {
/// The table name of the SQLite table.
final String tableName;

/// List of [ForeignKey] constraints on this entity.
final List<ForeignKey> foreignKeys;

const Entity({this.tableName, this.foreignKeys});
}

/// Marks a class as a database entity (table).
const entity = Entity();
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
import 'package:meta/meta.dart';

/// Marks a class as a FloorDatabase.
class Database {
/// Marks a class as a FloorDatabase.
const Database();
}

/// Marks a class as a database entity (table).
class Entity {
/// The table name of the SQLite table.
final String tableName;

/// List of [ForeignKey] constraints on this entity.
final List<ForeignKey> foreignKeys;

const Entity({this.tableName, this.foreignKeys});
}

/// Marks a class as a database entity (table).
const entity = Entity();

/// Allows customization of the column associated with this field.
class ColumnInfo {
/// The custom name of the column.
final String name;

/// Defines if the associated column is allowed to contain 'null'.
final bool nullable;

const ColumnInfo({this.name, this.nullable = true});
}

/// Marks a field in an [Entity] as the primary key.
class PrimaryKey {
/// Let SQLite auto generate the unique id.
final bool autoGenerate;

/// Defaults [autoGenerate] to false.
const PrimaryKey({this.autoGenerate = false});
}

/// Declares a foreign key on another [Entity].
class ForeignKey {
/// The list of column names in the current [Entity].
@@ -124,76 +84,3 @@ abstract class ForeignKeyAction {
/// to match the new parent key values.
static const CASCADE = 5;
}

/// Marks a method as a query method.
class Query {
/// The SQLite query.
final String value;

const Query(this.value);
}

/// Marks a method as an insert method.
class Insert {
/// How to handle conflicts. Defaults to [OnConflictStrategy.ABORT].
final int onConflict;

/// Marks a method as an insert method.
const Insert({this.onConflict = OnConflictStrategy.ABORT});
}

/// Marks a method as an insert method.
///
/// Defaults conflict strategy to [OnConflictStrategy.ABORT].
const insert = Insert();

/// Marks a method as an update method.
class Update {
/// How to handle conflicts. Defaults to [OnConflictStrategy.ABORT].
final int onConflict;

/// Marks a method as an update method.
const Update({this.onConflict = OnConflictStrategy.ABORT});
}

/// Marks a method as an update method.
///
/// Defaults conflict strategy to [OnConflictStrategy.ABORT].
const update = Update();

/// Marks a method as a delete method.
class Delete {
const Delete();
}

/// Marks a method as a delete method.
const delete = Delete();

/// Set of conflict handling strategies for insert and update methods.
///
/// Check SQLite conflict documentation for details.
abstract class OnConflictStrategy {
/// OnConflict strategy constant to replace the old data and continue the
/// transaction.
static const REPLACE = 1;

/// OnConflict strategy constant to rollback the transaction.
static const ROLLBACK = 2;

/// OnConflict strategy constant to abort the transaction.
static const ABORT = 3;

/// OnConflict strategy constant to fail the transaction.
static const FAIL = 4;

/// OnConflict strategy constant to ignore the conflict.
static const IGNORE = 5;
}

/// Marks a method as a transaction method.
class _Transaction {
const _Transaction();
}

/// Marks a method as a transaction method.
const transaction = _Transaction();
15 changes: 15 additions & 0 deletions floor_annotation/lib/src/insert.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:floor_annotation/src/on_conflict_strategy.dart';

/// Marks a method as an insert method.
class Insert {
/// How to handle conflicts. Defaults to [OnConflictStrategy.ABORT].
final int onConflict;

/// Marks a method as an insert method.
const Insert({this.onConflict = OnConflictStrategy.ABORT});
}

/// Marks a method as an insert method.
///
/// Defaults conflict strategy to [OnConflictStrategy.ABORT].
const insert = Insert();
20 changes: 20 additions & 0 deletions floor_annotation/lib/src/on_conflict_strategy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// Set of conflict handling strategies for insert and update methods.
///
/// Check SQLite conflict documentation for details.
abstract class OnConflictStrategy {
/// OnConflict strategy constant to replace the old data and continue the
/// transaction.
static const REPLACE = 1;

/// OnConflict strategy constant to rollback the transaction.
static const ROLLBACK = 2;

/// OnConflict strategy constant to abort the transaction.
static const ABORT = 3;

/// OnConflict strategy constant to fail the transaction.
static const FAIL = 4;

/// OnConflict strategy constant to ignore the conflict.
static const IGNORE = 5;
}
8 changes: 8 additions & 0 deletions floor_annotation/lib/src/primary_key.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Marks a field in an [Entity] as the primary key.
class PrimaryKey {
/// Let SQLite auto generate the unique id.
final bool autoGenerate;

/// Defaults [autoGenerate] to false.
const PrimaryKey({this.autoGenerate = false});
}
7 changes: 7 additions & 0 deletions floor_annotation/lib/src/query.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Marks a method as a query method.
class Query {
/// The SQLite query.
final String value;

const Query(this.value);
}
7 changes: 7 additions & 0 deletions floor_annotation/lib/src/transaction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Marks a method as a transaction method.
class _Transaction {
const _Transaction();
}

/// Marks a method as a transaction method.
const transaction = _Transaction();
15 changes: 15 additions & 0 deletions floor_annotation/lib/src/update.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:floor_annotation/src/on_conflict_strategy.dart';

/// Marks a method as an update method.
class Update {
/// How to handle conflicts. Defaults to [OnConflictStrategy.ABORT].
final int onConflict;

/// Marks a method as an update method.
const Update({this.onConflict = OnConflictStrategy.ABORT});
}

/// Marks a method as an update method.
///
/// Defaults conflict strategy to [OnConflictStrategy.ABORT].
const update = Update();
13 changes: 13 additions & 0 deletions floor_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: floor_annotation
description: >
A supportive SQLite abstraction for your Flutter applications.
This library is the runtime dependency.
version: 0.0.1
homepage: https://github.com/vitusortner/floor
author: vitusortner

environment:
sdk: '>=2.1.0 <3.0.0'

dependencies:
meta: ^1.1.6
2 changes: 2 additions & 0 deletions floor_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -19,3 +19,5 @@ dependencies:
dev_dependencies:
test: ^1.5.3
build_test: ^0.10.6
floor_annotation:
path: ../floor_annotation/
Loading

0 comments on commit fc60a51

Please sign in to comment.