You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
eorm 支持的字段类型和你选择的结果集处理器有关。
在 eorm 里面,我们有 unsafe 和 反射两种实现。其中反射就是支持任何数据类型,准确说是标准库和驱动支持什么类型,我们就支持什么类型。
但是在使用 unsafe 的时候,我们就只支持有限的数据类型:
int 族及其对应的指针
uint 族及其对应的指针
float 族及其对应的指针
bool 及其对应的指针
[]byte,不支持对应的指针
string,不支持对应的指针
实现了 driver.Valuer 接口和sql.Scanner接口的类型。注意因为 Go 语法特性的原因,所以需要注意究竟是指针实现了这两个接口,还是结构体实现了这两个接口。Go 不同版本提供了不同的实现,在 1.18 里面它提供了:
sql.NullString
sql.NullInt16
sql.NullInt32
sql.NullInt64
sql.NullBool
sql.NullByte
sql.NullFloat64
要注意的是,这些字段在使用的时候只能使用它们的指针。因为只有它们对应的指针实现了sql.Scanner接口。
有一些类型,虽然理论上来说可以支持,但是目前并不打算支持的:
byte,*byte 和 sql.NullByte:这是因为在反射(unsafe也部分依赖于反射 API)的角度,我们无法区别是 byte 还是 uint8。sql.NullByte 则是因为它的 Scan 方法无法处理 *[]byte 输入
time.Time 类型和sql.NullTime也不支持。要支持time.Time需要引入一些特殊逻辑,而且部分情况下,我们认为存储时间应该存储时间戳,也就是存储 64 位数字;
剩下的类型都可以看做是未定义类型。也就是说,目前我们并没有考虑清楚剩下的类型究竟是报错,还是不管,还是在将来某一天的时候支持。但是说到底,用户都不应该使用其它类型,否则行为将不可预期
Beta Was this translation helpful? Give feedback.
All reactions