DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
5.95k stars 404 forks source link

Mock columnsWithAlias #336

Closed raxod502-plaid closed 2 months ago

raxod502-plaid commented 2 months ago

I would like a sqlmock instance to return column names with table aliases, the same way as the mysql driver does when enabling the columnsWithAlias option documented here.

Proposal

The New function takes a variadic list of options defined in options.go, one could be added to return table aliases.

Use-cases

In order to join two tables that share a column name, it is necessary to use columnsWithAlias in order to correctly identify columns in the returned records. Such code cannot be mocked by sqlmock without a similar feature.

raxod502-plaid commented 2 months ago

Invalid feature request. You can already do this by simply specifying the desired table alias as part of the column name when constructing the sqlmock.Rows object to return.