taon-type-sql 21.0.68 → 21.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 (249) hide show
  1. package/VERIFIED-BUILD-DATA.jsonc +3 -3
  2. package/browser/package.json +1 -1
  3. package/browser-prod/package.json +1 -1
  4. package/full-dts/build-info._auto-generated_.d.ts +1 -1
  5. package/lib/build-info._auto-generated_.d.ts +1 -1
  6. package/lib/build-info._auto-generated_.js +1 -1
  7. package/lib/package.json +1 -1
  8. package/lib-esm/lib/build-info._auto-generated_.d.ts +1 -1
  9. package/lib-esm/lib/build-info._auto-generated_.js +1 -1
  10. package/lib-prod/build-info._auto-generated_.d.ts +1 -1
  11. package/lib-prod/build-info._auto-generated_.js +1 -1
  12. package/lib-prod/package.json +1 -1
  13. package/package.json +1 -1
  14. package/ts-source/browser-code/build-info._auto-generated_.ts +18 -0
  15. package/ts-source/browser-code/builder/column/basic-column.ts +24 -0
  16. package/ts-source/browser-code/builder/column/boolean-column.ts +25 -0
  17. package/ts-source/browser-code/builder/column/comparable-column.ts +52 -0
  18. package/ts-source/browser-code/builder/column/date-column.ts +25 -0
  19. package/ts-source/browser-code/builder/column/number-column.ts +30 -0
  20. package/ts-source/browser-code/builder/column/query-column.ts +33 -0
  21. package/ts-source/browser-code/builder/column/string-column.ts +47 -0
  22. package/ts-source/browser-code/builder/column/value-column.ts +44 -0
  23. package/ts-source/browser-code/builder/condition/query-column-condition.ts +34 -0
  24. package/ts-source/browser-code/builder/condition/query-condition-chain.ts +44 -0
  25. package/ts-source/browser-code/builder/condition/query-condition.ts +19 -0
  26. package/ts-source/browser-code/builder/condition/query-join-condition.ts +33 -0
  27. package/ts-source/browser-code/builder/helpers/generics-helper.ts +14 -0
  28. package/ts-source/browser-code/builder/helpers/internal-types.ts +27 -0
  29. package/ts-source/browser-code/builder/join/joined-tables-chain.ts +22 -0
  30. package/ts-source/browser-code/builder/join/joined-tables.ts +30 -0
  31. package/ts-source/browser-code/builder/other/query-ordering.ts +31 -0
  32. package/ts-source/browser-code/builder/query/select-query.ts +65 -0
  33. package/ts-source/browser-code/builder/query/table-condition-query.ts +36 -0
  34. package/ts-source/browser-code/builder/query/table-query.ts +68 -0
  35. package/ts-source/browser-code/builder/query-source.ts +34 -0
  36. package/ts-source/browser-code/builder/query-table.ts +34 -0
  37. package/ts-source/browser-code/client/mysql.ts +19 -0
  38. package/ts-source/browser-code/client/pg.ts +19 -0
  39. package/ts-source/browser-code/client/query-processor.ts +65 -0
  40. package/ts-source/browser-code/converter/param-converter.ts +36 -0
  41. package/ts-source/browser-code/converter/parameterized-converter.ts +27 -0
  42. package/ts-source/browser-code/converter/query-converter.ts +292 -0
  43. package/ts-source/browser-code/converter/result-converter.ts +98 -0
  44. package/ts-source/browser-code/converter/sql-converter.ts +18 -0
  45. package/ts-source/browser-code/converter/type-converter.ts +48 -0
  46. package/ts-source/browser-code/converter/types.ts +17 -0
  47. package/ts-source/browser-code/index._auto-generated_.ts +12 -0
  48. package/ts-source/browser-code/index.scss +11 -0
  49. package/ts-source/browser-code/index.ts +37 -0
  50. package/ts-source/browser-code/lib-info.md +8 -0
  51. package/ts-source/browser-code/migrations/index.ts +13 -0
  52. package/ts-source/browser-code/migrations/migrations-info.md +6 -0
  53. package/ts-source/browser-code/migrations/migrations_index._auto-generated_.ts +12 -0
  54. package/ts-source/browser-code-prod/build-info._auto-generated_.split-namespaces.json +4 -0
  55. package/ts-source/browser-code-prod/build-info._auto-generated_.ts +18 -0
  56. package/ts-source/browser-code-prod/builder/column/basic-column.split-namespaces.json +4 -0
  57. package/ts-source/browser-code-prod/builder/column/basic-column.ts +24 -0
  58. package/ts-source/browser-code-prod/builder/column/boolean-column.split-namespaces.json +4 -0
  59. package/ts-source/browser-code-prod/builder/column/boolean-column.ts +25 -0
  60. package/ts-source/browser-code-prod/builder/column/comparable-column.split-namespaces.json +4 -0
  61. package/ts-source/browser-code-prod/builder/column/comparable-column.ts +52 -0
  62. package/ts-source/browser-code-prod/builder/column/date-column.split-namespaces.json +4 -0
  63. package/ts-source/browser-code-prod/builder/column/date-column.ts +25 -0
  64. package/ts-source/browser-code-prod/builder/column/number-column.split-namespaces.json +4 -0
  65. package/ts-source/browser-code-prod/builder/column/number-column.ts +30 -0
  66. package/ts-source/browser-code-prod/builder/column/query-column.split-namespaces.json +4 -0
  67. package/ts-source/browser-code-prod/builder/column/query-column.ts +33 -0
  68. package/ts-source/browser-code-prod/builder/column/string-column.split-namespaces.json +4 -0
  69. package/ts-source/browser-code-prod/builder/column/string-column.ts +47 -0
  70. package/ts-source/browser-code-prod/builder/column/value-column.split-namespaces.json +4 -0
  71. package/ts-source/browser-code-prod/builder/column/value-column.ts +44 -0
  72. package/ts-source/browser-code-prod/builder/condition/query-column-condition.split-namespaces.json +4 -0
  73. package/ts-source/browser-code-prod/builder/condition/query-column-condition.ts +34 -0
  74. package/ts-source/browser-code-prod/builder/condition/query-condition-chain.split-namespaces.json +4 -0
  75. package/ts-source/browser-code-prod/builder/condition/query-condition-chain.ts +44 -0
  76. package/ts-source/browser-code-prod/builder/condition/query-condition.split-namespaces.json +4 -0
  77. package/ts-source/browser-code-prod/builder/condition/query-condition.ts +19 -0
  78. package/ts-source/browser-code-prod/builder/condition/query-join-condition.split-namespaces.json +4 -0
  79. package/ts-source/browser-code-prod/builder/condition/query-join-condition.ts +33 -0
  80. package/ts-source/browser-code-prod/builder/helpers/generics-helper.split-namespaces.json +4 -0
  81. package/ts-source/browser-code-prod/builder/helpers/generics-helper.ts +14 -0
  82. package/ts-source/browser-code-prod/builder/helpers/internal-types.split-namespaces.json +4 -0
  83. package/ts-source/browser-code-prod/builder/helpers/internal-types.ts +27 -0
  84. package/ts-source/browser-code-prod/builder/join/joined-tables-chain.split-namespaces.json +4 -0
  85. package/ts-source/browser-code-prod/builder/join/joined-tables-chain.ts +22 -0
  86. package/ts-source/browser-code-prod/builder/join/joined-tables.split-namespaces.json +4 -0
  87. package/ts-source/browser-code-prod/builder/join/joined-tables.ts +30 -0
  88. package/ts-source/browser-code-prod/builder/other/query-ordering.split-namespaces.json +4 -0
  89. package/ts-source/browser-code-prod/builder/other/query-ordering.ts +31 -0
  90. package/ts-source/browser-code-prod/builder/query/select-query.split-namespaces.json +4 -0
  91. package/ts-source/browser-code-prod/builder/query/select-query.ts +65 -0
  92. package/ts-source/browser-code-prod/builder/query/table-condition-query.split-namespaces.json +4 -0
  93. package/ts-source/browser-code-prod/builder/query/table-condition-query.ts +36 -0
  94. package/ts-source/browser-code-prod/builder/query/table-query.split-namespaces.json +4 -0
  95. package/ts-source/browser-code-prod/builder/query/table-query.ts +68 -0
  96. package/ts-source/browser-code-prod/builder/query-source.split-namespaces.json +4 -0
  97. package/ts-source/browser-code-prod/builder/query-source.ts +34 -0
  98. package/ts-source/browser-code-prod/builder/query-table.split-namespaces.json +4 -0
  99. package/ts-source/browser-code-prod/builder/query-table.ts +34 -0
  100. package/ts-source/browser-code-prod/client/mysql.split-namespaces.json +4 -0
  101. package/ts-source/browser-code-prod/client/mysql.ts +19 -0
  102. package/ts-source/browser-code-prod/client/pg.split-namespaces.json +4 -0
  103. package/ts-source/browser-code-prod/client/pg.ts +19 -0
  104. package/ts-source/browser-code-prod/client/query-processor.split-namespaces.json +4 -0
  105. package/ts-source/browser-code-prod/client/query-processor.ts +65 -0
  106. package/ts-source/browser-code-prod/converter/param-converter.split-namespaces.json +4 -0
  107. package/ts-source/browser-code-prod/converter/param-converter.ts +36 -0
  108. package/ts-source/browser-code-prod/converter/parameterized-converter.split-namespaces.json +4 -0
  109. package/ts-source/browser-code-prod/converter/parameterized-converter.ts +27 -0
  110. package/ts-source/browser-code-prod/converter/query-converter.split-namespaces.json +4 -0
  111. package/ts-source/browser-code-prod/converter/query-converter.ts +292 -0
  112. package/ts-source/browser-code-prod/converter/result-converter.split-namespaces.json +4 -0
  113. package/ts-source/browser-code-prod/converter/result-converter.ts +98 -0
  114. package/ts-source/browser-code-prod/converter/sql-converter.split-namespaces.json +4 -0
  115. package/ts-source/browser-code-prod/converter/sql-converter.ts +18 -0
  116. package/ts-source/browser-code-prod/converter/type-converter.split-namespaces.json +4 -0
  117. package/ts-source/browser-code-prod/converter/type-converter.ts +48 -0
  118. package/ts-source/browser-code-prod/converter/types.split-namespaces.json +4 -0
  119. package/ts-source/browser-code-prod/converter/types.ts +17 -0
  120. package/ts-source/browser-code-prod/index._auto-generated_.split-namespaces.json +4 -0
  121. package/ts-source/browser-code-prod/index._auto-generated_.ts +12 -0
  122. package/ts-source/browser-code-prod/index.scss +11 -0
  123. package/ts-source/browser-code-prod/index.split-namespaces.json +4 -0
  124. package/ts-source/browser-code-prod/index.ts +37 -0
  125. package/ts-source/browser-code-prod/lib-info.md +8 -0
  126. package/ts-source/browser-code-prod/migrations/index.split-namespaces.json +4 -0
  127. package/ts-source/browser-code-prod/migrations/index.ts +13 -0
  128. package/ts-source/browser-code-prod/migrations/migrations-info.md +6 -0
  129. package/ts-source/browser-code-prod/migrations/migrations_index._auto-generated_.split-namespaces.json +4 -0
  130. package/ts-source/browser-code-prod/migrations/migrations_index._auto-generated_.ts +12 -0
  131. package/ts-source/websql-code/build-info._auto-generated_.ts +18 -0
  132. package/ts-source/websql-code/builder/column/basic-column.ts +24 -0
  133. package/ts-source/websql-code/builder/column/boolean-column.ts +25 -0
  134. package/ts-source/websql-code/builder/column/comparable-column.ts +52 -0
  135. package/ts-source/websql-code/builder/column/date-column.ts +25 -0
  136. package/ts-source/websql-code/builder/column/number-column.ts +30 -0
  137. package/ts-source/websql-code/builder/column/query-column.ts +33 -0
  138. package/ts-source/websql-code/builder/column/string-column.ts +47 -0
  139. package/ts-source/websql-code/builder/column/value-column.ts +44 -0
  140. package/ts-source/websql-code/builder/condition/query-column-condition.ts +34 -0
  141. package/ts-source/websql-code/builder/condition/query-condition-chain.ts +44 -0
  142. package/ts-source/websql-code/builder/condition/query-condition.ts +19 -0
  143. package/ts-source/websql-code/builder/condition/query-join-condition.ts +33 -0
  144. package/ts-source/websql-code/builder/helpers/generics-helper.ts +14 -0
  145. package/ts-source/websql-code/builder/helpers/internal-types.ts +27 -0
  146. package/ts-source/websql-code/builder/join/joined-tables-chain.ts +22 -0
  147. package/ts-source/websql-code/builder/join/joined-tables.ts +30 -0
  148. package/ts-source/websql-code/builder/other/query-ordering.ts +31 -0
  149. package/ts-source/websql-code/builder/query/select-query.ts +65 -0
  150. package/ts-source/websql-code/builder/query/table-condition-query.ts +36 -0
  151. package/ts-source/websql-code/builder/query/table-query.ts +68 -0
  152. package/ts-source/websql-code/builder/query-source.ts +34 -0
  153. package/ts-source/websql-code/builder/query-table.ts +34 -0
  154. package/ts-source/websql-code/client/mysql.ts +19 -0
  155. package/ts-source/websql-code/client/pg.ts +19 -0
  156. package/ts-source/websql-code/client/query-processor.ts +65 -0
  157. package/ts-source/websql-code/converter/param-converter.ts +36 -0
  158. package/ts-source/websql-code/converter/parameterized-converter.ts +27 -0
  159. package/ts-source/websql-code/converter/query-converter.ts +292 -0
  160. package/ts-source/websql-code/converter/result-converter.ts +98 -0
  161. package/ts-source/websql-code/converter/sql-converter.ts +18 -0
  162. package/ts-source/websql-code/converter/type-converter.ts +48 -0
  163. package/ts-source/websql-code/converter/types.ts +17 -0
  164. package/ts-source/websql-code/index._auto-generated_.ts +12 -0
  165. package/ts-source/websql-code/index.scss +11 -0
  166. package/ts-source/websql-code/index.ts +37 -0
  167. package/ts-source/websql-code/lib-info.md +8 -0
  168. package/ts-source/websql-code/migrations/index.ts +13 -0
  169. package/ts-source/websql-code/migrations/migrations-info.md +6 -0
  170. package/ts-source/websql-code/migrations/migrations_index._auto-generated_.ts +12 -0
  171. package/ts-source/websql-code-prod/build-info._auto-generated_.split-namespaces.json +4 -0
  172. package/ts-source/websql-code-prod/build-info._auto-generated_.ts +18 -0
  173. package/ts-source/websql-code-prod/builder/column/basic-column.split-namespaces.json +4 -0
  174. package/ts-source/websql-code-prod/builder/column/basic-column.ts +24 -0
  175. package/ts-source/websql-code-prod/builder/column/boolean-column.split-namespaces.json +4 -0
  176. package/ts-source/websql-code-prod/builder/column/boolean-column.ts +25 -0
  177. package/ts-source/websql-code-prod/builder/column/comparable-column.split-namespaces.json +4 -0
  178. package/ts-source/websql-code-prod/builder/column/comparable-column.ts +52 -0
  179. package/ts-source/websql-code-prod/builder/column/date-column.split-namespaces.json +4 -0
  180. package/ts-source/websql-code-prod/builder/column/date-column.ts +25 -0
  181. package/ts-source/websql-code-prod/builder/column/number-column.split-namespaces.json +4 -0
  182. package/ts-source/websql-code-prod/builder/column/number-column.ts +30 -0
  183. package/ts-source/websql-code-prod/builder/column/query-column.split-namespaces.json +4 -0
  184. package/ts-source/websql-code-prod/builder/column/query-column.ts +33 -0
  185. package/ts-source/websql-code-prod/builder/column/string-column.split-namespaces.json +4 -0
  186. package/ts-source/websql-code-prod/builder/column/string-column.ts +47 -0
  187. package/ts-source/websql-code-prod/builder/column/value-column.split-namespaces.json +4 -0
  188. package/ts-source/websql-code-prod/builder/column/value-column.ts +44 -0
  189. package/ts-source/websql-code-prod/builder/condition/query-column-condition.split-namespaces.json +4 -0
  190. package/ts-source/websql-code-prod/builder/condition/query-column-condition.ts +34 -0
  191. package/ts-source/websql-code-prod/builder/condition/query-condition-chain.split-namespaces.json +4 -0
  192. package/ts-source/websql-code-prod/builder/condition/query-condition-chain.ts +44 -0
  193. package/ts-source/websql-code-prod/builder/condition/query-condition.split-namespaces.json +4 -0
  194. package/ts-source/websql-code-prod/builder/condition/query-condition.ts +19 -0
  195. package/ts-source/websql-code-prod/builder/condition/query-join-condition.split-namespaces.json +4 -0
  196. package/ts-source/websql-code-prod/builder/condition/query-join-condition.ts +33 -0
  197. package/ts-source/websql-code-prod/builder/helpers/generics-helper.split-namespaces.json +4 -0
  198. package/ts-source/websql-code-prod/builder/helpers/generics-helper.ts +14 -0
  199. package/ts-source/websql-code-prod/builder/helpers/internal-types.split-namespaces.json +4 -0
  200. package/ts-source/websql-code-prod/builder/helpers/internal-types.ts +27 -0
  201. package/ts-source/websql-code-prod/builder/join/joined-tables-chain.split-namespaces.json +4 -0
  202. package/ts-source/websql-code-prod/builder/join/joined-tables-chain.ts +22 -0
  203. package/ts-source/websql-code-prod/builder/join/joined-tables.split-namespaces.json +4 -0
  204. package/ts-source/websql-code-prod/builder/join/joined-tables.ts +30 -0
  205. package/ts-source/websql-code-prod/builder/other/query-ordering.split-namespaces.json +4 -0
  206. package/ts-source/websql-code-prod/builder/other/query-ordering.ts +31 -0
  207. package/ts-source/websql-code-prod/builder/query/select-query.split-namespaces.json +4 -0
  208. package/ts-source/websql-code-prod/builder/query/select-query.ts +65 -0
  209. package/ts-source/websql-code-prod/builder/query/table-condition-query.split-namespaces.json +4 -0
  210. package/ts-source/websql-code-prod/builder/query/table-condition-query.ts +36 -0
  211. package/ts-source/websql-code-prod/builder/query/table-query.split-namespaces.json +4 -0
  212. package/ts-source/websql-code-prod/builder/query/table-query.ts +68 -0
  213. package/ts-source/websql-code-prod/builder/query-source.split-namespaces.json +4 -0
  214. package/ts-source/websql-code-prod/builder/query-source.ts +34 -0
  215. package/ts-source/websql-code-prod/builder/query-table.split-namespaces.json +4 -0
  216. package/ts-source/websql-code-prod/builder/query-table.ts +34 -0
  217. package/ts-source/websql-code-prod/client/mysql.split-namespaces.json +4 -0
  218. package/ts-source/websql-code-prod/client/mysql.ts +19 -0
  219. package/ts-source/websql-code-prod/client/pg.split-namespaces.json +4 -0
  220. package/ts-source/websql-code-prod/client/pg.ts +19 -0
  221. package/ts-source/websql-code-prod/client/query-processor.split-namespaces.json +4 -0
  222. package/ts-source/websql-code-prod/client/query-processor.ts +65 -0
  223. package/ts-source/websql-code-prod/converter/param-converter.split-namespaces.json +4 -0
  224. package/ts-source/websql-code-prod/converter/param-converter.ts +36 -0
  225. package/ts-source/websql-code-prod/converter/parameterized-converter.split-namespaces.json +4 -0
  226. package/ts-source/websql-code-prod/converter/parameterized-converter.ts +27 -0
  227. package/ts-source/websql-code-prod/converter/query-converter.split-namespaces.json +4 -0
  228. package/ts-source/websql-code-prod/converter/query-converter.ts +292 -0
  229. package/ts-source/websql-code-prod/converter/result-converter.split-namespaces.json +4 -0
  230. package/ts-source/websql-code-prod/converter/result-converter.ts +98 -0
  231. package/ts-source/websql-code-prod/converter/sql-converter.split-namespaces.json +4 -0
  232. package/ts-source/websql-code-prod/converter/sql-converter.ts +18 -0
  233. package/ts-source/websql-code-prod/converter/type-converter.split-namespaces.json +4 -0
  234. package/ts-source/websql-code-prod/converter/type-converter.ts +48 -0
  235. package/ts-source/websql-code-prod/converter/types.split-namespaces.json +4 -0
  236. package/ts-source/websql-code-prod/converter/types.ts +17 -0
  237. package/ts-source/websql-code-prod/index._auto-generated_.split-namespaces.json +4 -0
  238. package/ts-source/websql-code-prod/index._auto-generated_.ts +12 -0
  239. package/ts-source/websql-code-prod/index.scss +11 -0
  240. package/ts-source/websql-code-prod/index.split-namespaces.json +4 -0
  241. package/ts-source/websql-code-prod/index.ts +37 -0
  242. package/ts-source/websql-code-prod/lib-info.md +8 -0
  243. package/ts-source/websql-code-prod/migrations/index.split-namespaces.json +4 -0
  244. package/ts-source/websql-code-prod/migrations/index.ts +13 -0
  245. package/ts-source/websql-code-prod/migrations/migrations-info.md +6 -0
  246. package/ts-source/websql-code-prod/migrations/migrations_index._auto-generated_.split-namespaces.json +4 -0
  247. package/ts-source/websql-code-prod/migrations/migrations_index._auto-generated_.ts +12 -0
  248. package/websql/package.json +1 -1
  249. package/websql-prod/package.json +1 -1
