package main import ( "github.com/go-xorm/xorm" _ "github.com/go-sql-driver/mysql" ) type User struct { Id int64 `xorm:"pk autoincr"` Username string `xorm:"unique notnull"` Email string `xorm:"unique notnull"` Password string `xorm:"notnull"` CreatedAt int64 `xorm:"notnull created"` UpdatedAt int64 `xorm:"notnull updated"` DeletedAt Nullable `xorm:"deleted"` } func main() { engine, err := xorm.NewEngine("mysql", "root:password@/mydb?charset=utf8") if err != nil { panic(err) } err = engine.Sync2(new(User)) if err != nil { panic(err) } }
package main import ( "fmt" "github.com/go-xorm/xorm" _ "github.com/mattn/go-sqlite3" ) type User struct { Id int64 `xorm:"pk autoincr"` Username string `xorm:"unique notnull"` Email string `xorm:"unique notnull"` Password string `xorm:"notnull"` CreatedAt int64 `xorm:"notnull created"` UpdatedAt int64 `xorm:"notnull updated"` DeletedAt Nullable `xorm:"deleted"` } func main() { engine, err := xorm.NewEngine("sqlite3", "./test.db") if err != nil { panic(err) } user := &User{} has, err := engine.Where("deleted_at IS NULL").Get(user) if err != nil { panic(err) } if has { fmt.Printf("User %+v", user) } else { fmt.Println("User not found.") } }In the above example, the Where clause retrieves records where the DeletedAt column is null by using the SQL IS NULL statement. The Nullable type allows the WHERE clause to check for null values in the column.