Add changelog entry, expand docs a bit

This commit is contained in:
Simon Binder 2022-04-03 12:34:21 +02:00
parent 4e508b62ab
commit 6047ec912f
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 22 additions and 5 deletions

View File

@ -1,5 +1,7 @@
## 1.6.0-dev
- Add the `unique()` method to columns and the `uniqueKeys` override to tables
to define unique constraints in Dart tables.
- Add the very experimental `package:drift/wasm.dart` library. It uses WebAssembly
to access sqlite3 without any external JavaScript libraries, but requires you to
add a [WebAssembly module](https://github.com/simolus3/sqlite3.dart/tree/main/sqlite3#wasm-web-support)

View File

@ -95,8 +95,8 @@ extension BuildColumn<T> on ColumnBuilder<T> {
/// [constraint] if that is desired.
///
/// This can be used to implement constraints that drift does not (yet)
/// support (e.g. unique keys, etc.). If you've found a common use-case for
/// this, it should be considered a limitation of drift itself. Please feel
/// support. If you've found a common use-case for this, it should be
/// considered a limitation of drift itself. Please feel
/// free to open an issue at https://github.com/simolus3/drift/issues/new to
/// report that.
///
@ -253,6 +253,9 @@ extension BuildGeneralColumn<T> on _BaseColumnBuilder<T> {
ColumnBuilder<T?> nullable() => _isGenerated();
/// Adds UNIQUE constraint to column.
///
/// Unique constraints spanning multiple keys can be added to a table by
/// overriding [Table.uniqueKeys].
ColumnBuilder<T?> unique() => _isGenerated();
/// Uses a custom [converter] to store custom Dart objects in a single column

View File

@ -62,7 +62,13 @@ abstract class Table extends HasResultSet {
@visibleForOverriding
Set<Column>? get primaryKey => null;
/// Unique constraints in this table.
///
/// When two rows have the same value in _any_ set specified in [uniqueKeys],
/// the database will reject the second row for inserts.
///
/// Override this to specify unique keys:
///
/// ```dart
/// class IngredientInRecipes extends Table {
/// @override
@ -73,10 +79,14 @@ abstract class Table extends HasResultSet {
/// IntColumn get ingredient => integer()();
///
/// IntColumn get amountInGrams => integer().named('amount')();
///}
/// ```
///
/// The getter must return a list of set literals using the `=>` syntax so
/// that the drift generator can understand the code.
///
/// Note that individual columns can also be marked as unique with
/// [BuildGeneralColumn.unique]. This is equivalent to adding a single-element
/// set to this list.
@visibleForOverriding
List<Set<Column>>? get uniqueKeys => null;

View File

@ -262,7 +262,8 @@ dependency_overrides:
moor:
path: /foo/bar
moor_generator:
hosted: foo
hosted:
url: foo
version: ^1.2.3
''');
@ -288,7 +289,8 @@ dependency_overrides:
drift:
path: /foo/bar
drift_dev:
hosted: foo
hosted:
url: foo
version: ^1.2.3
'''),
]).validate();