{"id":25463110,"url":"https://github.com/piotr-maker/sqlinq","last_synced_at":"2026-04-25T23:36:38.354Z","repository":{"id":277898556,"uuid":"909642856","full_name":"piotr-maker/sqlinq","owner":"piotr-maker","description":"SQLinq is a C++ library that enables easy and efficient integration with SQL databases, using a syntax similar to LINQ from C#.","archived":false,"fork":false,"pushed_at":"2025-10-18T16:15:17.000Z","size":121,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-19T09:52:40.122Z","etag":null,"topics":["cpp","cpp20-library","databases","linq","orm","sql","sqlite"],"latest_commit_sha":null,"homepage":"","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/piotr-maker.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-29T10:59:18.000Z","updated_at":"2025-10-18T16:15:20.000Z","dependencies_parsed_at":"2025-09-23T18:17:11.281Z","dependency_job_id":"37a68a33-a7a7-416f-903c-f07d8b6f8d72","html_url":"https://github.com/piotr-maker/sqlinq","commit_stats":null,"previous_names":["piotr-maker/sqlinq"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/piotr-maker/sqlinq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-maker%2Fsqlinq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-maker%2Fsqlinq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-maker%2Fsqlinq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-maker%2Fsqlinq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piotr-maker","download_url":"https://codeload.github.com/piotr-maker/sqlinq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotr-maker%2Fsqlinq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32280979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"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":["cpp","cpp20-library","databases","linq","orm","sql","sqlite"],"created_at":"2025-02-18T06:19:35.021Z","updated_at":"2026-04-25T23:36:38.349Z","avatar_url":"https://github.com/piotr-maker.png","language":"C++","readme":"![Linux](https://github.com/piotr-maker/sqlinq/actions/workflows/ci-linux.yml/badge.svg) ![macOS](https://github.com/piotr-maker/sqlinq/actions/workflows/ci-macos.yml/badge.svg) ![Windows](https://github.com/piotr-maker/sqlinq/actions/workflows/ci-windows.yml/badge.svg)\n\n# SQLinq - SQL Query Library in C++\n\nSQLinq is a modern C++ library that enables easy and type-safe integration with SQL databases.\nIt takes inspiration from LINQ in C# and functional programming, while remaining close to SQL.\nWith SQLinq, you can:\n- Build queries with a fluent LINQ-like API\n- Use it as a lightweight ORM with create, find, get_all, update, remove\n- Write aggregate queries (count, sum, avg, …)\n- Stay type-safe thanks to lambdas and member pointers (no raw SQL strings)\n\n## Demo Project\n\nA full demo application using SQLinq is available here: \n[SQLinq Blog Demo](https://github.com/piotr-maker/sqlinq-blog-demo.git)\n\nIt shows:\n- Automatic schema generation\n- Setting up SQLinq with SQLite\n- Fluent query composition with LINQ-style API\n- Integration with CMake and configuration files\n\n## Database Connection\n\nDatabase connection can be configured either via:\n- Environment variables\n- Configuration file (`db.conf`)\n\nFor full instructions, see the [Configuration Guide](doc/config/README.md).\n\n## Defining tables\n\nSQLinq gives you full control over how your C++ structs map to SQL tables.\nThis is done by specializing the `sqlinq::Table\u003cEntity\u003e` template and providing a `meta()` function with column definitions.\n\n### Example\n\n```cpp\nstruct User {\n  int id;\n  std::string name;\n  int age;\n};\n\ntemplate\u003c\u003e struct sqlinq::Table\u003cUser\u003e {\n  SQLINQ_COLUMN(0, User, id)\n  SQLINQ_COLUMN(1, User, name)\n  SQLINQ_COLUMN(2, User, age)\n\n  static consteval auto meta() {\n    using namespace sqlinq;\n    return make_table\u003cUser\u003e(\n      \"users\",\n      SQLINQ_COLUMN_META(User, id, \"user_id\")\n          .primary_key()\n          .autoincrement(),\n      SQLINQ_COLUMN_META(User, name, \"user_name\"),\n      SQLINQ_COLUMN_META(User, age, \"user_age\")\n    );\n  }\n}\n\n```\nThis approach is explicit and flexible:\n- You can decide how struct fields map to SQL column name.\n- You can declare primary_key, autoincrement, unique and more.\n- In future metadata can also be used for automatic schema generation.\n\n---\n\n### Automatic table generation (optional)\n\nIn addition to manual table definitions, SQLinq can **automatically generate**  \nC++ table metadata and Atlas schemas from annotated structs.\n\nYou can define a struct with modern C++ attributes:\n\n```cpp\nstruct [[table(\"comments\")]] Comment {\n  [[name(\"comment_id\"), autoincrement, primary_key]]\n  int id;\n  [[foreign_key(\"posts.post_id\")]]\n  int post_id;\n  std::string author;\n  std::string content;\n};\n```\nThese annotated structures are discovered automatically during the CMake build\nand converted into:\n- `generated/include/table_schema.hpp` — for C++ queries\n- `generated/schema.my.hcl` — for database migrations with Atlas\n\nTo enable automatic schema generation, add to your `CMakeLists.txt` at the end of file:\n```cmake\nsqlinq_init_venv()\nsqlinq_generate_schema()\n```\nThen simply include the generated header:\n```cpp\n#include \"table_schema.hpp\"\n```\nFor details on automatic generation, see [SQLinq Table Definitions](doc/tables/README.md).\nFor migration workflow, see [Configuration Guide](doc/migrations/README.md).\n\n## Usage\n\n### ORM-style (CRUD operations)\n```cpp\nint main() {\n  SQLiteBackend backend;\n  backend.connect(\"database.db\");\n\n  Database db{backend};\n\n  // Create new record\n  User u{ .id = 0, .name = \"Alice\", .age = 30};\n  db.create(u);\n\n  // Find by primary key\n  auto found = db.find\u003cUser\u003e(u.id);\n\n  // Get all users\n  auto users = db.get_all\u003cUser\u003e();\n\n  // Update\n  if (found) {\n    found-\u003eage = 31;\n    db.update(*found);\n  }\n\n  // Delete\n  db.remove\u003cUser\u003e(u.id);\n}\n```\n\n### LINQ-style (fluent queries)\n```cpp\nint main() {\n  SQLiteBackend sqlite;\n  sqlite.connect(\"database.db\");\n\n  Database db{backend};\n  auto q = Query\u003cUser\u003e()\n        .select_all()\n        .order_by(\u0026User::name)\n        .where([](const auto \u0026user) { return user.age \u003e 18; });\n  for (auto \u0026user : db.execute(q)) {\n    std::cout \u003c\u003c user.id \u003c\u003c ' ' \u003c\u003c user.name \u003c\u003c '\\n';\n  }\n}\n```\n### Aggregates\n```cpp\nint main() {\n  SQLiteBackend sqlite;\n  sqlite.connect(\"database.db\");\n\n  int64_t user_count;\n  Database db{backend};\n  auto q = Query\u003cUser\u003e().select(count(\u0026User::id));\n  auto cursor = db.execute(q);\n  if (cursor.next()) {\n    user_count = std::get\u003c0\u003e(cursor.current());\n  }\n}\n```\nFor complete runnable examples demonstrating both SQLite and MySQL backends, see [Examples](examples/README.md)\n\n## Roadmap\nPlanned features and improvements for SQLinq:\n\n- [x] Type-safe query API (lambdas, member pointers instead of raw SQL strings)\n- [x] Support for both ORM-style and LINQ-style usage\n- [x] Aggregate functions (`COUNT`)\n- [x] Column constraints: `primary_key`, `autoincrement`, `unique`\n\n### Short-term\n- [ ] Aggregate functions (`SUM`, `AVG`, `MIN`, `MAX`)\n- [ ] Join support via `include\u003cEntity\u003e()`\n- [ ] Schema generation from C++ metadata (`meta()`) → auto-create SQL DDL\n- [ ] Introduce `fetch_one()` and `fetch_optional()` for easier single-record queries\n- [ ] Better error handling with dedicated exception hierarchy\n- [ ] Expand unit test coverage to the full codebase (integration + edge cases)\n\n### Mid-term\n- [ ] Support for more SQL dialects (PostgreSQL backend)\n- [ ] Composite primary keys\n- [ ] Default values for columns (`default()`)\n- [ ] Optimize query execution to minimize copies (move semantics everywhere)\n- [ ] Improve developer ergonomics (clearer error messages, better compile-time diagnostics)\n\n### Long-term\n- [ ] Migration support (auto-generate `ALTER TABLE` from metadata changes)\n- [ ] Code generation tooling (e.g. generate C++ structs from existing DB schema)\n- [ ] Async database operations (C++20 coroutines)\n- [ ] Connection pooling\n- [ ] Benchmarking \u0026 performance tuning\n\n## Requirements\n* C++20 or higher\n* CMake version 3.16 or higher\n* Python 3.11 (Schema generation)\n* SQL database development package installed (MySQL, SQLite3)\n  _If SQLite3 is not installed system-wide, the library will automatically download and build it using CMake FetchContent_\n\n## License\nSQLinq is available under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotr-maker%2Fsqlinq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiotr-maker%2Fsqlinq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotr-maker%2Fsqlinq/lists"}