Skip to content

Conversation

mrnugget
Copy link
Contributor

Before this change it was possible to generate duplicate import statements.

Take this schema:

  {
    "version": "1",
    "packages": [{
        "schema": "schema.sql",
        "queries": "queries.sql",
        "name": "queries",
        "path": "."
    }],
    "overrides": [
      { "column": "toy.owner_id", "go_type": "database/sql.NullInt64" },
      { "column": "toy.manufacturer_id", "go_type": "database/sql.NullInt64" }
    ]
  }

That would generate a models.go file with two imports for database/sql.

What the change here does is to make all imports, in the queries and the
models file, unique.

Before this change it was possible to generate duplicate import statements.

Take this scheme:

  {
    "version": "1",
    "packages": [{
        "schema": "schema.sql",
        "queries": "queries.sql",
        "name": "queries",
        "path": "."
    }],
    "overrides": [
      { "column": "toy.owner_id", "go_type": "database/sql.NullInt64" },
      { "column": "toy.manufacturer_id", "go_type": "database/sql.NullInt64" }
    ]
  }

That would generate a `models.go` file with two imports for `database/sql`.

What the change here does is to make all imports, in the queries and the
models file, unique.
@kyleconroy
Copy link
Collaborator

Thanks! This does have a slight problem in that import order could change, as map key iteration is randomized. I'm going to open a follow-up pull request that sorts the imports before returning them.

@mrnugget
Copy link
Contributor Author

Thanks for merging and doing the follow-up fix!

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