visionling

Three ways of supporting SQL NULL in Golang

Jun 21st, 2022 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.28 KB | None | 0 0
  1. // Golang 支持数据库 NULL 的三种方式
  2.  
  3. import "database/sql"
  4.  
  5. // 1. 使用指针
  6. type Info struct {
  7.     Name *string
  8. }
  9.  
  10. // 2. 使用 sql.NullString
  11. type Info2 struct {
  12.     Name sql.NullString
  13. }
  14.  
  15. // 3. 使用 SQL 函数
  16. // SELECT IFNULL(NULL, 'default-value');
  17.  
Add Comment
Please, Sign In to add comment