/tests/testcrate/tests/ui/aggregate_syntax.rs

https://github.com/antoyo/tql · Rust · 64 lines · 26 code · 10 blank · 28 comment · 1 complexity · 3320518373c96398b35055d8f5023ebb MD5 · raw file

  1. /*
  2. * Copyright (c) 2017-2018 Boucher, Antoni <bouanto@zoho.com>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. //! Tests of the aggregate() method.
  22. #![feature(proc_macro_hygiene)]
  23. extern crate tql;
  24. #[macro_use]
  25. extern crate tql_macros;
  26. #[macro_use]
  27. mod connection;
  28. backend_extern_crate!();
  29. use tql::PrimaryKey;
  30. use tql_macros::sql;
  31. #[derive(SqlTable)]
  32. struct Table {
  33. id: PrimaryKey,
  34. field1: String,
  35. i32_field: i32,
  36. }
  37. use connection::{Connection, get_connection};
  38. fn main() {
  39. let connection = get_connection();
  40. sql!(Table.aggregate(avh(i32_field)));
  41. //~^ ERROR unresolved name `avh`
  42. //~| HELP did you mean avg?
  43. sql!(Table.values("test").aggregate(avg(i32_field)));
  44. //~^ ERROR Expected identifier
  45. sql!(Table.aggregate(avg(i32_field, field1)));
  46. //~^ ERROR this function takes 1 parameter but 2 parameters were supplied
  47. sql!(Table.values(i32_field).aggregate(average = avg(i32_field)).filter(avg < 20));
  48. //~^ ERROR no aggregate field named `avg` found
  49. //sql!(Table.values(i32_field).aggregate(average = avg(i32_field)).filter(avrage < 20));
  50. // TODO: propose similar names.
  51. if let Ok(aggregate) = sql!(Table.aggregate(average = avg(field2))) {
  52. println!("{}", aggregate.average);
  53. }
  54. }