Skip to content

Commit 9466035

Browse files
committed
add bare column function
1 parent e7348e0 commit 9466035

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

column.go

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ type BasicColumn struct {
66
name string
77
}
88

9+
func BareColumn(name string) *BasicColumn {
10+
return &BasicColumn{name: name}
11+
}
12+
913
func (c *BasicColumn) AsNamedShort(s *Serializer) {
1014
s.N(c.name)
1115
}

sqlbuilder_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,21 @@ func TestCTEMultipleRecursive(t *testing.T) {
286286
a.Equal(`WITH RECURSIVE "c1" AS (SELECT "tbl"."id", "tbl"."parent_id" FROM "tbl"), "c2" AS (SELECT "tbl"."id", "tbl"."parent_id" FROM "tbl") SELECT "c1"."id", "c2"."id"`, qs)
287287
a.Equal([]interface{}(nil), qv)
288288
}
289+
290+
func TestBareColumn(t *testing.T) {
291+
for _, e := range [][2]string{
292+
{"a", "a"},
293+
{"a b", "\"a \""},
294+
{"a.b", "\"a.b\""},
295+
} {
296+
t.Run(e[0], func(t *testing.T) {
297+
a := assert.New(t)
298+
299+
s := NewSerializer(DialectGeneric{})
300+
301+
qs, _, err := s.F(BareColumn("a").AsExpr).ToSQL()
302+
a.NoError(err)
303+
a.Equal("a", qs)
304+
})
305+
}
306+
}

0 commit comments

Comments
 (0)