{"id":15036257,"url":"https://github.com/craigmccauley/queryr","last_synced_at":"2025-04-09T23:23:36.756Z","repository":{"id":65135535,"uuid":"582468972","full_name":"craigmccauley/QueryR","owner":"craigmccauley","description":"Ad-Hoc querying library for .Net","archived":false,"fork":false,"pushed_at":"2025-01-25T09:18:26.000Z","size":142,"stargazers_count":47,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T01:12:50.505Z","etag":null,"topics":["csharp","csharp-library","query-builder"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/QueryR/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/craigmccauley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-26T23:52:55.000Z","updated_at":"2025-03-03T16:17:16.000Z","dependencies_parsed_at":"2024-05-31T23:37:14.196Z","dependency_job_id":"a25d2d64-86cf-4ca5-bb35-4098f01d2c13","html_url":"https://github.com/craigmccauley/QueryR","commit_stats":{"total_commits":29,"total_committers":1,"mean_commits":29.0,"dds":0.0,"last_synced_commit":"786b9a06f433a1a3bfb08a3a17aaabe4c0741fc3"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigmccauley%2FQueryR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigmccauley%2FQueryR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigmccauley%2FQueryR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigmccauley%2FQueryR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/craigmccauley","download_url":"https://codeload.github.com/craigmccauley/QueryR/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126924,"owners_count":21052100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-library","query-builder"],"created_at":"2024-09-24T20:30:38.733Z","updated_at":"2025-04-09T23:23:36.734Z","avatar_url":"https://github.com/craigmccauley.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QueryR\n\n![QueryR Logo](./assets/logo.png)\n\n[![.NET](https://github.com/craigmccauley/QueryR/actions/workflows/dotnet.yml/badge.svg)](https://github.com/craigmccauley/QueryR/actions/workflows/dotnet.yml)\n\nQueryR provides a simple interface for executing ad hoc queries against `IQueryable\u003cT\u003e` implementations.\n\nThis is useful in situations where there is a need to provide end users with the ability to create custom queries without increasing the complexity of the solution.\n\nIn practice you will have your own domain query criteria object that collects what you want to query. You will perform a map to the `QueryR.Query` object and send it to the `IQueryable\u003cT\u003e.Query` method.\n\nIf you intend to use QueryR with EntityFrameworkCore, please use [QueryR.EntityFrameworkCore](https://github.com/craigmccauley/QueryR.EntityFrameworkCore).\n\n## Basic Functionality Example\n\n```CSharp\nvar kerbals = new List\u003cKerbal\u003e\n{\n    new Kerbal { FirstName = \"Bob\", LastName = \"Kerman\" },\n    new Kerbal { FirstName = \"Bill\", LastName = \"Kerman\" },\n    new Kerbal { FirstName = \"Jeb\", LastName = \"Kerman\" },\n    new Kerbal { FirstName = \"Val\", LastName = \"Kerman\" },\n};\n\n//Note: \nvar queryResult = kerbals.AsQueryable().Query(new Filter\n{\n    PropertyName = nameof(Kerbal.FirstName),\n    Operator = FilterOperators.StartsWith,\n    Value = \"B\"\n}).ToList();\n\nConsole.WriteLine($\"Filter matched {queryResult.Count} Kerbal(s). They are:\");\nforeach(var item in queryResult)\n{\n    Console.WriteLine($\" - {item.FirstName}\");\n}\n\n// Expected Output :\n// Filter matched 2 Kerbal(s). They are:\n//  - Bob\n//  - Bill\n\n```\n\n## QueryR Full Functionality Example\n\nQueryR can perform the following `IQueryAction`s.\n\n- Filter - Reduce the amount of records returned by specifying conditions. Does not support \"OR\", if you need \"OR\", run a seond query.\n- Paging\n- Sort\n- Sparse Fieldsets - Restrict the fields returned for a specified entity.\n\n```CSharp\nvar (Count, Items) = kerbals.AsQueryable().Query(new Query\n{\n    Filters = new List\u003cFilter\u003e\n    {\n        new Filter\n        {\n            PropertyName = nameof(Kerbal.FirstName),\n            Operator = FilterOperators.Contains,\n            Value = \"l\"\n        },\n    },\n    PagingOptions = new PagingOptions\n    {\n        PageNumber = 2,\n        PageSize = 1\n    },\n    Sorts = new List\u003cSort\u003e\n    {\n        new Sort\n        {\n            IsAscending = false,\n            PropertyName = nameof(Kerbal.FirstName)\n        },\n    },\n    SparseFields = new List\u003cSparseField\u003e\n    {\n        new SparseField\n        {\n            EntityName = nameof(Kerbal),\n            PropertyNames = new List\u003cstring\u003e { nameof(Kerbal.FirstName) }\n        },\n    }\n}).GetCountAndList();\n\nConsole.WriteLine($\"{Count} Kerbal(s) match filter, {Items.Count} Kerbal(s) returned:\");\nforeach(var item in queryResult)\n{\n    Console.WriteLine($\" - {item.FirstName} {item.LastName} was found.\");\n}\n\n// Expected output:\n// 2 Kerbal(s) match filter, 1 Kerbal(s) returned:\n// - Bill  was found.\n```\n\n## QueryR Filters\n\nQueryR provides the following filters:\n\n- Equal\n- GreaterThan\n- GreaterThanOrEqual\n- LessThan\n- LessThanOrEqual\n- NotEqual\n- Contains\n- In\n- StartsWith\n- EndsWith\n- CollectionContains\n\nExtra filters can be defined and used as if they were a part of QueryR.\nFor example, if a string length filter was needed.\n\nWe could do\n\n```CSharp\npublic static class ExtendedFilterOperators\n{\n    public static readonly FilterOperator LengthLessThan = new FilterOperator(\"llt\", nameof(LengthLessThan),\n        (property, target) =\u003e Expression.LessThan(Expression.Property(property, nameof(string.Length)), target));\n}\n```\n\nand use it like so\n\n```CSharp\nvar queryResult = kerbals.AsQueryable().Query(new Filter\n{\n    PropertyName = nameof(Kerbal.FirstName),\n    Operator = ExtendedFilterOperators.LengthLessThan,\n    Value = 4\n}).ToList();\n\nConsole.WriteLine($\"Filter matched {queryResult.Count} Kerbal(s). They are:\");\nforeach(var item in queryResult)\n{\n    Console.WriteLine($\" - {item.FirstName}\");\n}\n\n// Expected Output :\n// Filter matched 3 Kerbal(s). They are:\n//  - Bob\n//  - Jeb\n//  - Val\n```\n\n## Working Example\n\nFor a working example of QueryR in action, check out the [ConsoleApp](https://github.com/craigmccauley/QueryR/tree/main/src/QueryR.Examples.ConsoleApp) example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraigmccauley%2Fqueryr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraigmccauley%2Fqueryr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraigmccauley%2Fqueryr/lists"}