sonamu 0.4.14 → 0.5.1

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 (385) hide show
  1. package/.swcrc +15 -0
  2. package/dist/api/base-frame.d.ts +8 -0
  3. package/dist/api/base-frame.d.ts.map +1 -0
  4. package/dist/api/base-frame.js +2 -0
  5. package/dist/api/base-frame.js.map +1 -0
  6. package/dist/api/caster.d.ts +5 -0
  7. package/dist/api/caster.d.ts.map +1 -0
  8. package/dist/api/caster.js +2 -0
  9. package/dist/api/caster.js.map +1 -0
  10. package/dist/api/code-converters.d.ts +23 -0
  11. package/dist/api/code-converters.d.ts.map +1 -0
  12. package/dist/api/code-converters.js +2 -0
  13. package/dist/api/code-converters.js.map +1 -0
  14. package/dist/api/context.d.ts +19 -0
  15. package/dist/api/context.d.ts.map +1 -0
  16. package/dist/api/context.js +2 -0
  17. package/dist/api/context.js.map +1 -0
  18. package/dist/api/decorators.d.ts +50 -0
  19. package/dist/api/decorators.d.ts.map +1 -0
  20. package/dist/api/decorators.js +2 -0
  21. package/dist/api/decorators.js.map +1 -0
  22. package/dist/api/index.d.ts +8 -0
  23. package/dist/api/index.d.ts.map +1 -0
  24. package/dist/api/index.js +2 -0
  25. package/dist/api/index.js.map +1 -0
  26. package/dist/api/sonamu.d.ts +84 -0
  27. package/dist/api/sonamu.d.ts.map +1 -0
  28. package/dist/api/sonamu.js +2 -0
  29. package/dist/api/sonamu.js.map +1 -0
  30. package/dist/bin/build-config.d.ts +9 -0
  31. package/dist/bin/build-config.d.ts.map +1 -0
  32. package/dist/bin/build-config.js +2 -0
  33. package/dist/bin/build-config.js.map +1 -0
  34. package/dist/bin/cli-wrapper.d.ts +2 -0
  35. package/dist/bin/cli-wrapper.d.ts.map +1 -0
  36. package/dist/bin/cli-wrapper.js +1 -38
  37. package/dist/bin/cli-wrapper.js.map +1 -1
  38. package/dist/bin/cli.d.ts +2 -2
  39. package/dist/bin/cli.d.ts.map +1 -0
  40. package/dist/bin/cli.js +1 -903
  41. package/dist/bin/cli.js.map +1 -1
  42. package/dist/database/_batch_update.d.ts +15 -0
  43. package/dist/database/_batch_update.d.ts.map +1 -0
  44. package/dist/database/_batch_update.js +2 -0
  45. package/dist/database/_batch_update.js.map +1 -0
  46. package/dist/database/base-model.d.ts +48 -0
  47. package/dist/database/base-model.d.ts.map +1 -0
  48. package/dist/database/base-model.js +2 -0
  49. package/dist/database/base-model.js.map +1 -0
  50. package/dist/database/code-generator.d.ts +13 -0
  51. package/dist/database/code-generator.d.ts.map +1 -0
  52. package/dist/database/code-generator.js +2 -0
  53. package/dist/database/code-generator.js.map +1 -0
  54. package/dist/database/db.d.ts +40 -0
  55. package/dist/database/db.d.ts.map +1 -0
  56. package/dist/database/db.js +2 -0
  57. package/dist/database/db.js.map +1 -0
  58. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +2 -0
  59. package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +1 -0
  60. package/dist/database/knex-plugins/knex-on-duplicate-update.js +2 -0
  61. package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +1 -0
  62. package/dist/database/puri-wrapper.d.ts +34 -0
  63. package/dist/database/puri-wrapper.d.ts.map +1 -0
  64. package/dist/database/puri-wrapper.js +2 -0
  65. package/dist/database/puri-wrapper.js.map +1 -0
  66. package/dist/database/puri.d.ts +83 -0
  67. package/dist/database/puri.d.ts.map +1 -0
  68. package/dist/database/puri.js +2 -0
  69. package/dist/database/puri.js.map +1 -0
  70. package/dist/database/puri.types.d.ts +60 -0
  71. package/dist/database/puri.types.d.ts.map +1 -0
  72. package/dist/database/puri.types.js +2 -0
  73. package/dist/database/puri.types.js.map +1 -0
  74. package/dist/database/transaction-context.d.ts +9 -0
  75. package/dist/database/transaction-context.d.ts.map +1 -0
  76. package/dist/database/transaction-context.js +2 -0
  77. package/dist/database/transaction-context.js.map +1 -0
  78. package/dist/database/upsert-builder.d.ts +34 -0
  79. package/dist/database/upsert-builder.d.ts.map +1 -0
  80. package/dist/database/upsert-builder.js +2 -0
  81. package/dist/database/upsert-builder.js.map +1 -0
  82. package/dist/entity/entity-manager.d.ts +32 -0
  83. package/dist/entity/entity-manager.d.ts.map +1 -0
  84. package/dist/entity/entity-manager.js +2 -0
  85. package/dist/entity/entity-manager.js.map +1 -0
  86. package/dist/entity/entity-utils.d.ts +61 -0
  87. package/dist/entity/entity-utils.d.ts.map +1 -0
  88. package/dist/entity/entity-utils.js +2 -0
  89. package/dist/entity/entity-utils.js.map +1 -0
  90. package/dist/entity/entity.d.ts +62 -0
  91. package/dist/entity/entity.d.ts.map +1 -0
  92. package/dist/entity/entity.js +2 -0
  93. package/dist/entity/entity.js.map +1 -0
  94. package/dist/entity/migrator.d.ts +135 -0
  95. package/dist/entity/migrator.d.ts.map +1 -0
  96. package/dist/entity/migrator.js +2 -0
  97. package/dist/entity/migrator.js.map +1 -0
  98. package/dist/exceptions/error-handler.d.ts +3 -0
  99. package/dist/exceptions/error-handler.d.ts.map +1 -0
  100. package/dist/exceptions/error-handler.js +2 -0
  101. package/dist/exceptions/error-handler.js.map +1 -0
  102. package/dist/exceptions/so-exceptions.d.ts +48 -0
  103. package/dist/exceptions/so-exceptions.d.ts.map +1 -0
  104. package/dist/exceptions/so-exceptions.js +2 -0
  105. package/dist/exceptions/so-exceptions.js.map +1 -0
  106. package/dist/file-storage/driver.d.ts +48 -0
  107. package/dist/file-storage/driver.d.ts.map +1 -0
  108. package/dist/file-storage/driver.js +2 -0
  109. package/dist/file-storage/driver.js.map +1 -0
  110. package/dist/file-storage/file-storage.d.ts +50 -0
  111. package/dist/file-storage/file-storage.d.ts.map +1 -0
  112. package/dist/file-storage/file-storage.js +2 -0
  113. package/dist/file-storage/file-storage.js.map +1 -0
  114. package/dist/index.d.ts +23 -813
  115. package/dist/index.d.ts.map +1 -0
  116. package/dist/index.js +1 -433
  117. package/dist/index.js.map +1 -1
  118. package/dist/migration/code-generation.d.ts +15 -0
  119. package/dist/migration/code-generation.d.ts.map +1 -0
  120. package/dist/migration/code-generation.js +2 -0
  121. package/dist/migration/code-generation.js.map +1 -0
  122. package/dist/migration/migration-set.d.ts +17 -0
  123. package/dist/migration/migration-set.d.ts.map +1 -0
  124. package/dist/migration/migration-set.js +2 -0
  125. package/dist/migration/migration-set.js.map +1 -0
  126. package/dist/migration/migrator.d.ts +130 -0
  127. package/dist/migration/migrator.d.ts.map +1 -0
  128. package/dist/migration/migrator.js +2 -0
  129. package/dist/migration/migrator.js.map +1 -0
  130. package/dist/migration/types.d.ts +52 -0
  131. package/dist/migration/types.d.ts.map +1 -0
  132. package/dist/migration/types.js +2 -0
  133. package/dist/migration/types.js.map +1 -0
  134. package/dist/stream/index.d.ts +2 -0
  135. package/dist/stream/index.d.ts.map +1 -0
  136. package/dist/stream/index.js +2 -0
  137. package/dist/stream/index.js.map +1 -0
  138. package/dist/stream/sse.d.ts +13 -0
  139. package/dist/stream/sse.d.ts.map +1 -0
  140. package/dist/stream/sse.js +2 -0
  141. package/dist/stream/sse.js.map +1 -0
  142. package/dist/syncer/index.d.ts +2 -0
  143. package/dist/syncer/index.d.ts.map +1 -0
  144. package/dist/syncer/index.js +2 -0
  145. package/dist/syncer/index.js.map +1 -0
  146. package/dist/syncer/syncer.d.ts +127 -0
  147. package/dist/syncer/syncer.d.ts.map +1 -0
  148. package/dist/syncer/syncer.js +2 -0
  149. package/dist/syncer/syncer.js.map +1 -0
  150. package/dist/templates/base-template.d.ts +13 -0
  151. package/dist/templates/base-template.d.ts.map +1 -0
  152. package/dist/templates/base-template.js +2 -0
  153. package/dist/templates/base-template.js.map +1 -0
  154. package/dist/templates/entity.template.d.ts +17 -0
  155. package/dist/templates/entity.template.d.ts.map +1 -0
  156. package/dist/templates/entity.template.js +2 -0
  157. package/dist/templates/entity.template.js.map +1 -0
  158. package/dist/templates/generated.template.d.ts +27 -0
  159. package/dist/templates/generated.template.d.ts.map +1 -0
  160. package/dist/templates/generated.template.js +2 -0
  161. package/dist/templates/generated.template.js.map +1 -0
  162. package/dist/templates/generated_http.template.d.ts +24 -0
  163. package/dist/templates/generated_http.template.d.ts.map +1 -0
  164. package/dist/templates/generated_http.template.js +2 -0
  165. package/dist/templates/generated_http.template.js.map +1 -0
  166. package/dist/templates/generated_sso.template.d.ts +20 -0
  167. package/dist/templates/generated_sso.template.d.ts.map +1 -0
  168. package/dist/templates/generated_sso.template.js +2 -0
  169. package/dist/templates/generated_sso.template.js.map +1 -0
  170. package/dist/templates/index.d.ts +2 -0
  171. package/dist/templates/index.d.ts.map +1 -0
  172. package/dist/templates/index.js +2 -0
  173. package/dist/templates/index.js.map +1 -0
  174. package/dist/templates/init_types.template.d.ts +17 -0
  175. package/dist/templates/init_types.template.d.ts.map +1 -0
  176. package/dist/templates/init_types.template.js +2 -0
  177. package/dist/templates/init_types.template.js.map +1 -0
  178. package/dist/templates/model.template.d.ts +17 -0
  179. package/dist/templates/model.template.d.ts.map +1 -0
  180. package/dist/templates/model.template.js +2 -0
  181. package/dist/templates/model.template.js.map +1 -0
  182. package/dist/templates/model_test.template.d.ts +17 -0
  183. package/dist/templates/model_test.template.d.ts.map +1 -0
  184. package/dist/templates/model_test.template.js +2 -0
  185. package/dist/templates/model_test.template.js.map +1 -0
  186. package/dist/templates/service.template.d.ts +29 -0
  187. package/dist/templates/service.template.d.ts.map +1 -0
  188. package/dist/templates/service.template.js +2 -0
  189. package/dist/templates/service.template.js.map +1 -0
  190. package/dist/templates/view_enums_buttonset.template.d.ts +17 -0
  191. package/dist/templates/view_enums_buttonset.template.d.ts.map +1 -0
  192. package/dist/templates/view_enums_buttonset.template.js +2 -0
  193. package/dist/templates/view_enums_buttonset.template.js.map +1 -0
  194. package/dist/templates/view_enums_dropdown.template.d.ts +18 -0
  195. package/dist/templates/view_enums_dropdown.template.d.ts.map +1 -0
  196. package/dist/templates/view_enums_dropdown.template.js +2 -0
  197. package/dist/templates/view_enums_dropdown.template.js.map +1 -0
  198. package/dist/templates/view_enums_select.template.d.ts +17 -0
  199. package/dist/templates/view_enums_select.template.d.ts.map +1 -0
  200. package/dist/templates/view_enums_select.template.js +2 -0
  201. package/dist/templates/view_enums_select.template.js.map +1 -0
  202. package/dist/templates/view_form.template.d.ts +26 -0
  203. package/dist/templates/view_form.template.d.ts.map +1 -0
  204. package/dist/templates/view_form.template.js +2 -0
  205. package/dist/templates/view_form.template.js.map +1 -0
  206. package/dist/templates/view_id_all_select.template.d.ts +17 -0
  207. package/dist/templates/view_id_all_select.template.d.ts.map +1 -0
  208. package/dist/templates/view_id_all_select.template.js +2 -0
  209. package/dist/templates/view_id_all_select.template.js.map +1 -0
  210. package/dist/templates/view_id_async_select.template.d.ts +17 -0
  211. package/dist/templates/view_id_async_select.template.d.ts.map +1 -0
  212. package/dist/templates/view_id_async_select.template.js +2 -0
  213. package/dist/templates/view_id_async_select.template.js.map +1 -0
  214. package/dist/templates/view_list.template.d.ts +38 -0
  215. package/dist/templates/view_list.template.d.ts.map +1 -0
  216. package/dist/templates/view_list.template.js +2 -0
  217. package/dist/templates/view_list.template.js.map +1 -0
  218. package/dist/templates/view_list_columns.template.d.ts +17 -0
  219. package/dist/templates/view_list_columns.template.d.ts.map +1 -0
  220. package/dist/templates/view_list_columns.template.js +2 -0
  221. package/dist/templates/view_list_columns.template.js.map +1 -0
  222. package/dist/templates/view_search_input.template.d.ts +17 -0
  223. package/dist/templates/view_search_input.template.d.ts.map +1 -0
  224. package/dist/templates/view_search_input.template.js +2 -0
  225. package/dist/templates/view_search_input.template.js.map +1 -0
  226. package/dist/testing/_relation-graph.d.ts +7 -0
  227. package/dist/testing/_relation-graph.d.ts.map +1 -0
  228. package/dist/testing/_relation-graph.js +2 -0
  229. package/dist/testing/_relation-graph.js.map +1 -0
  230. package/dist/testing/fixture-manager.d.ts +35 -0
  231. package/dist/testing/fixture-manager.d.ts.map +1 -0
  232. package/dist/testing/fixture-manager.js +2 -0
  233. package/dist/testing/fixture-manager.js.map +1 -0
  234. package/dist/types/types.d.ts +611 -0
  235. package/dist/types/types.d.ts.map +1 -0
  236. package/dist/types/types.js +2 -0
  237. package/dist/types/types.js.map +1 -0
  238. package/dist/typings/knex.d.js +2 -0
  239. package/dist/typings/knex.d.js.map +1 -0
  240. package/dist/utils/async-utils.d.ts +25 -0
  241. package/dist/utils/async-utils.d.ts.map +1 -0
  242. package/dist/utils/async-utils.js +2 -0
  243. package/dist/utils/async-utils.js.map +1 -0
  244. package/dist/utils/controller.d.ts +9 -0
  245. package/dist/utils/controller.d.ts.map +1 -0
  246. package/dist/utils/controller.js +2 -0
  247. package/dist/utils/controller.js.map +1 -0
  248. package/dist/utils/fs-utils.d.ts +9 -0
  249. package/dist/utils/fs-utils.d.ts.map +1 -0
  250. package/dist/utils/fs-utils.js +2 -0
  251. package/dist/utils/fs-utils.js.map +1 -0
  252. package/dist/utils/lodash-able.d.ts +2 -0
  253. package/dist/utils/lodash-able.d.ts.map +1 -0
  254. package/dist/utils/lodash-able.js +2 -0
  255. package/dist/utils/lodash-able.js.map +1 -0
  256. package/dist/utils/model.d.ts +17 -0
  257. package/dist/utils/model.d.ts.map +1 -0
  258. package/dist/utils/model.js +2 -0
  259. package/dist/utils/model.js.map +1 -0
  260. package/dist/utils/sql-parser.d.ts +4 -0
  261. package/dist/utils/sql-parser.d.ts.map +1 -0
  262. package/dist/utils/sql-parser.js +2 -0
  263. package/dist/utils/sql-parser.js.map +1 -0
  264. package/dist/utils/utils.d.ts +9 -0
  265. package/dist/utils/utils.d.ts.map +1 -0
  266. package/dist/utils/utils.js +2 -0
  267. package/dist/utils/utils.js.map +1 -0
  268. package/dist/utils/zod-error.d.ts +8 -0
  269. package/dist/utils/zod-error.d.ts.map +1 -0
  270. package/dist/utils/zod-error.js +2 -0
  271. package/dist/utils/zod-error.js.map +1 -0
  272. package/nodemon.json +6 -0
  273. package/package.json +32 -45
  274. package/src/api/base-frame.ts +3 -4
  275. package/src/api/caster.ts +22 -23
  276. package/src/api/code-converters.ts +170 -134
  277. package/src/api/context.ts +15 -3
  278. package/src/api/decorators.ts +144 -20
  279. package/src/api/index.ts +2 -0
  280. package/src/api/sonamu.ts +408 -165
  281. package/src/bin/build-config.ts +10 -0
  282. package/src/bin/cli-wrapper.ts +35 -32
  283. package/src/bin/cli.ts +141 -204
  284. package/src/database/_batch_update.ts +10 -15
  285. package/src/database/base-model.ts +326 -216
  286. package/src/database/db.ts +191 -21
  287. package/src/database/{drivers/knex/plugins → knex-plugins}/knex-on-duplicate-update.ts +1 -1
  288. package/src/database/puri-wrapper.ts +129 -0
  289. package/src/database/puri.ts +808 -0
  290. package/src/database/puri.types.ts +222 -0
  291. package/src/database/transaction-context.ts +18 -0
  292. package/src/database/upsert-builder.ts +32 -35
  293. package/src/entity/entity-manager.ts +7 -15
  294. package/src/entity/entity.ts +9 -31
  295. package/src/entity/migrator-/354/235/264/354/202/254/352/260/224/354/226/264/354/232/224.md +1 -0
  296. package/src/file-storage/driver.ts +131 -0
  297. package/src/file-storage/file-storage.ts +100 -0
  298. package/src/index.ts +15 -11
  299. package/src/migration/code-generation.ts +777 -0
  300. package/src/migration/migration-set.ts +453 -0
  301. package/src/migration/migrator.ts +823 -0
  302. package/src/migration/types.ts +53 -0
  303. package/src/shared/web.shared.ts.txt +33 -2
  304. package/src/stream/index.ts +1 -0
  305. package/src/stream/sse.ts +49 -0
  306. package/src/syncer/syncer.ts +294 -127
  307. package/src/templates/generated.template.ts +13 -1
  308. package/src/templates/generated_http.template.ts +15 -12
  309. package/src/templates/generated_sso.template.ts +50 -2
  310. package/src/templates/model.template.ts +138 -2
  311. package/src/templates/service.template.ts +0 -1
  312. package/src/templates/view_form.template.ts +11 -7
  313. package/src/templates/view_list.template.ts +12 -4
  314. package/src/testing/fixture-manager.ts +229 -174
  315. package/src/types/types.ts +108 -14
  316. package/src/utils/async-utils.ts +64 -0
  317. package/src/utils/fs-utils.ts +17 -0
  318. package/src/utils/model.ts +0 -2
  319. package/src/utils/utils.ts +14 -58
  320. package/src/utils/zod-error.ts +12 -176
  321. package/tsconfig.json +6 -0
  322. package/tsup.config.js +4 -2
  323. package/.pnp.cjs +0 -14363
  324. package/.pnp.loader.mjs +0 -2047
  325. package/.vscode/extensions.json +0 -6
  326. package/.vscode/settings.json +0 -9
  327. package/.yarnrc.yml +0 -5
  328. package/dist/base-model-CEB0H0aO.d.mts +0 -43
  329. package/dist/base-model-CrqDMYhI.d.ts +0 -43
  330. package/dist/bin/cli-wrapper.d.mts +0 -1
  331. package/dist/bin/cli-wrapper.mjs +0 -43
  332. package/dist/bin/cli-wrapper.mjs.map +0 -1
  333. package/dist/bin/cli.d.mts +0 -2
  334. package/dist/bin/cli.mjs +0 -907
  335. package/dist/bin/cli.mjs.map +0 -1
  336. package/dist/chunk-2WAC2GER.js +0 -7625
  337. package/dist/chunk-2WAC2GER.js.map +0 -1
  338. package/dist/chunk-C3IPIF6O.mjs +0 -1581
  339. package/dist/chunk-C3IPIF6O.mjs.map +0 -1
  340. package/dist/chunk-EXHKSVTE.js +0 -280
  341. package/dist/chunk-EXHKSVTE.js.map +0 -1
  342. package/dist/chunk-FCERKIIF.mjs +0 -7623
  343. package/dist/chunk-FCERKIIF.mjs.map +0 -1
  344. package/dist/chunk-HGIBJYOU.mjs +0 -231
  345. package/dist/chunk-HGIBJYOU.mjs.map +0 -1
  346. package/dist/chunk-JKSOJRQA.mjs +0 -280
  347. package/dist/chunk-JKSOJRQA.mjs.map +0 -1
  348. package/dist/chunk-OTKKFP3Y.js +0 -1581
  349. package/dist/chunk-OTKKFP3Y.js.map +0 -1
  350. package/dist/chunk-PTFDTOJU.mjs +0 -19
  351. package/dist/chunk-PTFDTOJU.mjs.map +0 -1
  352. package/dist/chunk-UZ2IY5VE.js +0 -231
  353. package/dist/chunk-UZ2IY5VE.js.map +0 -1
  354. package/dist/database/drivers/knex/base-model.d.mts +0 -16
  355. package/dist/database/drivers/knex/base-model.d.ts +0 -16
  356. package/dist/database/drivers/knex/base-model.js +0 -55
  357. package/dist/database/drivers/knex/base-model.js.map +0 -1
  358. package/dist/database/drivers/knex/base-model.mjs +0 -56
  359. package/dist/database/drivers/knex/base-model.mjs.map +0 -1
  360. package/dist/database/drivers/kysely/base-model.d.mts +0 -22
  361. package/dist/database/drivers/kysely/base-model.d.ts +0 -22
  362. package/dist/database/drivers/kysely/base-model.js +0 -64
  363. package/dist/database/drivers/kysely/base-model.js.map +0 -1
  364. package/dist/database/drivers/kysely/base-model.mjs +0 -65
  365. package/dist/database/drivers/kysely/base-model.mjs.map +0 -1
  366. package/dist/index.d.mts +0 -813
  367. package/dist/index.mjs +0 -435
  368. package/dist/index.mjs.map +0 -1
  369. package/dist/model-aFgomcdc.d.mts +0 -1112
  370. package/dist/model-aFgomcdc.d.ts +0 -1112
  371. package/src/database/base-model.abstract.ts +0 -97
  372. package/src/database/db.abstract.ts +0 -75
  373. package/src/database/drivers/knex/base-model.ts +0 -55
  374. package/src/database/drivers/knex/client.ts +0 -209
  375. package/src/database/drivers/knex/db.ts +0 -232
  376. package/src/database/drivers/knex/generator.ts +0 -659
  377. package/src/database/drivers/kysely/base-model.ts +0 -89
  378. package/src/database/drivers/kysely/client.ts +0 -309
  379. package/src/database/drivers/kysely/db.ts +0 -238
  380. package/src/database/drivers/kysely/generator.ts +0 -714
  381. package/src/database/types.ts +0 -118
  382. package/src/entity/migrator.ts +0 -1400
  383. package/src/smd/smd-manager.ts +0 -139
  384. package/src/smd/smd.ts +0 -571
  385. package/src/templates/kysely_types.template.ts +0 -205
