go-gorm / go-gorm/sqlserver

uint8 in Golang should correspond to tinyint in SQL Server

Open
#128 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
66
Forks
52
PR merge metrics
No merged PRs in 30d

Description

https://github.com/go-gorm/sqlserver/blob/ef8f762cc01457cd331d3d93cf5648f2d8dc5661/sqlserver.go#L188-L202

- https://learn.microsoft.com/zh-cn/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql?view=sql-server-ver16

Because in SQL Server, the range of values for the `tinyint` type is from `0` to `255`, which exactly matches the range of `uint8`, so when `field.Size < 16` and `field.DataType == schema.Uint`, should `sqlType` be `tinyint`? Like this:

```go
case schema.Int, schema.Uint:
var sqlType string
switch {
case field.Size < 16:
if field.DataType == schema.Uint {
sqlType = "tinyint"
} else {
sqlType = "smallint"
}
case field.Size < 31:
sqlType = "int"
default:
sqlType = "bigint"
}

if field.AutoIncrement {
return sqlType + " IDENTITY(1,1)"
}
return sqlType
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.