Replace null with Optional
This commit is contained in:
parent
0204977281
commit
8d3c8b9121
34 changed files with 403 additions and 333 deletions
|
@ -19,7 +19,8 @@ abstract class QueryBase<T> {
|
|||
|
||||
/// The list of fields returned by this query.
|
||||
///
|
||||
/// If it's `null`, then this query will perform a `SELECT *`.
|
||||
/// @deprecated If it's `null`, then this query will perform a `SELECT *`.
|
||||
/// If it's empty, then this query will perform a `SELECT *`.
|
||||
List<String> get fields;
|
||||
|
||||
/// A String of all [fields], joined by a comma (`,`).
|
||||
|
@ -42,6 +43,7 @@ abstract class QueryBase<T> {
|
|||
|
||||
Future<List<T>> get(QueryExecutor executor) async {
|
||||
var sql = compile({});
|
||||
|
||||
return executor
|
||||
.query(tableName, sql, substitutionValues)
|
||||
.then((it) => it.map(deserialize).toList());
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:angel_orm_test/src/models/car.dart';
|
|||
@Expose('/api/cars')
|
||||
class CarController extends Controller {
|
||||
@Expose('/luxury')
|
||||
Future<List<Car?>> getLuxuryCars(QueryExecutor connection) {
|
||||
Future<List<Car>> getLuxuryCars(QueryExecutor connection) {
|
||||
var query = CarQuery();
|
||||
query.where
|
||||
?..familyFriendly.equals(false)
|
||||
|
|
|
@ -2,6 +2,8 @@ import 'dart:async';
|
|||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'models/book.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
import 'util.dart';
|
||||
|
||||
belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||
|
@ -17,10 +19,10 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
// Insert an author
|
||||
var query = AuthorQuery()..values.name = 'J.K. Rowling';
|
||||
jkRowling = await query.insert(executor);
|
||||
jkRowling = (await query.insert(executor)).value;
|
||||
|
||||
query.values.name = 'J.K. Jameson';
|
||||
jameson = await query.insert(executor);
|
||||
jameson = (await query.insert(executor)).value;
|
||||
|
||||
// And a book
|
||||
var bookQuery = BookQuery();
|
||||
|
@ -29,7 +31,7 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
..partnerAuthorId = int.parse(jameson!.id!)
|
||||
..name = 'Deathly Hallows';
|
||||
|
||||
deathlyHallows = await bookQuery.insert(executor);
|
||||
deathlyHallows = (await bookQuery.insert(executor)).value;
|
||||
});
|
||||
|
||||
tearDown(() => close!(executor));
|
||||
|
@ -37,10 +39,10 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
group('selects', () {
|
||||
test('select all', () async {
|
||||
var query = BookQuery();
|
||||
List<Book?> books = await query.get(executor);
|
||||
List<Book> books = await query.get(executor);
|
||||
expect(books, hasLength(1));
|
||||
|
||||
var book = books.first!;
|
||||
var book = books.first;
|
||||
print(book.toJson());
|
||||
expect(book.id, deathlyHallows!.id);
|
||||
expect(book.name, deathlyHallows!.name);
|
||||
|
@ -70,10 +72,10 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
test('where clause', () async {
|
||||
var query = BookQuery()
|
||||
..where!.name.equals('Goblet of Fire')
|
||||
..orWhere((w) => w!.authorId.equals(int.parse(jkRowling!.id!)));
|
||||
..orWhere((w) => w.authorId.equals(int.parse(jkRowling!.id!)));
|
||||
print(query.compile(Set()));
|
||||
|
||||
List<Book> books = await query.get(executor) as List<Book>;
|
||||
List<Book> books = await query.get(executor);
|
||||
expect(books, hasLength(1));
|
||||
|
||||
var book = books.first;
|
||||
|
@ -97,10 +99,10 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
..unionAll(query3);
|
||||
print(query1.compile(Set()));
|
||||
|
||||
List<Book?> books = await query1.get(executor);
|
||||
List<Book> books = await query1.get(executor);
|
||||
expect(books, hasLength(1));
|
||||
|
||||
var book = books.first!;
|
||||
var book = books.first;
|
||||
print(book.toJson());
|
||||
expect(book.id, deathlyHallows!.id);
|
||||
expect(book.name, deathlyHallows!.name);
|
||||
|
@ -113,7 +115,7 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
test('order by', () async {
|
||||
var query = AuthorQuery()..orderBy(AuthorFields.name, descending: true);
|
||||
List<Author?> authors = await query.get(executor);
|
||||
List<Author> authors = await query.get(executor);
|
||||
expect(authors, [jkRowling, jameson]);
|
||||
});
|
||||
});
|
||||
|
@ -128,7 +130,7 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
printSeparator('Delete stream test');
|
||||
var query = BookQuery()..where!.name.equals(deathlyHallows!.name!);
|
||||
print(query.compile(Set(), preamble: 'DELETE', withFields: false));
|
||||
List<Book>? books = await query.delete(executor) as List<Book>;
|
||||
List<Book>? books = await query.delete(executor);
|
||||
expect(books, hasLength(1));
|
||||
|
||||
var book = books.first;
|
||||
|
|
|
@ -18,7 +18,7 @@ customExprTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
nQuery.values
|
||||
..createdAt = now
|
||||
..updatedAt = now;
|
||||
numbersModel = await nQuery.insert(executor);
|
||||
numbersModel = (await nQuery.insert(executor)).value;
|
||||
});
|
||||
|
||||
tearDown(() => close!(executor));
|
||||
|
|
|
@ -25,7 +25,7 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
setUp(() async {
|
||||
var query = UnorthodoxQuery()..values.name = 'Hey';
|
||||
unorthodox = await query.insert(executor);
|
||||
unorthodox = (await query.insert(executor)).value;
|
||||
});
|
||||
|
||||
test('belongs to', () async {
|
||||
|
@ -42,12 +42,12 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
setUp(() async {
|
||||
var wjQuery = WeirdJoinQuery()..values.joinName = unorthodox!.name;
|
||||
weirdJoin = await wjQuery.insert(executor);
|
||||
weirdJoin = (await wjQuery.insert(executor)).value;
|
||||
|
||||
var gbQuery = SongQuery()
|
||||
..values.weirdJoinId = weirdJoin!.id
|
||||
..values.title = 'Girl Blue';
|
||||
girlBlue = await gbQuery.insert(executor);
|
||||
girlBlue = (await gbQuery.insert(executor)).value;
|
||||
});
|
||||
|
||||
test('has one', () async {
|
||||
|
@ -65,7 +65,7 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
..values.parent = weirdJoin!.id
|
||||
..values.i = i;
|
||||
var model = await query.insert(executor);
|
||||
numbas.add(model);
|
||||
numbas.add(model.value);
|
||||
}
|
||||
|
||||
var query = WeirdJoinQuery()..where!.id.equals(weirdJoin!.id!);
|
||||
|
@ -76,7 +76,8 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
test('many to many', () async {
|
||||
var fooQuery = FooQuery()..values.bar = 'baz';
|
||||
var fooBar = await fooQuery.insert(executor).then((foo) => foo!.bar!);
|
||||
var fooBar =
|
||||
await fooQuery.insert(executor).then((foo) => foo.value.bar);
|
||||
var pivotQuery = FooPivotQuery()
|
||||
..values.weirdJoinId = weirdJoin!.id
|
||||
..values.fooBar = fooBar;
|
||||
|
@ -86,7 +87,7 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
var foo = await (fooQuery.getOne(executor) as FutureOr<Foo>);
|
||||
print(foo.toJson());
|
||||
print(weirdJoin!.toJson());
|
||||
expect(foo.weirdJoins![0]!.id, weirdJoin!.id);
|
||||
expect(foo.weirdJoins![0].id, weirdJoin!.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ enumAndNestedTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
setUp(() async {
|
||||
var query = HasCarQuery();
|
||||
query.values.type = CarType.sedan;
|
||||
initialValue = await query.insert(executor);
|
||||
initialValue = (await query.insert(executor)).value;
|
||||
});
|
||||
|
||||
test('query by enum', () async {
|
||||
|
|
|
@ -14,7 +14,7 @@ hasManyTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
var query = TreeQuery()..values.rings = 10;
|
||||
|
||||
executor = await createExecutor();
|
||||
appleTree = await query.insert(executor);
|
||||
appleTree = (await query.insert(executor)).value;
|
||||
treeId = int.parse(appleTree!.id!);
|
||||
});
|
||||
|
||||
|
@ -44,8 +44,8 @@ hasManyTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
..values.treeId = treeId
|
||||
..values.commonName = 'Banana';
|
||||
|
||||
apple = await appleQuery.insert(executor);
|
||||
banana = await bananaQuery.insert(executor);
|
||||
apple = (await appleQuery.insert(executor)).value;
|
||||
banana = (await bananaQuery.insert(executor)).value;
|
||||
});
|
||||
|
||||
test('can fetch any children', () async {
|
||||
|
|
|
@ -44,7 +44,7 @@ hasMapTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
query.values
|
||||
..value = {'foo': 'bar'}
|
||||
..list = ['1', 2, 3.0];
|
||||
initialValue = await query.insert(executor);
|
||||
initialValue = (await query.insert(executor)).value;
|
||||
});
|
||||
|
||||
test('get all', () async {
|
||||
|
|
|
@ -12,7 +12,7 @@ hasOneTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
setUp(() async {
|
||||
executor = await createExecutor();
|
||||
var query = LegQuery()..values.name = 'Left';
|
||||
originalLeg = await query.insert(executor);
|
||||
originalLeg = (await query.insert(executor)).value;
|
||||
});
|
||||
|
||||
tearDown(() => close!(executor));
|
||||
|
|
|
@ -48,10 +48,10 @@ manyToManyTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
var canPubQuery = RoleQuery()..values.name = 'can_pub';
|
||||
var canSubQuery = RoleQuery()..values.name = 'can_sub';
|
||||
canPub = await canPubQuery.insert(executor);
|
||||
canPub = (await canPubQuery.insert(executor)).value;
|
||||
print('=== CANPUB: ${canPub?.toJson()}');
|
||||
// await dumpQuery(canPubQuery.compile(Set()));
|
||||
canSub = await canSubQuery.insert(executor);
|
||||
canSub = (await canSubQuery.insert(executor)).value;
|
||||
print('=== CANSUB: ${canSub?.toJson()}');
|
||||
|
||||
var thosakweQuery = UserQuery();
|
||||
|
@ -59,7 +59,7 @@ manyToManyTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
..username = 'thosakwe'
|
||||
..password = 'Hahahahayoureallythoughtiwasstupidenoughtotypethishere'
|
||||
..email = 'thosakwe AT gmail.com';
|
||||
thosakwe = await thosakweQuery.insert(executor);
|
||||
thosakwe = (await thosakweQuery.insert(executor)).value;
|
||||
print('=== THOSAKWE: ${thosakwe?.toJson()}');
|
||||
|
||||
// Allow thosakwe to publish...
|
||||
|
@ -95,7 +95,7 @@ manyToManyTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
Future<User?> fetchThosakwe() async {
|
||||
var query = UserQuery()..where!.id.equals(int.parse(thosakwe!.id!));
|
||||
return await query.getOne(executor);
|
||||
return (await query.getOne(executor)).value;
|
||||
}
|
||||
|
||||
test('fetch roles for user', () async {
|
||||
|
|
|
@ -4,6 +4,8 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'book.g.dart';
|
||||
|
||||
@serializable
|
||||
|
|
|
@ -50,7 +50,7 @@ class AuthorMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class BookQuery extends Query<Book?, BookQueryWhere?> {
|
||||
class BookQuery extends Query<Book, BookQueryWhere> {
|
||||
BookQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -106,8 +106,10 @@ class BookQuery extends Query<Book?, BookQueryWhere?> {
|
|||
return BookQueryWhere(this);
|
||||
}
|
||||
|
||||
static Book? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Book> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Book(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -115,18 +117,19 @@ class BookQuery extends Query<Book?, BookQueryWhere?> {
|
|||
name: (row[5] as String?));
|
||||
if (row.length > 6) {
|
||||
model = model.copyWith(
|
||||
author: AuthorQuery.parseRow(row.skip(6).take(4).toList()));
|
||||
author: AuthorQuery.parseRow(row.skip(6).take(4).toList()).value);
|
||||
}
|
||||
if (row.length > 10) {
|
||||
model = model.copyWith(
|
||||
partnerAuthor: AuthorQuery.parseRow(row.skip(10).take(4).toList()));
|
||||
partnerAuthor:
|
||||
AuthorQuery.parseRow(row.skip(10).take(4).toList()).value);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Book deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
AuthorQuery? get author {
|
||||
|
@ -215,7 +218,7 @@ class BookQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class AuthorQuery extends Query<Author?, AuthorQueryWhere?> {
|
||||
class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
||||
AuthorQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -253,19 +256,21 @@ class AuthorQuery extends Query<Author?, AuthorQueryWhere?> {
|
|||
return AuthorQueryWhere(this);
|
||||
}
|
||||
|
||||
static Author? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Author> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Author(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
updatedAt: (row[2] as DateTime?),
|
||||
name: (row[3] as String?));
|
||||
return model;
|
||||
createdAt: (row[1]),
|
||||
updatedAt: (row[2]),
|
||||
name: (row[3]));
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Author deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
part 'car.g.dart';
|
||||
|
||||
@serializable
|
||||
|
|
|
@ -30,7 +30,7 @@ class CarMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class CarQuery extends Query<Car?, CarQueryWhere?> {
|
||||
class CarQuery extends Query<Car, CarQueryWhere> {
|
||||
CarQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -75,8 +75,10 @@ class CarQuery extends Query<Car?, CarQueryWhere?> {
|
|||
return CarQueryWhere(this);
|
||||
}
|
||||
|
||||
static Car? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Car> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Car(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -85,12 +87,12 @@ class CarQuery extends Query<Car?, CarQueryWhere?> {
|
|||
description: (row[4] as String?),
|
||||
familyFriendly: (row[5] as bool?),
|
||||
recalledAt: (row[6] as DateTime?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Car deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'custom_expr.g.dart';
|
||||
|
||||
@serializable
|
||||
|
|
|
@ -46,7 +46,7 @@ class AlphabetMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class NumbersQuery extends Query<Numbers?, NumbersQueryWhere?> {
|
||||
class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
|
||||
NumbersQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -85,19 +85,21 @@ class NumbersQuery extends Query<Numbers?, NumbersQueryWhere?> {
|
|||
return NumbersQueryWhere(this);
|
||||
}
|
||||
|
||||
static Numbers? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Numbers> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Numbers(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
updatedAt: (row[2] as DateTime?),
|
||||
two: (row[3] as int?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Numbers deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +148,7 @@ class NumbersQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class AlphabetQuery extends Query<Alphabet?, AlphabetQueryWhere?> {
|
||||
class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
|
||||
AlphabetQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -190,8 +192,10 @@ class AlphabetQuery extends Query<Alphabet?, AlphabetQueryWhere?> {
|
|||
return AlphabetQueryWhere(this);
|
||||
}
|
||||
|
||||
static Alphabet? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Alphabet> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Alphabet(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -199,14 +203,14 @@ class AlphabetQuery extends Query<Alphabet?, AlphabetQueryWhere?> {
|
|||
value: (row[3] as String?));
|
||||
if (row.length > 5) {
|
||||
model = model.copyWith(
|
||||
numbers: NumbersQuery.parseRow(row.skip(5).take(4).toList()));
|
||||
numbers: NumbersQuery.parseRow(row.skip(5).take(4).toList()).value);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Alphabet deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
NumbersQuery? get numbers {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:angel_migration/angel_migration.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'email_indexed.g.dart';
|
||||
|
||||
// * https://github.com/angel-dart/angel/issues/116
|
||||
|
|
|
@ -75,7 +75,7 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
@override
|
||||
final RoleQueryValues values = RoleQueryValues();
|
||||
|
||||
RoleQueryWhere? _where;
|
||||
late RoleQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
|
@ -102,42 +102,44 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
return RoleQueryWhere(this);
|
||||
}
|
||||
|
||||
static Role? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Role> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Role(role: (row[0] as String?));
|
||||
if (row.length > 1) {
|
||||
model = model.copyWith(
|
||||
users: [UserQuery.parseRow(row.skip(1).take(3).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
var rowData = UserQuery.parseRow(row.skip(1).take(3).toList());
|
||||
if (rowData.isPresent) {
|
||||
model = model.copyWith(users: [rowData.value]);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Role deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline?.contains('roles') == true &&
|
||||
trampoline?.contains('role_users') == true));
|
||||
return (!(trampoline.contains('roles') == true &&
|
||||
trampoline.contains('role_users') == true));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.role == model!.role);
|
||||
var idx = out.indexWhere((m) => m.role == model.role);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users)..addAll(model!.users));
|
||||
users: List<_User>.from(l.users)..addAll(model.users));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -146,16 +148,16 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<Role?>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m!.role == model!.role);
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.role == model.role);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx]!;
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users)..addAll(model!.users));
|
||||
users: List<_User>.from(l.users)..addAll(model.users));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -165,15 +167,15 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.role == model!.role);
|
||||
var idx = out.indexWhere((m) => m.role == model.role);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users)..addAll(model!.users));
|
||||
users: List<_User>.from(l.users)..addAll(model.users));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -208,7 +210,7 @@ class RoleQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class RoleUserQuery extends Query<RoleUser?, RoleUserQueryWhere?> {
|
||||
class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||
RoleUserQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -257,23 +259,30 @@ class RoleUserQuery extends Query<RoleUser?, RoleUserQueryWhere?> {
|
|||
return RoleUserQueryWhere(this);
|
||||
}
|
||||
|
||||
static RoleUser? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<RoleUser> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = RoleUser();
|
||||
if (row.length > 2) {
|
||||
model = model.copyWith(
|
||||
role: RoleQuery.parseRow(row.skip(2).take(1).toList()));
|
||||
var r = RoleQuery.parseRow(row.skip(2).take(1).toList());
|
||||
if (r.isPresent) {
|
||||
model = model.copyWith(role: r.value);
|
||||
}
|
||||
}
|
||||
if (row.length > 3) {
|
||||
model = model.copyWith(
|
||||
user: UserQuery.parseRow(row.skip(3).take(3).toList()));
|
||||
var u = UserQuery.parseRow(row.skip(3).take(3).toList());
|
||||
if (u.isPresent) {
|
||||
model = model.copyWith(
|
||||
user: UserQuery.parseRow(row.skip(3).take(3).toList()).value);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
RoleUser deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
RoleQuery? get role {
|
||||
|
@ -342,7 +351,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
|||
@override
|
||||
final UserQueryValues values = UserQueryValues();
|
||||
|
||||
UserQueryWhere _where;
|
||||
UserQueryWhere? _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
|
@ -360,7 +369,7 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
|||
}
|
||||
|
||||
@override
|
||||
UserQueryWhere get where {
|
||||
UserQueryWhere? get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
|
@ -369,30 +378,34 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
|||
return UserQueryWhere(this);
|
||||
}
|
||||
|
||||
static User? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<User> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = User(
|
||||
email: (row[0] as String?),
|
||||
name: (row[1] as String?),
|
||||
password: (row[2] as String?));
|
||||
if (row.length > 3) {
|
||||
model = model.copyWith(
|
||||
roles: [RoleQuery.parseRow(row.skip(3).take(1).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
var d = RoleQuery.parseRow(row.skip(3).take(1).toList());
|
||||
|
||||
model = model.copyWith(roles: [d.value]);
|
||||
// roles: [RoleQuery.parseRow(row.skip(3).take(1).toList())]
|
||||
// .where((x) => x != null)
|
||||
// .toList());
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
User deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline?.contains('users') == true &&
|
||||
trampoline?.contains('role_users') == true));
|
||||
return (!(trampoline.contains('users') == true &&
|
||||
trampoline.contains('role_users') == true));
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -586,15 +599,12 @@ class User implements _User {
|
|||
final List<_Role> roles;
|
||||
|
||||
User copyWith(
|
||||
{String? email,
|
||||
String? name,
|
||||
String? password,
|
||||
List<_Role> roles = const []}) {
|
||||
{String? email, String? name, String? password, List<_Role>? roles}) {
|
||||
return User(
|
||||
email: email ?? this.email,
|
||||
name: name ?? this.name,
|
||||
password: password ?? this.password,
|
||||
roles: roles);
|
||||
roles: roles ?? []);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
|
|
|
@ -2,6 +2,8 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
// import 'car.dart';
|
||||
part 'has_car.g.dart';
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class HasCarMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class HasCarQuery extends Query<HasCar?, HasCarQueryWhere?> {
|
||||
class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
||||
HasCarQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -65,19 +65,21 @@ class HasCarQuery extends Query<HasCar?, HasCarQueryWhere?> {
|
|||
return HasCarQueryWhere(this);
|
||||
}
|
||||
|
||||
static HasCar? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<HasCar> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = HasCar(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
updatedAt: (row[2] as DateTime?),
|
||||
type: row[3] == null ? null : CarType.values[(row[3] as int)]);
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
HasCar deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'has_map.g.dart';
|
||||
|
||||
// String _boolToCustom(bool v) => v ? 'yes' : 'no';
|
||||
|
|
|
@ -25,7 +25,7 @@ class HasMapMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class HasMapQuery extends Query<HasMap?, HasMapQueryWhere?> {
|
||||
class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
||||
HasMapQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -63,17 +63,19 @@ class HasMapQuery extends Query<HasMap?, HasMapQueryWhere?> {
|
|||
return HasMapQueryWhere(this);
|
||||
}
|
||||
|
||||
static HasMap? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<HasMap> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = HasMap(
|
||||
value: (row[0] as Map<dynamic, dynamic>?),
|
||||
list: (row[1] as List<dynamic>?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
HasMap deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'leg.g.dart';
|
||||
|
||||
@serializable
|
||||
|
|
|
@ -45,7 +45,7 @@ class FootMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class LegQuery extends Query<Leg?, LegQueryWhere?> {
|
||||
class LegQuery extends Query<Leg, LegQueryWhere> {
|
||||
LegQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -94,8 +94,10 @@ class LegQuery extends Query<Leg?, LegQueryWhere?> {
|
|||
return LegQueryWhere(this);
|
||||
}
|
||||
|
||||
static Leg? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Leg> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Leg(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -103,14 +105,14 @@ class LegQuery extends Query<Leg?, LegQueryWhere?> {
|
|||
name: (row[3] as String?));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(
|
||||
foot: FootQuery.parseRow(row.skip(4).take(5).toList()));
|
||||
foot: FootQuery.parseRow(row.skip(4).take(5).toList()).value);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Leg deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
FootQuery? get foot {
|
||||
|
@ -172,7 +174,7 @@ class LegQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class FootQuery extends Query<Foot?, FootQueryWhere?> {
|
||||
class FootQuery extends Query<Foot, FootQueryWhere> {
|
||||
FootQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -209,20 +211,22 @@ class FootQuery extends Query<Foot?, FootQueryWhere?> {
|
|||
return FootQueryWhere(this);
|
||||
}
|
||||
|
||||
static Foot? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Foot> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Foot(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
updatedAt: (row[2] as DateTime?),
|
||||
legId: (row[3] as int?),
|
||||
nToes: double.tryParse(row[4].toString()));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Foot deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'order.g.dart';
|
||||
|
||||
@orm
|
||||
|
|
|
@ -48,7 +48,7 @@ class CustomerMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class OrderQuery extends Query<Order?, OrderQueryWhere?> {
|
||||
class OrderQuery extends Query<Order, OrderQueryWhere> {
|
||||
OrderQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -99,8 +99,10 @@ class OrderQuery extends Query<Order?, OrderQueryWhere?> {
|
|||
return OrderQueryWhere(this);
|
||||
}
|
||||
|
||||
static Order? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Order> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Order(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -110,14 +112,14 @@ class OrderQuery extends Query<Order?, OrderQueryWhere?> {
|
|||
shipperId: (row[6] as int?));
|
||||
if (row.length > 7) {
|
||||
model = model.copyWith(
|
||||
customer: CustomerQuery.parseRow(row.skip(7).take(3).toList()));
|
||||
customer: CustomerQuery.parseRow(row.skip(7).take(3).toList()).value);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Order deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
CustomerQuery? get customer {
|
||||
|
@ -216,7 +218,7 @@ class OrderQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class CustomerQuery extends Query<Customer?, CustomerQueryWhere?> {
|
||||
class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
||||
CustomerQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -254,18 +256,20 @@ class CustomerQuery extends Query<Customer?, CustomerQueryWhere?> {
|
|||
return CustomerQueryWhere(this);
|
||||
}
|
||||
|
||||
static Customer? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Customer> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Customer(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
updatedAt: (row[2] as DateTime?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Customer deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import 'package:angel_model/angel_model.dart';
|
|||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'tree.g.dart';
|
||||
|
||||
@serializable
|
||||
|
|
|
@ -45,7 +45,7 @@ class FruitMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class TreeQuery extends Query<Tree?, TreeQueryWhere?> {
|
||||
class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
||||
TreeQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -94,8 +94,10 @@ class TreeQuery extends Query<Tree?, TreeQueryWhere?> {
|
|||
return TreeQueryWhere(this);
|
||||
}
|
||||
|
||||
static Tree? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Tree> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Tree(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -103,16 +105,14 @@ class TreeQuery extends Query<Tree?, TreeQueryWhere?> {
|
|||
rings: (row[3] as int?));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(
|
||||
fruits: [FruitQuery.parseRow(row.skip(4).take(5).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
fruits: [FruitQuery.parseRow(row.skip(4).take(5).toList()).value]);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Tree deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
FruitQuery? get fruits {
|
||||
|
@ -122,17 +122,17 @@ class TreeQuery extends Query<Tree?, TreeQueryWhere?> {
|
|||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<Tree?>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m!.id == model!.id);
|
||||
return result.fold<List<Tree>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx]!;
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
fruits: List<_Fruit>.from(l.fruits ?? [])
|
||||
..addAll(model!.fruits ?? []));
|
||||
..addAll(model.fruits ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -141,17 +141,17 @@ class TreeQuery extends Query<Tree?, TreeQueryWhere?> {
|
|||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<Tree?>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m!.id == model!.id);
|
||||
return result.fold<List<Tree>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx]!;
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
fruits: List<_Fruit>.from(l.fruits ?? [])
|
||||
..addAll(model!.fruits ?? []));
|
||||
..addAll(model.fruits ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -161,16 +161,16 @@ class TreeQuery extends Query<Tree?, TreeQueryWhere?> {
|
|||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<Tree>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
fruits: List<_Fruit>.from(l.fruits ?? [])
|
||||
..addAll(model!.fruits ?? []));
|
||||
..addAll(model.fruits ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -231,7 +231,7 @@ class TreeQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class FruitQuery extends Query<Fruit?, FruitQueryWhere?> {
|
||||
class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
||||
FruitQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -268,20 +268,22 @@ class FruitQuery extends Query<Fruit?, FruitQueryWhere?> {
|
|||
return FruitQueryWhere(this);
|
||||
}
|
||||
|
||||
static Fruit? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Fruit> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Fruit(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
updatedAt: (row[2] as DateTime?),
|
||||
treeId: (row[3] as int?),
|
||||
commonName: (row[4] as String?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Fruit deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ import 'package:angel_migration/angel_migration.dart';
|
|||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'unorthodox.g.dart';
|
||||
|
||||
@serializable
|
||||
|
|
|
@ -105,7 +105,7 @@ class FooPivotMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class UnorthodoxQuery extends Query<Unorthodox?, UnorthodoxQueryWhere?> {
|
||||
class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
|
||||
UnorthodoxQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -143,15 +143,17 @@ class UnorthodoxQuery extends Query<Unorthodox?, UnorthodoxQueryWhere?> {
|
|||
return UnorthodoxQueryWhere(this);
|
||||
}
|
||||
|
||||
static Unorthodox? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Unorthodox> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Unorthodox(name: (row[0] as String?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Unorthodox deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +185,7 @@ class UnorthodoxQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class WeirdJoinQuery extends Query<WeirdJoin?, WeirdJoinQueryWhere?> {
|
||||
class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
|
||||
WeirdJoinQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -252,35 +254,34 @@ class WeirdJoinQuery extends Query<WeirdJoin?, WeirdJoinQueryWhere?> {
|
|||
return WeirdJoinQueryWhere(this);
|
||||
}
|
||||
|
||||
static WeirdJoin? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<WeirdJoin> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = WeirdJoin(id: (row[0] as int?));
|
||||
if (row.length > 2) {
|
||||
model = model.copyWith(
|
||||
unorthodox: UnorthodoxQuery.parseRow(row.skip(2).take(1).toList()));
|
||||
unorthodox:
|
||||
UnorthodoxQuery.parseRow(row.skip(2).take(1).toList()).value);
|
||||
}
|
||||
if (row.length > 3) {
|
||||
model = model.copyWith(
|
||||
song: SongQuery.parseRow(row.skip(3).take(5).toList()));
|
||||
song: SongQuery.parseRow(row.skip(3).take(5).toList()).value);
|
||||
}
|
||||
if (row.length > 8) {
|
||||
model = model.copyWith(
|
||||
numbas: [NumbaQuery.parseRow(row.skip(8).take(2).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
numbas: [NumbaQuery.parseRow(row.skip(8).take(2).toList()).value]);
|
||||
}
|
||||
if (row.length > 10) {
|
||||
model = model.copyWith(
|
||||
foos: [FooQuery.parseRow(row.skip(10).take(1).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
foos: [FooQuery.parseRow(row.skip(10).take(1).toList()).value]);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
WeirdJoin deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
UnorthodoxQuery? get unorthodox {
|
||||
|
@ -297,28 +298,25 @@ class WeirdJoinQuery extends Query<WeirdJoin?, WeirdJoinQueryWhere?> {
|
|||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline?.contains('weird_joins') == true &&
|
||||
trampoline?.contains('foo_pivots') == true));
|
||||
return (!(trampoline.contains('weird_joins') == true &&
|
||||
trampoline.contains('foo_pivots') == true));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<WeirdJoin>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
numbas: List<_Numba>.from(l.numbas ?? [])
|
||||
..addAll(model == null
|
||||
? []
|
||||
: List<_Numba>.from(model.numbas ?? [])),
|
||||
foos: List<_Foo?>.from(l.foos ?? [])
|
||||
..addAll(model?.foos ?? []));
|
||||
..addAll(List<_Numba>.from(model.numbas ?? [])),
|
||||
foos: List<_Foo?>.from(l.foos ?? [])..addAll(model.foos ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -328,16 +326,16 @@ class WeirdJoinQuery extends Query<WeirdJoin?, WeirdJoinQueryWhere?> {
|
|||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<WeirdJoin>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
numbas: List<_Numba?>.from(l.numbas ?? [])
|
||||
..addAll(model!.numbas ?? []),
|
||||
..addAll(model.numbas ?? []),
|
||||
foos: List<_Foo?>.from(l.foos ?? [])..addAll(model.foos ?? []));
|
||||
}
|
||||
});
|
||||
|
@ -348,16 +346,16 @@ class WeirdJoinQuery extends Query<WeirdJoin?, WeirdJoinQueryWhere?> {
|
|||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<WeirdJoin>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
numbas: List<_Numba?>.from(l.numbas ?? [])
|
||||
..addAll(model!.numbas ?? []),
|
||||
..addAll(model.numbas ?? []),
|
||||
foos: List<_Foo?>.from(l.foos ?? [])..addAll(model.foos ?? []));
|
||||
}
|
||||
});
|
||||
|
@ -404,7 +402,7 @@ class WeirdJoinQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class SongQuery extends Query<Song?, SongQueryWhere?> {
|
||||
class SongQuery extends Query<Song, SongQueryWhere> {
|
||||
SongQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -441,20 +439,22 @@ class SongQuery extends Query<Song?, SongQueryWhere?> {
|
|||
return SongQueryWhere(this);
|
||||
}
|
||||
|
||||
static Song? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Song> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Song(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
updatedAt: (row[2] as DateTime?),
|
||||
weirdJoinId: (row[3] as int?),
|
||||
title: (row[4] as String?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Song deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -521,7 +521,7 @@ class SongQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class NumbaQuery extends Query<Numba?, NumbaQueryWhere?> {
|
||||
class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
|
||||
NumbaQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -558,15 +558,17 @@ class NumbaQuery extends Query<Numba?, NumbaQueryWhere?> {
|
|||
return NumbaQueryWhere(this);
|
||||
}
|
||||
|
||||
static Numba? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Numba> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Numba(i: (row[0] as int?), parent: (row[1] as int?));
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Numba deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -607,7 +609,7 @@ class NumbaQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class FooQuery extends Query<Foo?, FooQueryWhere?> {
|
||||
class FooQuery extends Query<Foo, FooQueryWhere> {
|
||||
FooQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -650,43 +652,44 @@ class FooQuery extends Query<Foo?, FooQueryWhere?> {
|
|||
return FooQueryWhere(this);
|
||||
}
|
||||
|
||||
static Foo? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Foo> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Foo(bar: (row[0] as String?));
|
||||
if (row.length > 1) {
|
||||
model = model.copyWith(
|
||||
weirdJoins: [WeirdJoinQuery.parseRow(row.skip(1).take(2).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
model = model.copyWith(weirdJoins: [
|
||||
WeirdJoinQuery.parseRow(row.skip(1).take(2).toList()).value
|
||||
]);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Foo deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline?.contains('foos') == true &&
|
||||
trampoline?.contains('foo_pivots') == true));
|
||||
return (!(trampoline.contains('foos') == true &&
|
||||
trampoline.contains('foo_pivots') == true));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<Foo?>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m!.bar == model!.bar);
|
||||
return result.fold<List<Foo>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.bar == model.bar);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx]!;
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
weirdJoins: List<_WeirdJoin?>.from(l.weirdJoins ?? [])
|
||||
..addAll(model!.weirdJoins ?? []));
|
||||
weirdJoins: List<_WeirdJoin>.from(l.weirdJoins ?? [])
|
||||
..addAll(model.weirdJoins ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -695,17 +698,17 @@ class FooQuery extends Query<Foo?, FooQueryWhere?> {
|
|||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<Foo?>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m!.bar == model!.bar);
|
||||
return result.fold<List<Foo>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.bar == model.bar);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx]!;
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
weirdJoins: List<_WeirdJoin?>.from(l.weirdJoins ?? [])
|
||||
..addAll(model!.weirdJoins ?? []));
|
||||
weirdJoins: List<_WeirdJoin>.from(l.weirdJoins ?? [])
|
||||
..addAll(model.weirdJoins ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -714,17 +717,17 @@ class FooQuery extends Query<Foo?, FooQueryWhere?> {
|
|||
@override
|
||||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<Foo?>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m!.bar == model!.bar);
|
||||
return result.fold<List<Foo>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.bar == model.bar);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx]!;
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
weirdJoins: List<_WeirdJoin?>.from(l.weirdJoins ?? [])
|
||||
..addAll(model!.weirdJoins ?? []));
|
||||
weirdJoins: List<_WeirdJoin>.from(l.weirdJoins ?? [])
|
||||
..addAll(model.weirdJoins ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -759,7 +762,7 @@ class FooQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class FooPivotQuery extends Query<FooPivot?, FooPivotQueryWhere?> {
|
||||
class FooPivotQuery extends Query<FooPivot, FooPivotQueryWhere> {
|
||||
FooPivotQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -807,23 +810,26 @@ class FooPivotQuery extends Query<FooPivot?, FooPivotQueryWhere?> {
|
|||
return FooPivotQueryWhere(this);
|
||||
}
|
||||
|
||||
static FooPivot? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<FooPivot> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = FooPivot();
|
||||
if (row.length > 2) {
|
||||
model = model.copyWith(
|
||||
weirdJoin: WeirdJoinQuery.parseRow(row.skip(2).take(2).toList()));
|
||||
weirdJoin:
|
||||
WeirdJoinQuery.parseRow(row.skip(2).take(2).toList()).value);
|
||||
}
|
||||
if (row.length > 4) {
|
||||
model =
|
||||
model.copyWith(foo: FooQuery.parseRow(row.skip(4).take(1).toList()));
|
||||
model = model.copyWith(
|
||||
foo: FooQuery.parseRow(row.skip(4).take(1).toList()).value);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
FooPivot deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
WeirdJoinQuery? get weirdJoin {
|
||||
|
@ -1070,9 +1076,9 @@ class Foo implements _Foo {
|
|||
final String? bar;
|
||||
|
||||
@override
|
||||
final List<_WeirdJoin?>? weirdJoins;
|
||||
final List<_WeirdJoin>? weirdJoins;
|
||||
|
||||
Foo copyWith({String? bar, List<_WeirdJoin?>? weirdJoins}) {
|
||||
Foo copyWith({String? bar, List<_WeirdJoin>? weirdJoins}) {
|
||||
return Foo(bar: bar ?? this.bar, weirdJoins: weirdJoins ?? this.weirdJoins);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import 'package:angel_model/angel_model.dart';
|
|||
import 'package:angel_orm/angel_orm.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
|
||||
part 'user.g.dart';
|
||||
|
||||
@serializable
|
||||
|
|
|
@ -61,7 +61,7 @@ class RoleMigration extends Migration {
|
|||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class UserQuery extends Query<User?, UserQueryWhere?> {
|
||||
class UserQuery extends Query<User, UserQueryWhere> {
|
||||
UserQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -111,8 +111,10 @@ class UserQuery extends Query<User?, UserQueryWhere?> {
|
|||
return UserQueryWhere(this);
|
||||
}
|
||||
|
||||
static User? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<User> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = User(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -122,37 +124,35 @@ class UserQuery extends Query<User?, UserQueryWhere?> {
|
|||
email: (row[5] as String?));
|
||||
if (row.length > 6) {
|
||||
model = model.copyWith(
|
||||
roles: [RoleQuery.parseRow(row.skip(6).take(4).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
roles: [RoleQuery.parseRow(row.skip(6).take(4).toList()).value]);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
User deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline?.contains('users') == true &&
|
||||
trampoline?.contains('role_users') == true));
|
||||
return (!(trampoline.contains('users') == true &&
|
||||
trampoline.contains('role_users') == true));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles)..addAll(model!.roles));
|
||||
roles: List<_Role>.from(l.roles)..addAll(model.roles));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -162,15 +162,15 @@ class UserQuery extends Query<User?, UserQueryWhere?> {
|
|||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles)..addAll(model!.roles));
|
||||
roles: List<_Role>.from(l.roles)..addAll(model.roles));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -180,15 +180,15 @@ class UserQuery extends Query<User?, UserQueryWhere?> {
|
|||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles)..addAll(model!.roles));
|
||||
roles: List<_Role>.from(l.roles)..addAll(model.roles));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -267,7 +267,7 @@ class UserQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class RoleUserQuery extends Query<RoleUser?, RoleUserQueryWhere?> {
|
||||
class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||
RoleUserQuery({Query? parent, Set<String>? trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
|
@ -324,23 +324,25 @@ class RoleUserQuery extends Query<RoleUser?, RoleUserQueryWhere?> {
|
|||
return RoleUserQueryWhere(this);
|
||||
}
|
||||
|
||||
static RoleUser? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<RoleUser> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = RoleUser();
|
||||
if (row.length > 2) {
|
||||
model = model.copyWith(
|
||||
role: RoleQuery.parseRow(row.skip(2).take(4).toList()));
|
||||
role: RoleQuery.parseRow(row.skip(2).take(4).toList()).value);
|
||||
}
|
||||
if (row.length > 6) {
|
||||
model = model.copyWith(
|
||||
user: UserQuery.parseRow(row.skip(6).take(6).toList()));
|
||||
user: UserQuery.parseRow(row.skip(6).take(6).toList()).value);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
RoleUser deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
RoleQuery? get role {
|
||||
|
@ -393,7 +395,7 @@ class RoleUserQueryValues extends MapQueryValues {
|
|||
}
|
||||
}
|
||||
|
||||
class RoleQuery extends Query<Role?, RoleQueryWhere?> {
|
||||
class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||
RoleQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
|
@ -443,8 +445,10 @@ class RoleQuery extends Query<Role?, RoleQueryWhere?> {
|
|||
return RoleQueryWhere(this);
|
||||
}
|
||||
|
||||
static Role? parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
static Optional<Role> parseRow(List row) {
|
||||
if (row.every((x) => x == null)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
var model = Role(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime?),
|
||||
|
@ -452,37 +456,35 @@ class RoleQuery extends Query<Role?, RoleQueryWhere?> {
|
|||
name: (row[3] as String?));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(
|
||||
users: [UserQuery.parseRow(row.skip(4).take(6).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
users: [UserQuery.parseRow(row.skip(4).take(6).toList()).value]);
|
||||
}
|
||||
return model;
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
Role deserialize(List row) {
|
||||
return parseRow(row).value;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline?.contains('roles') == true &&
|
||||
trampoline?.contains('role_users') == true));
|
||||
return (!(trampoline.contains('roles') == true &&
|
||||
trampoline.contains('role_users') == true));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users)..addAll(model!.users));
|
||||
users: List<_User>.from(l.users)..addAll(model.users));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -491,16 +493,16 @@ class RoleQuery extends Query<Role?, RoleQueryWhere?> {
|
|||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<Role?>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m!.id == model!.id);
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx]!;
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users)..addAll(model!.users));
|
||||
users: List<_User>.from(l.users)..addAll(model.users));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -510,15 +512,15 @@ class RoleQuery extends Query<Role?, RoleQueryWhere?> {
|
|||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model!.id);
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model!);
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users)..addAll(model!.users));
|
||||
users: List<_User>.from(l.users)..addAll(model.users));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ standaloneTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
// var row = [0, 'Mazda', 'CX9', true, y2k, y2k, y2k];
|
||||
var row = [0, y2k, y2k, 'Mazda', 'CX9', true, y2k];
|
||||
print(row);
|
||||
var car = CarQuery().deserialize(row)!;
|
||||
var car = CarQuery().deserialize(row);
|
||||
print(car.toJson());
|
||||
expect(car.id, '0');
|
||||
expect(car.make, 'Mazda');
|
||||
|
@ -47,7 +47,7 @@ standaloneTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
group('selects', () {
|
||||
test('select all', () async {
|
||||
List<Car?> cars = await CarQuery().get(executor);
|
||||
List<Car> cars = await CarQuery().get(executor);
|
||||
expect(cars, []);
|
||||
});
|
||||
|
||||
|
@ -60,19 +60,19 @@ standaloneTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
..make = 'Ferrari東'
|
||||
..description = 'Vroom vroom!'
|
||||
..familyFriendly = false;
|
||||
ferrari = await query.insert(executor);
|
||||
ferrari = (await query.insert(executor)).value;
|
||||
});
|
||||
|
||||
test('where clause is applied', () async {
|
||||
var query = CarQuery()..where!.familyFriendly.isTrue;
|
||||
List<Car?> cars = await query.get(executor);
|
||||
List<Car> cars = await query.get(executor);
|
||||
expect(cars, isEmpty);
|
||||
|
||||
var sportsCars = CarQuery()..where!.familyFriendly.isFalse;
|
||||
cars = await sportsCars.get(executor);
|
||||
print(cars.map((c) => c!.toJson()));
|
||||
print(cars.map((c) => c.toJson()));
|
||||
|
||||
var car = cars.first!;
|
||||
var car = cars.first;
|
||||
expect(car.make, ferrari!.make);
|
||||
expect(car.description, ferrari!.description);
|
||||
expect(car.familyFriendly, ferrari!.familyFriendly);
|
||||
|
@ -80,10 +80,10 @@ standaloneTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
});
|
||||
|
||||
test('union', () async {
|
||||
var query1 = CarQuery()..where!.make.like('%Fer%');
|
||||
var query2 = CarQuery()..where!.familyFriendly.isTrue;
|
||||
var query3 = CarQuery()..where!.description.equals('Submarine');
|
||||
Union<Car?> union = query1.union(query2).unionAll(query3);
|
||||
var query1 = CarQuery()..where?.make.like('%Fer%');
|
||||
var query2 = CarQuery()..where?.familyFriendly.isTrue;
|
||||
var query3 = CarQuery()..where?.description.equals('Submarine');
|
||||
Union<Car> union = query1.union(query2).unionAll(query3);
|
||||
print(union.compile(Set()));
|
||||
var cars = await union.get(executor);
|
||||
expect(cars, hasLength(1));
|
||||
|
@ -93,17 +93,17 @@ standaloneTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
var query = CarQuery()
|
||||
..where!.make.like('Fer%')
|
||||
..orWhere((where) => where
|
||||
?..familyFriendly.isTrue
|
||||
..familyFriendly.isTrue
|
||||
..make.equals('Honda'));
|
||||
print(query.compile(Set()));
|
||||
List<Car?> cars = await query.get(executor);
|
||||
List<Car> cars = await query.get(executor);
|
||||
expect(cars, hasLength(1));
|
||||
});
|
||||
|
||||
test('limit obeyed', () async {
|
||||
var query = CarQuery()..limit(0);
|
||||
print(query.compile(Set()));
|
||||
List<Car?> cars = await query.get(executor);
|
||||
List<Car> cars = await query.get(executor);
|
||||
expect(cars, isEmpty);
|
||||
});
|
||||
|
||||
|
@ -120,28 +120,28 @@ standaloneTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
var car = await (query.deleteOne(executor) as FutureOr<Car>);
|
||||
expect(car.toJson(), ferrari!.toJson());
|
||||
|
||||
List<Car?> cars = await CarQuery().get(executor);
|
||||
List<Car> cars = await CarQuery().get(executor);
|
||||
expect(cars, isEmpty);
|
||||
});
|
||||
|
||||
test('delete stream', () async {
|
||||
var query = CarQuery()
|
||||
..where!.make.equals('Ferrari東')
|
||||
..orWhere((w) => w!.familyFriendly.isTrue);
|
||||
..orWhere((w) => w.familyFriendly.isTrue);
|
||||
print(query.compile(Set(), preamble: 'DELETE FROM "cars"'));
|
||||
|
||||
List<Car?>? cars = await query.delete(executor);
|
||||
List<Car> cars = await query.delete(executor);
|
||||
expect(cars, hasLength(1));
|
||||
expect(cars.first!.toJson(), ferrari!.toJson());
|
||||
expect(cars.first.toJson(), ferrari!.toJson());
|
||||
});
|
||||
|
||||
test('update', () async {
|
||||
var query = CarQuery()
|
||||
..where!.id.equals(int.parse(ferrari!.id!))
|
||||
..values.make = 'Hyundai';
|
||||
List<Car?> cars = await query.update(executor);
|
||||
List<Car> cars = await query.update(executor);
|
||||
expect(cars, hasLength(1));
|
||||
expect(cars.first!.make, 'Hyundai');
|
||||
expect(cars.first.make, 'Hyundai');
|
||||
});
|
||||
|
||||
test('update car', () async {
|
||||
|
|
|
@ -38,6 +38,7 @@ dev_dependencies:
|
|||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/framework
|
||||
build_runner: ^2.0.1
|
||||
optional: ^6.0.0-nullsafety.2
|
||||
|
||||
#dependency_overrides:
|
||||
# angel_orm:
|
||||
|
|
Loading…
Reference in a new issue