@@ -0,0 +1,10 @@
1
+ /**
2
+ * SWC 빌드 명령어
3
+ */
4
+ export const SWC_BUILD_COMMAND =
5
+ "swc src -d dist --strip-leading-paths --source-maps -C module.type=commonjs -C jsc.parser.syntax=typescript -C jsc.parser.decorators=true -C jsc.target=es5";
6
+
7
+ /**
8
+ * TSC 타입 체크 명령어
9
+ */
10
+ export const TSC_TYPE_CHECK_COMMAND = "tsc --noEmit";
@@ -1,41 +1,44 @@
1
1
  #!/usr/bin/env ts-node
2
2
 
3
- import { spawnSync } from "child_process";
4
- import { extname, resolve } from "path";
5
- import { existsSync, readFileSync } from "fs";
6
-
7
- const cjsPath = resolve(__dirname, "bin/cli.js");
8
- const esmPath = resolve(__dirname, "bin/cli.mjs");
9
-
10
- const isESM = () => {
11
- const packageJsonPath = resolve(process.cwd(), "package.json");
12
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
13
-
14
- // package.json에 "type": "module" 설정 확인
15
- if (packageJson.type === "module") {
16
- return true;
17
- }
18
-
19
- // 환경 변수에서 ESM 여부 확인
20
- if (process.env.USE_ESM === "true") {
21
- return true;
3
+ import { spawnSync, execSync } from "child_process";
4
+ import { resolve } from "path";
5
+ import { existsSync } from "fs";
6
+ import chalk from "chalk";
7
+ import { SWC_BUILD_COMMAND, TSC_TYPE_CHECK_COMMAND } from "./build-config";
8
+
9
+ const scriptPath = resolve(__dirname, "cli.js");
10
+ const args = process.argv.slice(2);
11
+
12
+ // build 명령어는 dist 없이도 실행 가능하도록 cli.ts 외부에서 처리(Sonamu.init에서 dist 필요)
13
+ function build(checkTypes: boolean = false) {
14
+ try {
15
+ execSync(SWC_BUILD_COMMAND, { cwd: process.cwd(), stdio: "inherit" });
16
+ } catch (error) {
17
+ console.error(chalk.red("Build failed."), error);
18
+ process.exit(1);
22
19
  }
23
20
 
24
- // package.json에 "type": "module" 설정
25
- if (existsSync(packageJsonPath)) {
26
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
27
- return packageJson.type === "module";
28
- }
29
-
30
- // main 필드가 .mjs로 끝나는지 확인
31
- if (packageJson.main && extname(packageJson.main) === ".mjs") {
32
- return true;
21
+ if (checkTypes) {
22
+ try {
23
+ console.log(chalk.blue("Checking types with tsc..."));
24
+ execSync(TSC_TYPE_CHECK_COMMAND, { cwd: process.cwd(), stdio: "inherit" });
25
+ } catch (error) {
26
+ console.error(chalk.red("Type check failed."), error);
27
+ process.exit(1);
28
+ }
33
29
  }
30
+ }
34
31
 
35
- return false;
36
- };
32
+ if (args[0] === "build") {
33
+ console.log(chalk.blue("Building the project..."));
34
+ build(true);
35
+ console.log(chalk.green("Build completed successfully."));
36
+ process.exit(0);
37
+ }
37
38
 
38
- const scriptPath = isESM() ? esmPath : cjsPath;
39
+ if (args[0] === "dev:serve") {
40
+ build();
41
+ }
39
42
 
40
43
  if (!existsSync(scriptPath)) {
41
44
  console.error(`Error: Script not found at ${scriptPath}`);
@@ -44,7 +47,7 @@ if (!existsSync(scriptPath)) {
44
47
 
45
48
  const result = spawnSync(
46
49
  process.execPath,
47
- [scriptPath, ...process.argv.slice(2)],
50
+ ["--no-warnings", scriptPath, ...args],
48
51
  {
49
52
  stdio: "inherit",
50
53
  }
package/src/bin/cli.ts CHANGED
@@ -1,37 +1,29 @@
1
- /* Global Begin */
2
1
  import chalk from "chalk";
3
- console.log(chalk.bgBlue(`BEGIN ${new Date()}`));
4
-
5
2
  import dotenv from "dotenv";
6
3
  dotenv.config();
7
4
 
8
5
  import path from "path";
9
6
  import { tsicli } from "tsicli";
10
7
  import { execSync } from "child_process";
11
- import fs from "fs-extra";
12
- import inflection from "inflection";
13
- import prettier from "prettier";
8
+ import { mkdir, readdir, readFile, writeFile } from "fs/promises";
9
+ import { exists } from "../utils/fs-utils";
14
10
  import process from "process";
15
- import _ from "lodash";
16
11
  import { Sonamu } from "../api";
12
+ import knex, { Knex } from "knex";
13
+ import { findApiRootPath } from "../utils/utils";
17
14
  import { EntityManager } from "../entity/entity-manager";
18
- import { Migrator } from "../entity/migrator";
15
+ import { Migrator } from "../migration/migrator";
19
16
  import { FixtureManager } from "../testing/fixture-manager";
20
- import { SMDManager } from "../smd/smd-manager";
21
- import { DB } from "../database/db";
22
- import {
23
- KnexConfig,
24
- KyselyConfig,
25
- SonamuKnexDBConfig,
26
- SonamuKyselyDBConfig,
27
- } from "../database/types";
28
- import { KnexClient } from "../database/drivers/knex/client";
29
- import { KyselyClient } from "../database/drivers/kysely/client";
17
+ // import { SWC_BUILD_COMMAND } from "./build-config";
18
+ import { NodemonSettings } from "nodemon";
30
19
 
31
20
  let migrator: Migrator;
32
21
 
33
22
  async function bootstrap() {
34
- await Sonamu.init(false, false);
23
+ // dev:serve 명령어가 아닌 경우에만 Sonamu 초기화
24
+ if (process.argv[2] !== "dev:serve") {
25
+ await Sonamu.init(false, false);
26
+ }
35
27
 
36
28
  await tsicli(process.argv, {
37
29
  types: {
@@ -64,7 +56,8 @@ async function bootstrap() {
64
56
  ["scaffold", "view_list", "#entityId"],
65
57
  ["scaffold", "view_form", "#entityId"],
66
58
  ["ui"],
67
- ["smd_migration"],
59
+ ["dev:serve"],
60
+ ["serve"],
68
61
  ],
69
62
  runners: {
70
63
  migrate_run,
@@ -83,7 +76,8 @@ async function bootstrap() {
83
76
  ui,
84
77
  // scaffold_view_list,
85
78
  // scaffold_view_form,
86
- smd_migration,
79
+ "dev:serve": dev_serve,
80
+ serve,
87
81
  },
88
82
  });
89
83
  }
@@ -91,12 +85,69 @@ bootstrap().finally(async () => {
91
85
  if (migrator) {
92
86
  await migrator.destroy();
93
87
  }
94
- await FixtureManager.destory();
95
-
96
- /* Global End */
97
- console.log(chalk.bgBlue(`END ${new Date()}\n`));
88
+ await FixtureManager.destroy();
98
89
  });
99
90
 
91
+ async function dev_serve() {
92
+ const nodemon = await import("nodemon");
93
+
94
+ const nodemonConfig = await (async () => {
95
+ const projectNodemonPath = path.join(findApiRootPath(), "nodemon.json");
96
+ const hasProjectNodemon = await exists(projectNodemonPath);
97
+
98
+ if (hasProjectNodemon) {
99
+ return JSON.parse(await readFile(projectNodemonPath, "utf8"));
100
+ }
101
+
102
+ return {
103
+ watch: ["src/index.ts"],
104
+ ignore: ["dist/**", "**/*.js", "**/*.d.ts"],
105
+ exec: [
106
+ // SWC_BUILD_COMMAND,
107
+ "node --no-warnings -r source-map-support/register -r dotenv/config dist/index.js",
108
+ ].join(" && "),
109
+ } as NodemonSettings;
110
+ })();
111
+ nodemon.default(nodemonConfig);
112
+
113
+ // 프로세스 종료 처리
114
+ const cleanup = async () => {
115
+ await Sonamu.server?.close();
116
+ process.exit(0);
117
+ };
118
+
119
+ process.on("SIGINT", cleanup);
120
+ process.on("SIGTERM", cleanup);
121
+ process.on("SIGUSR2", cleanup);
122
+ }
123
+
124
+ async function serve() {
125
+ const distIndexPath = path.join(Sonamu.apiRootPath, "dist", "index.js");
126
+
127
+ if (!(await exists(distIndexPath))) {
128
+ console.log(
129
+ chalk.red("dist/index.js not found. Please build your project first.")
130
+ );
131
+ console.log(chalk.blue("Run: yarn sonamu build"));
132
+ return;
133
+ }
134
+
135
+ const { spawn } = await import("child_process");
136
+ const serverProcess = spawn(
137
+ "node",
138
+ ["-r", "source-map-support/register", "-r", "dotenv/config", distIndexPath],
139
+ {
140
+ cwd: Sonamu.apiRootPath,
141
+ stdio: "inherit",
142
+ }
143
+ );
144
+
145
+ process.on("SIGINT", () => {
146
+ serverProcess.kill("SIGTERM");
147
+ process.exit(0);
148
+ });
149
+ }
150
+
100
151
  async function setupMigrator() {
101
152
  // migrator
102
153
  migrator = new Migrator({
@@ -149,97 +200,93 @@ async function migrate_reset() {
149
200
  }
150
201
 
151
202
  async function fixture_init() {
152
- const _db = DB.getClient("development_master");
153
- const srcConn = _db.connectionInfo;
154
-
203
+ const srcConfig = Sonamu.dbConfig.development_master;
155
204
  const targets = [
156
205
  {
157
206
  label: "(REMOTE) Fixture DB",
158
- connKey: "fixture_remote",
207
+ config: Sonamu.dbConfig.fixture_remote,
159
208
  },
160
209
  {
161
210
  label: "(LOCAL) Fixture DB",
162
- connKey: "fixture_local",
211
+ config: Sonamu.dbConfig.fixture_local,
212
+ toSkip: (() => {
213
+ const remoteConn = Sonamu.dbConfig.fixture_remote
214
+ .connection as Knex.ConnectionConfig;
215
+ const localConn = Sonamu.dbConfig.fixture_local
216
+ .connection as Knex.ConnectionConfig;
217
+ return (
218
+ remoteConn.host === localConn.host &&
219
+ remoteConn.database === localConn.database
220
+ );
221
+ })(),
163
222
  },
164
223
  {
165
224
  label: "(LOCAL) Testing DB",
166
- connKey: "test",
225
+ config: Sonamu.dbConfig.test,
167
226
  },
168
227
  ] as {
169
228
  label: string;
170
- connKey: keyof SonamuKnexDBConfig | keyof SonamuKyselyDBConfig;
229
+ config: Knex.Config;
230
+ toSkip?: boolean;
171
231
  }[];
172
232
 
173
233
  // 1. 기준DB 스키마를 덤프
174
234
  console.log("DUMP...");
175
235
  const dumpFilename = `/tmp/sonamu-fixture-init-${Date.now()}.sql`;
236
+ const srcConn = srcConfig.connection as Knex.ConnectionConfig;
176
237
  const migrationsDump = `/tmp/sonamu-fixture-init-migrations-${Date.now()}.sql`;
177
238
  execSync(
178
- `mysqldump -h${srcConn.host} -P${srcConn.port} -u${srcConn.user} -p${srcConn.password} --single-transaction -d --no-create-db --triggers ${srcConn.database} > ${dumpFilename}`
239
+ `mysqldump -h${srcConn.host} -u${srcConn.user} -p${srcConn.password} --single-transaction -d --no-create-db --triggers ${srcConn.database} > ${dumpFilename}`
179
240
  );
180
-
181
- // 2. 마이그레이션 테이블이 존재하면 덤프
182
- const dbClient = DB.baseConfig!.client;
183
- const migrationTable = DB.migrationTable;
184
- const [migrations] = await _db.raw<{ count: number }>(
185
- "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = ?",
186
- [srcConn.database, migrationTable]
241
+ const _db = knex(srcConfig);
242
+ const [[migrations]] = await _db.raw(
243
+ "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = 'knex_migrations'",
244
+ [srcConn.database]
187
245
  );
188
246
  if (migrations.count > 0) {
189
247
  execSync(
190
- `mysqldump -h${srcConn.host} -P${srcConn.port} -u${srcConn.user} -p${srcConn.password} --single-transaction --no-create-db --triggers ${srcConn.database} ${migrationTable} ${migrationTable}_lock > ${migrationsDump}`
248
+ `mysqldump -h${srcConn.host} -u${srcConn.user} -p${srcConn.password} --single-transaction --no-create-db --triggers ${srcConn.database} knex_migrations knex_migrations_lock > ${migrationsDump}`
191
249
  );
192
250
  }
193
251
 
194
252
  // 2. 대상DB 각각에 대하여 존재여부 확인 후 붓기
195
- for await (const { label, connKey } of targets) {
196
- const config = DB.connectionInfo[connKey];
197
-
198
- if (
199
- label === "(LOCAL) Fixture DB" &&
200
- targets.find(
201
- (t) =>
202
- t.label === "(REMOTE) Fixture DB" &&
203
- DB.connectionInfo[t.connKey].host === config.host &&
204
- DB.connectionInfo[t.connKey].database === config.database
205
- )
206
- ) {
253
+ for await (const { label, config, toSkip } of targets) {
254
+ const conn = config.connection as Knex.ConnectionConfig;
255
+
256
+ if (toSkip === true) {
207
257
  console.log(chalk.red(`${label}: Skipped!`));
208
258
  continue;
209
259
  }
210
260
 
211
- const db = (() => {
212
- if (dbClient === "knex") {
213
- const config = _.cloneDeep(DB.fullConfig[connKey]) as KnexConfig;
214
- config.connection.database = undefined;
215
- return new KnexClient(config);
216
- } else {
217
- const config = _.cloneDeep(DB.fullConfig[connKey]) as KyselyConfig;
218
- config.database = undefined;
219
- return new KyselyClient(config);
220
- }
221
- })();
222
-
223
- const [row] = await db.raw(`SHOW DATABASES LIKE "${config.database}"`);
261
+ const db = knex({
262
+ ...config,
263
+ connection: {
264
+ ...((config.connection ?? {}) as Knex.ConnectionConfig),
265
+ database: undefined,
266
+ },
267
+ });
268
+ const [[row]] = await db.raw(`SHOW DATABASES LIKE "${conn.database}"`);
224
269
  if (row) {
225
270
  console.log(
226
- chalk.yellow(`${label}: Database "${config.database}" Already exists`)
271
+ chalk.yellow(`${label}: Database "${conn.database}" Already exists`)
227
272
  );
228
273
  await db.destroy();
229
274
  continue;
230
275
  }
231
276
 
232
277
  console.log(`SYNC to ${label}...`);
233
- const mysqlCmd = `mysql -h${config.host} -P${srcConn.port} -u${config.user} -p${config.password}`;
234
- execSync(`${mysqlCmd} -e 'DROP DATABASE IF EXISTS \`${config.database}\`'`);
235
- execSync(`${mysqlCmd} -e 'CREATE DATABASE \`${config.database}\`'`);
236
- execSync(`${mysqlCmd} ${config.database} < ${dumpFilename}`);
237
- if (fs.existsSync(migrationsDump)) {
238
- execSync(`${mysqlCmd} ${config.database} < ${migrationsDump}`);
278
+ const mysqlCmd = `mysql -h${conn.host} -u${conn.user} -p${conn.password}`;
279
+ execSync(`${mysqlCmd} -e 'DROP DATABASE IF EXISTS \`${conn.database}\`'`);
280
+ execSync(`${mysqlCmd} -e 'CREATE DATABASE \`${conn.database}\`'`);
281
+ execSync(`${mysqlCmd} ${conn.database} < ${dumpFilename}`);
282
+ if (await exists(migrationsDump)) {
283
+ execSync(`${mysqlCmd} ${conn.database} < ${migrationsDump}`);
239
284
  }
240
285
 
241
286
  await db.destroy();
242
287
  }
288
+
289
+ await _db.destroy();
243
290
  }
244
291
 
245
292
  async function fixture_import(entityId: string, recordIds: number[]) {
@@ -257,11 +304,11 @@ async function fixture_sync() {
257
304
 
258
305
  async function stub_practice(name: string) {
259
306
  const practiceDir = path.join(Sonamu.apiRootPath, "src", "practices");
260
- const fileNames = fs.readdirSync(practiceDir);
307
+ const fileNames = await readdir(practiceDir);
261
308
 
262
- const maxSeqNo = (() => {
263
- if (fs.existsSync(practiceDir) === false) {
264
- fs.mkdirSync(practiceDir, { recursive: true });
309
+ const maxSeqNo = await (async () => {
310
+ if (!(await exists(practiceDir))) {
311
+ await mkdir(practiceDir, { recursive: true });
265
312
  }
266
313
 
267
314
  const filteredSeqs = fileNames
@@ -285,25 +332,22 @@ async function stub_practice(name: string) {
285
332
  const fileName = `p${currentSeqNo}-${name}.ts`;
286
333
  const dstPath = path.join(practiceDir, fileName);
287
334
 
288
- // FIXME
289
335
  const code = [
290
- `import { BaseModel } from "sonamu";`,
336
+ `import { Sonamu } from "sonamu";`,
291
337
  "",
292
338
  `console.clear();`,
293
339
  `console.log("${fileName}");`,
294
340
  "",
295
- `async function bootstrap() {`,
341
+ `Sonamu.runScript(async () => {`,
296
342
  ` // TODO`,
297
- `}`,
298
- `bootstrap().finally(async () => {`,
299
- `await BaseModel.destroy();`,
300
343
  `});`,
344
+ "",
301
345
  ].join("\n");
302
- fs.writeFileSync(dstPath, code);
346
+ await writeFile(dstPath, code);
303
347
 
304
348
  execSync(`code ${dstPath}`);
305
349
 
306
- const runCode = `yarn node -r source-map-support/register dist/practices/${fileName.replace(
350
+ const runCode = `yarn node -r dotenv/config -r source-map-support/register dist/practices/${fileName.replace(
307
351
  ".ts",
308
352
  ".js"
309
353
  )}`;
@@ -329,10 +373,20 @@ async function scaffold_model_test(entityId: string) {
329
373
 
330
374
  async function ui() {
331
375
  try {
376
+ type StartServersOptions = {
377
+ projectName: string;
378
+ apiRootPath: string;
379
+ port: number;
380
+ };
332
381
  const sonamuUI: {
333
- startServers: (appRootPath: string) => void;
382
+ startServers: (options: StartServersOptions) => void;
334
383
  } = await import("@sonamu-kit/ui" as string);
335
- sonamuUI.startServers(Sonamu.apiRootPath);
384
+ sonamuUI.startServers({
385
+ projectName:
386
+ Sonamu.config.projectName ?? path.basename(Sonamu.apiRootPath),
387
+ apiRootPath: Sonamu.apiRootPath,
388
+ port: Sonamu.config.ui?.port ?? 57000,
389
+ });
336
390
  } catch (e: unknown) {
337
391
  if (e instanceof Error && e.message.includes("isn't declared")) {
338
392
  console.log(`You need to install ${chalk.blue(`@sonamu-kit/ui`)} first.`);
@@ -341,120 +395,3 @@ async function ui() {
341
395
  throw e;
342
396
  }
343
397
  }
344
-
345
- async function smd_migration() {
346
- await SMDManager.autoload();
347
- const smdIds = SMDManager.getAllIds();
348
-
349
- function enumLabelsToEntityEnums(
350
- entityId: string,
351
- enumLabels: {
352
- [enumName: string]: { [name: string]: { ko: string } };
353
- }
354
- ): { [enumName: string]: { [name: string]: string } } {
355
- return Object.fromEntries(
356
- Object.entries(enumLabels).map(([enumLabelName, enumLabel]) => {
357
- const enumName =
358
- entityId + inflection.camelize(enumLabelName.toLowerCase(), false);
359
- return [
360
- enumName,
361
- Object.fromEntries(
362
- Object.entries(enumLabel).map(([name, { ko }]) => [name, ko])
363
- ),
364
- ];
365
- })
366
- );
367
- }
368
- for await (const smdId of smdIds) {
369
- const smd = SMDManager.get(smdId);
370
- const entityJson = {
371
- id: smd.id,
372
- ...(smd.parentId && { parentId: smd.parentId }),
373
- title: smd.title,
374
- props: smd.props,
375
- indexes: smd.indexes,
376
- subsets: smd.subsets,
377
- enums: enumLabelsToEntityEnums(smd.id, smd.enumLabels),
378
- };
379
-
380
- const parentNames = SMDManager.getNamesFromId(smd.parentId ?? smd.id);
381
- const names = SMDManager.getNamesFromId(smd.id);
382
- const dstPath = path.join(
383
- Sonamu.apiRootPath,
384
- "src",
385
- "application",
386
- parentNames.fs,
387
- `${names.fs}.entity.json`
388
- );
389
-
390
- const formatted = await prettier.format(JSON.stringify(entityJson), {
391
- parser: "json",
392
- });
393
- fs.writeFileSync(dstPath, formatted);
394
- console.log(chalk.blue(`CREATED: ${dstPath}`));
395
-
396
- // smd.ts, enums.ts, genereated.ts 삭제 (트랜스파일 된 js파일도 삭제)
397
- const srcSmdPath = path.join(
398
- Sonamu.apiRootPath,
399
- "src",
400
- "application",
401
- parentNames.fs,
402
- `${names.fs}.smd.ts`
403
- );
404
- const dstSmdPath = srcSmdPath
405
- .replace("/src/", "/dist/")
406
- .replace(/\.ts$/, ".js");
407
- const srcEnumsPath = path.join(
408
- Sonamu.apiRootPath,
409
- "src",
410
- "application",
411
- parentNames.fs,
412
- `${names.fs}.enums.ts`
413
- );
414
- const dstEnumsPath = srcEnumsPath
415
- .replace("/src/", "/dist/")
416
- .replace(/\.ts$/, ".js");
417
- const srcGeneratedPath = path.join(
418
- Sonamu.apiRootPath,
419
- "src",
420
- "application",
421
- parentNames.fs,
422
- `${names.fs}.generated.ts`
423
- );
424
- const dstGeneratedPath = srcGeneratedPath
425
- .replace("/src/", "/dist/")
426
- .replace(/\.ts$/, ".js");
427
-
428
- [
429
- srcSmdPath,
430
- dstSmdPath,
431
- srcEnumsPath,
432
- dstEnumsPath,
433
- ...Sonamu.config.sync.targets.map((target) =>
434
- srcEnumsPath
435
- .replace(Sonamu.apiRootPath, path.join(Sonamu.appRootPath, target))
436
- .replace("/src/application/", "/src/services/")
437
- ),
438
- srcGeneratedPath,
439
- dstGeneratedPath,
440
- ].map((p) => {
441
- if (fs.existsSync(p) === false) {
442
- console.log(chalk.yellow(`NOT FOUND: ${p}`));
443
- return;
444
- }
445
- fs.unlinkSync(p);
446
- console.log(chalk.red(`DELETED: ${p}`));
447
- });
448
- }
449
-
450
- // Entity로 reload
451
- console.log("Entity로 다시 로드합니다.");
452
- EntityManager.isAutoloaded = false;
453
- await EntityManager.autoload();
454
-
455
- // Entity를 통해 generated.ts 재생성
456
- const entityIds = EntityManager.getAllParentIds();
457
- for await (const entityId of entityIds) {
458
- await Sonamu.syncer.generateTemplate("generated", { entityId });
459
- }
460
- }
@@ -4,11 +4,6 @@
4
4
  */
5
5
 
6
6
  import { Knex } from "knex";
7
- import { DB } from "./db";
8
- import { KnexClient } from "./drivers/knex/client";
9
- import { KyselyClient } from "./drivers/kysely/client";
10
- import { Transaction } from "kysely";
11
- import { Database } from "./types";
12
7
 
13
8
  export type RowWithId<Id extends string> = {
14
9
  [key in Id]: any;
@@ -24,12 +19,12 @@ export type RowWithId<Id extends string> = {
24
19
  * @param trx
25
20
  */
26
21
  export async function batchUpdate<Id extends string>(
27
- db: KnexClient | KyselyClient,
22
+ knex: Knex,
28
23
  tableName: string,
29
24
  ids: Id[],
30
25
  rows: RowWithId<Id>[],
31
26
  chunkSize = 50,
32
- trx: Knex.Transaction | Transaction<Database> | null = null
27
+ trx: Knex.Transaction | null = null
33
28
  ) {
34
29
  const chunks: RowWithId<Id>[][] = [];
35
30
  for (let i = 0; i < rows.length; i += chunkSize) {
@@ -38,18 +33,18 @@ export async function batchUpdate<Id extends string>(
38
33
 
39
34
  const executeUpdate = async (
40
35
  chunk: RowWithId<Id>[],
41
- transaction: KyselyClient | KnexClient
36
+ transaction: Knex.Transaction
42
37
  ) => {
43
- const sql = generateBatchUpdateSQL(db, tableName, chunk, ids);
44
- return transaction.raw(sql);
38
+ const sql = generateBatchUpdateSQL(knex, tableName, chunk, ids);
39
+ return knex.raw(sql).transacting(transaction);
45
40
  };
46
41
 
47
42
  if (trx) {
48
43
  for (const chunk of chunks) {
49
- await executeUpdate(chunk, DB.toClient(trx));
44
+ await executeUpdate(chunk, trx);
50
45
  }
51
46
  } else {
52
- await db.trx(async (newTrx) => {
47
+ await knex.transaction(async (newTrx) => {
53
48
  for (const chunk of chunks) {
54
49
  await executeUpdate(chunk, newTrx);
55
50
  }
@@ -75,7 +70,7 @@ function generateKeySetFromData(data: Record<string, any>[]) {
75
70
  }
76
71
 
77
72
  function generateBatchUpdateSQL<Id extends string>(
78
- db: KnexClient | KyselyClient,
73
+ db: Knex,
79
74
  tableName: string,
80
75
  data: Record<string, any>[],
81
76
  identifiers: Id[]
@@ -117,10 +112,10 @@ function generateBatchUpdateSQL<Id extends string>(
117
112
  data.map((row) => row[col])
118
113
  );
119
114
 
120
- const sql = db.createRawQuery(
115
+ const sql = db.raw(
121
116
  `UPDATE \`${tableName}\` SET ${cases.join(", ")} WHERE ${whereInClauses}`,
122
117
  [...bindings, ...whereInBindings]
123
118
  );
124
119
 
125
- return sql;
120
+ return sql.toQuery();
126
121
  }