Explicitly import dart:async for 2.0.0 support

This commit is contained in:
Simon Binder 2019-02-20 17:54:00 +01:00
parent 383120fc97
commit db4948f842
22 changed files with 41 additions and 220 deletions

View File

@ -84,7 +84,7 @@ class MyDatabase {
```
__⚠ Warning:__ Even though it might look like it, the content of a `Table` class does not support full Dart code. It can only
be used to declare the table name, it's primary keys and columns. The code inside of a table class will never be
be used to declare the table name, its primary key and columns. The code inside of a table class will never be
executed. Instead, the generator will take a look at your table classes to figure out how their structure looks like.
This won't work if the body of your tables is not constant. This should not be problem, but please be aware of this as you can't put logic inside these classes.
@ -260,4 +260,4 @@ Implementing this will very likely result in backwards-incompatible changes.
accessible for the generated code
- `GROUP BY` grouping functions
- Support for different database engines
- Support webapps via `AlaSQL` or a different engine
- Support webapps via `AlaSQL` or a different engine

View File

@ -1,11 +0,0 @@
# Files and directories created by pub
.dart_tool/
.packages
# Remove the following pattern if you wish to check in your lock file
pubspec.lock
# Conventional directory for build outputs
build/
# Directory created by dartdoc
doc/api/

View File

@ -1 +0,0 @@
../analysis_options.yaml

View File

@ -1,20 +0,0 @@
import 'package:sally/sally.dart';
part 'tables.g.dart';
class Users extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get userName => text().named('name').withLength(min: 6, max: 12)();
TextColumn get bio => text()();
}
@UseSally(tables: [Users])
class ExampleDb extends _$ExampleDb {
ExampleDb(QueryExecutor e) : super(e);
@override
MigrationStrategy get migration => MigrationStrategy();
@override
int get schemaVersion => 1;
}

View File

@ -1,87 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'tables.dart';
// **************************************************************************
// SallyGenerator
// **************************************************************************
class User {
final int id;
final String userName;
final String bio;
User({this.id, this.userName, this.bio});
@override
int get hashCode =>
((id.hashCode) * 31 + userName.hashCode) * 31 + bio.hashCode;
@override
bool operator ==(other) =>
identical(this, other) ||
(other is User &&
other.id == id &&
other.userName == userName &&
other.bio == bio);
}
class _$UsersTable extends Users implements TableInfo<Users, User> {
final GeneratedDatabase _db;
_$UsersTable(this._db);
@override
GeneratedIntColumn get id =>
GeneratedIntColumn('id', false, hasAutoIncrement: true);
@override
GeneratedTextColumn get userName => GeneratedTextColumn(
'name',
false,
);
@override
GeneratedTextColumn get bio => GeneratedTextColumn(
'bio',
false,
);
@override
List<GeneratedColumn> get $columns => [id, userName, bio];
@override
Users get asDslTable => this;
@override
String get $tableName => 'users';
@override
void validateIntegrity(User instance, bool isInserting) =>
id.isAcceptableValue(instance.id, isInserting) &&
userName.isAcceptableValue(instance.userName, isInserting) &&
bio.isAcceptableValue(instance.bio, isInserting);
@override
Set<GeneratedColumn> get $primaryKey => Set();
@override
User map(Map<String, dynamic> data) {
final intType = _db.typeSystem.forDartType<int>();
final stringType = _db.typeSystem.forDartType<String>();
return User(
id: intType.mapFromDatabaseResponse(data['id']),
userName: stringType.mapFromDatabaseResponse(data['name']),
bio: stringType.mapFromDatabaseResponse(data['bio']),
);
}
@override
Map<String, Variable> entityToSql(User d) {
final map = <String, Variable>{};
if (d.id != null) {
map['id'] = Variable<int, IntType>(d.id);
}
if (d.userName != null) {
map['name'] = Variable<String, StringType>(d.userName);
}
if (d.bio != null) {
map['bio'] = Variable<String, StringType>(d.bio);
}
return map;
}
}
abstract class _$ExampleDb extends GeneratedDatabase {
_$ExampleDb(QueryExecutor e) : super(const SqlTypeSystem.withDefaults(), e);
_$UsersTable get users => _$UsersTable(this);
@override
List<TableInfo> get allTables => [users];
}

View File

@ -1,42 +0,0 @@
import 'package:sally/sally.dart';
import 'package:sqlite2/sqlite.dart';
class MemoryDatabase extends QueryExecutor {
Database _db;
@override
Future<bool> ensureOpen() {
_db ??= Database.inMemory();
return Future.value(true);
}
@override
Future<void> runCustom(String statement) {
return _db.execute(statement);
}
@override
Future<int> runDelete(String statement, List args) {
return _db.execute(statement,
params: args.map((x) => x.toString()).toList());
}
@override
Future<int> runInsert(String statement, List args) {
return runDelete(statement, args);
}
@override
Future<List<Map<String, dynamic>>> runSelect(String statement, List args) {
return _db
.query(statement, params: args.map((x) => x.toString()).toList())
.fold([], (list, row) {
return list..add(row.toMap());
});
}
@override
Future<int> runUpdate(String statement, List args) {
return runDelete(statement, args);
}
}

View File

@ -1,19 +0,0 @@
name: end_to_end_testing
description: A project to test sally.
environment:
sdk: '>=2.0.0 <3.0.0'
dependencies:
sally:
path: ../sally
sqlite2: ^0.5.0
path: ^1.4.1
dev_dependencies:
sally_generator:
path: ../sally_generator
built_value_generator: ^6.3.0
build_runner:
build_test:
test: ^1.0.0

View File

@ -1,11 +0,0 @@
import 'package:end_to_end_testing/tables.dart';
import 'package:end_to_end_testing/vm_database.dart';
import 'package:test_api/test_api.dart';
void main() {
test('Generates tables', () async* {
final db = ExampleDb(MemoryDatabase());
await db.handleDatabaseCreation(executor: db.executor.runCustom);
});
}

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sally/sally.dart';
import 'package:sally/src/runtime/structure/columns.dart';
import 'package:sally/src/runtime/structure/table_info.dart';

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sally/src/runtime/components/component.dart';
import 'package:sally/src/runtime/executor/executor.dart';
import 'package:sally/src/runtime/statements/query.dart';

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:sally/sally.dart';
import 'package:sally/src/runtime/components/component.dart';

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sally/sally.dart';
import 'package:sally/src/runtime/components/component.dart';
import 'package:sally/src/runtime/components/limit.dart';

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sally/sally.dart';
import 'package:sally/src/runtime/components/component.dart';

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sally/sally.dart';
import 'package:test_api/test_api.dart';

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sally/sally.dart';
import 'package:test_api/test_api.dart';

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:sally/sally.dart';
import 'package:test_api/test_api.dart';

View File

@ -84,7 +84,7 @@ class MyDatabase {
```
__⚠ Warning:__ Even though it might look like it, the content of a `Table` class does not support full Dart code. It can only
be used to declare the table name, it's primary keys and columns. The code inside of a table class will never be
be used to declare the table name, its primary key and columns. The code inside of a table class will never be
executed. Instead, the generator will take a look at your table classes to figure out how their structure looks like.
This won't work if the body of your tables is not constant. This should not be problem, but please be aware of this as you can't put logic inside these classes.

View File

@ -32,16 +32,13 @@ class Database extends _$Database {
int get schemaVersion => 1;
@override
MigrationStrategy get migration => MigrationStrategy(
onCreate: (Migrator m) {
return m.createAllTables();
},
onUpgrade: (Migrator m, int from, int to) async {
if (from == 1) {
await m.addColumn(todos, todos.targetDate);
}
}
);
MigrationStrategy get migration => MigrationStrategy(onCreate: (Migrator m) {
return m.createAllTables();
}, onUpgrade: (Migrator m, int from, int to) async {
if (from == 1) {
await m.addColumn(todos, todos.targetDate);
}
});
Stream<List<TodoEntry>> allEntries() {
return select(todos).watch();

View File

@ -12,7 +12,6 @@ class MyApp extends StatefulWidget {
}
class MyAppState extends State<MyApp> {
Database _db;
@override
@ -37,7 +36,6 @@ class MyAppState extends State<MyApp> {
}
class DatabaseProvider extends InheritedWidget {
final Database db;
DatabaseProvider({@required this.db, Widget child}) : super(child: child);
@ -47,5 +45,7 @@ class DatabaseProvider extends InheritedWidget {
return oldWidget.db != db;
}
static Database provideDb(BuildContext ctx) => (ctx.inheritFromWidgetOfExactType(DatabaseProvider) as DatabaseProvider).db;
}
static Database provideDb(BuildContext ctx) =>
(ctx.inheritFromWidgetOfExactType(DatabaseProvider) as DatabaseProvider)
.db;
}

View File

@ -3,7 +3,6 @@ import 'package:sally_example/database.dart';
import 'package:sally_example/main.dart';
class TodoCard extends StatelessWidget {
final TodoEntry entry;
TodoCard(this.entry) : super(key: ObjectKey(entry.id));

View File

@ -3,17 +3,21 @@ import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:sally/diff_util.dart';
typedef Widget ItemBuilder<T>(BuildContext context, T item, Animation<double> anim);
typedef Widget RemovedItemBuilder<T>(BuildContext context, T item, Animation<double> anim);
typedef Widget ItemBuilder<T>(
BuildContext context, T item, Animation<double> anim);
typedef Widget RemovedItemBuilder<T>(
BuildContext context, T item, Animation<double> anim);
/// An [AnimatedList] that shows the result of a sally query stream.
class SallyAnimatedList<T> extends StatefulWidget {
final Stream<List<T>> stream;
final ItemBuilder<T> itemBuilder;
final RemovedItemBuilder<T> removedItemBuilder;
SallyAnimatedList({@required this.stream, @required this.itemBuilder, @required this.removedItemBuilder});
SallyAnimatedList(
{@required this.stream,
@required this.itemBuilder,
@required this.removedItemBuilder});
@override
_SallyAnimatedListState createState() {
@ -22,7 +26,6 @@ class SallyAnimatedList<T> extends StatefulWidget {
}
class _SallyAnimatedListState<T> extends State<SallyAnimatedList<T>> {
List<T> _lastSnapshot;
int _initialItemCount;
@ -101,8 +104,7 @@ class _SallyAnimatedListState<T> extends State<SallyAnimatedList<T>> {
@override
Widget build(BuildContext context) {
if (_lastSnapshot == null)
return const SizedBox();
if (_lastSnapshot == null) return const SizedBox();
return AnimatedList(
key: _key,
@ -115,4 +117,4 @@ class _SallyAnimatedListState<T> extends State<SallyAnimatedList<T>> {
},
);
}
}
}

View File

@ -1,3 +1 @@
void insertIntoSortedList<T>(List<T> list, T entry, {int compare(T a, T b)}) {
}
void insertIntoSortedList<T>(List<T> list, T entry, {int compare(T a, T b)}) {}