{"id":26296041,"url":"https://github.com/mo42/sqlc","last_synced_at":"2025-03-15T04:16:45.420Z","repository":{"id":240805899,"uuid":"803509302","full_name":"mo42/sqlc","owner":"mo42","description":"POC to compile SQL to C++","archived":false,"fork":false,"pushed_at":"2024-12-23T21:15:09.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T11:06:26.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/mo42.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-05-20T21:26:04.000Z","updated_at":"2024-12-23T21:15:12.000Z","dependencies_parsed_at":"2024-05-21T00:14:14.571Z","dependency_job_id":"0e9e9e00-a34b-4a7f-82fa-e32fdfb93a41","html_url":"https://github.com/mo42/sqlc","commit_stats":null,"previous_names":["mo42/sqlc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mo42%2Fsqlc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mo42%2Fsqlc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mo42%2Fsqlc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mo42%2Fsqlc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mo42","download_url":"https://codeload.github.com/mo42/sqlc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243681046,"owners_count":20330155,"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":[],"created_at":"2025-03-15T04:16:44.925Z","updated_at":"2025-03-15T04:16:45.412Z","avatar_url":"https://github.com/mo42.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlc - Compile SQL to Type-Checked C++\n\nProof-of-concept for a compiler that translates SQL queries to type-checked C++ code.\n\n## Motivation\n- Performance: build ML pipelines than run faster than those written in Python with Pandas ([DataFrame performance](https://github.com/hosseinmoein/DataFrame?tab=readme-ov-file#performance)).\n- Security: no need for a SQL runtime, just run a single-purpose C++ program that can be audited.\n- Integration: run SQL on (embedded) systems that don't support a heavy DBMS but can handle self-contained C++ programs.\n\n## Technical Details\n- SQL parser based on [sqlparser-rs](https://github.com/sqlparser-rs/sqlparser-rs).\n- Generated C++ code uses [DataFrame](https://github.com/hosseinmoein/DataFrame)\n\n## Installation\n```sh\ngit clone https://github.com/mo42/sqlc.git \u0026\u0026 cd sqlc\ncargo build --release\n```\n\n## Example\n\nCompiling the example SQL file:\n```sh\ncargo run -- example.sql \u003e example.cpp\n```\n\n```sql\nSELECT\n  date,\n  column2\nFROM\n  'example.csv'\n  JOIN 'join.csv' USING(column2)\nWHERE\n  joined_string = \"Join string 3\"\nORDER BY date ASC, column2 DESC\n```\n\n```cpp\n#include \u003cDataFrame/DataFrame.h\u003e\n\n#include \u003ciostream\u003e\nusing namespace hmdf;\ntypedef ulong idx_t;\nusing SqlcDataFrame = StdDataFrame\u003cidx_t\u003e;\nint main(int, char**) {\n  SqlcDataFrame df_main;\n  df_main.read(\"example.csv\", io_format::csv2);\n  SqlcDataFrame df_join0;\n  df_join0.read(\"join.csv\", io_format::csv2);\n  SqlcDataFrame df = df_main.join_by_column\u003cdecltype(df_join0), int, double,\n                                            std::string, int, long, ulong\u003e(\n      df_join0, \"column2\", hmdf::join_policy::inner_join);\n  auto where_functor = [](const idx_t\u0026,\n                          const std::string\u0026 joined_string) -\u003e bool {\n    return (joined_string == \"Join string 3\");\n  };\n  auto where_df = df.get_data_by_sel\u003cstd::string, decltype(where_functor),\n                                     double, std::string, int, long, ulong\u003e(\n      \"joined_string\", where_functor);\n  where_df.sort\u003cstd::string, int, double, std::string, int, long, ulong\u003e(\n      \"date\", sort_spec::ascen, \"column2\", sort_spec::desce);\n  std::vector\u003cidx_t\u003e idx = where_df.get_index();\n  std::vector\u003cstd::string\u003e date = where_df.get_column\u003cstd::string\u003e(\"date\");\n  std::vector\u003cint\u003e column2 = where_df.get_column\u003cint\u003e(\"column2\");\n  SqlcDataFrame select;\n  select.load_index(std::move(idx));\n  select.load_column(\"date\", std::move(date));\n  select.load_column(\"column2\", std::move(column2));\n  select.write\u003cstd::ostream, std::string, int\u003e(std::cout, hmdf::io_format::csv,\n                                               5, false, 100);\n  return 0;\n}\n```\n\n# Documentation\n\nOrder of execution of SQL statements:\n\n1. FROM\n2. JOIN\n3. WHERE\n4. GROUP BY\n5. HAVING\n6. SELECT (column-wise computations like `2 * col1 AS twice`, window functions)\n7. ORDER BY\n8. LIMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmo42%2Fsqlc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmo42%2Fsqlc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmo42%2Fsqlc/lists"}