Skip to content

Commit d7210d8

Browse files
committed
stuff
1 parent 08dfcd7 commit d7210d8

10 files changed

+78
-8
lines changed

sqlx/as.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ func As(stmt Sqlizer, alias string) *AsClause {
1414
}
1515

1616
func (self AsClause) Sql() string {
17-
return fmt.Sprintf(`%s as "%s"`, self.stmt.Sql(), self.alias)
17+
return fmt.Sprintf(`%s AS "%s"`, self.stmt.Sql(), self.alias)
1818
}
1919

2020
func (self AsClause) SqlPretty(indent string) string {
21-
return fmt.Sprintf(`%s as "%s"`, self.stmt.SqlPretty(indent), self.alias)
21+
return fmt.Sprintf(`%s AS "%s"`, self.stmt.SqlPretty(indent), self.alias)
2222
}
2323

2424
func (self *AsClause) setDepth(depth uint) {

sqlx/select_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,32 @@ func TestSelect(t *testing.T) {
217217
}
218218
})
219219

220+
t.Run("all", func(t *testing.T) {
221+
expected, err := os.ReadFile("./testcases/select/all.sql")
222+
223+
if err != nil {
224+
t.Fatal(err)
225+
}
226+
227+
sql := sqlx.Select(
228+
"a",
229+
"b",
230+
).ColumnAs(
231+
sqlx.Select("*").From("test").Limit("1"),
232+
"tester",
233+
).From(
234+
"test",
235+
).Where(
236+
"a = 1",
237+
).Or(
238+
sqlx.Where("a = 2").And("b = 3"),
239+
).GroupBy("a").OrderBy("a", sqlx.Asc).Sql()
240+
241+
if sql != strings.TrimSuffix(string(expected), "\n") {
242+
t.Fatalf(sql)
243+
}
244+
})
245+
220246
t.Run("pretty", func(t *testing.T) {
221247
t.Run("column", func(t *testing.T) {
222248
t.Run("string", func(t *testing.T) {
@@ -425,5 +451,31 @@ func TestSelect(t *testing.T) {
425451
t.Fatalf(sql)
426452
}
427453
})
454+
455+
t.Run("all", func(t *testing.T) {
456+
expected, err := os.ReadFile("./testcases/select/all_pretty.sql")
457+
458+
if err != nil {
459+
t.Fatal(err)
460+
}
461+
462+
sql := sqlx.Select(
463+
"a",
464+
"b",
465+
).ColumnAs(
466+
sqlx.Select("*").From("test").Limit("1"),
467+
"tester",
468+
).From(
469+
"test",
470+
).Where(
471+
"a = 1",
472+
).Or(
473+
sqlx.Where("a = 2").And("b = 3"),
474+
).GroupBy("a").OrderBy("a", sqlx.Asc).SqlPretty(" ")
475+
476+
if sql != strings.TrimSuffix(string(expected), "\n") {
477+
t.Fatalf(sql)
478+
}
479+
})
428480
})
429481
}

sqlx/testcases/select/all.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT a, b, (SELECT * FROM test LIMIT 1) AS "tester" FROM test WHERE a = 1 OR (a = 2 AND b = 3) GROUP BY a ORDER BY a ASC;

sqlx/testcases/select/all_pretty.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT
2+
a,
3+
b,
4+
(
5+
SELECT
6+
*
7+
FROM test
8+
LIMIT 1
9+
) AS "tester"
10+
FROM test
11+
WHERE a = 1
12+
OR (
13+
a = 2
14+
AND b = 3
15+
)
16+
GROUP BY a
17+
ORDER BY a ASC;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SELECT (SELECT a, b, c FROM test) as "results";
1+
SELECT (SELECT a, b, c FROM test) AS "results";

sqlx/testcases/select/column_select_pretty.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ SELECT
55
b,
66
c
77
FROM test
8-
) as "results";
8+
) AS "results";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SELECT 1, 2, (SELECT a, b, c FROM test) as "results";
1+
SELECT 1, 2, (SELECT a, b, c FROM test) AS "results";

sqlx/testcases/select/column_string_select_pretty.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ SELECT
77
b,
88
c
99
FROM test
10-
) as "results";
10+
) AS "results";

sqlx/testcases/select/from_select.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SELECT a, b, c FROM (SELECT d, e, f FROM test) as "test";
1+
SELECT a, b, c FROM (SELECT d, e, f FROM test) AS "test";

sqlx/testcases/select/from_select_pretty.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ FROM (
88
e,
99
f
1010
FROM test
11-
) as "test";
11+
) AS "test";

0 commit comments

Comments
 (0)