Skip to content

JSON Parser fails for type override on complex package names #255

Closed

Description

@rupertevill

The standard syntax for defining a type override in the lib at the moment is:

"overrides": [ { "go_type": "github.com/gofrs/uuid.UUID", "postgres_type": "uuid" } ]

This results in the following import statement and type (in the struct) in the auto gen code:

import (
    "github.com/gofrs/uuid"
)

type test struct {
    columnOne uuid.UUID
}

However, the parser fails if the package name containing the desired type override is more complex, for example "gopkg.in/guregu/null.v3".

Have looked at the parser as it is at the moment and the bug fix doesn't look to bad, let me if you want any contribution 👍

Activity

  1. maxiride commented on Apr 26, 2020

    @maxiride

    I've closed #462 since I'm pretty sure it was a duplicate issue.
    Is the bug caused by the presence of a dot in the package name?

  2. rupertevill commented on Apr 26, 2020

    @rupertevill
    Author

    I've closed #462 since I'm pretty sure it was a duplicate issue.

    Is the bug caused by the presence of a dot in the package name?

    Correct @maxiride. The presence of a dot in the package name causes the issue.

  3. maxiride commented on Apr 26, 2020

    @maxiride

    Too bad... those packages are my holy grail.

    Anyway,

    Have looked at the parser as it is at the moment and the bug fix doesn't look to bad, let me if you want any contribution 👍

    @rupertevill did you eventually started working on a PR?


    As a temporary (hopefully) fix I went down the dangerous path of issuing a replace all in the models and the functions generated.


    I went on with a plausible hotfix myself.

  4. kyleconroy commented on Nov 15, 2020

    @kyleconroy
    Collaborator

    This has been fixed in main and will be released in the next version. Here's what it looks like:

    {
      "version": "1",
      "packages": [
        {
          "path": "go",
          "name": "override",
          "engine": "postgresql",
          "schema": "schema.sql",
          "queries": "query.sql",
          "overrides": [
            {
              "column": "foo.bio",
              "nullable": true,
              "go_type": {
                "import": "gopkg.in/guregu/null.v4",
                "type": "String"
              },
            }
          ]
        }
      ]
    }
    import (
        null_v4 "gopkg.in/guregu/null.v4"
    )
    
    type test struct {
        columnOne null_v4.String
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions