-
Notifications
You must be signed in to change notification settings - Fork 19
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
nicetip
wants to merge
1
commit into
herenow:master
Choose a base branch
from
nicetip:ColumnTypes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,9 +120,10 @@ func (c *CrateDriver) Query(stmt string, args []driver.Value) (driver.Rows, erro | |
|
||
// Rows reader | ||
rows := &Rows{ | ||
columns: res.Cols, | ||
values: res.Rows, | ||
rowcount: res.Rowcount, | ||
columns: res.Cols, | ||
columnTypes: res.ColumnTypes, | ||
values: res.Rows, | ||
rowcount: res.Rowcount, | ||
} | ||
|
||
return rows, nil | ||
|
@@ -159,10 +160,11 @@ func (r *Result) RowsAffected() (int64, error) { | |
|
||
// Rows reader | ||
type Rows struct { | ||
columns []string | ||
values [][]interface{} | ||
rowcount int64 | ||
pos int64 // index position on the values array | ||
columns []string | ||
columnTypes []interface{} | ||
values [][]interface{} | ||
rowcount int64 | ||
pos int64 // index position on the values array | ||
} | ||
|
||
// Row columns | ||
|
@@ -191,6 +193,34 @@ func (r *Rows) Close() error { | |
return nil | ||
} | ||
|
||
var typeMap = map[int]string{ | ||
2: "byte", | ||
3: "boolean", | ||
4: "string", | ||
5: "ip", | ||
6: "double", | ||
7: "float", | ||
8: "short", | ||
9: "integer", | ||
10: "long", | ||
11: "timestamp", | ||
12: "object", | ||
13: "geo_point", | ||
14: "geo_shape", | ||
} | ||
|
||
func (r *Rows) ColumnTypeDatabaseTypeName(index int) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method Rows.ColumnTypeDatabaseTypeName should have comment or be unexported |
||
switch r.columnTypes[index].(type) { | ||
case []interface{}: | ||
x := r.columnTypes[index].([]interface{}) | ||
val, _ := x[1].(json.Number).Int64() | ||
return fmt.Sprintf("array(%s)", typeMap[int(val)]) | ||
default: | ||
val, _ := r.columnTypes[index].(json.Number).Int64() | ||
return typeMap[int(val)] | ||
} | ||
} | ||
|
||
// Yet not supported | ||
func (c *CrateDriver) Begin() (driver.Tx, error) { | ||
err := errors.New("Transactions are not supported by this driver.") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.