{"id":19993040,"url":"https://github.com/BraspagDevelopers/fluent-query-builder","last_synced_at":"2025-05-04T12:30:41.524Z","repository":{"id":135584365,"uuid":"102152791","full_name":"BraspagDevelopers/fluent-query-builder","owner":"BraspagDevelopers","description":"The purpose of this project is to make easier the construction of dynamic queries that are commonly used in the implementation of reports with several optional filters.","archived":false,"fork":false,"pushed_at":"2023-12-15T20:17:58.000Z","size":31,"stargazers_count":15,"open_issues_count":2,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-07T20:43:44.361Z","etag":null,"topics":["csharp","netstandard","sql"],"latest_commit_sha":null,"homepage":null,"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/BraspagDevelopers.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":"2017-09-01T21:02:40.000Z","updated_at":"2023-07-26T10:50:01.000Z","dependencies_parsed_at":"2023-12-15T21:46:16.982Z","dependency_job_id":"1a8acdaa-f4ff-48e6-bfee-8749471dc010","html_url":"https://github.com/BraspagDevelopers/fluent-query-builder","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BraspagDevelopers%2Ffluent-query-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BraspagDevelopers%2Ffluent-query-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BraspagDevelopers%2Ffluent-query-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BraspagDevelopers%2Ffluent-query-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BraspagDevelopers","download_url":"https://codeload.github.com/BraspagDevelopers/fluent-query-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252334048,"owners_count":21731323,"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","netstandard","sql"],"created_at":"2024-11-13T04:52:26.051Z","updated_at":"2025-05-04T12:30:38.462Z","avatar_url":"https://github.com/BraspagDevelopers.png","language":"C#","readme":"# FluentQueryValidator  ![](https://braspag.visualstudio.com/_apis/public/build/definitions/30d2b6ae-399c-49ac-997b-e563386809e0/327/badge)\n\n### What is it? \n\nThe purpose of this project is to make easier the construction of dynamic queries that are commonly used in the implementation of reports with several optional filters.\n\n### What is not the purpose of this project?\n\nThis project does not want to be like the awesome [Dapper](https://github.com/StackExchange/Dapper) that is an Object Mapper. We only want to build the query as easy as possible and then we use this query with [Dapper](https://github.com/StackExchange/Dapper).\n\nThis project also does not validade order of the method calls, so beware!\n\nBelow is an example of converting queries with IFs to **SelectBuilder**.\n\n``` csharp\nvar sql = string.Concat(\"SELECT C.Id, C.Name, C.Identity, C.Phone, A.State \",\n                        \"FROM Client C \",\n                        \"INNER JOIN Address A ON C.Id = E.ClientId \",\n                        \"WHERE C.Active = 1 AND C.RegisterDate \u003e '2017-01-01'\";\n                        \nif(!string.IsNullOrEmpty(filter.Name))\n{\n  sql = string.Concat(\"AND C.Name LIKE '%' + @clientName + '%'\");\n}\nif(!string.IsNullOrEmpty(filter.State))\n{\n  sql = string.Concat(\"AND A.State = @state\");\n}\n```\nThis type of code become confuse and hard to read very quickly. The approach using **SelectBuilder** is:\n``` csharp\nvar sql = new SelectBuilder()\n  .Select(\"C.Id, C.Name, C.Identity, C.Phone, A.State\")\n  .From(\"Cliente C\")\n  .InnerJoin(\"Address A\", \"C.Id = A.ClientId\")\n  .Where(\"C.Active = 1\")\n  .And(\"C.Active = 1\")\n  .And(\"C.RegisterDate \u003e '2017-01-01'\")\n  .AndIf(\"C.Name LIKE '%' + @clientName + '%'\", !string.IsNullOrEmpty(filter.Name))\n  .AndIf(\"E.Staste = @state\", !string.IsNullOrEmpty(filter.State));\n```\nAs you can see, the **SelectBuilder** approach is much cleaner than using IFs. The API will be detailed in the next sections.\n\n# Getting Started\nYou only need to install the **Braspag.FluentQueryBuilder** package from Nuget.org and you a ready to build your queries.\n```\nPM\u003e install-package Braspag.FluentQueryBuilder\n```\n\n# SelectBuilder Fluent Api\nThe **SelectBuilder** is designed to have an API as fluent as possible, so it will not be hard to you understand. Below are the list of all the methods:\n\n- **Select(** *string fields* **)**   \n  \u0026rarr; Adds the SELECT statement to Query\n\n- **Select(** *string[] fields* **)**   \n  \u0026rarr; Adds the SELECT statement to Query\n  \n- **From(** *string table* **)**   \n  \u0026rarr; Adds the FROM of the query\n\n- **InnerJoin(** *string table, string on* **)**    \n  \u0026rarr; Adds an INNER JOIN with ON clause\n\n- **LeftJoin(** *string table, string on* **)**   \n  \u0026rarr; Adds an LEFT JOIN with ON clause\n\n- **FullOuterJoin(** *string table, string on* **)**    \n  \u0026rarr; Adds an FULL OUTER JOIN with ON clause\n\n- **Where(** *string condition* **)**    \n  \u0026rarr; Adds the where clause with the first condition\n\n- **And(** *string predicate* **)**   \n  \u0026rarr;  Adds an AND condition to WHERE statement\n\n- **And(** *string predicate, Func\u003cWhereBuilder, WhereBuilder\u003e predicates* **)**    \n  \u0026rarr; Adds an AND group condition to WHERE statement\n\n- **AndIf(** *string predicate, bool condition* **)**    \n  \u0026rarr; Conditionally adds an AND condition to WHERE statement\n\n- **AndIf(** *string predicate, Func\u003cWhereBuilder, WhereBuilder\u003e predicates, bool condition* **)**   \n  \u0026rarr; Conditionally adds an AND group condition to WHERE statement\n\n- **Or(** *string predicate* **)**    \n  \u0026rarr; Adds an OR condition to WHERE statement\n\n- **Or(** *string predicate, Func\u003cWhereBuilder, WhereBuilder\u003e predicates* **)**    \n  \u0026rarr; Adds an OR group condition to WHERE statement\n\n- **OrIf(** *string predicate, bool condition* **)**    \n  \u0026rarr; Conditionally adds an OR condition to WHERE statement\n\n- **OrIf(** *string predicate, Func\u003cWhereBuilder, WhereBuilder\u003e predicates, bool condition* **)** \n  \u0026rarr; Conditionally adds an OR group condition to WHERE statement\n\n- **GroupBy(** *string group* **)**   \n  \u0026rarr; Adds the GROUP BY statement to query\n\n- **GroupBy(** *string[] group* **)**   \n  \u0026rarr; Adds the GROUP BY statement to query\n\n- **OrderBy(** *string order* **)**   \n  \u0026rarr; Adds the ORDER BY statement to query\n\n- **OrderBy(** *string[] order* **)**   \n  \u0026rarr; Adds the ORDER BY statement to query\n  \n- **Paginated(** *int pageSize, int currentPage* **)**     \n  \u0026rarr; Adds pagination using the OFFSET/FETCH statements\n\n- **With(** *string hint* **)**     \n  \u0026rarr; Adds the WITH statement to use query hints\n\n- **With(** *string[] hint* **)**     \n  \u0026rarr; Adds multiple hints to use the WITH statement\n\n- **Option(** *string hint* **)**     \n  \u0026rarr; Adds the OPTION clause to use query hints\n\n- **Option(** *string[] hint* **)**     \n  \u0026rarr; Adds multiple hints to use with OPTION clause\n \n# Sample\n\nSelecting filds \"*Field1, Field2, Field3*\" from table \"*Table1*\" where \"*Field1 = 'A very cool value'*\".\n\n``` csharp\nvar sql = new SelectBuilder()\n  .Select(\"Field1,Field2,Field3\")\n  .From(\"Table1\")\n  .Where(\"Field1 = 'A very cool value'\")\n  .Build();\n\nsql.Should().Be(\"SELECT Campo1,Campo2,Campo3 FROM Tabela1 WHERE Campo1 = 'A very cool value'\");\n```\n\nWant more samples? Look a the [tests](https://github.com/BraspagDevelopers/fluent-query-builder/blob/master/src/Braspag.FluentQueryBuilder.Tests/QueryBuilderTests.cs)! Every method has a test.\n\n# Build and Test\nTo build this project you will need Visual Studio 2017.3. If you already have it, clone this repo and have fun!\n","funding_links":[],"categories":["C\\#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBraspagDevelopers%2Ffluent-query-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBraspagDevelopers%2Ffluent-query-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBraspagDevelopers%2Ffluent-query-builder/lists"}