@simplysm/orm-common 13.0.69 → 13.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +54 -1447
  2. package/dist/create-db-context.d.ts +10 -10
  3. package/dist/create-db-context.js +9 -9
  4. package/dist/create-db-context.js.map +1 -1
  5. package/dist/ddl/column-ddl.d.ts +4 -4
  6. package/dist/ddl/initialize.d.ts +17 -17
  7. package/dist/ddl/initialize.js +2 -2
  8. package/dist/ddl/initialize.js.map +1 -1
  9. package/dist/ddl/relation-ddl.d.ts +6 -6
  10. package/dist/ddl/schema-ddl.d.ts +4 -4
  11. package/dist/ddl/table-ddl.d.ts +24 -24
  12. package/dist/ddl/table-ddl.js +4 -4
  13. package/dist/ddl/table-ddl.js.map +1 -1
  14. package/dist/errors/db-transaction-error.d.ts +15 -15
  15. package/dist/errors/db-transaction-error.d.ts.map +1 -1
  16. package/dist/exec/executable.d.ts +23 -23
  17. package/dist/exec/executable.js +3 -3
  18. package/dist/exec/executable.js.map +1 -1
  19. package/dist/exec/queryable.d.ts +160 -160
  20. package/dist/exec/queryable.js +119 -119
  21. package/dist/exec/queryable.js.map +1 -1
  22. package/dist/exec/search-parser.d.ts +37 -37
  23. package/dist/exec/search-parser.d.ts.map +1 -1
  24. package/dist/expr/expr-unit.d.ts +4 -4
  25. package/dist/expr/expr.d.ts +257 -257
  26. package/dist/expr/expr.js +265 -265
  27. package/dist/expr/expr.js.map +1 -1
  28. package/dist/query-builder/base/expr-renderer-base.d.ts +9 -9
  29. package/dist/query-builder/base/expr-renderer-base.js +2 -2
  30. package/dist/query-builder/base/expr-renderer-base.js.map +1 -1
  31. package/dist/query-builder/base/query-builder-base.d.ts +26 -26
  32. package/dist/query-builder/base/query-builder-base.d.ts.map +1 -1
  33. package/dist/query-builder/base/query-builder-base.js +22 -22
  34. package/dist/query-builder/base/query-builder-base.js.map +1 -1
  35. package/dist/query-builder/mssql/mssql-expr-renderer.d.ts +4 -4
  36. package/dist/query-builder/mssql/mssql-expr-renderer.d.ts.map +1 -1
  37. package/dist/query-builder/mssql/mssql-expr-renderer.js +18 -18
  38. package/dist/query-builder/mssql/mssql-expr-renderer.js.map +1 -1
  39. package/dist/query-builder/mssql/mssql-query-builder.d.ts +2 -2
  40. package/dist/query-builder/mssql/mssql-query-builder.d.ts.map +1 -1
  41. package/dist/query-builder/mssql/mssql-query-builder.js +11 -11
  42. package/dist/query-builder/mssql/mssql-query-builder.js.map +1 -1
  43. package/dist/query-builder/mysql/mysql-expr-renderer.d.ts +4 -4
  44. package/dist/query-builder/mysql/mysql-expr-renderer.d.ts.map +1 -1
  45. package/dist/query-builder/mysql/mysql-expr-renderer.js +17 -17
  46. package/dist/query-builder/mysql/mysql-expr-renderer.js.map +1 -1
  47. package/dist/query-builder/mysql/mysql-query-builder.d.ts +8 -8
  48. package/dist/query-builder/mysql/mysql-query-builder.d.ts.map +1 -1
  49. package/dist/query-builder/mysql/mysql-query-builder.js +5 -5
  50. package/dist/query-builder/mysql/mysql-query-builder.js.map +1 -1
  51. package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts +4 -4
  52. package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts.map +1 -1
  53. package/dist/query-builder/postgresql/postgresql-expr-renderer.js +17 -17
  54. package/dist/query-builder/postgresql/postgresql-expr-renderer.js.map +1 -1
  55. package/dist/query-builder/postgresql/postgresql-query-builder.d.ts +5 -5
  56. package/dist/query-builder/postgresql/postgresql-query-builder.d.ts.map +1 -1
  57. package/dist/query-builder/postgresql/postgresql-query-builder.js +8 -8
  58. package/dist/query-builder/postgresql/postgresql-query-builder.js.map +1 -1
  59. package/dist/query-builder/query-builder.d.ts +1 -1
  60. package/dist/schema/factory/column-builder.d.ts +79 -79
  61. package/dist/schema/factory/column-builder.js +42 -42
  62. package/dist/schema/factory/index-builder.d.ts +39 -39
  63. package/dist/schema/factory/index-builder.js +26 -26
  64. package/dist/schema/factory/relation-builder.d.ts +99 -99
  65. package/dist/schema/factory/relation-builder.d.ts.map +1 -1
  66. package/dist/schema/factory/relation-builder.js +38 -38
  67. package/dist/schema/procedure-builder.d.ts +49 -49
  68. package/dist/schema/procedure-builder.d.ts.map +1 -1
  69. package/dist/schema/procedure-builder.js +33 -33
  70. package/dist/schema/table-builder.d.ts +59 -59
  71. package/dist/schema/table-builder.d.ts.map +1 -1
  72. package/dist/schema/table-builder.js +43 -43
  73. package/dist/schema/view-builder.d.ts +49 -49
  74. package/dist/schema/view-builder.d.ts.map +1 -1
  75. package/dist/schema/view-builder.js +32 -32
  76. package/dist/types/column.d.ts +22 -22
  77. package/dist/types/column.js +1 -1
  78. package/dist/types/column.js.map +1 -1
  79. package/dist/types/db.d.ts +40 -40
  80. package/dist/types/expr.d.ts +59 -59
  81. package/dist/types/expr.d.ts.map +1 -1
  82. package/dist/types/query-def.d.ts +44 -44
  83. package/dist/types/query-def.d.ts.map +1 -1
  84. package/dist/utils/result-parser.d.ts +11 -11
  85. package/dist/utils/result-parser.js +3 -3
  86. package/dist/utils/result-parser.js.map +1 -1
  87. package/package.json +5 -5
  88. package/src/create-db-context.ts +20 -20
  89. package/src/ddl/column-ddl.ts +4 -4
  90. package/src/ddl/initialize.ts +259 -259
  91. package/src/ddl/relation-ddl.ts +89 -89
  92. package/src/ddl/schema-ddl.ts +4 -4
  93. package/src/ddl/table-ddl.ts +189 -189
  94. package/src/errors/db-transaction-error.ts +13 -13
  95. package/src/exec/executable.ts +25 -25
  96. package/src/exec/queryable.ts +2033 -2033
  97. package/src/exec/search-parser.ts +57 -57
  98. package/src/expr/expr-unit.ts +4 -4
  99. package/src/expr/expr.ts +2140 -2140
  100. package/src/query-builder/base/expr-renderer-base.ts +237 -237
  101. package/src/query-builder/base/query-builder-base.ts +213 -213
  102. package/src/query-builder/mssql/mssql-expr-renderer.ts +607 -607
  103. package/src/query-builder/mssql/mssql-query-builder.ts +650 -650
  104. package/src/query-builder/mysql/mysql-expr-renderer.ts +613 -613
  105. package/src/query-builder/mysql/mysql-query-builder.ts +759 -759
  106. package/src/query-builder/postgresql/postgresql-expr-renderer.ts +611 -611
  107. package/src/query-builder/postgresql/postgresql-query-builder.ts +686 -686
  108. package/src/query-builder/query-builder.ts +19 -19
  109. package/src/schema/factory/column-builder.ts +423 -423
  110. package/src/schema/factory/index-builder.ts +164 -164
  111. package/src/schema/factory/relation-builder.ts +453 -453
  112. package/src/schema/procedure-builder.ts +232 -232
  113. package/src/schema/table-builder.ts +319 -319
  114. package/src/schema/view-builder.ts +221 -221
  115. package/src/types/column.ts +188 -188
  116. package/src/types/db.ts +208 -208
  117. package/src/types/expr.ts +697 -697
  118. package/src/types/query-def.ts +513 -513
  119. package/src/utils/result-parser.ts +458 -458
  120. package/tests/db-context/create-db-context.spec.ts +224 -0
  121. package/tests/db-context/define-db-context.spec.ts +68 -0
  122. package/tests/ddl/basic.expected.ts +341 -0
  123. package/tests/ddl/basic.spec.ts +714 -0
  124. package/tests/ddl/column-builder.expected.ts +310 -0
  125. package/tests/ddl/column-builder.spec.ts +637 -0
  126. package/tests/ddl/index-builder.expected.ts +38 -0
  127. package/tests/ddl/index-builder.spec.ts +202 -0
  128. package/tests/ddl/procedure-builder.expected.ts +52 -0
  129. package/tests/ddl/procedure-builder.spec.ts +234 -0
  130. package/tests/ddl/relation-builder.expected.ts +36 -0
  131. package/tests/ddl/relation-builder.spec.ts +372 -0
  132. package/tests/ddl/table-builder.expected.ts +113 -0
  133. package/tests/ddl/table-builder.spec.ts +433 -0
  134. package/tests/ddl/view-builder.expected.ts +38 -0
  135. package/tests/ddl/view-builder.spec.ts +176 -0
  136. package/tests/dml/delete.expected.ts +96 -0
  137. package/tests/dml/delete.spec.ts +160 -0
  138. package/tests/dml/insert.expected.ts +192 -0
  139. package/tests/dml/insert.spec.ts +288 -0
  140. package/tests/dml/update.expected.ts +176 -0
  141. package/tests/dml/update.spec.ts +318 -0
  142. package/tests/dml/upsert.expected.ts +215 -0
  143. package/tests/dml/upsert.spec.ts +242 -0
  144. package/tests/errors/queryable-errors.spec.ts +177 -0
  145. package/tests/escape.spec.ts +100 -0
  146. package/tests/examples/pivot.expected.ts +211 -0
  147. package/tests/examples/pivot.spec.ts +533 -0
  148. package/tests/examples/sampling.expected.ts +69 -0
  149. package/tests/examples/sampling.spec.ts +104 -0
  150. package/tests/examples/unpivot.expected.ts +120 -0
  151. package/tests/examples/unpivot.spec.ts +226 -0
  152. package/tests/exec/search-parser.spec.ts +283 -0
  153. package/tests/executable/basic.expected.ts +18 -0
  154. package/tests/executable/basic.spec.ts +54 -0
  155. package/tests/expr/comparison.expected.ts +282 -0
  156. package/tests/expr/comparison.spec.ts +400 -0
  157. package/tests/expr/conditional.expected.ts +134 -0
  158. package/tests/expr/conditional.spec.ts +276 -0
  159. package/tests/expr/date.expected.ts +332 -0
  160. package/tests/expr/date.spec.ts +526 -0
  161. package/tests/expr/math.expected.ts +62 -0
  162. package/tests/expr/math.spec.ts +106 -0
  163. package/tests/expr/string.expected.ts +218 -0
  164. package/tests/expr/string.spec.ts +356 -0
  165. package/tests/expr/utility.expected.ts +147 -0
  166. package/tests/expr/utility.spec.ts +182 -0
  167. package/tests/select/basic.expected.ts +322 -0
  168. package/tests/select/basic.spec.ts +502 -0
  169. package/tests/select/filter.expected.ts +357 -0
  170. package/tests/select/filter.spec.ts +1068 -0
  171. package/tests/select/group.expected.ts +169 -0
  172. package/tests/select/group.spec.ts +244 -0
  173. package/tests/select/join.expected.ts +582 -0
  174. package/tests/select/join.spec.ts +805 -0
  175. package/tests/select/order.expected.ts +150 -0
  176. package/tests/select/order.spec.ts +189 -0
  177. package/tests/select/recursive-cte.expected.ts +244 -0
  178. package/tests/select/recursive-cte.spec.ts +514 -0
  179. package/tests/select/result-meta.spec.ts +270 -0
  180. package/tests/select/subquery.expected.ts +363 -0
  181. package/tests/select/subquery.spec.ts +537 -0
  182. package/tests/select/view.expected.ts +155 -0
  183. package/tests/select/view.spec.ts +235 -0
  184. package/tests/select/window.expected.ts +345 -0
  185. package/tests/select/window.spec.ts +618 -0
  186. package/tests/setup/MockExecutor.ts +18 -0
  187. package/tests/setup/TestDbContext.ts +59 -0
  188. package/tests/setup/models/Company.ts +13 -0
  189. package/tests/setup/models/Employee.ts +10 -0
  190. package/tests/setup/models/MonthlySales.ts +11 -0
  191. package/tests/setup/models/Post.ts +16 -0
  192. package/tests/setup/models/Sales.ts +10 -0
  193. package/tests/setup/models/User.ts +19 -0
  194. package/tests/setup/procedure/GetAllUsers.ts +9 -0
  195. package/tests/setup/procedure/GetUserById.ts +12 -0
  196. package/tests/setup/test-utils.ts +72 -0
  197. package/tests/setup/views/ActiveUsers.ts +8 -0
  198. package/tests/setup/views/UserSummary.ts +11 -0
  199. package/tests/types/nullable-queryable-record.spec.ts +145 -0
  200. package/tests/utils/result-parser-perf.spec.ts +210 -0
  201. package/tests/utils/result-parser.spec.ts +701 -0
  202. package/docs/expressions.md +0 -172
  203. package/docs/queries.md +0 -444
  204. package/docs/schema.md +0 -245
