MCPcopy
hub / github.com/gogf/gf / Test_Model_Insert

Function Test_Model_Insert

contrib/drivers/dm/dm_z_unit_model_test.go:84–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func Test_Model_Insert(t *testing.T) {
85 // g.Model.insert not lost default not null column
86 table := "A_tables"
87 createInitTable(table)
88 defer dropTable(table)
89
90 gtest.C(t, func(t *gtest.T) {
91 i := 200
92 data := User{
93 ID: int64(i),
94 AccountName: fmt.Sprintf(`A%dtwo`, i),
95 PwdReset: 0,
96 AttrIndex: 99,
97 CreatedTime: time.Now(),
98 UpdatedTime: time.Now(),
99 }
100 result, err := db.Model(table).Insert(&data)
101 gtest.AssertNil(err)
102 n, err := result.RowsAffected()
103 gtest.AssertNil(err)
104 gtest.Assert(n, 1)
105 })
106
107 gtest.C(t, func(t *gtest.T) {
108 i := 201
109 data := User{
110 ID: int64(i),
111 AccountName: fmt.Sprintf(`A%dtwoONE`, i),
112 PwdReset: 1,
113 CreatedTime: time.Now(),
114 AttrIndex: 98,
115 UpdatedTime: time.Now(),
116 }
117 result, err := db.Model(table).Data(&data).Insert()
118 gtest.AssertNil(err)
119 n, err := result.RowsAffected()
120 gtest.AssertNil(err)
121 gtest.Assert(n, 1)
122 })
123}
124
125func Test_Model_InsertIgnore(t *testing.T) {
126 table := createInitTable()

Callers

nothing calls this directly

Calls 9

CFunction · 0.92
AssertNilFunction · 0.92
AssertFunction · 0.92
createInitTableFunction · 0.70
dropTableFunction · 0.70
InsertMethod · 0.65
ModelMethod · 0.65
DataMethod · 0.65
RowsAffectedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…