mirror of https://github.com/AMT-Cheif/drift.git
Merge pull request #321 from DmitriyZaitsev/dz/fix-sql-example
Fix code example for `Getting started with sql` doc
This commit is contained in:
commit
17a1a4f95c
|
@ -55,7 +55,7 @@ CREATE TABLE todos (
|
||||||
|
|
||||||
CREATE TABLE categories (
|
CREATE TABLE categories (
|
||||||
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
|
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
description TEXT,
|
description TEXT
|
||||||
) AS Category; -- see the explanation on "AS Category" below
|
) AS Category; -- see the explanation on "AS Category" below
|
||||||
|
|
||||||
/* after declaring your tables, you can put queries in here. Just
|
/* after declaring your tables, you can put queries in here. Just
|
||||||
|
@ -66,7 +66,7 @@ todosInCategory: SELECT * FROM todos WHERE category = ?;
|
||||||
category, including those entries which aren't in any category at all. */
|
category, including those entries which aren't in any category at all. */
|
||||||
countEntries:
|
countEntries:
|
||||||
SELECT
|
SELECT
|
||||||
c.desc,
|
c.description,
|
||||||
(SELECT COUNT(*) FROM todos WHERE category = c.id) AS amount
|
(SELECT COUNT(*) FROM todos WHERE category = c.id) AS amount
|
||||||
FROM categories c
|
FROM categories c
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
@ -91,6 +91,8 @@ a file called `database.dart` next to the `tables.moor` file you wrote
|
||||||
in the previous step.
|
in the previous step.
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:moor/moor.dart';
|
import 'package:moor/moor.dart';
|
||||||
// These imports are only needed to open the database
|
// These imports are only needed to open the database
|
||||||
import 'package:moor_ffi/moor_ffi.dart';
|
import 'package:moor_ffi/moor_ffi.dart';
|
||||||
|
@ -117,7 +119,7 @@ LazyDatabase _openConnection() {
|
||||||
// put the database file, called db.sqlite here, into the documents folder
|
// put the database file, called db.sqlite here, into the documents folder
|
||||||
// for your app.
|
// for your app.
|
||||||
final dbFolder = await getApplicationDocumentsDirectory();
|
final dbFolder = await getApplicationDocumentsDirectory();
|
||||||
final file = File(p.join(dbFolder, 'db.sqlite'));
|
final file = File(p.join(dbFolder.path, 'db.sqlite'));
|
||||||
return VmDatabase(file);
|
return VmDatabase(file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue