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

Are fixtures for sql.Nullstring supported? #17

Closed
merefield opened this issue Jun 10, 2021 · 5 comments
Closed

Are fixtures for sql.Nullstring supported? #17

merefield opened this issue Jun 10, 2021 · 5 comments

Comments

@merefield
Copy link

merefield commented Jun 10, 2021

I'm getting this when trying to load fixtures

2021/06/10 15:18:28 yaml: unmarshal errors:
  line 47: cannot unmarshal !!str `https:/...` into sql.NullString

.yaml extract:

- model: Client
  rows:
    - id: 3392e754-ba3e-424f-a687-add9a8ab39c9
      application_name: test_client_1
      key: test_client_1
      secret: '$2a$10$CUoGytf1pR7CC6Y043gt/.vFJUV4IRqvH5R6F0VfITP8s2TqrQ.4e'
      redirect_uri: https://www.example.com

Model

type Client struct {
	IDRecord
	Key                 string         `bun:"type:varchar(254),unique,notnull"`
	Secret              string         `bun:"type:varchar(60),notnull"`
	RedirectURI         sql.NullString `bun:"type:varchar(200)"`
	ApplicationName     sql.NullString `bun:"type:varchar(200)"`
	ApplicationHostname sql.NullString `bun:"type:varchar(200)"`
	ApplicationURL      sql.NullString `bun:"type:varchar(200)"`
}
@merefield
Copy link
Author

merefield commented Jun 11, 2021

I realised you are using package: https://pkg.go.dev/gopkg.in/yaml.v3#readme-compatibility

As NullStrings are held in a struct you need to address the specific attribute, I think?

So this, removes the error and the fixture loading completes, However, i'm yet to see the data in the db, I'm seeing nulls for these values?

- model: Client
  rows:
    - id: 3392e754-ba3e-424f-a687-add9a8ab39c9
      application_name:
        String: test_client_1
      key: test_client_1
      secret: '$2a$10$CUoGytf1pR7CC6Y043gt/.vFJUV4IRqvH5R6F0VfITP8s2TqrQ.4e'
      redirect_uri:
        String: https://www.example.com

@merefield merefield reopened this Jun 11, 2021
@vmihailenco
Copy link
Member

Can you try to add Valid: true:

- model: Client
  rows:
    - id: 3392e754-ba3e-424f-a687-add9a8ab39c9
      application_name:
        String: test_client_1
        Valid: true
      key: test_client_1
      secret: '$2a$10$CUoGytf1pR7CC6Y043gt/.vFJUV4IRqvH5R6F0VfITP8s2TqrQ.4e'
      redirect_uri:
        String: https://www.example.com
        Valid: true

@merefield
Copy link
Author

Still the same issue.

Test project here: https://github.com/merefield/buncheck

@vmihailenco
Copy link
Member

Looks like keys should be lower cased

        string: Smith
        valid: true

@merefield
Copy link
Author

Boom! 🚀 thanks!

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

No branches or pull requests

2 participants