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

[]byte encoded as string with postgres dialect #436

Open
1 of 3 tasks
MokoshHydro opened this issue Nov 30, 2024 · 0 comments
Open
1 of 3 tasks

[]byte encoded as string with postgres dialect #436

MokoshHydro opened this issue Nov 30, 2024 · 0 comments

Comments

@MokoshHydro
Copy link

Describe the bug

[]byte are encoded as strings leading to queries not accepted by Postgres.

To Reproduce

package main
import (
	"log"
	"github.com/doug-martin/goqu/v9"
)

type Test struct {
	Total uint32 `db:"total"`
	CardHash []byte `db:"card_hash"`
}

func main() {
	dialect := goqu.Dialect("postgres")
	t := &Test{
		Total: 100,
		CardHash: []byte{40, 41, 42, 250, 0x0, 0x0},
	}
	req := dialect.Insert("transactions").Rows(goqu.Record{"total": t.Total, "hash": t.CardHash}).Returning("id")
	sql, _, err := req.ToSQL()
	if err != nil {
		log.Fatal(err)
	}
	log.Println(sql)
	req = dialect.Insert("transactions").Rows(t).Returning("id")
	sql, _, err = req.ToSQL()
	if err != nil {
		log.Fatal(err)
	}
	log.Println(sql)
}

Expected behavior

[]byte must be "hexified".

Dialect:

  • postgres
  • mysql
  • sqlite3

Additional context

Related #353.

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

1 participant