GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Generate read-only Queries by jarri-abidi · Pull Request #3291 · sqlc-dev/sqlc

Conversation

@jarri-abidi

@jarri-abidi jarri-abidi commented Mar 25, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Solution for #3187

no support for pgx
sorry if the code looks messy at all - open to feedback

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jarri-abidi
Generate read-only Queries
d373474
K-odesome
K-odesome reviewed Mar 25, 2024
View reviewed changes
Comment thread internal/codegen/golang/gen.go Outdated
if !strings.Contains(qsql, "SELECT") {
continue
}
if strings.Contains(qsql, "UPDATE") || strings.Contains(qsql, "INSERT") {

@K-odesome K-odesome Mar 25, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also check for delete as well if queries have

something like

DELETE FROM your_table
WHERE some_condition IN (
    SELECT some_column
    FROM another_table
    WHERE your_condition
);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jarri-abidi reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jarri-abidi
Handle DELETE
d4666b6
K-odesome
K-odesome reviewed Mar 25, 2024
View reviewed changes
Comment thread internal/codegen/golang/gen.go
rq = append(rq, q)
}
return rq
}

@K-odesome K-odesome Mar 25, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do it something like this

func readOnly(queries []Query) []Query {
	var rq []Query
	for _, q := range queries {
		if !q.hasRetType() {
			continue
		}

		qsql := strings.ToUpper(q.SQL)
		if !containsOnlyAllowedKeywords(qsql) {
			continue
		}

		rq = append(rq, q)
	}
	return rq
}

func containsOnlyAllowedKeywords(query string) bool {
	keywords := []string{"INSERT", "UPDATE", "DELETE","CREATE","ALTER"} // and the other keywords
		for _, keyword := range keywords {
                          if strings.Contains(qsql, keyword) {
                             return false
                          }		
	}

	return true
}

So that we can define the list of exluded words

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jarri-abidi jarri-abidi Mar 25, 2024

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queries wont/shouldn't have ddl. so we can rule out CREATE and ALTER

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

K-odesome reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jarri-abidi jarri-abidi changed the title Generate read-only Queries feat: Generate read-only Queries Mar 25, 2024
@jarri-abidi
Fix bug where column called updated_at was being skipped in readonly …
771c044
…queries
@jarri-abidi jarri-abidi mentioned this pull request Mar 26, 2024
Option to Segregate Read and Write queries to have separate db users with each type of query. #3187
Open
@jarri-abidi
Exclude SELECT FOR UPDATE queries from readonly ones
f50efd8
@jarri-abidi

jarri-abidi commented Mar 29, 2024

Copy link
Copy Markdown
Author

hey @kyleconroy can i get a review on this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jarri-abidi

jarri-abidi commented Apr 19, 2024

Copy link
Copy Markdown
Author

@kyleconroy is this good to go?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jarri-abidi

jarri-abidi commented Apr 30, 2024

Copy link
Copy Markdown
Author

bump @kyleconroy

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

2 similar comments
@jarri-abidi

jarri-abidi commented Sep 2, 2024

Copy link
Copy Markdown
Author

bump @kyleconroy

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jarri-abidi

jarri-abidi commented Oct 3, 2024

Copy link
Copy Markdown
Author

bump @kyleconroy

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost

ghost commented Mar 3, 2025 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

bump @kyleconroy

I am also interested in this feature! @jarri-abidi maybe you want to make the piplines work, I think thats the reason why its not being merged.

jarri-abidi reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jarri-abidi jarri-abidi closed this May 29, 2025
@jarri-abidi jarri-abidi reopened this May 29, 2025
@kyleconroy Claude

kyleconroy commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

🤖 Automated message

This PR has been closed because it has merge conflicts with main. To reopen it, rebase onto the latest main to resolve the conflicts, then reopen the PR.


Generated by Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kyleconroy kyleconroy closed this Jun 8, 2026
@jarri-abidi jarri-abidi mentioned this pull request Oct 29, 2026
feat(golang): add emit_read_only_prepared to generate read-only queries #4669
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@K-odesome K-odesome K-odesome left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jarri-abidi @kyleconroy @K-odesome
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.