Skip to content

How can I enable rows.Scan() to support []string? #193

@chengguangyu

Description

@chengguangyu

Hello,

I've been using a lot of go-sqlmock. However, I didn't find a way to mock the returned type from rows.Scan() when called database.Query (a rows object).

I have already successfully inplement the ConvertValue() func for my own custom type type StringSliceType []string which will make mock.NewRows([]string{"myarray"}).AddRow(StringSliceType {"hello", "world"}). enabled. I can input custom type to mock the Query result.

My 3rd party library (https://github.com/kshvakov/clickhouse) supports []string as supported data types so I can write:

var myArray []string
	if err := rows.Scan(&myArray); err != nil {
		e = err
		return
	}

However, there will be a type mismatch.

How could I extend go-sqlmock to allow mocking custom data types with the Scan function?

Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions