{"id":33914902,"url":"https://github.com/kiebor81/querykit","last_synced_at":"2026-01-13T22:01:06.557Z","repository":{"id":327297017,"uuid":"1108718820","full_name":"kiebor81/querykit","owner":"kiebor81","description":"Ruby SQL query builder and micro-ORM inspired by SqlKata and Dapper","archived":false,"fork":false,"pushed_at":"2025-12-04T09:08:14.000Z","size":118,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-02T12:32:42.866Z","etag":null,"topics":["fluent-api","mico-orm","mysql","orm","postgres","query-builder","querydsl","ruby","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/kiebor81.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-02T20:32:15.000Z","updated_at":"2025-12-04T09:08:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/kiebor81/querykit","commit_stats":null,"previous_names":["kiebor81/quby"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kiebor81/querykit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiebor81%2Fquerykit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiebor81%2Fquerykit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiebor81%2Fquerykit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiebor81%2Fquerykit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiebor81","download_url":"https://codeload.github.com/kiebor81/querykit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiebor81%2Fquerykit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28400397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["fluent-api","mico-orm","mysql","orm","postgres","query-builder","querydsl","ruby","sqlite3"],"created_at":"2025-12-12T06:43:51.432Z","updated_at":"2026-01-13T22:01:06.550Z","avatar_url":"https://github.com/kiebor81.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# QueryKit \n\n[![RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)\n\n[![Gem Version](https://badge.fury.io/rb/querykit.svg)](https://badge.fury.io/rb/querykit)\n[![Documentation](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/gems/querykit)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\nA fluent, intuitive query builder and micro-ORM for Ruby inspired by .NET''s SqlKata. Perfect for projects where Active Record feels like overkill.\n\n## Features\n\n- **Zero dependencies** (except database drivers)\n- **Fluent, chainable API** inspired by SqlKata\n- **Multiple database adapters** (SQLite3, PostgreSQL, MySQL)\n- **Comprehensive WHERE clauses** (operators, IN, NULL, BETWEEN, EXISTS, raw SQL)\n- **JOIN support** (INNER, LEFT, RIGHT, CROSS)\n- **Aggregate shortcuts** (count, avg, sum, min, max)\n- **UNION/UNION ALL** for combining queries\n- **Optional model mapping** (Dapper-style)\n- **Optional repository pattern** (C#-style)\n- **Transaction support**\n- **Raw SQL when you need it**\n- **SQL injection protection** via parameterized queries\n\n## Installation\n\n```bash\n\ngem install querykit\n\n```\n\nThen your preferred database driver.\n\n```bash\n# SQLite\ngem install sqlite3\n\n# PostgreSQL\ngem install pg\n\n# MySQL\ngem install mysql2\n```\n## Quick Start\n\nSee [`demo.rb`](examples/demo.rb) for more extensive examples.\n\n```ruby\nrequire 'querykit'\n\n# Configure once\nQueryKit.setup(:sqlite, database: 'app.db')\n\n# Query builder\nusers = QueryKit.connection.get(\n  QueryKit.connection.query('users')\n    .where('age', '\u003e', 18)\n    .order_by('name')\n    .limit(10)\n)\n\n# Repository pattern (query scoping)\nclass UserRepository \u003c QueryKit::Repository\n  table 'users'\n  model User\nend\n\nrepo = UserRepository.new\nuser = repo.find(1)\nusers = repo.where('age', '\u003e', 18)\n```\n\n## Documentation\n\n- [Getting Started](docs/getting-started.md) - Setup and basic usage\n- [Query Builder](docs/query-builder.md) - SELECT, INSERT, UPDATE, DELETE\n- [Advanced Features](docs/advanced-features.md) - Model mapping, repositories, transactions\n- [API Reference](docs/api-reference.md) - Complete API documentation\n- [Security Best Practices](docs/security.md) - SQL injection protection and safe usage\n- [Concurrency \u0026 Thread Safety](docs/concurrency.md) - Multi-threaded usage and connection management\n- [CASE WHEN Extension](docs/extensions/case-when.md) - Optional fluent CASE expressions\n\n**Full documentation site:** https://kiebor81.github.io/querykit\n\n**API documentation (YARD):** Generate locally with `rake doc`\n\n## Why QueryKit?\n\n**vs Active Record:** Much lighter, no DSL, no magic. Just build queries and execute them.\n\n**vs Sequel:** Simpler API, fewer features by design. If you need a full ORM, use Sequel.\n\n**vs Raw SQL:** Type-safe, composable queries with protection against SQL injection.\n\n## Security\n\nQueryKit uses **parameterized queries by default**, protecting against SQL injection when used correctly:\n\n```ruby\n# SAFE - Values are automatically parameterized\ndb.query('users').where('email', user_input)\n\n# UNSAFE - Never interpolate user input\ndb.raw(\"SELECT * FROM users WHERE email = '#{user_input}'\")\n\n# SAFE - Use placeholders with raw SQL\ndb.raw('SELECT * FROM users WHERE email = ?', user_input)\n```\n\n**See [Security Best Practices](docs/security.md) for detailed guidance.**\n\n## Philosophy\n\n- **Minimal dependencies** - Only database drivers required\n- **Simple and explicit** - No hidden magic or metaprogramming\n- **Composable** - Build queries piece by piece\n- **Flexible** - Use what you need, ignore what you don't\n- **Extensible** - Opt-in extensions for advanced features\n\n## Extensions\n\nQueryKit supports optional extensions that add advanced features without bloating the core:\n\n```ruby\nrequire 'querykit/extensions/case_when'\n\n# Load extensions at startup\nQueryKit.use_extensions(QueryKit::CaseWhenExtension)\n\n# Or load multiple extensions\nQueryKit.use_extensions([Extension1, Extension2])\n```\n\nAvailable extensions:\n- **CASE WHEN** - Fluent CASE expression builder ([docs](docs/extensions/case-when.md))\n\nExtensions use Ruby's `prepend` to cleanly override methods without monkey-patching.\n\n## What QueryKit Doesn't Do\n\nThese features are intentionally excluded to maintain simplicity:\n\n- **Migrations** - Use a dedicated migration tool\n- **Associations** - Write explicit JOINs instead\n- **Validations** - Handle in your business logic layer\n- **Callbacks** - Keep side effects explicit\n- **Soft Deletes** - Implement as a WHERE filter in repositories\n- **Eager Loading** - Use JOINs or accept N+1 queries\n\nFor advanced SQL features, use raw SQL:\n\n```ruby\n# Common Table Expressions (CTEs)\ndb.raw(\u003c\u003c~SQL, user_id)\n  WITH ranked_orders AS (\n    SELECT *, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC) as rn\n    FROM orders\n  )\n  SELECT * FROM ranked_orders WHERE rn = 1 AND user_id = ?\nSQL\n\n# Window Functions\ndb.raw('SELECT *, AVG(salary) OVER (PARTITION BY department) as dept_avg FROM employees')\n\n# Upsert (SQLite)\ndb.raw('INSERT INTO users (id, name) VALUES (?, ?) ON CONFLICT(id) DO UPDATE SET name=excluded.name', id, name)\n```\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\nThis project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.\n\n## Acknowledgments\n\nInspired by [SqlKata](https://sqlkata.com/) (.NET) and [Arel](https://github.com/rails/arel) (Ruby).\n\n## License\n\nThis is a personal project, but suggestions and bug reports are welcome via issues.\n\nMIT License - see [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiebor81%2Fquerykit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiebor81%2Fquerykit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiebor81%2Fquerykit/lists"}