github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/pkg/sqlbuilder/def_column_collection_test.go (about) 1 package sqlbuilder_test 2 3 import ( 4 "testing" 5 6 "github.com/octohelm/storage/internal/testutil" 7 . "github.com/octohelm/storage/pkg/sqlbuilder" 8 ) 9 10 func BenchmarkCols(b *testing.B) { 11 cols := Cols() 12 13 (cols).(ColumnCollectionManger).AddCol( 14 Col("f_id", ColField("ID"), ColTypeOf(1, `,autoincrement`)), 15 Col("f_name", ColField("Name"), ColTypeOf(1, ``)), 16 Col("f_f1", ColField("F1"), ColTypeOf(1, ``)), 17 Col("f_f2", ColField("F2"), ColTypeOf(1, ``)), 18 Col("f_f3", ColField("F3"), ColTypeOf(1, ``)), 19 Col("f_f4", ColField("F4"), ColTypeOf(1, ``)), 20 Col("f_f5", ColField("F5"), ColTypeOf(1, ``)), 21 Col("f_f6", ColField("F6"), ColTypeOf(1, ``)), 22 Col("f_f7", ColField("F7"), ColTypeOf(1, ``)), 23 Col("f_f8", ColField("F8"), ColTypeOf(1, ``)), 24 Col("f_f9", ColField("F9"), ColTypeOf(1, ``)), 25 ) 26 27 b.Run("pick", func(b *testing.B) { 28 for i := 0; i < b.N; i++ { 29 _ = cols.F("F3") 30 } 31 }) 32 33 b.Run("multi pick", func(b *testing.B) { 34 for i := 0; i < b.N; i++ { 35 _ = cols.Cols("ID", "Name") 36 } 37 }) 38 39 b.Run("multi pick all", func(b *testing.B) { 40 for i := 0; i < b.N; i++ { 41 _ = cols.Cols() 42 } 43 }) 44 45 } 46 47 func TestColumns(t *testing.T) { 48 cols := Cols() 49 50 t.Run("empty columns", func(t *testing.T) { 51 testutil.Expect(t, cols.Len(), testutil.Equal(0)) 52 //testutil.Expect(t, columns.AutoIncrement(), testutil.Be[*Column](nil)) 53 }) 54 55 t.Run("added cols", func(t *testing.T) { 56 cols.(ColumnCollectionManger).AddCol( 57 Col("F_id", ColField("ID"), ColTypeOf(1, `,autoincrement`)), 58 ) 59 60 //autoIncrementCol := cols.AutoIncrement() 61 // 62 //testutil.Expect(t, autoIncrementCol, testutil.Not(testutil.Be[*Column](nil))) 63 //testutil.Expect(t, autoIncrementCol.Name(), testutil.Equal("f_id")) 64 65 t.Run("get col by FieldName", func(t *testing.T) { 66 testutil.Expect(t, cols.F("ID2"), testutil.Be[Column](nil)) 67 68 testutil.Expect(t, cols.Cols("ID").Len(), testutil.Equal(1)) 69 testutil.Expect(t, cols.Cols().Len(), testutil.Equal(1)) 70 }) 71 72 t.Run("get col by ColName", func(t *testing.T) { 73 testutil.Expect(t, cols.Cols("f_id").Len(), testutil.Equal(1)) 74 testutil.Expect(t, cols.Cols().Len(), testutil.Be(1)) 75 }) 76 }) 77 }