| 2083 | ) |
| 2084 | |
| 2085 | def test_orderby_groupby(self): |
| 2086 | self.assert_compile( |
| 2087 | table2.select().order_by( |
| 2088 | table2.c.otherid, asc(table2.c.othername) |
| 2089 | ), |
| 2090 | "SELECT myothertable.otherid, myothertable.othername FROM " |
| 2091 | "myothertable ORDER BY myothertable.otherid, " |
| 2092 | "myothertable.othername ASC", |
| 2093 | ) |
| 2094 | |
| 2095 | self.assert_compile( |
| 2096 | table2.select().order_by( |
| 2097 | table2.c.otherid, table2.c.othername.desc() |
| 2098 | ), |
| 2099 | "SELECT myothertable.otherid, myothertable.othername FROM " |
| 2100 | "myothertable ORDER BY myothertable.otherid, " |
| 2101 | "myothertable.othername DESC", |
| 2102 | ) |
| 2103 | |
| 2104 | # generative order_by |
| 2105 | self.assert_compile( |
| 2106 | table2.select() |
| 2107 | .order_by(table2.c.otherid) |
| 2108 | .order_by(table2.c.othername.desc()), |
| 2109 | "SELECT myothertable.otherid, myothertable.othername FROM " |
| 2110 | "myothertable ORDER BY myothertable.otherid, " |
| 2111 | "myothertable.othername DESC", |
| 2112 | ) |
| 2113 | |
| 2114 | self.assert_compile( |
| 2115 | table2.select() |
| 2116 | .order_by(table2.c.otherid) |
| 2117 | .order_by(table2.c.othername.desc()) |
| 2118 | .order_by(None), |
| 2119 | "SELECT myothertable.otherid, myothertable.othername " |
| 2120 | "FROM myothertable", |
| 2121 | ) |
| 2122 | |
| 2123 | self.assert_compile( |
| 2124 | select(table2.c.othername, func.count(table2.c.otherid)).group_by( |
| 2125 | table2.c.othername |
| 2126 | ), |
| 2127 | "SELECT myothertable.othername, " |
| 2128 | "count(myothertable.otherid) AS count_1 " |
| 2129 | "FROM myothertable GROUP BY myothertable.othername", |
| 2130 | ) |
| 2131 | |
| 2132 | # generative group by |
| 2133 | self.assert_compile( |
| 2134 | select(table2.c.othername, func.count(table2.c.otherid)).group_by( |
| 2135 | table2.c.othername |
| 2136 | ), |
| 2137 | "SELECT myothertable.othername, " |
| 2138 | "count(myothertable.otherid) AS count_1 " |
| 2139 | "FROM myothertable GROUP BY myothertable.othername", |
| 2140 | ) |
| 2141 | |
| 2142 | self.assert_compile( |