github.com/octohelm/storage@v0.0.0-20240516030302-1ac2cc1ea347/pkg/sqlbuilder/addition_order_by_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 TestOrderBy(t *testing.T) {
    11  	table := T("T")
    12  
    13  	t.Run("select Order", func(t *testing.T) {
    14  		testutil.ShouldBeExpr(t,
    15  			Select(nil).
    16  				From(
    17  					table,
    18  					OrderBy(
    19  						AscOrder(Col("F_a")),
    20  						DescOrder(Col("F_b")),
    21  					),
    22  					Where(
    23  						TypedCol[int]("F_a").V(Eq(1)),
    24  					),
    25  				),
    26  			`
    27  SELECT * FROM T
    28  WHERE f_a = ?
    29  ORDER BY (f_a) ASC,(f_b) DESC
    30  `,
    31  			1,
    32  		)
    33  	})
    34  }