@@ -0,0 +1,582 @@
1
+ /**
2
+ * SELECT - JOIN test expected SQL
3
+ */
4
+ import { mysql, pgsql, tsql } from "@simplysm/core-common";
5
+ import type { ExpectedSql } from "../setup/test-utils";
6
+
7
+ //#region ========== Basic JOIN ==========
8
+
9
+ export const joinBasic: ExpectedSql = {
10
+ mysql: mysql`
11
+ SELECT
12
+ \`T1\`.\`id\` AS \`id\`,
13
+ \`T1\`.\`name\` AS \`name\`,
14
+ \`T1\`.\`email\` AS \`email\`,
15
+ \`T1\`.\`age\` AS \`age\`,
16
+ \`T1\`.\`isActive\` AS \`isActive\`,
17
+ \`T1\`.\`companyId\` AS \`companyId\`,
18
+ \`T1\`.\`createdAt\` AS \`createdAt\`,
19
+ \`T1.post\`.\`id\` AS \`post.id\`,
20
+ \`T1.post\`.\`userId\` AS \`post.userId\`,
21
+ \`T1.post\`.\`title\` AS \`post.title\`,
22
+ \`T1.post\`.\`content\` AS \`post.content\`,
23
+ \`T1.post\`.\`viewCount\` AS \`post.viewCount\`,
24
+ \`T1.post\`.\`publishedAt\` AS \`post.publishedAt\`
25
+ FROM \`TestDb\`.\`User\` AS \`T1\`
26
+ LEFT OUTER JOIN \`TestDb\`.\`Post\` AS \`T1.post\` ON \`T1.post\`.\`userId\` <=> \`T1\`.\`id\`
27
+ `,
28
+ mssql: tsql`
29
+ SELECT
30
+ [T1].[id] AS [id],
31
+ [T1].[name] AS [name],
32
+ [T1].[email] AS [email],
33
+ [T1].[age] AS [age],
34
+ [T1].[isActive] AS [isActive],
35
+ [T1].[companyId] AS [companyId],
36
+ [T1].[createdAt] AS [createdAt],
37
+ [T1.post].[id] AS [post.id],
38
+ [T1.post].[userId] AS [post.userId],
39
+ [T1.post].[title] AS [post.title],
40
+ [T1.post].[content] AS [post.content],
41
+ [T1.post].[viewCount] AS [post.viewCount],
42
+ [T1.post].[publishedAt] AS [post.publishedAt]
43
+ FROM [TestDb].[TestSchema].[User] AS [T1]
44
+ LEFT OUTER JOIN [TestDb].[TestSchema].[Post] AS [T1.post] ON (([T1.post].[userId] IS NULL AND [T1].[id] IS NULL) OR [T1.post].[userId] = [T1].[id])
45
+ `,
46
+ postgresql: pgsql`
47
+ SELECT
48
+ "T1"."id" AS "id",
49
+ "T1"."name" AS "name",
50
+ "T1"."email" AS "email",
51
+ "T1"."age" AS "age",
52
+ "T1"."isActive" AS "isActive",
53
+ "T1"."companyId" AS "companyId",
54
+ "T1"."createdAt" AS "createdAt",
55
+ "T1.post"."id" AS "post.id",
56
+ "T1.post"."userId" AS "post.userId",
57
+ "T1.post"."title" AS "post.title",
58
+ "T1.post"."content" AS "post.content",
59
+ "T1.post"."viewCount" AS "post.viewCount",
60
+ "T1.post"."publishedAt" AS "post.publishedAt"
61
+ FROM "TestSchema"."User" AS "T1"
62
+ LEFT OUTER JOIN "TestSchema"."Post" AS "T1.post" ON "T1.post"."userId" IS NOT DISTINCT FROM "T1"."id"
63
+ `,
64
+ };
65
+
66
+ export const joinSingle: ExpectedSql = {
67
+ mysql: mysql`
68
+ SELECT
69
+ \`T1\`.\`id\` AS \`id\`,
70
+ \`T1\`.\`userId\` AS \`userId\`,
71
+ \`T1\`.\`title\` AS \`title\`,
72
+ \`T1\`.\`content\` AS \`content\`,
73
+ \`T1\`.\`viewCount\` AS \`viewCount\`,
74
+ \`T1\`.\`publishedAt\` AS \`publishedAt\`,
75
+ \`T1.user\`.\`id\` AS \`user.id\`,
76
+ \`T1.user\`.\`name\` AS \`user.name\`,
77
+ \`T1.user\`.\`email\` AS \`user.email\`,
78
+ \`T1.user\`.\`age\` AS \`user.age\`,
79
+ \`T1.user\`.\`isActive\` AS \`user.isActive\`,
80
+ \`T1.user\`.\`companyId\` AS \`user.companyId\`,
81
+ \`T1.user\`.\`createdAt\` AS \`user.createdAt\`
82
+ FROM \`TestDb\`.\`Post\` AS \`T1\`
83
+ LEFT OUTER JOIN \`TestDb\`.\`User\` AS \`T1.user\` ON \`T1.user\`.\`id\` <=> \`T1\`.\`userId\`
84
+ `,
85
+ mssql: tsql`
86
+ SELECT
87
+ [T1].[id] AS [id],
88
+ [T1].[userId] AS [userId],
89
+ [T1].[title] AS [title],
90
+ [T1].[content] AS [content],
91
+ [T1].[viewCount] AS [viewCount],
92
+ [T1].[publishedAt] AS [publishedAt],
93
+ [T1.user].[id] AS [user.id],
94
+ [T1.user].[name] AS [user.name],
95
+ [T1.user].[email] AS [user.email],
96
+ [T1.user].[age] AS [user.age],
97
+ [T1.user].[isActive] AS [user.isActive],
98
+ [T1.user].[companyId] AS [user.companyId],
99
+ [T1.user].[createdAt] AS [user.createdAt]
100
+ FROM [TestDb].[TestSchema].[Post] AS [T1]
101
+ LEFT OUTER JOIN [TestDb].[TestSchema].[User] AS [T1.user] ON (([T1.user].[id] IS NULL AND [T1].[userId] IS NULL) OR [T1.user].[id] = [T1].[userId])
102
+ `,
103
+ postgresql: pgsql`
104
+ SELECT
105
+ "T1"."id" AS "id",
106
+ "T1"."userId" AS "userId",
107
+ "T1"."title" AS "title",
108
+ "T1"."content" AS "content",
109
+ "T1"."viewCount" AS "viewCount",
110
+ "T1"."publishedAt" AS "publishedAt",
111
+ "T1.user"."id" AS "user.id",
112
+ "T1.user"."name" AS "user.name",
113
+ "T1.user"."email" AS "user.email",
114
+ "T1.user"."age" AS "user.age",
115
+ "T1.user"."isActive" AS "user.isActive",
116
+ "T1.user"."companyId" AS "user.companyId",
117
+ "T1.user"."createdAt" AS "user.createdAt"
118
+ FROM "TestSchema"."Post" AS "T1"
119
+ LEFT OUTER JOIN "TestSchema"."User" AS "T1.user" ON "T1.user"."id" IS NOT DISTINCT FROM "T1"."userId"
120
+ `,
121
+ };
122
+
123
+ export const joinSingleLateral: ExpectedSql = {
124
+ mysql: mysql`
125
+ SELECT
126
+ \`T1\`.\`id\` AS \`id\`,
127
+ \`T1\`.\`name\` AS \`name\`,
128
+ \`T1\`.\`email\` AS \`email\`,
129
+ \`T1\`.\`age\` AS \`age\`,
130
+ \`T1\`.\`isActive\` AS \`isActive\`,
131
+ \`T1\`.\`companyId\` AS \`companyId\`,
132
+ \`T1\`.\`createdAt\` AS \`createdAt\`,
133
+ \`T1.latestPost\`.\`id\` AS \`latestPost.id\`,
134
+ \`T1.latestPost\`.\`userId\` AS \`latestPost.userId\`,
135
+ \`T1.latestPost\`.\`title\` AS \`latestPost.title\`,
136
+ \`T1.latestPost\`.\`content\` AS \`latestPost.content\`,
137
+ \`T1.latestPost\`.\`viewCount\` AS \`latestPost.viewCount\`,
138
+ \`T1.latestPost\`.\`publishedAt\` AS \`latestPost.publishedAt\`
139
+ FROM \`TestDb\`.\`User\` AS \`T1\`
140
+ LEFT OUTER JOIN LATERAL (
141
+ SELECT * FROM \`TestDb\`.\`Post\` AS \`T1.latestPost\`
142
+ WHERE \`T1.latestPost\`.\`userId\` <=> \`T1\`.\`id\`
143
+ ORDER BY \`T1.latestPost\`.\`publishedAt\` DESC
144
+ LIMIT 1
145
+ ) AS \`T1.latestPost\` ON TRUE
146
+ `,
147
+ mssql: tsql`
148
+ SELECT
149
+ [T1].[id] AS [id],
150
+ [T1].[name] AS [name],
151
+ [T1].[email] AS [email],
152
+ [T1].[age] AS [age],
153
+ [T1].[isActive] AS [isActive],
154
+ [T1].[companyId] AS [companyId],
155
+ [T1].[createdAt] AS [createdAt],
156
+ [T1.latestPost].[id] AS [latestPost.id],
157
+ [T1.latestPost].[userId] AS [latestPost.userId],
158
+ [T1.latestPost].[title] AS [latestPost.title],
159
+ [T1.latestPost].[content] AS [latestPost.content],
160
+ [T1.latestPost].[viewCount] AS [latestPost.viewCount],
161
+ [T1.latestPost].[publishedAt] AS [latestPost.publishedAt]
162
+ FROM [TestDb].[TestSchema].[User] AS [T1]
163
+ OUTER APPLY (
164
+ SELECT TOP 1 * FROM [TestDb].[TestSchema].[Post] AS [T1.latestPost]
165
+ WHERE (([T1.latestPost].[userId] IS NULL AND [T1].[id] IS NULL) OR [T1.latestPost].[userId] = [T1].[id])
166
+ ORDER BY [T1.latestPost].[publishedAt] DESC
167
+ ) AS [T1.latestPost]
168
+ `,
169
+ postgresql: pgsql`
170
+ SELECT
171
+ "T1"."id" AS "id",
172
+ "T1"."name" AS "name",
173
+ "T1"."email" AS "email",
174
+ "T1"."age" AS "age",
175
+ "T1"."isActive" AS "isActive",
176
+ "T1"."companyId" AS "companyId",
177
+ "T1"."createdAt" AS "createdAt",
178
+ "T1.latestPost"."id" AS "latestPost.id",
179
+ "T1.latestPost"."userId" AS "latestPost.userId",
180
+ "T1.latestPost"."title" AS "latestPost.title",
181
+ "T1.latestPost"."content" AS "latestPost.content",
182
+ "T1.latestPost"."viewCount" AS "latestPost.viewCount",
183
+ "T1.latestPost"."publishedAt" AS "latestPost.publishedAt"
184
+ FROM "TestSchema"."User" AS "T1"
185
+ LEFT OUTER JOIN LATERAL (
186
+ SELECT * FROM "TestSchema"."Post" AS "T1.latestPost"
187
+ WHERE "T1.latestPost"."userId" IS NOT DISTINCT FROM "T1"."id"
188
+ ORDER BY "T1.latestPost"."publishedAt" DESC
189
+ LIMIT 1
190
+ ) AS "T1.latestPost" ON TRUE
191
+ `,
192
+ };
193
+
194
+ export const joinSingleLateralAgg: ExpectedSql = {
195
+ mysql: mysql`
196
+ SELECT
197
+ \`T1\`.\`id\` AS \`id\`,
198
+ \`T1\`.\`name\` AS \`name\`,
199
+ \`T1\`.\`email\` AS \`email\`,
200
+ \`T1\`.\`age\` AS \`age\`,
201
+ \`T1\`.\`isActive\` AS \`isActive\`,
202
+ \`T1\`.\`companyId\` AS \`companyId\`,
203
+ \`T1\`.\`createdAt\` AS \`createdAt\`,
204
+ \`T1.postStats\`.\`cnt\` AS \`postStats.cnt\`
205
+ FROM \`TestDb\`.\`User\` AS \`T1\`
206
+ LEFT OUTER JOIN LATERAL (
207
+ SELECT COUNT(*) AS \`cnt\`
208
+ FROM \`TestDb\`.\`Post\` AS \`T1.postStats\`
209
+ WHERE \`T1.postStats\`.\`userId\` <=> \`T1\`.\`id\`
210
+ ) AS \`T1.postStats\` ON TRUE
211
+ `,
212
+ mssql: tsql`
213
+ SELECT
214
+ [T1].[id] AS [id],
215
+ [T1].[name] AS [name],
216
+ [T1].[email] AS [email],
217
+ [T1].[age] AS [age],
218
+ [T1].[isActive] AS [isActive],
219
+ [T1].[companyId] AS [companyId],
220
+ [T1].[createdAt] AS [createdAt],
221
+ [T1.postStats].[cnt] AS [postStats.cnt]
222
+ FROM [TestDb].[TestSchema].[User] AS [T1]
223
+ OUTER APPLY (
224
+ SELECT COUNT(*) AS [cnt]
225
+ FROM [TestDb].[TestSchema].[Post] AS [T1.postStats]
226
+ WHERE (([T1.postStats].[userId] IS NULL AND [T1].[id] IS NULL) OR [T1.postStats].[userId] = [T1].[id])
227
+ ) AS [T1.postStats]
228
+ `,
229
+ postgresql: pgsql`
230
+ SELECT
231
+ "T1"."id" AS "id",
232
+ "T1"."name" AS "name",
233
+ "T1"."email" AS "email",
234
+ "T1"."age" AS "age",
235
+ "T1"."isActive" AS "isActive",
236
+ "T1"."companyId" AS "companyId",
237
+ "T1"."createdAt" AS "createdAt",
238
+ "T1.postStats"."cnt" AS "postStats.cnt"
239
+ FROM "TestSchema"."User" AS "T1"
240
+ LEFT OUTER JOIN LATERAL (
241
+ SELECT COUNT(*) AS "cnt"
242
+ FROM "TestSchema"."Post" AS "T1.postStats"
243
+ WHERE "T1.postStats"."userId" IS NOT DISTINCT FROM "T1"."id"
244
+ ) AS "T1.postStats" ON TRUE
245
+ `,
246
+ };
247
+
248
+ export const joinSingleMultiLevel: ExpectedSql = {
249
+ mysql: mysql`
250
+ SELECT
251
+ \`T1\`.\`id\` AS \`id\`,
252
+ \`T1\`.\`userId\` AS \`userId\`,
253
+ \`T1\`.\`title\` AS \`title\`,
254
+ \`T1\`.\`content\` AS \`content\`,
255
+ \`T1\`.\`viewCount\` AS \`viewCount\`,
256
+ \`T1\`.\`publishedAt\` AS \`publishedAt\`,
257
+ \`T1.user\`.\`id\` AS \`user.id\`,
258
+ \`T1.user\`.\`name\` AS \`user.name\`,
259
+ \`T1.user\`.\`email\` AS \`user.email\`,
260
+ \`T1.user\`.\`age\` AS \`user.age\`,
261
+ \`T1.user\`.\`isActive\` AS \`user.isActive\`,
262
+ \`T1.user\`.\`companyId\` AS \`user.companyId\`,
263
+ \`T1.user\`.\`createdAt\` AS \`user.createdAt\`,
264
+ \`T1.user\`.\`company.id\` AS \`user.company.id\`,
265
+ \`T1.user\`.\`company.name\` AS \`user.company.name\`,
266
+ \`T1.user\`.\`company.foundedAt\` AS \`user.company.foundedAt\`
267
+ FROM \`TestDb\`.\`Post\` AS \`T1\`
268
+ LEFT OUTER JOIN LATERAL (
269
+ SELECT
270
+ \`T1.user\`.\`id\` AS \`id\`,
271
+ \`T1.user\`.\`name\` AS \`name\`,
272
+ \`T1.user\`.\`email\` AS \`email\`,
273
+ \`T1.user\`.\`age\` AS \`age\`,
274
+ \`T1.user\`.\`isActive\` AS \`isActive\`,
275
+ \`T1.user\`.\`companyId\` AS \`companyId\`,
276
+ \`T1.user\`.\`createdAt\` AS \`createdAt\`,
277
+ \`T1.user.company\`.\`id\` AS \`company.id\`,
278
+ \`T1.user.company\`.\`name\` AS \`company.name\`,
279
+ \`T1.user.company\`.\`foundedAt\` AS \`company.foundedAt\`
280
+ FROM \`TestDb\`.\`User\` AS \`T1.user\`
281
+ LEFT OUTER JOIN \`TestDb\`.\`Company\` AS \`T1.user.company\`
282
+ ON \`T1.user.company\`.\`id\` <=> \`T1.user\`.\`companyId\`
283
+ WHERE \`T1.user\`.\`id\` <=> \`T1\`.\`userId\`
284
+ ) AS \`T1.user\` ON TRUE
285
+ `,
286
+ mssql: tsql`
287
+ SELECT
288
+ [T1].[id] AS [id],
289
+ [T1].[userId] AS [userId],
290
+ [T1].[title] AS [title],
291
+ [T1].[content] AS [content],
292
+ [T1].[viewCount] AS [viewCount],
293
+ [T1].[publishedAt] AS [publishedAt],
294
+ [T1.user].[id] AS [user.id],
295
+ [T1.user].[name] AS [user.name],
296
+ [T1.user].[email] AS [user.email],
297
+ [T1.user].[age] AS [user.age],
298
+ [T1.user].[isActive] AS [user.isActive],
299
+ [T1.user].[companyId] AS [user.companyId],
300
+ [T1.user].[createdAt] AS [user.createdAt],
301
+ [T1.user].[company.id] AS [user.company.id],
302
+ [T1.user].[company.name] AS [user.company.name],
303
+ [T1.user].[company.foundedAt] AS [user.company.foundedAt]
304
+ FROM [TestDb].[TestSchema].[Post] AS [T1]
305
+ OUTER APPLY (
306
+ SELECT
307
+ [T1.user].[id] AS [id],
308
+ [T1.user].[name] AS [name],
309
+ [T1.user].[email] AS [email],
310
+ [T1.user].[age] AS [age],
311
+ [T1.user].[isActive] AS [isActive],
312
+ [T1.user].[companyId] AS [companyId],
313
+ [T1.user].[createdAt] AS [createdAt],
314
+ [T1.user.company].[id] AS [company.id],
315
+ [T1.user.company].[name] AS [company.name],
316
+ [T1.user.company].[foundedAt] AS [company.foundedAt]
317
+ FROM [TestDb].[TestSchema].[User] AS [T1.user]
318
+ LEFT OUTER JOIN [TestDb].[TestSchema].[Company] AS [T1.user.company]
319
+ ON (([T1.user.company].[id] IS NULL AND [T1.user].[companyId] IS NULL) OR [T1.user.company].[id] = [T1.user].[companyId])
320
+ WHERE (([T1.user].[id] IS NULL AND [T1].[userId] IS NULL) OR [T1.user].[id] = [T1].[userId])
321
+ ) AS [T1.user]
322
+ `,
323
+ postgresql: pgsql`
324
+ SELECT
325
+ "T1"."id" AS "id",
326
+ "T1"."userId" AS "userId",
327
+ "T1"."title" AS "title",
328
+ "T1"."content" AS "content",
329
+ "T1"."viewCount" AS "viewCount",
330
+ "T1"."publishedAt" AS "publishedAt",
331
+ "T1.user"."id" AS "user.id",
332
+ "T1.user"."name" AS "user.name",
333
+ "T1.user"."email" AS "user.email",
334
+ "T1.user"."age" AS "user.age",
335
+ "T1.user"."isActive" AS "user.isActive",
336
+ "T1.user"."companyId" AS "user.companyId",
337
+ "T1.user"."createdAt" AS "user.createdAt",
338
+ "T1.user"."company.id" AS "user.company.id",
339
+ "T1.user"."company.name" AS "user.company.name",
340
+ "T1.user"."company.foundedAt" AS "user.company.foundedAt"
341
+ FROM "TestSchema"."Post" AS "T1"
342
+ LEFT OUTER JOIN LATERAL (
343
+ SELECT
344
+ "T1.user"."id" AS "id",
345
+ "T1.user"."name" AS "name",
346
+ "T1.user"."email" AS "email",
347
+ "T1.user"."age" AS "age",
348
+ "T1.user"."isActive" AS "isActive",
349
+ "T1.user"."companyId" AS "companyId",
350
+ "T1.user"."createdAt" AS "createdAt",
351
+ "T1.user.company"."id" AS "company.id",
352
+ "T1.user.company"."name" AS "company.name",
353
+ "T1.user.company"."foundedAt" AS "company.foundedAt"
354
+ FROM "TestSchema"."User" AS "T1.user"
355
+ LEFT OUTER JOIN "TestSchema"."Company" AS "T1.user.company"
356
+ ON "T1.user.company"."id" IS NOT DISTINCT FROM "T1.user"."companyId"
357
+ WHERE "T1.user"."id" IS NOT DISTINCT FROM "T1"."userId"
358
+ ) AS "T1.user" ON TRUE
359
+ `,
360
+ };
361
+
362
+ //#endregion
363
+
364
+ //#region ========== INCLUDE ==========
365
+
366
+ export const includeFk: ExpectedSql = {
367
+ mysql: mysql`
368
+ SELECT
369
+ \`T1\`.\`id\` AS \`id\`,
370
+ \`T1\`.\`userId\` AS \`userId\`,
371
+ \`T1\`.\`title\` AS \`title\`,
372
+ \`T1\`.\`content\` AS \`content\`,
373
+ \`T1\`.\`viewCount\` AS \`viewCount\`,
374
+ \`T1\`.\`publishedAt\` AS \`publishedAt\`,
375
+ \`T1.user\`.\`id\` AS \`user.id\`,
376
+ \`T1.user\`.\`name\` AS \`user.name\`,
377
+ \`T1.user\`.\`email\` AS \`user.email\`,
378
+ \`T1.user\`.\`age\` AS \`user.age\`,
379
+ \`T1.user\`.\`isActive\` AS \`user.isActive\`,
380
+ \`T1.user\`.\`companyId\` AS \`user.companyId\`,
381
+ \`T1.user\`.\`createdAt\` AS \`user.createdAt\`
382
+ FROM \`TestDb\`.\`Post\` AS \`T1\`
383
+ LEFT OUTER JOIN \`TestDb\`.\`User\` AS \`T1.user\` ON \`T1.user\`.\`id\` <=> \`T1\`.\`userId\`
384
+ `,
385
+ mssql: tsql`
386
+ SELECT
387
+ [T1].[id] AS [id],
388
+ [T1].[userId] AS [userId],
389
+ [T1].[title] AS [title],
390
+ [T1].[content] AS [content],
391
+ [T1].[viewCount] AS [viewCount],
392
+ [T1].[publishedAt] AS [publishedAt],
393
+ [T1.user].[id] AS [user.id],
394
+ [T1.user].[name] AS [user.name],
395
+ [T1.user].[email] AS [user.email],
396
+ [T1.user].[age] AS [user.age],
397
+ [T1.user].[isActive] AS [user.isActive],
398
+ [T1.user].[companyId] AS [user.companyId],
399
+ [T1.user].[createdAt] AS [user.createdAt]
400
+ FROM [TestDb].[TestSchema].[Post] AS [T1]
401
+ LEFT OUTER JOIN [TestDb].[TestSchema].[User] AS [T1.user] ON (([T1.user].[id] IS NULL AND [T1].[userId] IS NULL) OR [T1.user].[id] = [T1].[userId])
402
+ `,
403
+ postgresql: pgsql`
404
+ SELECT
405
+ "T1"."id" AS "id",
406
+ "T1"."userId" AS "userId",
407
+ "T1"."title" AS "title",
408
+ "T1"."content" AS "content",
409
+ "T1"."viewCount" AS "viewCount",
410
+ "T1"."publishedAt" AS "publishedAt",
411
+ "T1.user"."id" AS "user.id",
412
+ "T1.user"."name" AS "user.name",
413
+ "T1.user"."email" AS "user.email",
414
+ "T1.user"."age" AS "user.age",
415
+ "T1.user"."isActive" AS "user.isActive",
416
+ "T1.user"."companyId" AS "user.companyId",
417
+ "T1.user"."createdAt" AS "user.createdAt"
418
+ FROM "TestSchema"."Post" AS "T1"
419
+ LEFT OUTER JOIN "TestSchema"."User" AS "T1.user" ON "T1.user"."id" IS NOT DISTINCT FROM "T1"."userId"
420
+ `,
421
+ };
422
+
423
+ export const includeFkt: ExpectedSql = {
424
+ mysql: mysql`
425
+ SELECT
426
+ \`T1\`.\`id\` AS \`id\`,
427
+ \`T1\`.\`name\` AS \`name\`,
428
+ \`T1\`.\`email\` AS \`email\`,
429
+ \`T1\`.\`age\` AS \`age\`,
430
+ \`T1\`.\`isActive\` AS \`isActive\`,
431
+ \`T1\`.\`companyId\` AS \`companyId\`,
432
+ \`T1\`.\`createdAt\` AS \`createdAt\`,
433
+ \`T1.posts\`.\`id\` AS \`posts.id\`,
434
+ \`T1.posts\`.\`userId\` AS \`posts.userId\`,
435
+ \`T1.posts\`.\`title\` AS \`posts.title\`,
436
+ \`T1.posts\`.\`content\` AS \`posts.content\`,
437
+ \`T1.posts\`.\`viewCount\` AS \`posts.viewCount\`,
438
+ \`T1.posts\`.\`publishedAt\` AS \`posts.publishedAt\`
439
+ FROM \`TestDb\`.\`User\` AS \`T1\`
440
+ LEFT OUTER JOIN \`TestDb\`.\`Post\` AS \`T1.posts\` ON \`T1.posts\`.\`userId\` <=> \`T1\`.\`id\`
441
+ `,
442
+ mssql: tsql`
443
+ SELECT
444
+ [T1].[id] AS [id],
445
+ [T1].[name] AS [name],
446
+ [T1].[email] AS [email],
447
+ [T1].[age] AS [age],
448
+ [T1].[isActive] AS [isActive],
449
+ [T1].[companyId] AS [companyId],
450
+ [T1].[createdAt] AS [createdAt],
451
+ [T1.posts].[id] AS [posts.id],
452
+ [T1.posts].[userId] AS [posts.userId],
453
+ [T1.posts].[title] AS [posts.title],
454
+ [T1.posts].[content] AS [posts.content],
455
+ [T1.posts].[viewCount] AS [posts.viewCount],
456
+ [T1.posts].[publishedAt] AS [posts.publishedAt]
457
+ FROM [TestDb].[TestSchema].[User] AS [T1]
458
+ LEFT OUTER JOIN [TestDb].[TestSchema].[Post] AS [T1.posts] ON (([T1.posts].[userId] IS NULL AND [T1].[id] IS NULL) OR [T1.posts].[userId] = [T1].[id])
459
+ `,
460
+ postgresql: pgsql`
461
+ SELECT
462
+ "T1"."id" AS "id",
463
+ "T1"."name" AS "name",
464
+ "T1"."email" AS "email",
465
+ "T1"."age" AS "age",
466
+ "T1"."isActive" AS "isActive",
467
+ "T1"."companyId" AS "companyId",
468
+ "T1"."createdAt" AS "createdAt",
469
+ "T1.posts"."id" AS "posts.id",
470
+ "T1.posts"."userId" AS "posts.userId",
471
+ "T1.posts"."title" AS "posts.title",
472
+ "T1.posts"."content" AS "posts.content",
473
+ "T1.posts"."viewCount" AS "posts.viewCount",
474
+ "T1.posts"."publishedAt" AS "posts.publishedAt"
475
+ FROM "TestSchema"."User" AS "T1"
476
+ LEFT OUTER JOIN "TestSchema"."Post" AS "T1.posts" ON "T1.posts"."userId" IS NOT DISTINCT FROM "T1"."id"
477
+ `,
478
+ };
479
+
480
+ export const include3Depth: ExpectedSql = {
481
+ mysql: mysql`
482
+ SELECT
483
+ \`T1\`.\`id\` AS \`id\`,
484
+ \`T1\`.\`userId\` AS \`userId\`,
485
+ \`T1\`.\`title\` AS \`title\`,
486
+ \`T1\`.\`content\` AS \`content\`,
487
+ \`T1\`.\`viewCount\` AS \`viewCount\`,
488
+ \`T1\`.\`publishedAt\` AS \`publishedAt\`,
489
+ \`T1.user\`.\`id\` AS \`user.id\`,
490
+ \`T1.user\`.\`name\` AS \`user.name\`,
491
+ \`T1.user\`.\`email\` AS \`user.email\`,
492
+ \`T1.user\`.\`age\` AS \`user.age\`,
493
+ \`T1.user\`.\`isActive\` AS \`user.isActive\`,
494
+ \`T1.user\`.\`companyId\` AS \`user.companyId\`,
495
+ \`T1.user\`.\`createdAt\` AS \`user.createdAt\`,
496
+ \`T1.user.posts\`.\`id\` AS \`user.posts.id\`,
497
+ \`T1.user.posts\`.\`userId\` AS \`user.posts.userId\`,
498
+ \`T1.user.posts\`.\`title\` AS \`user.posts.title\`,
499
+ \`T1.user.posts\`.\`content\` AS \`user.posts.content\`,
500
+ \`T1.user.posts\`.\`viewCount\` AS \`user.posts.viewCount\`,
501
+ \`T1.user.posts\`.\`publishedAt\` AS \`user.posts.publishedAt\`,
502
+ \`T1.user.posts.user\`.\`id\` AS \`user.posts.user.id\`,
503
+ \`T1.user.posts.user\`.\`name\` AS \`user.posts.user.name\`,
504
+ \`T1.user.posts.user\`.\`email\` AS \`user.posts.user.email\`,
505
+ \`T1.user.posts.user\`.\`age\` AS \`user.posts.user.age\`,
506
+ \`T1.user.posts.user\`.\`isActive\` AS \`user.posts.user.isActive\`,
507
+ \`T1.user.posts.user\`.\`companyId\` AS \`user.posts.user.companyId\`,
508
+ \`T1.user.posts.user\`.\`createdAt\` AS \`user.posts.user.createdAt\`
509
+ FROM \`TestDb\`.\`Post\` AS \`T1\`
510
+ LEFT OUTER JOIN \`TestDb\`.\`User\` AS \`T1.user\` ON \`T1.user\`.\`id\` <=> \`T1\`.\`userId\`
511
+ LEFT OUTER JOIN \`TestDb\`.\`Post\` AS \`T1.user.posts\` ON \`T1.user.posts\`.\`userId\` <=> \`T1.user\`.\`id\`
512
+ LEFT OUTER JOIN \`TestDb\`.\`User\` AS \`T1.user.posts.user\` ON \`T1.user.posts.user\`.\`id\` <=> \`T1.user.posts\`.\`userId\`
513
+ `,
514
+ mssql: tsql`
515
+ SELECT
516
+ [T1].[id] AS [id],
517
+ [T1].[userId] AS [userId],
518
+ [T1].[title] AS [title],
519
+ [T1].[content] AS [content],
520
+ [T1].[viewCount] AS [viewCount],
521
+ [T1].[publishedAt] AS [publishedAt],
522
+ [T1.user].[id] AS [user.id],
523
+ [T1.user].[name] AS [user.name],
524
+ [T1.user].[email] AS [user.email],
525
+ [T1.user].[age] AS [user.age],
526
+ [T1.user].[isActive] AS [user.isActive],
527
+ [T1.user].[companyId] AS [user.companyId],
528
+ [T1.user].[createdAt] AS [user.createdAt],
529
+ [T1.user.posts].[id] AS [user.posts.id],
530
+ [T1.user.posts].[userId] AS [user.posts.userId],
531
+ [T1.user.posts].[title] AS [user.posts.title],
532
+ [T1.user.posts].[content] AS [user.posts.content],
533
+ [T1.user.posts].[viewCount] AS [user.posts.viewCount],
534
+ [T1.user.posts].[publishedAt] AS [user.posts.publishedAt],
535
+ [T1.user.posts.user].[id] AS [user.posts.user.id],
536
+ [T1.user.posts.user].[name] AS [user.posts.user.name],
537
+ [T1.user.posts.user].[email] AS [user.posts.user.email],
538
+ [T1.user.posts.user].[age] AS [user.posts.user.age],
539
+ [T1.user.posts.user].[isActive] AS [user.posts.user.isActive],
540
+ [T1.user.posts.user].[companyId] AS [user.posts.user.companyId],
541
+ [T1.user.posts.user].[createdAt] AS [user.posts.user.createdAt]
542
+ FROM [TestDb].[TestSchema].[Post] AS [T1]
543
+ LEFT OUTER JOIN [TestDb].[TestSchema].[User] AS [T1.user] ON (([T1.user].[id] IS NULL AND [T1].[userId] IS NULL) OR [T1.user].[id] = [T1].[userId])
544
+ LEFT OUTER JOIN [TestDb].[TestSchema].[Post] AS [T1.user.posts] ON (([T1.user.posts].[userId] IS NULL AND [T1.user].[id] IS NULL) OR [T1.user.posts].[userId] = [T1.user].[id])
545
+ LEFT OUTER JOIN [TestDb].[TestSchema].[User] AS [T1.user.posts.user] ON (([T1.user.posts.user].[id] IS NULL AND [T1.user.posts].[userId] IS NULL) OR [T1.user.posts.user].[id] = [T1.user.posts].[userId])
546
+ `,
547
+ postgresql: pgsql`
548
+ SELECT
549
+ "T1"."id" AS "id",
550
+ "T1"."userId" AS "userId",
551
+ "T1"."title" AS "title",
552
+ "T1"."content" AS "content",
553
+ "T1"."viewCount" AS "viewCount",
554
+ "T1"."publishedAt" AS "publishedAt",
555
+ "T1.user"."id" AS "user.id",
556
+ "T1.user"."name" AS "user.name",
557
+ "T1.user"."email" AS "user.email",
558
+ "T1.user"."age" AS "user.age",
559
+ "T1.user"."isActive" AS "user.isActive",
560
+ "T1.user"."companyId" AS "user.companyId",
561
+ "T1.user"."createdAt" AS "user.createdAt",
562
+ "T1.user.posts"."id" AS "user.posts.id",
563
+ "T1.user.posts"."userId" AS "user.posts.userId",
564
+ "T1.user.posts"."title" AS "user.posts.title",
565
+ "T1.user.posts"."content" AS "user.posts.content",
566
+ "T1.user.posts"."viewCount" AS "user.posts.viewCount",
567
+ "T1.user.posts"."publishedAt" AS "user.posts.publishedAt",
568
+ "T1.user.posts.user"."id" AS "user.posts.user.id",
569
+ "T1.user.posts.user"."name" AS "user.posts.user.name",
570
+ "T1.user.posts.user"."email" AS "user.posts.user.email",
571
+ "T1.user.posts.user"."age" AS "user.posts.user.age",
572
+ "T1.user.posts.user"."isActive" AS "user.posts.user.isActive",
573
+ "T1.user.posts.user"."companyId" AS "user.posts.user.companyId",
574
+ "T1.user.posts.user"."createdAt" AS "user.posts.user.createdAt"
575
+ FROM "TestSchema"."Post" AS "T1"
576
+ LEFT OUTER JOIN "TestSchema"."User" AS "T1.user" ON "T1.user"."id" IS NOT DISTINCT FROM "T1"."userId"
577
+ LEFT OUTER JOIN "TestSchema"."Post" AS "T1.user.posts" ON "T1.user.posts"."userId" IS NOT DISTINCT FROM "T1.user"."id"
578
+ LEFT OUTER JOIN "TestSchema"."User" AS "T1.user.posts.user" ON "T1.user.posts.user"."id" IS NOT DISTINCT FROM "T1.user.posts"."userId"
579
+ `,
580
+ };
581
+
582
+ //#endregion