mirror of https://github.com/AMT-Cheif/drift.git
Copy updated readme
This commit is contained in:
parent
c4d696a04c
commit
e43a5dea60
30
README.md
30
README.md
|
@ -189,6 +189,34 @@ If a column is nullable or has a default value (this includes auto-increments),
|
||||||
can be omitted. All other fields must be set and non-null. The `insert` method will throw
|
can be omitted. All other fields must be set and non-null. The `insert` method will throw
|
||||||
otherwise.
|
otherwise.
|
||||||
|
|
||||||
|
### Custom statements
|
||||||
|
You can also issue custom queries by calling `customUpdate` for update and deletes and
|
||||||
|
`customSelect` or `customSelectStream` for select statements. Using the todo example
|
||||||
|
above, here is a simple custom query that loads all categories and how many items are
|
||||||
|
in each category:
|
||||||
|
```dart
|
||||||
|
class CategoryWithCount {
|
||||||
|
final Category category;
|
||||||
|
final int count; // amount of entries in this category
|
||||||
|
|
||||||
|
CategoryWithCount(this.category, this.count);
|
||||||
|
}
|
||||||
|
|
||||||
|
// then, in the database class:
|
||||||
|
Stream<List<CategoryWithCount>> categoriesWithCount() {
|
||||||
|
// select all categories and load how many associated entries there are for
|
||||||
|
// each category
|
||||||
|
return customSelectStream(
|
||||||
|
'SELECT *, (SELECT COUNT(*) FROM todos WHERE category = c.id) AS "amount" FROM categories c;',
|
||||||
|
readsFrom: Set.of([todos, categories])).map((rows) {
|
||||||
|
// when we have the result set, map each row to the data class
|
||||||
|
return rows
|
||||||
|
.map((row) => CategoryWithCount(Category.fromData(row.data, this), row.readInt('amount')))
|
||||||
|
.toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Migrations
|
## Migrations
|
||||||
Sally provides a migration API that can be used to gradually apply schema changes after bumping
|
Sally provides a migration API that can be used to gradually apply schema changes after bumping
|
||||||
the `schemaVersion` getter inside the `Database` class. To use it, override the `migration`
|
the `schemaVersion` getter inside the `Database` class. To use it, override the `migration`
|
||||||
|
@ -226,6 +254,8 @@ You can also add individual tables or drop them.
|
||||||
|
|
||||||
## TODO-List and current limitations
|
## TODO-List and current limitations
|
||||||
### Limitations (at the moment)
|
### Limitations (at the moment)
|
||||||
|
Please note that a workaround for most on this list exists with custom statements.
|
||||||
|
|
||||||
- No joins
|
- No joins
|
||||||
- No `group by` or window functions
|
- No `group by` or window functions
|
||||||
- Custom primary key support is very limited
|
- Custom primary key support is very limited
|
||||||
|
|
Loading…
Reference in New Issue