Skip to content

Commit

Permalink
Prepare 2.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Oct 6, 2022
1 parent ee8499a commit a2e10d9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
21 changes: 21 additions & 0 deletions docs/lib/snippets/tables/advanced.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:drift/drift.dart';

import 'filename.dart';

// #docregion unique
class WithUniqueConstraints extends Table {
IntColumn get a => integer().unique()();
Expand All @@ -15,3 +17,22 @@ class WithUniqueConstraints extends Table {
// Effectively, this table has two unique key sets: (a) and (b, c).
}
// #enddocregion unique

// #docregion view
abstract class CategoryTodoCount extends View {
// Getters define the tables that this view is reading from.
Todos get todos;
Categories get categories;

// Custom expressions can be given a name by defining them as a getter:.
Expression<int> get itemCount => todos.id.count();

@override
Query as() =>
// Views can select columns defined as expression getters on the class, or
// they can reference columns from other tables.
select([categories.description, itemCount])
.from(categories)
.join([innerJoin(todos, todos.category.equalsExp(categories.id))]);
}
// #enddocregion view
38 changes: 22 additions & 16 deletions docs/pages/docs/Getting started/advanced_dart_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ option, toggling this behavior is not compatible with existing database schemas:
As the second point is specific to usages in your app, this documentation only
describes how to migrate stored columns between the format:

{% assign snippets = "package:drift_docs/snippets/migrations/datetime_conversion.dart.excerpt.json" | readString | json_decode %}
{% assign conversion = "package:drift_docs/snippets/migrations/datetime_conversion.dart.excerpt.json" | readString | json_decode %}

Note that the JSON serialization generated by default is not affected by the
datetime mode chosen. By default, drift will serialize `DateTime` values to a
Expand All @@ -308,7 +308,7 @@ text, follow these steps:
__Remember that triggers, views or other custom SQL entries in your database
will require a custom migration that is not covered by this guide.__

{% include "blocks/snippet" snippets = snippets name = "unix-to-text" %}
{% include "blocks/snippet" snippets = conversion name = "unix-to-text" %}

##### Migrating from text to unix timestamps

Expand All @@ -324,7 +324,7 @@ steps:
__Remember that triggers, views or other custom SQL entries in your database
will require a custom migration that is not covered by this guide.__

{% include "blocks/snippet" snippets = snippets name = "text-to-unix" %}
{% include "blocks/snippet" snippets = conversion name = "text-to-unix" %}

Note that this snippet uses the `unixepoch` sqlite3 function, which has been
added in sqlite 3.38. To support older sqlite3 versions, you can use `strftime`
Expand Down Expand Up @@ -391,19 +391,7 @@ as Dart classes.
To do so, write an abstract class extending `View`. This example declares a view reading
the amount of todo-items added to a category in the schema from [the example]({{ 'index.md' | pageUrl }}):

```dart
abstract class CategoryTodoCount extends View {
TodosTable get todos;
Categories get categories;
Expression<int> get itemCount => todos.id.count();
@override
Query as() => select([categories.description, itemCount])
.from(categories)
.join([innerJoin(todos, todos.category.equalsExp(categories.id))]);
}
```
{% include "blocks/snippet" snippets = snippets name = 'view' %}

Inside a Dart view, use

Expand All @@ -425,3 +413,21 @@ Finally, a view needs to be added to a database or accessor by including it in t
@DriftDatabase(tables: [Todos, Categories], views: [CategoryTodoCount])
class MyDatabase extends _$MyDatabase {
```

### Nullability of columns in a view

For a Dart-defined views, expressions defined as an `Expression` getter are
_always_ nullable. This behavior matches `TypedResult.read`, the method used to
read results from a complex select statement with custom columns.

Columns that reference another table's column are nullable if the referenced
column is nullable, or if the selected table does not come from an inner join
(because the whole table could be `null` in that case).

Considering the view from the example above,

- the `itemCount` column is nullable because it is defined as a complex
`Expression`
- the `description` column, referencing `categories.description`, is non-nullable.
This is because it references `categories`, the primary table of the view's
select statement.
2 changes: 1 addition & 1 deletion drift/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.2.0-dev
## 2.2.0

- Always escape column names, avoiding the costs of using a regular expression
to check whether they need to be escaped.
Expand Down
2 changes: 1 addition & 1 deletion drift/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: drift
description: Drift is a reactive library to store relational data in Dart and Flutter applications.
version: 2.1.0
version: 2.2.0
repository: https://github.com/simolus3/drift
homepage: https://drift.simonbinder.eu/
issue_tracker: https://github.com/simolus3/drift/issues
Expand Down
2 changes: 1 addition & 1 deletion drift_dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.2.0-dev
## 2.2.0

- __Potentially breaking bug-fix__: Fix the nullability of columns generated for
Dart-defined views.
Expand Down
4 changes: 2 additions & 2 deletions drift_dev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: drift_dev
description: Dev-dependency for users of drift. Contains a the generator and development tools.
version: 2.2.0-dev
version: 2.2.0
repository: https://github.com/simolus3/drift
homepage: https://drift.simonbinder.eu/
issue_tracker: https://github.com/simolus3/drift/issues
Expand All @@ -25,7 +25,7 @@ dependencies:
io: ^1.0.3

# Drift-specific analysis and apis
drift: '>=2.0.0 <2.2.0'
drift: '>=2.0.0 <2.3.0'
sqlite3: '>=0.1.6 <2.0.0'
sqlparser: ^0.23.2

Expand Down

0 comments on commit a2e10d9

Please sign in to comment.