CollQL

A powerful and expressive Dart library for in-memory collection querying and manipulation, inspired by MongoDB. CollQL makes it easy to filter, update, and transform your data using a familiar, fluent API—perfect for Dart and Flutter projects.

pub package GitHub stars

Overview

CollQL is a Dart library inspired by MongoDB queries, designed for expressive and flexible in-memory collection manipulation and filtering.

  • 🔍 Filters: Create complex queries using logical and comparison operators.
  • ✏️ Modifiers: Update collections and documents with MongoDB-like operations.
  • 🧩 Extensions: Utility methods to simplify usage with Dart collections.
  • 🍰 Proxies: Builders for fluent construction of filters and modifiers.

For a comprehensive overview of all features, examples, and API references, please see the official documentation.

Getting Started

import 'package:collql/collql.dart';

final List<Document> data = [
  Document({'name': "john", 'age': 45}),
  Document({'name': "bob", 'age': 21}),
  Document({'name': "alice", 'age': 60}),
  Document({'name': "ted", 'age': 10}),
];

final filter = and([
  'age'.gte(18),
  'age'.lte(50)
]);

final List<Document> result = CollectionQL(data).fetch(filter).toList();
assert(result.length == 2); // true

Quick Guide

Documents

These are the basic data structure in CollQL. Each document is represented by an object containing key-value pairs, similar to a map or JSON object. [Read more]

import 'package:collql/collql.dart';

final doc = Document({
  "name": "John",
  "age": 30
});

assert(doc.get('/name') == "John"); // true
doc.set('/age', 31);
assert(doc.get('/age') == 31); // true

Filters

Allow you to select documents from a collection or test values based on conditions. They are inspired by MongoDB operators. [Read more]

import 'package:collql/collql.dart';

final List<Document> data = [
  Document({'name': "john", 'age': 45}),
  // ... //
];

final query = and([
  'age'.gte(18),
  'age'.lte(50)
]);

assert(query.apply(data[0]) == true);  // true

Some operators: eq, notEq, gt, gte, lt, lte, and, or

Modifiers

Allow you to update documents declaratively. [Read more]

import 'package:collql/collql.dart';

final List<Document> data = [
  Document({'name': "john", 'age': 45}),
  // ... //
];

final doc = Document({ "name": "john", "age": 45 });
final update = 'name'.rename('fullName');
update.apply(doc);
assert(doc.get('/name') == null); // true
assert(doc.get('/fullName') != null); // true
assert(data[0].get('/name') == doc.get('/fullName')); // true

Some modifiers: get, set, unset, rename, push, pull

Credits

CollQL is inspired by Nitrite, and combines concepts from both MongoDB and Dart's collection manipulation capabilities. It aims to provide a seamless and expressive way to work with in-memory data structures.

License

CollQL is distributed under the MIT License, allowing you to use, modify, and distribute the library freely in your own projects. See the LICENSE file for details.

Libraries

abstractions/abstractions
abstractions/document
abstractions/exceptions
abstractions/filters
abstractions/modifiers
abstractions/types
collql
extensions/extensions
implementations/collection
implementations/document
implementations/filters/comparables/equals
implementations/filters/comparables/regex
implementations/filters/comparables_list/element_match
implementations/filters/comparables_list/in
implementations/filters/comparables_list/not_in
implementations/filters/filters
implementations/filters/logicals/and
implementations/filters/logicals/not
implementations/filters/logicals/or
implementations/filters/sortings_aware/greater_equal
implementations/filters/sortings_aware/greater_than
implementations/filters/sortings_aware/lesser_equal
implementations/filters/sortings_aware/lesser_than
implementations/implementations
implementations/modifiers/conditionated/max
implementations/modifiers/conditionated/min
implementations/modifiers/modifiers
implementations/modifiers/setters/current_date
implementations/modifiers/setters/inc
implementations/modifiers/setters/mul
implementations/modifiers/setters/rename
implementations/modifiers/setters/set
implementations/modifiers/setters/unset
implementations/modifiers/setters_list/add_to_set
implementations/modifiers/setters_list/pop
implementations/modifiers/setters_list/pull
implementations/modifiers/setters_list/push
implementations/modifiers/setters_list/sort
proxies/filter_builder
proxies/modifier_builder
proxies/proxies
utils/utils