session_insert_test.go 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2017 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. import (
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestInsertOne(t *testing.T) {
  11. assert.NoError(t, prepareEngine())
  12. type Test struct {
  13. Id int64 `xorm:"autoincr pk"`
  14. Msg string `xorm:"varchar(255)"`
  15. Created time.Time `xorm:"created"`
  16. }
  17. assert.NoError(t, testEngine.Sync2(new(Test)))
  18. data := Test{Msg: "hi"}
  19. _, err := testEngine.InsertOne(data)
  20. assert.NoError(t, err)
  21. }
  22. func TestInsertOne2(t *testing.T) {
  23. assert.NoError(t, prepareEngine())
  24. type Test2 struct {
  25. Id int64 `xorm:"autoincr pk"`
  26. Msg string `xorm:"varchar(255)"`
  27. Created time.Time `xorm:"datetime created"`
  28. }
  29. assert.NoError(t, testEngine.Sync2(new(Test2)))
  30. data := Test2{Msg: "hi"}
  31. _, err := testEngine.InsertOne(data)
  32. assert.NoError(t, err)
  33. }