2018-12-31 12:24:21 +00:00
|
|
|
import 'dart:async';
|
2019-04-30 15:21:05 +00:00
|
|
|
import 'package:angel_migration/angel_migration.dart';
|
2018-12-31 12:24:21 +00:00
|
|
|
import 'package:angel_model/angel_model.dart';
|
|
|
|
import 'package:angel_orm/angel_orm.dart';
|
|
|
|
import 'package:angel_orm/src/query.dart';
|
|
|
|
import 'package:angel_serialize/angel_serialize.dart';
|
|
|
|
part 'main.g.dart';
|
|
|
|
|
|
|
|
main() async {
|
2019-08-17 22:35:55 +00:00
|
|
|
var query = EmployeeQuery()
|
2018-12-31 12:24:21 +00:00
|
|
|
..where.firstName.equals('Rich')
|
|
|
|
..where.lastName.equals('Person')
|
|
|
|
..orWhere((w) => w.salary.greaterThanOrEqualTo(75000))
|
|
|
|
..join('companies', 'company_id', 'id');
|
|
|
|
|
2019-08-17 22:35:55 +00:00
|
|
|
var richPerson = await query.getOne(_FakeExecutor());
|
2018-12-31 12:24:21 +00:00
|
|
|
print(richPerson.toJson());
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FakeExecutor extends QueryExecutor {
|
|
|
|
const _FakeExecutor();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<List<List>> query(
|
2019-02-13 05:00:30 +00:00
|
|
|
String tableName, String query, Map<String, dynamic> substitutionValues,
|
2018-12-31 12:24:21 +00:00
|
|
|
[returningFields]) async {
|
2019-08-17 22:35:55 +00:00
|
|
|
var now = DateTime.now();
|
2018-12-31 12:24:21 +00:00
|
|
|
print(
|
|
|
|
'_FakeExecutor received query: $query and values: $substitutionValues');
|
|
|
|
return [
|
|
|
|
[1, 'Rich', 'Person', 100000.0, now, now]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2019-08-17 22:32:58 +00:00
|
|
|
Future<T> transaction<T>(FutureOr<T> Function(QueryExecutor) f) {
|
2019-08-17 22:35:55 +00:00
|
|
|
throw UnsupportedError('Transactions are not supported.');
|
2018-12-31 12:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@orm
|
|
|
|
@serializable
|
|
|
|
abstract class _Employee extends Model {
|
|
|
|
String get firstName;
|
|
|
|
|
|
|
|
String get lastName;
|
|
|
|
|
2019-04-30 15:21:05 +00:00
|
|
|
@Column(indexType: IndexType.unique)
|
|
|
|
String uniqueId;
|
2018-12-31 12:24:21 +00:00
|
|
|
|
2019-04-30 15:21:05 +00:00
|
|
|
double get salary;
|
2018-12-31 12:24:21 +00:00
|
|
|
}
|