queries 0.0.6

queries #

IQueryable collections for Dart language.

Version 0.0.6

Sample code:

import 'dart:math';
import 'package:queries/queries.dart';

void main() {
  const int NUMBER_OF_ORDERS = 50;
  const int NUMBER_OF_ORDER_DETAILS = NUMBER_OF_ORDERS * 5;
  const int NUMBER_OF_PRODUCTS = 15;
  var rnd = new Random(0);
  // Generate products
  var products = IQueryable.range(0, NUMBER_OF_PRODUCTS)
      .select(
          (id) => new Product(id, "Product $id", rnd.nextInt(10).toDouble())).toCollection();
  // Generate orders
  var orders = IQueryable.range(0, NUMBER_OF_ORDERS)
      .select(
          (id) => new Order(id, new DateTime(2013, 12, rnd.nextInt(30) + 1)))
      .toCollection();
  // Generate order details
  var orderDetails = IQueryable.range(0, NUMBER_OF_ORDER_DETAILS)
      .select((id) {
          var orderId = rnd.nextInt(NUMBER_OF_ORDERS - 1);
          var orderDetail = new OrderDetail(id, orders.single((Order o) => o.id == orderId));
          var productId = rnd.nextInt(NUMBER_OF_PRODUCTS - 1);
          orderDetail.product = products.single((Product p) => p.id == productId);
          orderDetail.price = orderDetail.product.price;
          orderDetail.quantity = rnd.nextInt(5);
          orderDetail.order.total += orderDetail.quantity * orderDetail.price;
          return orderDetail;
       }).toCollection();
  //
  var sales = orders
      .join(
          orderDetails,
          (Order o) => o,
          (OrderDetail od) => od.order,
          (Order o, OrderDetail od) => {
              "order"       : o,
              "orderDetail" : od})
      .groupBy(
          (row) => row["order"])
      .select((group) => {
          "order" : group.key,
          "sum"   : group.sum((row) => row["orderDetail"].quantity * row["orderDetail"].price),
          "lines" : group.count()})
      .orderBy(
          (row) => row["order"].date);
  //
  printResult("Products", products);
  printResult("Orders", orders);
  printResult("Sales", sales);
}

void printResult(String title, result) {
  print("========================");
  print(title);
  print("------------------------");
  for(var item in result) {
    print(item);
  }
}

class Order {
  int id;
  DateTime date;
  double total = 0.0;

  Order(this.id, this.date);

  operator ==(other) {
    if(identical(this, other)) {
      return true;
    }

    if(other is Order) {
      return id == other.id;
    }

    return false;
  }

  String toString() {
    return "Order #$id ${date} $total";
  }
}

class OrderDetail {
  int id;
  Order order;
  Product product;
  double price = 0.0;
  int quantity = 0;
  double total = 0.0;

  OrderDetail(this.id, this.order);

  String toString() {
    return "$product $quantity $price";
  }
}

class Product {
  int id;
  String name;
  double price;

  Product(this.id, this.name, this.price);

  String toString() {
    return name;
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  queries: ^0.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:queries/queries.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
94
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
47
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.