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

Unable to mock results with datetime columns #1

Closed
Hebo opened this issue Feb 13, 2014 · 2 comments · Fixed by #2
Closed

Unable to mock results with datetime columns #1

Hebo opened this issue Feb 13, 2014 · 2 comments · Fixed by #2

Comments

@Hebo
Copy link
Contributor

Hebo commented Feb 13, 2014

Hey,

How can I mock columns that are stored as datetimes? It seems that RowsFromCSVString sets driver.Values that are always []byte, and Scan is unable to parse time.time objects from them:

Scan error on column index 4: unsupported driver -> Scan pair: []uint8 -> *time.Time

I'd guess this would work if either RowsFromCSVString was able to directly create time.time objects when it encounters them or there was another way to assemble sqlmock.rows objects.

Example:

sqlmock.ExpectQuery("SELECT now()").
    WillReturnRows(sqlmock.RowsFromCSVString([]string{"now"}, "2014-02-12 16:04:15.879588-08"))

# sql: Scan error on column index 0: unsupported driver -> Scan pair: []uint8 -> *time.Time
Hebo added a commit to Hebo/go-sqlmock that referenced this issue Feb 13, 2014
@Hebo
Copy link
Contributor Author

Hebo commented Feb 13, 2014

Hacked together an example in my fork of how giving native types to Scan will let the parsing handle more types (for the ones in this list, at least). I couldn't work out a good API for multiple rows though, or I'd clean it up and submit a PR.

Current example use:

WillReturnRows(sqlmock.RowFromInterface([]string{"now"}, time.Now()))

Thoughts?

@l3pp4rd
Copy link
Member

l3pp4rd commented Feb 13, 2014

Hi, yes there could be more ways to build sql driver rows. one for example, could be used to read struct data, like sqlstruct uses tags. another from an array of interface{}. I would really appreciate any contributions regarding it. So if you come up with a nice way of doing it, I would be happy to include it in the library. database sql rows interface gives us a flexible way to create them differently. I will take a look at your fork, this week, busy days recently.

l3pp4rd added a commit that referenced this issue Feb 13, 2014
* hebo/typed_rows:
  Allow for multiple rows by manually creating each row
  Create a single row from an interface list - #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants