File tree 8 files changed +41
-8
lines changed
src/masoniteorm/query/grammars
8 files changed +41
-8
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ class MSSQLGrammar(BaseGrammar):
10
10
"MIN" : "MIN" ,
11
11
"AVG" : "AVG" ,
12
12
"COUNT" : "COUNT" ,
13
- "AVG" : "AVG" ,
14
13
}
15
14
16
15
join_keywords = {
@@ -37,7 +36,7 @@ def select_no_table(self):
37
36
return "SELECT {columns}"
38
37
39
38
def select_format (self ):
40
- return "SELECT {keyword} {limit} {columns} FROM {table} {lock} {joins} {wheres} {group_by} {order_by } {offset } {having }"
39
+ return "SELECT {keyword} {limit} {columns} FROM {table} {lock} {joins} {wheres} {group_by} {having } {order_by } {offset }"
41
40
42
41
def update_format (self ):
43
42
return "UPDATE {table} SET {key_equals} {wheres}"
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ class MySQLGrammar(BaseGrammar):
10
10
"MIN" : "MIN" ,
11
11
"AVG" : "AVG" ,
12
12
"COUNT" : "COUNT" ,
13
- "AVG" : "AVG" ,
14
13
}
15
14
16
15
join_keywords = {
@@ -50,7 +49,7 @@ class MySQLGrammar(BaseGrammar):
50
49
locks = {"share" : "LOCK IN SHARE MODE" , "update" : "FOR UPDATE" }
51
50
52
51
def select_format (self ):
53
- return "SELECT {keyword} {columns} FROM {table} {joins} {wheres} {group_by} {order_by } {limit } {offset } {having } {lock}"
52
+ return "SELECT {keyword} {columns} FROM {table} {joins} {wheres} {group_by} {having } {order_by } {limit } {offset } {lock}"
54
53
55
54
def select_no_table (self ):
56
55
return "SELECT {columns} {lock}"
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ class PostgresGrammar(BaseGrammar):
11
11
"MIN" : "MIN" ,
12
12
"AVG" : "AVG" ,
13
13
"COUNT" : "COUNT" ,
14
- "AVG" : "AVG" ,
15
14
}
16
15
17
16
join_keywords = {
@@ -38,7 +37,7 @@ def select_no_table(self):
38
37
return "SELECT {columns} {lock}"
39
38
40
39
def select_format (self ):
41
- return "SELECT {keyword} {columns} FROM {table} {joins} {wheres} {group_by} {order_by } {limit } {offset } {having } {lock}"
40
+ return "SELECT {keyword} {columns} FROM {table} {joins} {wheres} {group_by} {having } {order_by } {limit } {offset } {lock}"
42
41
43
42
def update_format (self ):
44
43
return "UPDATE {table} SET {key_equals} {wheres}"
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ class SQLiteGrammar(BaseGrammar):
11
11
"MIN" : "MIN" ,
12
12
"AVG" : "AVG" ,
13
13
"COUNT" : "COUNT" ,
14
- "AVG" : "AVG" ,
15
14
}
16
15
17
16
join_keywords = {
@@ -35,7 +34,7 @@ class SQLiteGrammar(BaseGrammar):
35
34
locks = {"share" : "" , "update" : "" }
36
35
37
36
def select_format (self ):
38
- return "SELECT {keyword} {columns} FROM {table} {joins} {wheres} {group_by} {order_by } {limit } {offset } {having } {lock}"
37
+ return "SELECT {keyword} {columns} FROM {table} {joins} {wheres} {group_by} {having } {order_by } {limit } {offset } {lock}"
39
38
40
39
def select_no_table (self ):
41
40
return "SELECT {columns} {lock}"
Original file line number Diff line number Diff line change @@ -246,6 +246,12 @@ def can_compile_having(self):
246
246
"""
247
247
return "SELECT SUM([users].[age]) AS age FROM [users] GROUP BY [users].[age] HAVING [users].[age]"
248
248
249
+ def can_compile_having_order (self ):
250
+ """
251
+ builder.sum('age').group_by('age').having('age').order_by('age', 'desc').to_sql()
252
+ """
253
+ return "SELECT SUM([users].[age]) AS age FROM [users] GROUP BY [users].[age] HAVING [users].[age] ORDER [users].[age] DESC"
254
+
249
255
def can_compile_between (self ):
250
256
"""
251
257
builder.between('age', 18, 21).to_sql()
@@ -308,6 +314,11 @@ def test_can_compile_having_raw(self):
308
314
to_sql , "SELECT COUNT(*) as counts FROM [users] HAVING counts > 10"
309
315
)
310
316
317
+ def test_can_compile_having_raw_order (self ):
318
+ to_sql = self .builder .select_raw ("COUNT(*) as counts" ).having_raw ("counts > 10" ).order_by_raw (
319
+ 'counts DESC' ).to_sql ()
320
+ self .assertEqual (to_sql , "SELECT COUNT(*) as counts FROM [users] HAVING counts > 10 ORDER BY counts DESC" )
321
+
311
322
def test_can_compile_select_raw (self ):
312
323
to_sql = self .builder .select_raw ("COUNT(*)" ).to_sql ()
313
324
sql = getattr (
Original file line number Diff line number Diff line change @@ -248,6 +248,12 @@ def can_compile_having(self):
248
248
"""
249
249
return "SELECT SUM(`users`.`age`) AS age FROM `users` GROUP BY `users`.`age` HAVING `users`.`age`"
250
250
251
+ def can_compile_having_order (self ):
252
+ """
253
+ builder.sum('age').group_by('age').having('age').order_by('age', 'desc').to_sql()
254
+ """
255
+ return "SELECT SUM(`users`.`age`) AS age FROM `users` GROUP BY `users`.`age` HAVING `users`.`age` ORDER `users`.`age` DESC"
256
+
251
257
def can_compile_having_with_expression (self ):
252
258
"""
253
259
builder.sum('age').group_by('age').having('age', 10).to_sql()
@@ -304,6 +310,10 @@ def test_can_compile_having_raw(self):
304
310
to_sql , "SELECT COUNT(*) as counts FROM `users` HAVING counts > 10"
305
311
)
306
312
313
+ def test_can_compile_having_raw_order (self ):
314
+ to_sql = self .builder .select_raw ("COUNT(*) as counts" ).having_raw ("counts > 10" ).order_by_raw ('counts DESC' ).to_sql ()
315
+ self .assertEqual (to_sql , "SELECT COUNT(*) as counts FROM `users` HAVING counts > 10 ORDER BY counts DESC" )
316
+
307
317
def test_can_compile_select_raw (self ):
308
318
to_sql = self .builder .select_raw ("COUNT(*)" ).to_sql ()
309
319
self .assertEqual (to_sql , "SELECT COUNT(*) FROM `users`" )
Original file line number Diff line number Diff line change @@ -247,6 +247,12 @@ def can_compile_having(self):
247
247
"""
248
248
return """SELECT SUM("users"."age") AS age FROM "users" GROUP BY "users"."age" HAVING "users"."age\" """
249
249
250
+ def can_compile_having_order (self ):
251
+ """
252
+ builder.sum('age').group_by('age').having('age').order_by('age', 'desc').to_sql()
253
+ """
254
+ return """SELECT SUM("users"."age") AS age FROM "users" GROUP BY "users"."age" HAVING "users"."age" ORDER "users"."age" DESC"""
255
+
250
256
def can_compile_having_with_expression (self ):
251
257
"""
252
258
builder.sum('age').group_by('age').having('age', 10).to_sql()
@@ -309,6 +315,10 @@ def test_can_compile_having_raw(self):
309
315
to_sql , """SELECT COUNT(*) as counts FROM "users" HAVING counts > 10"""
310
316
)
311
317
318
+ def test_can_compile_having_raw_order (self ):
319
+ to_sql = self .builder .select_raw ("COUNT(*) as counts" ).having_raw ("counts > 10" ).order_by_raw ('counts DESC' ).to_sql ()
320
+ self .assertEqual (to_sql , """SELECT COUNT(*) as counts FROM "users" HAVING counts > 10 ORDER BY counts DESC""" )
321
+
312
322
def test_can_compile_where_raw_and_where_with_multiple_bindings (self ):
313
323
query = self .builder .where_raw (
314
324
""" "age" = '?' AND "is_admin" = '?'""" , [18 , True ]
Original file line number Diff line number Diff line change @@ -239,6 +239,12 @@ def can_compile_having(self):
239
239
"""
240
240
return """SELECT SUM("users"."age") AS age FROM "users" GROUP BY "users"."age" HAVING "users"."age\" """
241
241
242
+ def can_compile_having_order (self ):
243
+ """
244
+ builder.sum('age').group_by('age').having('age').order_by('age', 'desc').to_sql()
245
+ """
246
+ return """SELECT SUM("users"."age") AS age FROM "users" GROUP BY "users"."age" HAVING "users"."age\" ORDER "users"."age" DESC"""
247
+
242
248
def can_compile_having_raw (self ):
243
249
"""
244
250
builder.select_raw("COUNT(*) as counts").having_raw("counts > 18").to_sql()
You can’t perform that action at this time.
0 commit comments