{"id":22495373,"url":"https://github.com/kaashyapan/sqlc-gen-fsharp","last_synced_at":"2025-08-03T02:31:16.291Z","repository":{"id":169165444,"uuid":"644700229","full_name":"kaashyapan/sqlc-gen-fsharp","owner":"kaashyapan","description":"Sqlc plugin to generate F# code from SQL","archived":false,"fork":false,"pushed_at":"2024-02-04T08:37:18.000Z","size":95,"stargazers_count":13,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-21T15:42:17.346Z","etag":null,"topics":["code-generator","codegen","fsharp","orm","postgresql","sql","sqlite","typeprovider"],"latest_commit_sha":null,"homepage":"","language":"Go","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/kaashyapan.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":"2023-05-24T04:36:12.000Z","updated_at":"2024-04-08T04:15:45.000Z","dependencies_parsed_at":"2024-02-04T08:21:17.916Z","dependency_job_id":"2f94bdd5-b056-4295-8211-966c12fc53f9","html_url":"https://github.com/kaashyapan/sqlc-gen-fsharp","commit_stats":null,"previous_names":["kaashyapan/sqlc-gen-fsharp"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaashyapan%2Fsqlc-gen-fsharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaashyapan%2Fsqlc-gen-fsharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaashyapan%2Fsqlc-gen-fsharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaashyapan%2Fsqlc-gen-fsharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaashyapan","download_url":"https://codeload.github.com/kaashyapan/sqlc-gen-fsharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228517303,"owners_count":17932433,"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":["code-generator","codegen","fsharp","orm","postgresql","sql","sqlite","typeprovider"],"created_at":"2024-12-06T19:27:18.456Z","updated_at":"2024-12-06T19:27:19.091Z","avatar_url":"https://github.com/kaashyapan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sqlc plugin for F# \n## Codegen F# from SQL\n`sqlc` is a command line program that generates type-safe database access code from SQL.\\\nSqlc documentation - https://sqlc.dev\n\n**Inputs**\n  - DB schema.sql file\n  - File containing SQL statements\n  - Configuration file. \n\n**Outputs**\n  - Models as F# data structures\n  - Queries as functions taking named-typed parameters\n  - Readers to decode DB response into F# data structures \n\n\n| Target    |  Library          |    |\n|-----------|-------------------|----|\n|Postgres   |`Npgsql.FSharp`    |   |\n|MySql      | Not supported     | Models will be generated|\n|Sqlite     |`Fumble`           |   |\n\n## Why this ?\nType safe DB access in F# is tedious with manually written data structures.\\\n[SqlHydra](https://github.com/JordanMarr/SqlHydra) is a great dotnet tool to generate F# boiler plate. Works great with ORMs.\\\nI found I was writing a lot of custom SQL and wanted a solution that can generate 90% of the code.\n  \nThis is intended for devs who prefer to write SQL by hand. \nYou can also auto generate basic crud SQLs for all your tables using [sqlc-gen-crud](https://github.com/kaashyapan/sqlc-gen-crud) \n\nRunning the 2 plugins in sequence should generate much of the boilerplate\n\n|SqlHydra  | Sqlc|\n|-----------|-------------------|\n|Uses a connection to the database to generate data structures| Uses schema file and SQL files|\n|Postgres, Oracle, MS-Sql \u0026 Sqlite | Postgres \u0026 Sqlite |\n|SqlHydra.Query uses Sqlkata and also has some Linq-to-Sql goodness | Basic CRUD using [sqlc-gen-crud](https://github.com/kaashyapan/sqlc-gen-crud). Handwritten Sql for anything more. |\n|Wraps Microsoft.Data.SqlClient. Flexible. Bring your own ADO.net wrapper| Wraps higher level F# libraries. Opinionated. Less generated code. |\n|Cannot introspect queries | Wraps the pg_query Postgres SQL parser. It syntax checks the SQL \u0026 DDL statements catching misspelt column names etc..|\n|Handwritten data structures are required for custom queries| Produces exact data structures and readers for custom queries |\n\nAnd there is also [Facil](https://github.com/cmeeren/Facil) but its MS-Sql only. Havent played around with it much.\n\n## How to use\n\n- Install [Sqlc](https://docs.sqlc.dev/en/latest/overview/install.html)\n- Create Schema.sql containing DDL statements. (or generate using pg_dump)\n- Create Query.sql containing SQL statements with an annotation like in [docs](https://docs.sqlc.dev/en/latest/reference/query-annotations.html)\n    ```sql\n    -- name: ListAuthors :many\n    SELECT * FROM authors ORDER BY name;\n    ```\n- Create sqlc.json \u0026 configure the options\n  ```json\n  {\n    \"version\": \"2\",\n    \"plugins\": [\n      {\n        \"name\": \"fsharp\",\n        \"wasm\": {\n          \"url\": \"https://github.com/kaashyapan/sqlc-gen-fsharp/releases/download/v1.0.1/sqlc-gen-fsharp.wasm\",\n          \"sha256\": \"fe0428d7cf1635b640d288be1ecfcc246ea15f882b397317394ee0d3108bdc81\"\n        }\n      }\n    ],\n    \"sql\": [\n      {\n        \"engine\": \"postgresql\",\n        \"schema\": \"schema.sql\",\n        \"queries\": \"query.sql\",\n        \"codegen\": [\n          {\n            \"out\": \u003c..target_folder...\u003e,\n            \"plugin\": \"fsharp\",\n            \"options\": {\n              \"namespace\": \u003c...Namespace...\u003e,\n              \"async\": false,\n              \"type_affinity\": true \n            }\n          }\n        ]\n      }\n    ]\n  }\n  ```\n- ```sqlc generate```\n\nSee the example folder for a sample setup.\n\n\n\n### fsharp config options\n`namespace`: The namespace to use for the generated code.\\\n`out`: Output directory for generated code.\\\n`emit_exact_table_names`: If true, use the exact table name for generated models. Otherwise, guess a singular form. Defaults to *false*.\\\n`async`: If true, all query functions generated will be async. Defaults to *false*.\\\n`type_affinity`: If true, all DB integers (except Bigint) will be mapped to F#int. All DB floats will be mapped to F#double. Defaults to *false*.\n\n\n### TODO\n- Support for enumerated column types.\n- Postgis type support\n- Optionally generate classes instead of records\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaashyapan%2Fsqlc-gen-fsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaashyapan%2Fsqlc-gen-fsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaashyapan%2Fsqlc-gen-fsharp/lists"}