René's URL Explorer Experiment


Title: RFC: nullability (and other metadata) for input arguments / parameters to a query · Issue #1525 · sqlc-dev/sqlc · GitHub

Open Graph Title: RFC: nullability (and other metadata) for input arguments / parameters to a query · Issue #1525 · sqlc-dev/sqlc

X Title: RFC: nullability (and other metadata) for input arguments / parameters to a query · Issue #1525 · sqlc-dev/sqlc

Description: What do you want to change? Kudos Before I start, I wanted to give a huge kudos for sqlc - I love it. As a backend developer who knows SQL very well, I fight every single ORM I have used trying to do any SQL more complicated than CRUD. T...

Open Graph Description: What do you want to change? Kudos Before I start, I wanted to give a huge kudos for sqlc - I love it. As a backend developer who knows SQL very well, I fight every single ORM I have used trying to ...

X Description: What do you want to change? Kudos Before I start, I wanted to give a huge kudos for sqlc - I love it. As a backend developer who knows SQL very well, I fight every single ORM I have used trying to ...

Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/1525

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"RFC: nullability (and other metadata) for input arguments / parameters to a query ","articleBody":"### What do you want to change?\n\n**Kudos**\r\nBefore I start, I wanted to give a huge kudos for sqlc - I love it. As a backend developer who knows SQL very well, I fight every single ORM I have used trying to do any SQL more complicated than CRUD.  Thank you for creating this.\r\n\r\n**Background**\r\nI use sqlc alongside Postgres, as sort of a foreign function interface to SQL.  I manage a PostgreSQL database with about 100 different tables and working in Typescript and Go to support every stage of solar operations for [Bright](https://www.ycombinator.com/companies/bright).  We do not currently use sqlc at Bright - but I do use it personally, but I am evaluating it Bright as well.\r\n\r\nThe types of problems I work on are not always CRUD-y (though sqlc works really well if they are).  And the challenge I am facing is that SQL is a little less-expressive than the target languages in some cases, and therefore using sqlc as a FFI is a little clunky.  A quick glance through the [some](https://github.com/kyleconroy/sqlc/issues/1446) [open](https://github.com/kyleconroy/sqlc/pull/1491) [issues](https://github.com/kyleconroy/sqlc/pull/1462), shows that \"nullability\" is one of those deficiencies.  sqlc does its best to always \"do the right thing\" and that has gotten it very far indeed. But I think a simple change can give developers full control, _and_ allow for sqlc to keep getting smarter (better interred mappings / types).\r\n\r\nSay for example, instead of finding a really good GeoJSON library in my target language, I wanted to rely on PostGIS.\r\n```sql\r\n- name: WKBToGeoJSON :one\r\nselect ST_AsGeoJSON(ST_GeomFromWKB(sqlc.arg('wkb_bytes'))::text as output;\r\n```\r\n\r\nI would love for this Go code to be generated:\r\n```Go\r\nfunc (q *Queries) WKBToGeoJSON(ctx context.Context, db DBTX, wkbBytes []byte) (string, error) {\r\n    // ...\r\n}\r\n```\r\n\r\n**Or perhaps a more common use case, partial updates**\r\n```sql\r\n-- name: EditThing :exec\r\nupdate thing\r\nset\r\n  name = coalesce(sqlc.arg('name'), name),\r\n  description = coalesce(sqlc.arg('description'), description),\r\n  status = coalesce(sqlc.arg('status'), status)\r\nwhere thing.id = sqlc.arg(id)\r\n\r\n-- name, description and status are all nullable arguments, id is not.\r\n```\r\n\r\n**Proposal**\r\nI think sqlc should expose a way (like overrides) _in the query itself_ to control aspects of the generated code in the target languages.  \r\n\r\nAllow `sqlc.arg(name)` to accept more variadic arguments (similar to jsonb_build_object) to build up string key, and json value pairs of \"configuration\" for that arguments.  I think sqlc itself should not really know too much about the semantics of these key/value pairs, and just pass them along to the code generators in the target language.\r\n\r\n```sql\r\n-- name: EditThing :exec\r\nupdate thing\r\nset\r\n  name = coalesce(sqlc.arg('new_name', 'nullable', true, 'type', 'string'), name),\r\n  description = coalesce(sqlc.arg('description', nullable, true), description),\r\n  status = coalesce(sqlc.arg('status', 'nullable', true), status)\r\nwhere thing.id = sqlc.arg(id)\r\n```\r\n\r\nThis also allows the developer to control the API interface much better, even if the database is a little wacky.  Imagine if there was a column `name` that was nullable for historical reasons, but any new insert to `name` it should be non null.  sqlc should support that use case too.\r\n\r\nI am not a super-polyglot, but if there were a C++ backend for sqlc, you probably wouldn't just want `nullable` but also maybe an option for the type of pointer that should be generated raw pointer? std::shared_ptr? std::unique_ptr? boost::? std::optional ?\r\n\r\n```sql\r\n-- name: GetThingForCpp :one\r\nselect\r\n  id,\r\n  first_name,\r\n  last_name,\r\n  sqlc.output(concat(first_name, ' ', last_name), 'nullable', false, 'ref_counted', true) as display_name\r\nwhere ....\r\n```\r\n\r\nThis is very similar to [overrides](https://docs.sqlc.dev/en/stable/reference/config.html?highlight=overrides#type-overrides), but on a query-by-query basis, and expressed directly in SQL instead of away from the code in a config file.\r\n\r\n**Implementation**\r\nI got pretty far along in the implementation, and I'd be happy to push it all the way through - but I hit a big snag at the SQL rewriting. Rewriting the AST is no big deal (and I had the code working for that). But the way in which sqlc rewrites the original source seems to be engine independent, and a [little hacky](https://github.com/kyleconroy/sqlc/blob/a83dba243990ae2c9e13665af3ed525960ea767a/internal/sql/rewrite/parameters.go#L82-L99).  Performing the source rewrites with an AST \"deparse\" (like in [pg_query_go](https://github.com/pganalyze/pg_query_go/blob/main/pg_query.go#L36)) would solve this with almost no problem.  Or if the AST has more source location info in it (not just a start location, but also an end location), that might work too. But this seemed like a bigger refactor, and I wanted to get feedback on it first.\r\n\r\nI'd love to know your thoughts @kyleconroy and from the general sqlc community too.  I'd be happy to help and make this a reality.\n\n### What database engines need to be changed?\n\nPostgreSQL, MySQL\n\n### What programming language backends need to be changed?\n\n_No response_","author":{"url":"https://github.com/skabbes","@type":"Person","name":"skabbes"},"datePublished":"2022-04-02T16:27:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/1525/sqlc/issues/1525"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6b32fcef-dfd7-26c4-ce18-39aa0eb0e36a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCB7A:291A44:D904D0:12612FE:6A516F20
html-safe-nonce1c1a8c03241e2751d78ab615f9f7c369716e5fdb20fbe2b1da9baa3a33f05e31
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjdBOjI5MUE0NDpEOTA0RDA6MTI2MTJGRTo2QTUxNkYyMCIsInZpc2l0b3JfaWQiOiI2Mjc1MjU5ODA4OTU5NTI0NjQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac5a74b53834b03d6af5ef21418dfb9b8a71b22ca87e9549e66fb18e6cbd25d55f
hovercard-subject-tagissue:1190677095
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlc-dev/sqlc/1525/issue_layout
twitter:imagehttps://opengraph.githubassets.com/bfa136b7fd759512b8ac3259a166bff94970c5839a5abc2bae407c56e0ab8c86/sqlc-dev/sqlc/issues/1525
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/bfa136b7fd759512b8ac3259a166bff94970c5839a5abc2bae407c56e0ab8c86/sqlc-dev/sqlc/issues/1525
og:image:altWhat do you want to change? Kudos Before I start, I wanted to give a huge kudos for sqlc - I love it. As a backend developer who knows SQL very well, I fight every single ORM I have used trying to ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameskabbes
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git
octolytics-dimension-user_id136738596
octolytics-dimension-user_loginsqlc-dev
octolytics-dimension-repository_id193160679
octolytics-dimension-repository_nwosqlc-dev/sqlc
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id193160679
octolytics-dimension-repository_network_root_nwosqlc-dev/sqlc
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseb19955a9dd40fd99462443f7911b522d7216776a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/sqlc-dev/sqlc/issues/1525#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsqlc-dev%2Fsqlc%2Fissues%2F1525
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsqlc-dev%2Fsqlc%2Fissues%2F1525
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=sqlc-dev%2Fsqlc
Reloadhttps://github.com/sqlc-dev/sqlc/issues/1525
Reloadhttps://github.com/sqlc-dev/sqlc/issues/1525
Reloadhttps://github.com/sqlc-dev/sqlc/issues/1525
Please reload this pagehttps://github.com/sqlc-dev/sqlc/issues/1525
sqlc-dev https://github.com/sqlc-dev
sqlchttps://github.com/sqlc-dev/sqlc
Notifications https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc
Fork 1.1k https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc
Star 18k https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc
Code https://github.com/sqlc-dev/sqlc
Issues 597 https://github.com/sqlc-dev/sqlc/issues
Pull requests 106 https://github.com/sqlc-dev/sqlc/pulls
Discussions https://github.com/sqlc-dev/sqlc/discussions
Actions https://github.com/sqlc-dev/sqlc/actions
Projects https://github.com/sqlc-dev/sqlc/projects
Security and quality 0 https://github.com/sqlc-dev/sqlc/security
Insights https://github.com/sqlc-dev/sqlc/pulse
Code https://github.com/sqlc-dev/sqlc
Issues https://github.com/sqlc-dev/sqlc/issues
Pull requests https://github.com/sqlc-dev/sqlc/pulls
Discussions https://github.com/sqlc-dev/sqlc/discussions
Actions https://github.com/sqlc-dev/sqlc/actions
Projects https://github.com/sqlc-dev/sqlc/projects
Security and quality https://github.com/sqlc-dev/sqlc/security
Insights https://github.com/sqlc-dev/sqlc/pulse
RFC: nullability (and other metadata) for input arguments / parameters to a query https://github.com/sqlc-dev/sqlc/issues/1525#top
enhancementNew feature or requesthttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22enhancement%22
triageNew issues that hasn't been reviewedhttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22triage%22
https://github.com/skabbes
skabbeshttps://github.com/skabbes
on Apr 2, 2022https://github.com/sqlc-dev/sqlc/issues/1525#issue-1190677095
Brighthttps://www.ycombinator.com/companies/bright
somehttps://github.com/kyleconroy/sqlc/issues/1446
openhttps://github.com/kyleconroy/sqlc/pull/1491
issueshttps://github.com/kyleconroy/sqlc/pull/1462
overrideshttps://docs.sqlc.dev/en/stable/reference/config.html?highlight=overrides#type-overrides
little hackyhttps://github.com/kyleconroy/sqlc/blob/a83dba243990ae2c9e13665af3ed525960ea767a/internal/sql/rewrite/parameters.go#L82-L99
pg_query_gohttps://github.com/pganalyze/pg_query_go/blob/main/pg_query.go#L36
@kyleconroyhttps://github.com/kyleconroy
enhancementNew feature or requesthttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22enhancement%22
triageNew issues that hasn't been reviewedhttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22triage%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.