func testIterate(engine *xorm.Engine, t *testing.T) { err := engine.Omit("is_man").Iterate(new(Userinfo), func(idx int, bean interface{}) error { user := bean.(*Userinfo) fmt.Println(idx, "--", user) return nil }) if err != nil { t.Error(err) panic(err) } }
func testInsertDefault2(engine *xorm.Engine, t *testing.T) { di := new(DefaultInsert2) err := engine.Sync2(di) if err != nil { t.Error(err) } var di2 = DefaultInsert2{Name: "test"} _, err = engine.Omit(engine.ColumnMapper.Obj2Table("CheckTime")).Insert(&di2) if err != nil { t.Error(err) } has, err := engine.Desc("(id)").Get(di) if err != nil { t.Error(err) } if !has { err = errors.New("error with no data") t.Error(err) panic(err) } has, err = engine.NoAutoCondition().Desc("(id)").Get(&di2) if err != nil { t.Error(err) } if !has { err = errors.New("error with no data") t.Error(err) panic(err) } if *di != di2 { err = fmt.Errorf("%v is not equal to %v", di, di2) t.Error(err) panic(err) } /*if di2.Updated.Unix() != di.Updated.Unix() { err = errors.New("updated should equal") t.Error(err, di.Updated, di2.Updated) panic(err) } if di2.Created.Unix() != di.Created.Unix() { err = errors.New("created should equal") t.Error(err, di.Created, di2.Created) panic(err) }*/ }
func testRows(engine *xorm.Engine, t *testing.T) { rows, err := engine.Omit("is_man").Rows(new(Userinfo)) if err != nil { t.Error(err) panic(err) } defer rows.Close() idx := 0 user := new(Userinfo) for rows.Next() { err = rows.Scan(user) if err != nil { t.Error(err) panic(err) } fmt.Println(idx, "--", user) idx++ } }
func testInsertDefault(engine *xorm.Engine, t *testing.T) { di := new(DefaultInsert) err := engine.Sync2(di) if err != nil { t.Error(err) } var di2 = DefaultInsert{Name: "test"} _, err = engine.Omit(engine.ColumnMapper.Obj2Table("Status")).Insert(&di2) if err != nil { t.Error(err) } has, err := engine.Desc("(id)").Get(di) if err != nil { t.Error(err) } if !has { err = errors.New("error with no data") t.Error(err) panic(err) } if di.Status != -1 { err = errors.New("inserted error data") t.Error(err) panic(err) } if di2.Updated.Unix() != di.Updated.Unix() { err = errors.New("updated should equal") t.Error(err, di.Updated, di2.Updated) panic(err) } if di2.Created.Unix() != di.Created.Unix() { err = errors.New("created should equal") t.Error(err, di.Created, di2.Created) panic(err) } testInsertDefault2(engine, t) }