Skip to content

Commit

Permalink
Release 0.11.0 (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitusortner authored Jan 26, 2020
1 parent 635bae7 commit 19036d5
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 69 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

# 0.11.0

### Changes

* Refactor string utility function into extension function
* Refactor annotation check functions to use extension functions
* Refactor type check functions to use extension functions

### 🚀 Features

* Ignore fields of entities by adding ignore annotation
* Handle named constructor parameters and ignore field order
* Exclude static fields from entity mapping

# 0.10.0

### Changes
Expand Down
94 changes: 35 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ This package is still in an early phase and the API will likely change.
1. [Migrations](#migrations)
1. [In-Memory Database](#in-memory-database)
1. [Callback](#callback)
1. [Ignore Fields](#ignore-fields)
1. [Examples](#examples)
1. [Naming](#naming)
1. [Bugs and Feedback](#bugs-and-feedback)
Expand All @@ -38,19 +37,19 @@ This package is still in an early phase and the API will likely change.
The third dependency is `build_runner` which has to be included as a dev dependency just like the generator.

- `floor` holds all the code you are going to use in your application.

- `floor_generator` includes the code for generating the database classes.

- `build_runner` enables a concrete way of generating source code files.

````yaml
dependencies:
flutter:
sdk: flutter
floor: ^0.10.0
floor: ^0.11.0

dev_dependencies:
floor_generator: ^0.10.0
floor_generator: ^0.11.0
build_runner: ^1.7.3
````

Expand All @@ -64,16 +63,16 @@ This package is still in an early phase and the API will likely change.

````dart
// entity/person.dart

import 'package:floor/floor.dart';

@entity
class Person {
@primaryKey
final int id;

final String name;

Person(this.id, this.name);
}
````
Expand All @@ -86,49 +85,49 @@ This package is still in an early phase and the API will likely change.
- You can define queries by adding the `@Query` annotation to a method.
The SQL statement has to get added in parenthesis.
The method must return a `Future` of the `Entity` you're querying for.

- `@insert` marks a method as an insertion method.

```dart
// dao/person_dao.dart
// dao/person_dao.dart
import 'package:floor/floor.dart';
@dao
abstract class PersonDao {
@Query('SELECT * FROM Person')
Future<List<Person>> findAllPersons();
@Query('SELECT * FROM Person WHERE id = :id')
Future<Person> findPersonById(int id);
@insert
Future<void> insertPerson(Person person);
}
```

1. Creating the *Database*

It has to be an abstract class which extends `FloorDatabase`.
Furthermore, it's required to add `@Database()` to the signature of the class.
Make sure to add the created entity to the `entities` attribute of the `@Database` annotation.

In order to make the generated code work, it's required to also add the listed imports.

```dart
// database.dart
// required package imports
import 'dart:async';
import 'package:floor/floor.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
import 'package:sqflite/sqflite.dart' as sqflite;
import 'dao/person_dao.dart';
import 'model/person.dart';
import 'model/person.dart';
part 'database.g.dart'; // the generated code will be there
@Database(version: 1, entities: [Person])
abstract class AppDatabase extends FloorDatabase {
PersonDao get personDao;
Expand All @@ -141,7 +140,7 @@ This package is still in an early phase and the API will likely change.

1. 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`.

1. Use the generated code.
For obtaining an instance of the database, use the generated `$FloorAppDatabase` class, which allows access to a database builder.
The name is composited from `$Floor` and the database class name.
Expand All @@ -154,7 +153,7 @@ This package is still in an early phase and the API will likely change.
final person = await database.findPersonById(1);
await database.insertPerson(person);
```

For further examples take a look at the [example](https://github.com/vitusortner/floor/tree/develop/example) and [floor_test](https://github.com/vitusortner/floor/tree/develop/floor_test) directories.

## Architecture
Expand Down Expand Up @@ -209,7 +208,7 @@ Future<List<City>> findPersonsWithNamesLike(String name);
// usage
final name = '%foo%';
await dao.findPersonsWithNamesLike(name);
```
```

## Persisting Data Changes
Use the `@insert`, `@update` and `@delete` annotations for inserting and changing persistent data.
Expand All @@ -224,7 +223,7 @@ All these methods accept single or multiple entity instances.
- `void` return nothing
- `int` return primary key of inserted item
- `List<int>` return primary keys of inserted items

- **Update**

`@update` marks a method as an update method.
Expand All @@ -233,16 +232,16 @@ All these methods accept single or multiple entity instances.
These methods can return a `Future` of either `void` or `int`.
- `void` return nothing
- `int` return number of changed rows
- **Delete**

- **Delete**

`@delete` marks a method as a deletion method.
These methods can return a `Future` of either `void` or `int`.
- `void` return nothing
- `int` return number of deleted rows

```dart
// examples of changing multiple items with return
// examples of changing multiple items with return
@insert
Future<List<int>> insertPersons(List<Person> person);
Expand Down Expand Up @@ -296,7 +295,7 @@ It has the additional attribute of `tableName` which opens up the possibility to
More information on how to use these can be found in the [Foreign Keys](#foreign-keys) section.
Indices are supported as well.
They can be used by adding an `Index` to the `indices` value of the entity.
For further information of these, please refer to the [Indices](#indices) section.
For further information of these, please refer to the [Indices](#indices) section.

`@PrimaryKey` marks property of a class as the primary key column.
This property has to be of type int.
Expand All @@ -306,11 +305,6 @@ For more information about primary keys and especially compound primary keys, re
`@ColumnInfo` enables custom mapping of single table columns.
With the annotation, it's possible to give columns a custom name and define if the column is able to store `null`.

`@ignore` excludes annotated fields from the library's mapping.
More information on that can be found in the [Ignore Fields](#ignore-fields) section.

Constructors with positional and named parameters are supported out of the box.

```dart
@Entity(tableName: 'person')
class Person {
Expand Down Expand Up @@ -343,7 +337,7 @@ class Person {
## Foreign Keys
Add a list of `ForeignKey`s to the `Entity` annotation of the referencing entity.
`childColumns` define the columns of the current entity, whereas `parentColumns` define the columns of the parent entity.
Foreign key actions can get triggered after defining them for the `onUpdate` and `onDelete` properties.
Foreign key actions can get triggered after defining them for the `onUpdate` and `onDelete` properties.

```dart
@Entity(
Expand Down Expand Up @@ -396,7 +390,7 @@ Whenever are doing changes to your entities, you're required to also migrate the
First, update your entity.
Next, Increase the database version.
Define a `Migration` which specifies a `startVersion`, an `endVersion` and a function that executes SQL to migrate the data.
At last, use `addMigrations()` on the obtained database builder to add migrations.
At last, use `addMigrations()` on the obtained database builder to add migrations.
Don't forget to trigger the code generator again, to create the code for handling the new entity.

```dart
Expand All @@ -408,7 +402,7 @@ class Person {
@ColumnInfo(name: 'custom_name', nullable: false)
final String name;
final String nickname;
Person(this.id, this.name, this.nickname);
Expand Down Expand Up @@ -462,24 +456,6 @@ final database = await $FloorAppDatabase
.build();
```

## Ignore Fields
The `hashCode` property and all static fields of entities are ignored by default and thus excluded from the library's mapping.
In case further fields should be ignored, the `@ignore` annotation should be used and applied as shown in the following snippet.

```dart
class Person {
@primaryKey
final int id;
final String name;
@ignore
String nickname;
Person(this.id, this.name);
}
```

## Examples
For further examples take a look at the [example](https://github.com/vitusortner/floor/tree/develop/example) and [floor_test](https://github.com/vitusortner/floor/tree/develop/floor_test) directories.

Expand Down
14 changes: 14 additions & 0 deletions floor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

# 0.11.0

### Changes

* Refactor string utility function into extension function
* Refactor annotation check functions to use extension functions
* Refactor type check functions to use extension functions

### 🚀 Features

* Ignore fields of entities by adding ignore annotation
* Handle named constructor parameters and ignore field order
* Exclude static fields from entity mapping

# 0.10.0

### Changes
Expand Down
4 changes: 2 additions & 2 deletions floor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ This package is still in an early phase and the API will likely change.
dependencies:
flutter:
sdk: flutter
floor: ^0.10.0
floor: ^0.11.0

dev_dependencies:
floor_generator: ^0.10.0
floor_generator: ^0.11.0
build_runner: ^1.7.3
````

Expand Down
5 changes: 2 additions & 3 deletions floor/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: floor
description: >
A supportive SQLite abstraction for your Flutter applications.
This library is the runtime dependency.
version: 0.10.0
version: 0.11.0
homepage: https://github.com/vitusortner/floor
author: Vitus Ortner <vitusortner.dev@gmail.com>

Expand All @@ -12,8 +12,7 @@ environment:
dependencies:
path: ^1.6.4
sqflite: ^1.2.0
floor_annotation:
path: ../floor_annotation/
floor_annotation: ^0.6.0
meta: ^1.1.8
flutter:
sdk: flutter
Expand Down
5 changes: 4 additions & 1 deletion floor_annotation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 0.6.0

* Add @ignore annotation

# 0.5.0

* Update dependency
Expand Down Expand Up @@ -31,7 +35,6 @@

* Correct mapper instance name referenced by generated query methods


# 0.2.0

### Changes
Expand Down
2 changes: 1 addition & 1 deletion floor_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: floor_annotation
description: >
A supportive SQLite abstraction for your Flutter applications.
Don't use this package. Import the floor package.
version: 0.5.0
version: 0.6.0
homepage: https://github.com/vitusortner/floor
author: Vitus Ortner <vitusortner.dev@gmail.com>

Expand Down
14 changes: 14 additions & 0 deletions floor_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

# 0.11.0

### Changes

* Refactor string utility function into extension function
* Refactor annotation check functions to use extension functions
* Refactor type check functions to use extension functions

### 🚀 Features

* Ignore fields of entities by adding ignore annotation
* Handle named constructor parameters and ignore field order
* Exclude static fields from entity mapping

# 0.10.0

### Changes
Expand Down
5 changes: 2 additions & 3 deletions floor_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: floor_generator
description: >
A supportive SQLite abstraction for your Flutter applications.
This library is the dev dependency.
version: 0.10.0
version: 0.11.0
homepage: https://github.com/vitusortner/floor
author: Vitus Ortner <vitusortner.dev@gmail.com>

Expand All @@ -17,8 +17,7 @@ dependencies:
source_gen: ^0.9.4+7
build_config: ^0.4.1+1
collection: ^1.14.11
floor_annotation:
path: ../floor_annotation/
floor_annotation: ^0.6.0

dev_dependencies:
test: ^1.11.0
Expand Down

0 comments on commit 19036d5

Please sign in to comment.