Skip to content
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

sqlx example doesn't seem to work #47

Closed
HenrikPoulsen opened this issue May 12, 2023 · 2 comments · Fixed by #50
Closed

sqlx example doesn't seem to work #47

HenrikPoulsen opened this issue May 12, 2023 · 2 comments · Fixed by #50

Comments

@HenrikPoulsen
Copy link

First time using musttag and sqlx.
I tried out the below config, which is the one recommended, which did not detect any issue

      - name: github.com/jmoiron/sqlx.Get
        # The struct tag whose presence should be ensured.
        tag: db
        # The position of the argument to check.
        arg-pos: 1

Whereas changing it to the following seems to work

      - name: (*github.com/jmoiron/sqlx.DB).Get
        # The struct tag whose presence should be ensured.
        tag: db
        # The position of the argument to check.
        arg-pos: 0

Code snipped I used for testing as follows:

type SchemaMigrations struct {
	Version int
	Dirty   bool
}


var migrations SchemaMigrations

err = conn.Get(&migrations, "select * from schema_migrations where version = $1", 1)
if err != nil {
    log.Fatal(err)
}

(*github.com/jmoiron/sqlx.DB).Get does call github.com/jmoiron/sqlx.Get so I would have assumed it would still work.
But I don't really know anything about how these linters work.
Just wanted to flag this. For my usecase I'll just add the extra config

@tmzane
Copy link
Member

tmzane commented May 14, 2023

Hello @HenrikPoulsen,

This example only covers the package-level sqlx.Get function, which is not the same as the sqlx.DB.Get method. You're absolutely right with the config you provided above, to detect issues with the latter, the (*github.com/jmoiron/sqlx.DB).Get function name should be specified.

I can now see why this example may be confusing, since Get as a method is definitely used more often. Thank you for pointing that out!

Anyway, I'm about to add support for sqlx out of the box in #6, so no additional configuration will be needed in your use case.

@tmzane
Copy link
Member

tmzane commented May 26, 2023

@HenrikPoulsen fyi, builtin sqlx support has been merged in v0.7.0

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 a pull request may close this issue.

2 participants