2018-12-08 02:03:03 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2024-10-13 01:45:27 +00:00
|
|
|
import 'package:protevus_orm/protevus_orm.dart';
|
|
|
|
import 'package:protevus_serialize/protevus_serialize.dart';
|
2021-05-04 15:03:15 +00:00
|
|
|
import 'package:optional/optional.dart';
|
|
|
|
|
2018-12-01 17:21:34 +00:00
|
|
|
part 'main.g.dart';
|
2018-05-04 03:51:17 +00:00
|
|
|
|
2021-05-02 07:32:24 +00:00
|
|
|
void main() async {
|
2019-07-04 21:30:21 +00:00
|
|
|
var query = EmployeeQuery()
|
2021-05-02 07:32:24 +00:00
|
|
|
..where?.firstName.equals('Rich')
|
|
|
|
..where?.lastName.equals('Person')
|
2022-01-06 04:06:56 +00:00
|
|
|
..where?.raw('COM.deleted = false')
|
2021-05-04 04:18:39 +00:00
|
|
|
..orWhere((w) => w.salary.greaterThanOrEqualTo(75000))
|
2022-01-06 04:06:56 +00:00
|
|
|
..join('companies', 'company_id', 'id', alias: 'COM');
|
2018-12-01 18:23:50 +00:00
|
|
|
|
2019-07-04 21:30:21 +00:00
|
|
|
var richPerson = await query.getOne(_FakeExecutor());
|
2021-05-03 13:27:12 +00:00
|
|
|
if (richPerson.isPresent) {
|
|
|
|
print(richPerson.first.toJson());
|
|
|
|
}
|
2018-05-04 03:51:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 17:21:34 +00:00
|
|
|
class _FakeExecutor extends QueryExecutor {
|
|
|
|
const _FakeExecutor();
|
2018-08-24 12:30:38 +00:00
|
|
|
|
2018-12-01 17:21:34 +00:00
|
|
|
@override
|
2018-12-31 11:36:08 +00:00
|
|
|
Future<List<List>> query(
|
2022-02-03 09:47:36 +00:00
|
|
|
String tableName, String query, Map<String, dynamic> substitutionValues,
|
|
|
|
{String returningQuery = '',
|
|
|
|
List<String> returningFields = const []}) async {
|
2019-07-04 21:30:21 +00:00
|
|
|
var now = DateTime.now();
|
2018-12-31 11:36:08 +00:00
|
|
|
print(
|
|
|
|
'_FakeExecutor received query: $query and values: $substitutionValues');
|
2018-12-01 17:21:34 +00:00
|
|
|
return [
|
2022-01-06 04:06:56 +00:00
|
|
|
[1, now, now, 'Rich', 'Person', 100000.0]
|
2018-12-01 17:21:34 +00:00
|
|
|
];
|
|
|
|
}
|
2018-12-08 02:03:03 +00:00
|
|
|
|
|
|
|
@override
|
2019-08-17 21:53:23 +00:00
|
|
|
Future<T> transaction<T>(FutureOr<T> Function(QueryExecutor) f) {
|
2019-07-04 21:30:21 +00:00
|
|
|
throw UnsupportedError('Transactions are not supported.');
|
2018-12-08 02:03:03 +00:00
|
|
|
}
|
2022-02-03 09:47:36 +00:00
|
|
|
|
|
|
|
final Dialect _dialect = const PostgreSQLDialect();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Dialect get dialect => _dialect;
|
2018-05-04 03:51:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 17:21:34 +00:00
|
|
|
@orm
|
|
|
|
@serializable
|
2018-08-24 12:30:38 +00:00
|
|
|
abstract class _Employee extends Model {
|
2021-05-02 07:32:24 +00:00
|
|
|
String? get firstName;
|
2018-05-04 03:51:17 +00:00
|
|
|
|
2021-05-02 07:32:24 +00:00
|
|
|
String? get lastName;
|
2018-05-04 03:51:17 +00:00
|
|
|
|
2021-05-02 07:32:24 +00:00
|
|
|
double? get salary;
|
2018-12-01 17:21:34 +00:00
|
|
|
}
|