{"id":13431362,"url":"https://github.com/sqlkata/querybuilder","last_synced_at":"2025-05-13T20:02:29.664Z","repository":{"id":37664890,"uuid":"90608506","full_name":"sqlkata/querybuilder","owner":"sqlkata","description":"SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird","archived":false,"fork":false,"pushed_at":"2025-02-02T21:16:03.000Z","size":843,"stargazers_count":3227,"open_issues_count":153,"forks_count":514,"subscribers_count":123,"default_branch":"main","last_synced_at":"2025-05-06T19:51:51.009Z","etag":null,"topics":["activerecord","c-sharp","csharp","data-access-layer","database","mysql","postgresql","query-builder","sql","sql-query","sql-query-builder","sql-server"],"latest_commit_sha":null,"homepage":"https://sqlkata.com","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/sqlkata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["ahmad-moussawi"],"patreon":null,"open_collective":"sqlkata","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-05-08T09:11:27.000Z","updated_at":"2025-05-06T09:45:34.000Z","dependencies_parsed_at":"2023-02-08T17:16:26.475Z","dependency_job_id":"a5469254-3c21-4d0b-8a09-39f0e9d59dd8","html_url":"https://github.com/sqlkata/querybuilder","commit_stats":{"total_commits":510,"total_committers":61,"mean_commits":8.360655737704919,"dds":"0.47058823529411764","last_synced_commit":"950fd0156e0d8b933483d950797ba114573f77ed"},"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlkata%2Fquerybuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlkata%2Fquerybuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlkata%2Fquerybuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqlkata%2Fquerybuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sqlkata","download_url":"https://codeload.github.com/sqlkata/querybuilder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020468,"owners_count":22000749,"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":["activerecord","c-sharp","csharp","data-access-layer","database","mysql","postgresql","query-builder","sql","sql-query","sql-query-builder","sql-server"],"created_at":"2024-07-31T02:01:02.517Z","updated_at":"2025-05-13T20:02:29.543Z","avatar_url":"https://github.com/sqlkata.png","language":"C#","readme":"\u003cp align=\"center\"\u003e\n    \u003cstrong style=\"font-size: 2em;\"\u003eSqlKata Query Builder\u003c/strong\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/sqlkata/querybuilder/actions/workflows/build.yml/badge.svg\"\u003e\n    \u003ca href=\"https://www.nuget.org/packages/SqlKata\"\u003e\u003cimg src=\"https://img.shields.io/nuget/vpre/SqlKata.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/sqlkata/querybuilder/network/members\"\u003e\u003cimg src=\"https://img.shields.io/github/forks/sqlkata/querybuilder\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/sqlkata/querybuilder/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/sqlkata/querybuilder\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://twitter.com/intent/tweet?text=Wow:\u0026url=https%3A%2F%2Fgithub.com%2Fsqlkata%2Fquerybuilder\"\u003e\u003cimg alt=\"Twitter\" src=\"https://img.shields.io/twitter/url?label=Tweet%20about%20SqlKata\u0026style=social\u0026url=https%3A%2F%2Fgithub.com%2Fsqlkata%2Fquerybuilder\"\u003e\u003c/a\u003e\t\t\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cstrong\u003eFollow and Upvote SqlKata on Product Hunt to encourage the development of this project\u003c/strong\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.producthunt.com/products/sqlkata?utm_source=badge-follow\u0026utm_medium=badge\u0026utm_souce=badge-sqlkata\" target=\"_blank\"\u003e\u003cimg src=\"https://api.producthunt.com/widgets/embed-image/v1/follow.svg?post_id=398417\u0026theme=light\" alt=\"SqlKata - Dynamic\u0026#0032;Sql\u0026#0032;query\u0026#0032;builder\u0026#0032;for\u0026#0032;dotnet | Product Hunt\" style=\"width: 250px; height: 54px;\" width=\"250\" height=\"54\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nhttps://private-user-images.githubusercontent.com/2517523/408899411-1f9ff89b-ed17-4d02-ae2f-afc1c66a5932.mp4\n\n## 🚀 Introduction\n\nSqlKata Query Builder is a powerful SQL query builder written in C#. It is secure, framework-agnostic, and inspired by top query builders like Laravel Query Builder and Knex.\n\n### ✨ Key Features\n- **Expressive API**: Clean and intuitive syntax similar to SQL.\n- **Database Agnostic**: Work with multiple databases using a unified API.\n- **Complex Queries**: Supports nested conditions, subqueries, conditional statements, and more.\n- **Execution Support**: Use the SqlKata.Execution package to execute queries with Dapper.\n\n## Installation\n\n```sh\n$ dotnet add package SqlKata\n$ dotnet add package SqlKata.Execution # (optional) If you want the execution support\n```\n\n## Quick Examples\n\n### Setup Connection\n\n```cs\nvar connection = new SqlConnection(\"...\");\nvar compiler = new SqlCompiler();\nvar db = new QueryFactory(connection, compiler);\n```\n\u003e `QueryFactory` is provided by the SqlKata.Execution package.\n\n### Retrieve all records\n\n```cs\nvar books = db.Query(\"Books\").Get();\n```\n\n### Retrieve published books only\n\n```cs\nvar books = db.Query(\"Books\").WhereTrue(\"IsPublished\").Get();\n```\n\n### Retrieve one book\n\n```cs\nvar introToSql = db.Query(\"Books\").Where(\"Id\", 145).Where(\"Lang\", \"en\").First();\n```\n\n### Retrieve recent books: last 10\n\n```cs\nvar recent = db.Query(\"Books\").OrderByDesc(\"PublishedAt\").Limit(10).Get();\n```\n\n### Include Author information\n\n```cs\nvar books = db.Query(\"Books\")\n    .Include(db.Query(\"Authors\")) // Assumes that the Books table has an `AuthorId` column\n    .Get();\n```\n\nThis will include the property \"Author\" on each \"Book\":\n```jsonc\n[{\n    \"Id\": 1,\n    \"PublishedAt\": \"2019-01-01\",\n    \"AuthorId\": 2,\n    \"Author\": { // \u003c-- included property\n        \"Id\": 2,\n        \"...\": \"\"\n    }\n}]\n```\n\n### Join with authors table\n\n```cs\nvar books = db.Query(\"Books\")\n    .Join(\"Authors\", \"Authors.Id\", \"Books.AuthorId\")\n    .Select(\"Books.*\", \"Authors.Name as AuthorName\")\n    .Get();\n\nforeach(var book in books)\n{\n    Console.WriteLine($\"{book.Title}: {book.AuthorName}\");\n}\n```\n\n### Conditional queries\n\n```cs\nvar isFriday = DateTime.Today.DayOfWeek == DayOfWeek.Friday;\n\nvar books = db.Query(\"Books\")\n    .When(isFriday, q =\u003e q.WhereIn(\"Category\", new [] {\"OpenSource\", \"MachineLearning\"}))\n    .Get();\n```\n\n### Pagination\n\n```cs\nvar page1 = db.Query(\"Books\").Paginate(10);\n\nforeach(var book in page1.List)\n{\n    Console.WriteLine(book.Name);\n}\n\n...\n\nvar page2 = page1.Next();\n```\n\n### Insert\n\n```cs\nint affected = db.Query(\"Users\").Insert(new {\n    Name = \"Jane\",\n    CountryId = 1\n});\n```\n\n### Update\n\n```cs\nint affected = db.Query(\"Users\").Where(\"Id\", 1).Update(new {\n    Name = \"Jane\",\n    CountryId = 1\n});\n```\n\n### Delete\n\n```cs\nint affected = db.Query(\"Users\").Where(\"Id\", 1).Delete();\n```\n\n## FAQ\n\n### How to know when a new release or a feature is available?\n\nI announce updates on my [Twitter Account](https://twitter.com/ahmadmuzavi), and you can subscribe to our newsletters from the website [https://sqlkata.com](https://sqlkata.com).\n\n### The database that I want is not supported. Why?\n\nIt's impossible to support all available database vendors, which is why we focus on the major ones. We encourage you to create your own compiler for your database.\n\n### Do you accept new compilers?\n\nUnfortunately, no. The reason is that this would add overhead for the project contributors. We prefer to improve the quality of the existing compilers instead.\n\n### How can I support the project?\n\n- ⭐ Star the project here on GitHub, and share it with your friends.\n- 🐱‍💻 Follow and upvote it on Product Hunt:\n  \u003ca href=\"https://www.producthunt.com/products/sqlkata?utm_source=badge-follow\u0026utm_medium=badge\u0026utm_souce=badge-sqlkata\" target=\"_blank\"\u003e\u003cimg src=\"https://api.producthunt.com/widgets/embed-image/v1/follow.svg?post_id=398417\u0026theme=light\u0026size=small\" alt=\"SqlKata - Dynamic\u0026#0032;Sql\u0026#0032;query\u0026#0032;builder\u0026#0032;for\u0026#0032;dotnet | Product Hunt\" style=\"width: 86px; height: 32px;\" width=\"250\" height=\"54\" /\u003e\u003c/a\u003e\n- 💰 You can also donate to support the project financially on open collection.\n","funding_links":["https://github.com/sponsors/ahmad-moussawi","https://opencollective.com/sqlkata"],"categories":["Frameworks, Libraries and Tools","C\\#","C# #","C#","Libraries","框架, 库和工具","SQL Server Web Resources","Query Builders","sql"],"sub_categories":["ORM","Query Builders","ORM and Micro-ORM","sql生成器"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqlkata%2Fquerybuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsqlkata%2Fquerybuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqlkata%2Fquerybuilder/lists"}