dart-backend / angel

A polished, production-ready backend framework in Dart for the VM, AOT, and Flutter.
https://github.com/dukefirehawk/angel
BSD 3-Clause "New" or "Revised" License
171 stars 22 forks source link

Add 'where.raw(String whereSql)' #43

Closed debuggerx01 closed 2 years ago

debuggerx01 commented 2 years ago

With this changes, this code:

var query = EmployeeQuery()
    ..where?.firstName.equals('Rich')
    ..where?.lastName.equals('Person')
    ..where?.raw('COM.deleted = false')
    ..orWhere((w) => w.salary.greaterThanOrEqualTo(75000))
    ..join('companies', 'company_id', 'id', alias: 'COM');

  var richPerson = await query.getOne(_FakeExecutor());

will generate sql:

SELECT employees.id, employees.created_at, employees.updated_at, employees.first_name, employees.last_name, CAST (employees.salary AS text) FROM employees  INNER JOIN companies COM ON employees.company_id=COM.id WHERE employees.first_name = @first_name AND employees.last_name = @last_name AND  (COM.deleted = false) OR (salary >= CAST ("75000.0" as decimal)) and values: {first_name: Rich, last_name: Person}
dukefirehawk commented 2 years ago

Can you run dart run build_runner build under angel_orm_test folder and then run dart test under angel_orm_postres folder with your changes to see if all unit tests are ok? Would be great if can add a unit test under angel_orm_test for this. This will guard against code change later from breaking it.

debuggerx01 commented 2 years ago

Can you run dart run build_runner build under angel_orm_test folder and then run dart test under angel_orm_postres folder with your changes to see if all unit tests are ok? Would be great if can add a unit test under angel_orm_test for this. This will guard against code change later from breaking it.

With pleasure, I will do it later.

debuggerx01 commented 2 years ago

Can you run dart run build_runner build under angel_orm_test folder and then run dart test under angel_orm_postres folder with your changes to see if all unit tests are ok? Would be great if can add a unit test under angel_orm_test for this. This will guard against code change later from breaking it.

Hi, I added join_test to angel_orm_test, and all the tests have passed, please check~

dukefirehawk commented 2 years ago

@debuggerx01 Nice work. BTW I've also setup Github Action to automate these tests. Let me know if you run into any issues. Note that dependency_overrides was added to pubspec.yaml to enable automated tests to run with the local packages.