8000 Msgpack tag does not work for sqlite database · Issue #1219 · uptrace/bun · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Msgpack tag does not work for sqlite database #1219
Open
@LeKSuS-04

Description

@LeKSuS-04

Hi! I've encountered issues when using msgpack struct tag with sqlite database:

Repo with code to reproduce

package main

import (
	"database/sql"
	"testing"

	"github.com/stretchr/testify/require"
	"github.com/uptrace/bun"
	"github.com/uptrace/bun/dialect/sqlitedialect"
	"github.com/uptrace/bun/driver/sqliteshim"
)

type Item struct {
	Something int `msgpack:"something"`
}

type Model struct {
	bun.BaseModel `bun:"table:models"`

	ID      int    `bun:",pk,autoincrement"`
	Name    string `bun:",notnull"`
	Encoded Item   `bun:",msgpack"`
}

func TestBunMsgpack(t *testing.T) {
	sqldb, err := sql.Open(sqliteshim.ShimName, ":memory:")
	require.NoError(t, err)
	sqldb.SetMaxIdleConns(1000)
	sqldb.SetConnMaxLifetime(0)

	db := bun.NewDB(sqldb, sqlitedialect.New())
	db.NewCreateTable().
		Model(&Model{}).
		Exec(t.Context())

	model := &Model{
		Name:    "test",
		Encoded: Item{Something: 1},
	}
	_, err = db.NewInsert().Model(model).Returning("id").Exec(t.Context(), &model.ID)
	require.NoError(t, err)

	model2 := &Model{}
	err = db.NewSelect().Model(model2).Where("id = ?", model.ID).Scan(t.Context())
	require.NoError(t, err)

	require.Equal(t, model, model2)
}

Running go test . gives following error:

--- FAIL: TestBunMsgpack (0.00s)
    main_test.go:45: 
                Error Trace:    /home/leksus/test/main_test.go:45
                Error:          Received unexpected error:
                                sql: Scan error on column index 2, name "encoded": msgpack: unexpected code=5c decoding map length
                Test:           TestBunMsgpack
FAIL
FAIL    example 0.006s
FAIL

Looks like the underlying issue is the same as in #519 ? If so, maybe it's worth documenting that msgpack is deprecated / should not be used outside of the postgres? Right now it's not clear at all that this is the case: https://bun.uptrace.dev/guide/models.html#struct-tags

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0