Skip to content

Override globs #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Override globs #862

wants to merge 3 commits into from

Conversation

zelch
Copy link
Contributor

@zelch zelch commented Jan 26, 2021

So, I'm going to start with the use case.

Our MariaDB database has a lot of KSUIDs, enough that I would be better off writing a tool to automate building the override statements than doing it by hand.

It would be nice if we could just override on type, replace 'binary(20)' with 'github.com/segmentio/ksuid.KSUID' and call it a day.

Sadly, at least the mysql parser turns 'binary(20)' into 'char' well before the override code gets it. In fact, it does this well before any of the sqlc code gets it.

That leaves doing it by column name, but as mentioned above... There are quite a lot of them.

On the other hand, our naming convention is at least vaguely straight forward. The columns all end with _ksuid, so we can automatically detect them.

But why write rules to do this, and have a huge override table, when we can just add globbing support to sqlc?

And so I did that instead. :)

This passes all of the tests, and is reasonably straight forward.

@kyleconroy
Copy link
Collaborator

Can you attach your sqlc.yaml or sqlc.json file? I'd like to see how this works in practice.

@zelch
Copy link
Contributor Author

zelch commented Jan 26, 2021

Looks like I should update to version 2, but here you go.

sqlc.yaml.txt

@zelch
Copy link
Contributor Author

zelch commented Feb 28, 2021

Ping on this @kyleconroy

Zephaniah E. Loss-Cutler-Hull added 3 commits April 12, 2021 10:18
This lets us say things like '*.*_ksuid' should be of type
'github.com/segmentio/ksuid.KSUID', instead of having to list every
single column in every single table.

We can even say '*.*.*_ksuid' for every column, in every table, in every
schema.

Now, ideally we would do a type replace on 'binary(20)', however that
gets turned into a char for at least the mysql code, which means that we
never get to see 'binary(20)', and so can't do a replacement on it.

This makes use of the github.com/gobwas/glob package for the globbing,
and it pretty much Just Works the way you expect it to.
This doesn't get used, and so we can get rid of it instead of adapting
it for globs.
Fairly straight forward, same changes as for the other code generators.
@zelch
Copy link
Contributor Author

zelch commented Apr 12, 2021

These changes have been rebased on the current head, specifically to add support for the python code generation.

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

I like this change in theory. Before we can get it merged, there will need to be more tests and documentation. If you'd like to write those tests, great. If not, it may be a few more months before this gets merged.

@kyleconroy
Copy link
Collaborator

@zelch Going to close this one out, as it has conflicts and no tests. I'd be happy to support this change, but it needs to have test coverage.

@kyleconroy kyleconroy closed this Sep 12, 2021
@zelch zelch mentioned this pull request Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants