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

ColumnTypes() improvement. #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

nicetip
Copy link

@nicetip nicetip commented Oct 31, 2017

it was impossible to extract column types with Rows.ColumnTypes() function.
but Crate's JSON response already contains column type information(col_types).
this commit contains implement col_types.
Look for following example codes.

Example Code:

package main

import (
"fmt"
"database/sql"
_ "go-crate"
)

func main() {
db, _ := sql.Open("crate", "http://127.0.0.1:4200")
rows, _ := db.Query("select col1, col2 from tbl")
types, _ := rows.ColumnTypes()
for i, l := 0, len(types); i < l; i++ {
t := types[i]
fmt.Println(t.Name(), ":", t.DatabaseTypeName())
}
}

it was impossible to extract column types with Rows.ColumnTypes() function.
but Crate's JSON response already contains column type information(col_types).
this commit contains implement `col_types`.
Look for following example codes.

Example Code:

package main

import (
    "fmt"
    "database/sql"
    _ "go-crate"
)

func main() {
    db, _ := sql.Open("crate", "http://127.0.0.1:4200")
    rows, _ := db.Query("select col1, col2 from tbl")
    types, _ := rows.ColumnTypes()
    for i, l := 0, len(types); i < l; i++ {
        t := types[i]
        fmt.Println(t.Name(), ":", t.DatabaseTypeName())
    }
}
@sourcelevel-bot
Copy link

Hello, @nicetip! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

14: "geo_shape",
}

func (r *Rows) ColumnTypeDatabaseTypeName(index int) string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method Rows.ColumnTypeDatabaseTypeName should have comment or be unexported

@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 2 possible new issues (including those that may have been commented here).

You can see more details about this review at https://ebertapp.io/github/herenow/go-crate/pulls/22.

@@ -191,6 +193,34 @@ func (r *Rows) Close() error {
return nil
}

var typeMap = map[int]string{
2: "byte",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question, Go's documentation specifies that types should be returned uppercased, here:

https://golang.org/pkg/database/sql/driver/#RowsColumnTypeDatabaseTypeName

Also here is the discussion about this feature.

golang/go#16652

Crate documents all of their types lowercased, I see no reason for us to uppercase them.

Before merging this, I would like to know if you have any thoughts on this.

Copy link
Author

@nicetip nicetip Nov 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello? @herenow
I didn't know there were a spec for upper/lowercase.
I just used lowercase cause crate's document was written in lowercase and it's easy to type.
I thought about this for a while and looked for other golang drivers implementations.
Other drivers also already knows about this and implemented in uppercase, even commented it should be uppercase.
So I think uppercase would be better, cause somebody who knows about this spec, may expect that function will return uppercased.
And others may not cares about it. : )
Thanks you for asking my opinion.

chughpiyush added a commit to chughpiyush/go-crate that referenced this pull request May 31, 2019
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

Successfully merging this pull request may close these issues.

2 participants