@@ -0,0 +1,68 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import QueryTable from "../query-table";
14
+ import TableConditionQuery from "./table-condition-query";
15
+ import QueryCondition from "../condition/query-condition";
16
+ import ValueColumn from "../column/value-column";
17
+ import QueryColumn from "../column/query-column";
18
+ import { QueryProcessor, QueryAction } from "../helpers/internal-types";
19
+ export default class TableQuery<Entity, Id, Table extends QueryTable<Entity, Id>> {
20
+ constructor(protected _queryProcessor: QueryProcessor, protected _table: Table) { }
21
+ protected _entity: Entity | Entity[] | Partial<Entity>;
22
+ protected _action: QueryAction;
23
+ protected _columns: QueryColumn<Table, any>[] = [];
24
+ where(...conditions: QueryCondition<Table>[]) {
25
+ return new TableConditionQuery<Entity, Table>(this._queryProcessor, this._table, conditions);
26
+ }
27
+ insert(entity: Entity): Promise<any>;
28
+ insert(entities: Entity[]): Promise<void>;
29
+ insert(param: any): Promise<any> {
30
+ this._entity = param;
31
+ this._action = 'insert';
32
+ return this._queryProcessor(this);
33
+ }
34
+ deleteAll(): Promise<number> {
35
+ this._action = 'delete';
36
+ return this._queryProcessor(this);
37
+ }
38
+ updateAll(entity: Partial<Entity>): Promise<number> {
39
+ this._entity = entity;
40
+ this._action = 'update';
41
+ return this._queryProcessor(this);
42
+ }
43
+ countAll(): Promise<number> {
44
+ this._columns = [this._table.$all.count()];
45
+ this._action = 'select';
46
+ return this._queryProcessor(this).then((rows: any[]) => rows[0]);
47
+ }
48
+ delete(id: Id): Promise<boolean> {
49
+ return this._whereId(id).delete().then(count => count > 0);
50
+ }
51
+ update(id: Id, entity: Partial<Entity>): Promise<boolean> {
52
+ return this._whereId(id).update(entity).then(count => count > 0);
53
+ }
54
+ get(id: Id): Promise<Entity | undefined> {
55
+ let query = this._whereId(id);
56
+ return this._queryProcessor({ _action: 'select', ...query })
57
+ .then((rows: Entity[]) => rows[0]);
58
+ }
59
+ _whereId(id: Id): TableConditionQuery<Entity, Table> {
60
+ let $id = (this._table as any).$id;
61
+ if ($id instanceof ValueColumn) {
62
+ return this.where($id.eq(id));
63
+ }
64
+ else {
65
+ return this.where(...Object.keys($id).map(key => ((this._table as any)[key] as ValueColumn<Table, any>).eq((id as any)[key] as any)));
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,34 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import QueryTable from './query-table';
14
+ import SelectQuery from './query/select-query';
15
+ import { QueryProcessor } from "./helpers/internal-types";
16
+ import JoinedTables from "./join/joined-tables";
17
+ import TableQuery from "./query/table-query";
18
+ export default class QuerySource {
19
+ constructor(protected _queryProcessor: QueryProcessor) { }
20
+ from<Entity, Table1 extends QueryTable<Entity, any>>(table1: Table1 & QueryTable<Entity, any>): SelectQuery<Entity, Table1>;
21
+ from<Tables extends QueryTable<any, any>>(tables: JoinedTables<Tables>): SelectQuery<any, Tables>;
22
+ from<Table1 extends QueryTable<any, any>, Table2 extends QueryTable<any, any>>(table1: Table1, table2: Table2): SelectQuery<any, Table1 | Table2>;
23
+ from<Table1 extends QueryTable<any, any>, Table2 extends QueryTable<any, any>, Table3 extends QueryTable<any, any>>(table1: Table1, table2: Table2, table3: Table3): SelectQuery<any, Table1 | Table2 | Table3>;
24
+ from<Entity, Table1 extends QueryTable<any, any>, Table2 extends QueryTable<any, any>, Table3 extends QueryTable<any, any>>(table1: any, table2?: any, table3?: any) {
25
+ if (table3 != null)
26
+ return new SelectQuery<any, Table1 | Table2 | Table3>(this._queryProcessor, [table1, table2, table3]);
27
+ else if (table2 != null)
28
+ return new SelectQuery<any, Table1 | Table2>(this._queryProcessor, [table1, table2]);
29
+ return new SelectQuery<Entity, Table1>(this._queryProcessor, [table1]);
30
+ }
31
+ table<Entity, Id, Table extends QueryTable<Entity, Id>>(table: Table & QueryTable<Entity, Id>): TableQuery<Entity, Id, Table> {
32
+ return new TableQuery<Entity, Id, Table>(this._queryProcessor, table);
33
+ }
34
+ }
@@ -0,0 +1,34 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import BasicColumn from "./column/basic-column";
14
+ import GenericsHelper from "./helpers/generics-helper";
15
+ import JoinedTablesChain from "./join/joined-tables-chain";
16
+ abstract class QueryTable<Entity, Id> {
17
+ constructor(protected _$name: string) { }
18
+ protected _$type: GenericsHelper<Entity>;
19
+ protected _$idType: GenericsHelper<Id>;
20
+ $all = new BasicColumn<this, Entity>(this, '*');
21
+ innerJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<this | JoinTable> {
22
+ return new JoinedTablesChain<this | JoinTable>(table, 'inner', this);
23
+ }
24
+ leftJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<this | JoinTable> {
25
+ return new JoinedTablesChain<this | JoinTable>(table, 'left', this);
26
+ }
27
+ rightJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<this | JoinTable> {
28
+ return new JoinedTablesChain<this | JoinTable>(table, 'right', this);
29
+ }
30
+ fullJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<this | JoinTable> {
31
+ return new JoinedTablesChain<this | JoinTable>(table, 'full', this);
32
+ }
33
+ }
34
+ export default QueryTable;
@@ -0,0 +1,19 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import QuerySource from "../builder/query-source";
14
+ import { QueryProcessorOptions, createQueryProcessor } from "./query-processor";
15
+ export default class MySqlQuerySource extends QuerySource {
16
+ constructor(client: any, options: QueryProcessorOptions = {}) {
17
+ super(createQueryProcessor(client, options, 'mysql'));
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import QuerySource from "../builder/query-source";
14
+ import { QueryProcessorOptions, createQueryProcessor } from "./query-processor";
15
+ export default class PgQuerySource extends QuerySource {
16
+ constructor(client: any, options: QueryProcessorOptions = {}) {
17
+ super(createQueryProcessor(client, options, 'pg'));
18
+ }
19
+ }
@@ -0,0 +1,65 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { Log, Level } from 'ng2-logger/websql';
14
+ import { convertQueryToParameterizedSQL } from '../converter/parameterized-converter';
15
+ import { convertQueryToSQL } from '../converter/sql-converter';
16
+ import { convertResult } from "../converter/result-converter";
17
+ import { QueryEngine, ConverterOptions } from '../converter/types';
18
+ import { QueryProcessor } from '../builder/helpers/internal-types';
19
+ import { Helpers } from 'tnp-core/websql';
20
+ const log = Log.create('query processor');
21
+ export interface QueryProcessorOptions {
22
+ lineBreaks?: boolean;
23
+ parameterized?: boolean;
24
+ logging?: boolean;
25
+ logger?: (sql: string, params?: any[]) => void;
26
+ identifierQuote?: string;
27
+ }
28
+ const DEFAULT_OPTIONS: QueryProcessorOptions = {
29
+ lineBreaks: false,
30
+ parameterized: true,
31
+ logging: true,
32
+ identifierQuote: '"'
33
+ };
34
+ function mySqlTypeCast(field: any, next: any) {
35
+ if (field.type == 'TINY' && field.length == 1) {
36
+ let value = field.string();
37
+ if (value == '1')
38
+ return true;
39
+ if (value == '0')
40
+ return false;
41
+ return null;
42
+ }
43
+ else if (field.type == 'JSON') {
44
+ let value = field.string();
45
+ return value == null ? null : JSON.parse(value);
46
+ }
47
+ return next();
48
+ }
49
+ export function createQueryProcessor(client: any, _options: QueryProcessorOptions = {}, engine: QueryEngine = 'pg'): QueryProcessor {
50
+ let options: QueryProcessorOptions = Object.assign({}, DEFAULT_OPTIONS, _options);
51
+ let queryOptions: ConverterOptions = {
52
+ lineBreak: options.lineBreaks ? '\n' : ' ',
53
+ nameEscape: _options.identifierQuote || (engine === 'mysql' ? '`' : '"')
54
+ };
55
+ return (query: any) => {
56
+ if (options.parameterized) {
57
+ let { sql, params } = convertQueryToParameterizedSQL(query, queryOptions, engine);
58
+ return client.query(sql, params);
59
+ }
60
+ else {
61
+ let sql = convertQueryToSQL(query, queryOptions, engine);
62
+ return client.query(sql, undefined);
63
+ }
64
+ };
65
+ }
@@ -0,0 +1,36 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ export function convertSubstitutionParam(param: any): string {
14
+ if (param == null)
15
+ return 'NULL';
16
+ if (typeof param === 'string' || param instanceof String) {
17
+ return `'${String(param)}'`;
18
+ }
19
+ else if (typeof param === 'boolean' || param instanceof Boolean) {
20
+ return String(param).toUpperCase();
21
+ }
22
+ else if (param instanceof Date) {
23
+ return `'${param.toISOString()}'`;
24
+ }
25
+ else if (typeof param === 'number' || param instanceof Number) {
26
+ return String(param);
27
+ }
28
+ return `'${JSON.stringify(param)}'`;
29
+ }
30
+ export function convertEscapedParam(param: any) {
31
+ if (typeof param === 'object' && !(param == null || param instanceof String || param instanceof Number ||
32
+ param instanceof Boolean || param instanceof Date)) {
33
+ return JSON.stringify(param);
34
+ }
35
+ return param;
36
+ }
@@ -0,0 +1,27 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { createQueryConverter } from "./query-converter";
14
+ import { convertEscapedParam } from './param-converter';
15
+ import { QueryEngine, ConverterOptions } from "./types";
16
+ let pgParamConverter = (index: number) => '$' + index;
17
+ let mySqlParamConverter = (index: number) => '?';
18
+ function convertSingleParam(param: any, params: any[], paramConverter: (param: any) => string): string {
19
+ params.push(convertEscapedParam(param));
20
+ return paramConverter(params.length);
21
+ }
22
+ export function convertQueryToParameterizedSQL(query: any, options: ConverterOptions, engine: QueryEngine) {
23
+ let params: any[] = [];
24
+ let paramConverter = engine === 'mysql' ? mySqlParamConverter : pgParamConverter;
25
+ let sql = createQueryConverter((param: any) => convertSingleParam(param, params, paramConverter), options, engine)(query);
26
+ return { sql, params };
27
+ }
@@ -0,0 +1,292 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside taon-type-sql project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { string, number, date, boolean } from './type-converter';
14
+ import { QueryEngine, ConverterOptions } from "./types";
15
+ export function createQueryConverter(paramConverter: (param: any) => string, options: ConverterOptions, engine: QueryEngine) {
16
+ return convertQuery;
17
+ function convertQuery(query: any): string {
18
+ if (query._action === 'select')
19
+ return convertSelectQuery(query);
20
+ if (query._action === 'delete')
21
+ return convertDeleteQuery(query);
22
+ if (query._action === 'update')
23
+ return convertUpdateQuery(query);
24
+ if (query._action === 'insert')
25
+ return convertInsertQuery(query);
26
+ throw new Error('Unknown query type:' + query._action);
27
+ }
28
+ function convertDeleteQuery(query: any): string {
29
+ let s = 'DELETE FROM ' + convertTable(query._table);
30
+ s += convertConditions(query._conditions);
31
+ return s;
32
+ }
33
+ function convertUpdateQuery(query: any): string {
34
+ let s = 'UPDATE ' + convertTable(query._table) + ' SET ';
35
+ s += convertUpdateSetters(query._table, query._entity);
36
+ s += convertConditions(query._conditions);
37
+ return s;
38
+ }
39
+ function convertUpdateSetters(table: any, entity: any): string {
40
+ return Object.keys(entity).sort().map(key => {
41
+ let value = entity[key];
42
+ let column = table[key];
43
+ return convertColumnName(column) + ' = ' + convertParam(column, value);
44
+ }).join(', ');
45
+ }
46
+ function convertInsertQuery(query: any): string {
47
+ let items: any[] = Array.isArray(query._entity) ? query._entity : [query._entity];
48
+ let keySet: Set<string> = items.reduce((set: Set<string>, item) => {
49
+ Object.keys(item).forEach(key => set.add(key));
50
+ return set;
51
+ }, new Set<string>());
52
+ let keys = Array.from(keySet).sort();
53
+ let s = 'INSERT INTO ' + convertTable(query._table) + ' ';
54
+ s += '(' + keys.map(key => convertColumnName(query._table[key])).join(', ') + ')';
55
+ s += options.lineBreak + 'VALUES ';
56
+ s += items.map(item => convertInsertItem(query._table, item, keys))
57
+ .map((row: string) => '(' + row + ')').join(', ');
58
+ s += getPgInsertReturningIfNeeded(query);
59
+ return s;
60
+ }
61
+ function getPgInsertReturningIfNeeded(query: any): string {
62
+ if (engine === 'pg' && query._action === 'insert' && !Array.isArray(query._entity) &&
63
+ query._table.$id && query._table.$id._table && query._table.$id._name) {
64
+ return ' RETURNING ' + convertColumnName(query._table.$id);
65
+ }
66
+ return '';
67
+ }
68
+ function convertInsertItem(table: any, entity: any, keys: string[]): string {
69
+ return keys.map(key => {
70
+ let value = entity[key];
71
+ let column = table[key];
72
+ return convertParam(column, value);
73
+ }).join(', ');
74
+ }
75
+ function convertSelectQuery(query: any): string {
76
+ let s = 'SELECT ';
77
+ if (query._distinct) {
78
+ s += 'DISTINCT ';
79
+ }
80
+ if (query._columns == null || query._columns.length === 0) {
81
+ s += '*';
82
+ }
83
+ else {
84
+ s += query._columns.map((column: any) => convertColumn(column)).join(', ');
85
+ }
86
+ s += options.lineBreak + 'FROM ';
87
+ if (query._tables) {
88
+ s += query._tables.map((table: any) => table._parent ? convertJoin(table) : convertTable(table)).join(', ');
89
+ }
90
+ else {
91
+ s += convertTable(query._table);
92
+ }
93
+ s += convertConditions(query._conditions);
94
+ if (query._groupBy && query._groupBy.length > 0) {
95
+ s += options.lineBreak + 'GROUP BY ';
96
+ s += query._groupBy.map((column: any) => convertColumn(column)).join(', ');
97
+ }
98
+ s += convertConditions(query._having, 'HAVING');
99
+ if (query._orderings && query._orderings.length > 0) {
100
+ s += options.lineBreak + 'ORDER BY ';
101
+ s += query._orderings.map((ordering: any) => convertOrdering(ordering)).join(', ');
102
+ }
103
+ if (query._limit != null) {
104
+ s += options.lineBreak + 'LIMIT ' + number(query._limit);
105
+ }
106
+ if (query._offset != null) {
107
+ s += options.lineBreak + 'OFFSET ' + number(query._offset);
108
+ }
109
+ return s;
110
+ }
111
+ function convertConditions(conditions: any[], keyword = 'WHERE'): string {
112
+ let s = '';
113
+ if (conditions && conditions.length > 0) {
114
+ s += options.lineBreak + keyword + ' ';
115
+ preprocessConditions(conditions);
116
+ s += conditions.map(condition => convertCondition(condition, true)).join(' AND ');
117
+ }
118
+ return s;
119
+ }
120
+ function convertJoin(joinChain: any): string {
121
+ let items: any[] = [];
122
+ while (joinChain) {
123
+ items.push(joinChain);
124
+ joinChain = joinChain._parent;
125
+ }
126
+ let root = items[items.length - 1];
127
+ let s = convertTable(root);
128
+ for (let i = items.length - 2; i >= 0; i -= 2) {
129
+ let table = items[i]._table;
130
+ let modifier = items[i]._modifier;
131
+ let condition = items[i - 1]._condition;
132
+ let param = convertColumn(condition._otherColumn);
133
+ s += ' ' + modifier.toUpperCase() + ' JOIN ' + convertTable(table) + ' ON ' +
134
+ convertColumnCondition(condition, param);
135
+ }
136
+ return s;
137
+ }
138
+ function convertOrdering(ordering: any): string {
139
+ if (ordering._column) {
140
+ let s = convertColumn(ordering._column);
141
+ if (ordering._nullsPosition != null) {
142
+ s += ' IS NULL ' + (ordering._nullsPosition === 'FIRST' ? 'DESC' : 'ASC') + ', ' + s;
143
+ }
144
+ if (ordering._direction === 'ASC')
145
+ s += ' ASC';
146
+ if (ordering._direction === 'DESC')
147
+ s += ' DESC';
148
+ return s;
149
+ }
150
+ else {
151
+ return convertColumn(ordering);
152
+ }
153
+ }
154
+ function convertTable(table: any): string {
155
+ return options.nameEscape + table._$name + options.nameEscape;
156
+ }
157
+ function convertColumn(column: any): string {
158
+ let s = '';
159
+ if (!(column._name === '*' && column._modifiers.length > 0 && column._modifiers[0].name === 'count')) {
160
+ s += convertTable(column._table) + '.';
161
+ }
162
+ s += convertColumnName(column);
163
+ return convertColumnModifiers(s, column);
164
+ }
165
+ function convertColumnModifiers(s: string, column: any): string {
166
+ if (column._modifiers) {
167
+ column._modifiers.forEach((modifier: any) => {
168
+ let name = modifier.name;
169
+ if (name === 'lower')
170
+ s = 'LOWER(' + s + ')';
171
+ else if (name === 'upper')
172
+ s = 'UPPER(' + s + ')';
173
+ else if (name === 'count')
174
+ s = 'COUNT(' + s + ')';
175
+ else if (name === 'sum')
176
+ s = 'SUM(' + s + ')';
177
+ else if (name === 'avg')
178
+ s = 'AVG(' + s + ')';
179
+ else if (name === 'min')
180
+ s = 'MIN(' + s + ')';
181
+ else if (name === 'max')
182
+ s = 'MAX(' + s + ')';
183
+ else if (name === 'as')
184
+ s = s + ' AS ' + options.nameEscape + modifier.params + options.nameEscape;
185
+ });
186
+ }
187
+ return s + '';
188
+ }
189
+ function convertColumnName(column: any): string {
190
+ if (column._name === '*')
191
+ return column._name;
192
+ let name = typeof column._name === 'string' ? column._name : column._name.name;
193
+ return options.nameEscape + name + options.nameEscape;
194
+ }
195
+ function preprocessConditions(conditions: any[]): void {
196
+ conditions.forEach(condition => {
197
+ if (conditions.length > 1 && condition._sibling) {
198
+ condition._parenthesis = true;
199
+ }
200
+ preprocessParams(condition);
201
+ });
202
+ }
203
+ function preprocessParams(condition: any): void {
204
+ if (condition._sibling) {
205
+ preprocessParams(condition._sibling);
206
+ }
207
+ if (!condition._sibling && !condition._child) {
208
+ condition.__param = getConditionParam(condition);
209
+ }
210
+ if (condition._child) {
211
+ preprocessParams(condition._child);
212
+ }
213
+ }
214
+ function convertCondition(condition: any, root = false): string {
215
+ if (!condition._sibling && !condition._child) {
216
+ return convertColumnCondition(condition, condition.__param);
217
+ }
218
+ let s = '';
219
+ if (condition._child) {
220
+ s += convertCondition(condition._child);
221
+ }
222
+ if (condition._sibling) {
223
+ s = convertCondition(condition._sibling, root) + ' ' + condition._chainType.toUpperCase() + ' ' + s;
224
+ }
225
+ if (condition._parenthesis || ((!root || condition._negation) && condition._child)) {
226
+ s = '( ' + s + ' )';
227
+ }
228
+ if (condition._negation) {
229
+ s = 'NOT ' + s;
230
+ }
231
+ return s;
232
+ }
233
+ function convertColumnCondition(condition: any, param: string): string {
234
+ let s = convertColumn(condition._column);
235
+ s += getConditionString(condition, param);
236
+ return s;
237
+ }
238
+ function getConditionString(condition: any, param: string): string {
239
+ switch (condition._type) {
240
+ case 'eq': return ' = ' + param;
241
+ case 'ne': return ' <> ' + param;
242
+ case 'lt': return ' < ' + param;
243
+ case 'gt': return ' > ' + param;
244
+ case 'lte': return ' <= ' + param;
245
+ case 'gte': return ' >= ' + param;
246
+ case 'is-null': return ' IS NULL';
247
+ case 'is-not-null': return ' IS NOT NULL';
248
+ case 'like': return ' LIKE ' + param;
249
+ case 'not-like': return ' NOT LIKE ' + param;
250
+ case 'in': return ' IN (' + param + ')';
251
+ case 'not-in': return ' NOT IN (' + param + ')';
252
+ case 'between': return ' BETWEEN ' + param;
253
+ case 'not-between': return ' NOT BETWEEN ' + param;
254
+ default: return '';
255
+ }
256
+ }
257
+ function getConditionParam(condition: any): string {
258
+ let param = '';
259
+ if (condition._otherColumn) {
260
+ param = convertColumn(condition._otherColumn);
261
+ }
262
+ else {
263
+ let _convertParam = (param: any) => convertParam(condition._column, param);
264
+ if (condition._type === 'in' || condition._type === 'not-in') {
265
+ param = condition._values.map((value: any) => _convertParam(value)).join(', ');
266
+ }
267
+ else if (condition._type === 'between' || condition._type === 'not-between') {
268
+ param = _convertParam(condition._values[0]) + ' AND ' + _convertParam(condition._values[1]);
269
+ }
270
+ else if (condition._type !== 'is-null' && condition._type !== 'is-not-null') {
271
+ param = _convertParam(condition._values[0]);
272
+ }
273
+ }
274
+ return param;
275
+ }
276
+ function convertParam(column: any, param: any): string {
277
+ if (param == null)
278
+ return 'NULL';
279
+ return paramConverter(getTypedParam(column._type, param));
280
+ }
281
+ function getTypedParam(type: string, param: any): any {
282
+ if (type === 'number')
283
+ return number(param);
284
+ else if (type === 'boolean')
285
+ return boolean(param);
286
+ else if (type === 'date')
287
+ return date(param);
288
+ else if (type === 'string')
289
+ return string(param);
290
+ return param;
291
+ }
292
+ }