fib-orm 2.0.0 → 3.0.0

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 (427) hide show
  1. package/README.md +42 -6
  2. package/index.d.ts +11 -0
  3. package/index.js +15 -0
  4. package/package.json +36 -34
  5. package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -26
  6. package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -31
  7. package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -28
  8. package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -10
  9. package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -33
  10. package/src/cli/helpers/ddl.ts +84 -0
  11. package/src/cli/helpers/package.ts +81 -0
  12. package/src/cli/index.ts +24 -0
  13. package/src/cli/wrapSubcommand.ts +66 -0
  14. package/src/db-driver/Typo.d.ts +141 -0
  15. package/src/db-driver/built-ins/base.class.ts +260 -0
  16. package/src/db-driver/built-ins/driver-dm.ts +62 -0
  17. package/src/db-driver/built-ins/driver-mssql.ts +67 -0
  18. package/src/db-driver/built-ins/driver-mysql.ts +44 -0
  19. package/src/db-driver/built-ins/driver-postgresql.ts +94 -0
  20. package/src/db-driver/built-ins/driver-redis.ts +45 -0
  21. package/src/db-driver/built-ins/driver-sqlite.ts +41 -0
  22. package/src/db-driver/index.ts +6 -0
  23. package/src/db-driver/parseQueryString.ts +76 -0
  24. package/src/db-driver/utils.ts +204 -0
  25. package/src/knex/deps/tarn/PendingOperation.ts +56 -0
  26. package/src/knex/deps/tarn/Pool.ts +610 -0
  27. package/src/knex/deps/tarn/PromiseInspection.ts +29 -0
  28. package/src/knex/deps/tarn/Resource.ts +22 -0
  29. package/src/knex/deps/tarn/TimeoutError.ts +1 -0
  30. package/src/knex/deps/tarn/tarn.ts +7 -0
  31. package/src/knex/deps/tarn/utils.ts +62 -0
  32. package/src/knex/knex.ts +11 -0
  33. package/src/knex/result.d.ts +27 -0
  34. package/src/knex/sandbox.ts +45 -0
  35. package/src/knex/tables.d.ts +4 -0
  36. package/src/knex/types.d.ts +3228 -0
  37. package/src/orm/Adapters.ts +53 -0
  38. package/src/orm/AggregateFunctions.ts +254 -0
  39. package/src/orm/Associations/Extend.ts +405 -0
  40. package/src/orm/Associations/Many.ts +784 -0
  41. package/src/orm/Associations/One.ts +494 -0
  42. package/src/orm/Associations/_utils.ts +72 -0
  43. package/src/orm/ChainFind.ts +427 -0
  44. package/src/orm/ChainInstance.ts +97 -0
  45. package/src/orm/Debug.ts +21 -0
  46. package/src/orm/Drivers/DB/base.ts +7 -0
  47. package/src/orm/Drivers/DB/dm.ts +35 -0
  48. package/src/orm/Drivers/DB/mssql.ts +35 -0
  49. package/src/orm/Drivers/DB/mysql.ts +35 -0
  50. package/src/orm/Drivers/DB/postgres.ts +35 -0
  51. package/src/orm/Drivers/DB/sqlite3.ts +60 -0
  52. package/src/orm/Drivers/DML/_ddl-sql.ts +85 -0
  53. package/src/orm/Drivers/DML/_dml-helpers.ts +66 -0
  54. package/src/orm/Drivers/DML/_shared.ts +61 -0
  55. package/src/orm/Drivers/DML/_utils.ts +112 -0
  56. package/{lib/orm/Drivers/DML/dm.js → src/orm/Drivers/DML/dm.ts} +178 -85
  57. package/src/orm/Drivers/DML/index.ts +10 -0
  58. package/src/orm/Drivers/DML/mssql.ts +366 -0
  59. package/src/orm/Drivers/DML/mysql.ts +347 -0
  60. package/src/orm/Drivers/DML/postgres.ts +382 -0
  61. package/src/orm/Drivers/DML/sqlite.ts +361 -0
  62. package/src/orm/Error.ts +49 -0
  63. package/src/orm/Helpers.ts +297 -0
  64. package/src/orm/Hook.ts +125 -0
  65. package/src/orm/Instance.ts +944 -0
  66. package/src/orm/LazyLoad.ts +117 -0
  67. package/src/orm/Model.ts +1235 -0
  68. package/src/orm/ORM.ts +301 -0
  69. package/src/orm/Patch/fib-cache.ts +7 -0
  70. package/src/orm/Patch/plugin.ts +25 -0
  71. package/src/orm/Property.ts +86 -0
  72. package/src/orm/Settings.ts +134 -0
  73. package/src/orm/Singleton.ts +97 -0
  74. package/src/orm/Typo/Adapter.d.ts +5 -0
  75. package/src/orm/Typo/DMLDriver.d.ts +260 -0
  76. package/src/orm/Typo/Db.d.ts +100 -0
  77. package/src/orm/Typo/Error.d.ts +36 -0
  78. package/src/orm/Typo/ORM.d.ts +315 -0
  79. package/src/orm/Typo/Validators.d.ts +39 -0
  80. package/src/orm/Typo/_common.d.ts +44 -0
  81. package/src/orm/Typo/assoc.d.ts +280 -0
  82. package/src/orm/Typo/hook.d.ts +68 -0
  83. package/src/orm/Typo/instance.d.ts +214 -0
  84. package/{lib → src}/orm/Typo/model.d.ts +297 -176
  85. package/src/orm/Typo/patch.d.ts +39 -0
  86. package/src/orm/Typo/property.d.ts +79 -0
  87. package/src/orm/Typo/query.d.ts +266 -0
  88. package/{lib → src}/orm/Typo/settings.d.ts +14 -7
  89. package/{lib → src}/orm/Typo/synchronous.d.ts +51 -26
  90. package/src/orm/Utilities.ts +1313 -0
  91. package/src/orm/Validators.ts +127 -0
  92. package/src/orm/Where/common.ts +8 -0
  93. package/src/orm/Where/filterDate.ts +74 -0
  94. package/src/orm/cloneDeep.ts +45 -0
  95. package/src/orm/index.ts +231 -0
  96. package/src/orm-core/callback.d.ts +15 -0
  97. package/{lib → src}/orm-core/dialect.d.ts +75 -52
  98. package/src/orm-core/error.ts +71 -0
  99. package/{lib/orm-core/index.d.ts → src/orm-core/index.ts} +8 -2
  100. package/src/orm-core/sync.d.ts +14 -0
  101. package/src/orm-core/utils.ts +4 -0
  102. package/src/orm-property/Property.ts +110 -0
  103. package/src/orm-property/Utils.ts +26 -0
  104. package/src/orm-property/customTypes.ts +13 -0
  105. package/src/orm-property/index.ts +34 -0
  106. package/src/orm-property/transformer.ts +16 -0
  107. package/{lib/orm-property/transformers/dm.js → src/orm-property/transformers/dm.ts} +128 -68
  108. package/src/orm-property/transformers/index.ts +10 -0
  109. package/src/orm-property/transformers/mssql.ts +285 -0
  110. package/src/orm-property/transformers/mysql.ts +395 -0
  111. package/src/orm-property/transformers/postgresql.ts +267 -0
  112. package/src/orm-property/transformers/sqlite.ts +217 -0
  113. package/src/plugins/orm-plugin-uacl/Typo.d.ts +173 -0
  114. package/src/plugins/orm-plugin-uacl/_utils.ts +237 -0
  115. package/src/plugins/orm-plugin-uacl/acl-tree.ts +440 -0
  116. package/src/plugins/orm-plugin-uacl/config-acl-tree.ts +592 -0
  117. package/src/plugins/orm-plugin-uacl/index.ts +180 -0
  118. package/src/plugins/orm-plugin-uacl/tree.ts +331 -0
  119. package/src/sql-ddl-sync/Dialects/dm.ts +493 -0
  120. package/{lib/sql-query/Dialects/index.d.ts → src/sql-ddl-sync/Dialects/index.ts} +3 -3
  121. package/src/sql-ddl-sync/Dialects/mssql.ts +441 -0
  122. package/src/sql-ddl-sync/Dialects/mysql.ts +414 -0
  123. package/src/sql-ddl-sync/Dialects/postgresql.ts +474 -0
  124. package/src/sql-ddl-sync/Dialects/sqlite.ts +439 -0
  125. package/src/sql-ddl-sync/SQL.ts +157 -0
  126. package/src/sql-ddl-sync/Typo/Collection.d.ts +19 -0
  127. package/src/sql-ddl-sync/Typo/DbIndex.d.ts +11 -0
  128. package/{lib → src}/sql-ddl-sync/Typo/Dialect.d.ts +67 -52
  129. package/src/sql-ddl-sync/Typo/Driver.d.ts +67 -0
  130. package/src/sql-ddl-sync/Typo/Query.d.ts +8 -0
  131. package/src/sql-ddl-sync/Typo/SQL.d.ts +45 -0
  132. package/src/sql-ddl-sync/Typo/_common.d.ts +59 -0
  133. package/src/sql-ddl-sync/Utils.ts +291 -0
  134. package/src/sql-ddl-sync/index.ts +599 -0
  135. package/src/sql-query/Comparators.ts +115 -0
  136. package/src/sql-query/Create.ts +87 -0
  137. package/{lib/sql-query/Dialects/dm.js → src/sql-query/Dialects/dm.ts} +42 -21
  138. package/src/sql-query/Dialects/index.ts +14 -0
  139. package/src/sql-query/Dialects/mssql.ts +91 -0
  140. package/src/sql-query/Dialects/mysql.ts +120 -0
  141. package/src/sql-query/Dialects/postgresql.ts +99 -0
  142. package/src/sql-query/Dialects/sqlite.ts +80 -0
  143. package/src/sql-query/Helpers.ts +303 -0
  144. package/src/sql-query/Insert.ts +41 -0
  145. package/src/sql-query/Query.ts +140 -0
  146. package/src/sql-query/Remove.ts +111 -0
  147. package/src/sql-query/Select.ts +719 -0
  148. package/src/sql-query/Set.ts +25 -0
  149. package/src/sql-query/Typo/Aggregation.d.ts +34 -0
  150. package/src/sql-query/Typo/Comparators.d.ts +156 -0
  151. package/src/sql-query/Typo/Dialect.d.ts +51 -0
  152. package/src/sql-query/Typo/Field.d.ts +10 -0
  153. package/src/sql-query/Typo/Helper.d.ts +4 -0
  154. package/src/sql-query/Typo/Query-ChainBuilder.d.ts +110 -0
  155. package/src/sql-query/Typo/Query.d.ts +65 -0
  156. package/src/sql-query/Typo/Sql.d.ts +192 -0
  157. package/src/sql-query/Typo/SubQuery.d.ts +52 -0
  158. package/{lib/sql-query/Typo/index.d.ts → src/sql-query/Typo/index.ts} +5 -2
  159. package/src/sql-query/Update.ts +50 -0
  160. package/src/sql-query/Where.ts +435 -0
  161. package/{lib/orm/Patch → src/typings}/fib-cache.d.ts +4 -3
  162. package/lib/cli/commands/ddlFrom.d.ts +0 -2
  163. package/lib/cli/commands/dumpModel.d.ts +0 -2
  164. package/lib/cli/commands/escape.d.ts +0 -2
  165. package/lib/cli/commands/spinner.d.ts +0 -2
  166. package/lib/cli/commands/upgrade.d.ts +0 -2
  167. package/lib/cli/helpers/ddl.d.ts +0 -17
  168. package/lib/cli/helpers/ddl.js +0 -55
  169. package/lib/cli/helpers/package.d.ts +0 -26
  170. package/lib/cli/helpers/package.js +0 -56
  171. package/lib/cli/index.d.ts +0 -2
  172. package/lib/cli/index.js +0 -18
  173. package/lib/db-driver/Typo.d.ts +0 -112
  174. package/lib/db-driver/Typo.js +0 -1
  175. package/lib/db-driver/built-ins/base.class.d.ts +0 -96
  176. package/lib/db-driver/built-ins/base.class.js +0 -186
  177. package/lib/db-driver/built-ins/driver-dm.d.ts +0 -18
  178. package/lib/db-driver/built-ins/driver-dm.js +0 -53
  179. package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -24
  180. package/lib/db-driver/built-ins/driver-mongodb.js +0 -46
  181. package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -18
  182. package/lib/db-driver/built-ins/driver-mysql.js +0 -37
  183. package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -22
  184. package/lib/db-driver/built-ins/driver-postgresql.js +0 -76
  185. package/lib/db-driver/built-ins/driver-redis.d.ts +0 -12
  186. package/lib/db-driver/built-ins/driver-redis.js +0 -35
  187. package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -17
  188. package/lib/db-driver/built-ins/driver-sqlite.js +0 -34
  189. package/lib/db-driver/index.d.ts +0 -3
  190. package/lib/db-driver/index.js +0 -4
  191. package/lib/db-driver/utils.d.ts +0 -14
  192. package/lib/db-driver/utils.js +0 -187
  193. package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +0 -12
  194. package/lib/knex/deps/tarn/dist/PendingOperation.js +0 -48
  195. package/lib/knex/deps/tarn/dist/Pool.d.ts +0 -97
  196. package/lib/knex/deps/tarn/dist/Pool.js +0 -516
  197. package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +0 -16
  198. package/lib/knex/deps/tarn/dist/PromiseInspection.js +0 -21
  199. package/lib/knex/deps/tarn/dist/Resource.d.ts +0 -9
  200. package/lib/knex/deps/tarn/dist/Resource.js +0 -19
  201. package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +0 -2
  202. package/lib/knex/deps/tarn/dist/TimeoutError.js +0 -5
  203. package/lib/knex/deps/tarn/dist/tarn.d.ts +0 -3
  204. package/lib/knex/deps/tarn/dist/tarn.js +0 -10
  205. package/lib/knex/deps/tarn/dist/utils.d.ts +0 -14
  206. package/lib/knex/deps/tarn/dist/utils.js +0 -60
  207. package/lib/knex/knex.d.ts +0 -2
  208. package/lib/knex/knex.js +0 -3
  209. package/lib/knex/sandbox.d.ts +0 -4
  210. package/lib/knex/sandbox.js +0 -22
  211. package/lib/orm/Adapters.d.ts +0 -3
  212. package/lib/orm/Adapters.js +0 -44
  213. package/lib/orm/AggregateFunctions.d.ts +0 -3
  214. package/lib/orm/AggregateFunctions.js +0 -176
  215. package/lib/orm/Associations/Extend.d.ts +0 -22
  216. package/lib/orm/Associations/Extend.js +0 -274
  217. package/lib/orm/Associations/Many.d.ts +0 -17
  218. package/lib/orm/Associations/Many.js +0 -569
  219. package/lib/orm/Associations/One.d.ts +0 -16
  220. package/lib/orm/Associations/One.js +0 -310
  221. package/lib/orm/Associations/_utils.d.ts +0 -15
  222. package/lib/orm/Associations/_utils.js +0 -52
  223. package/lib/orm/ChainFind.d.ts +0 -3
  224. package/lib/orm/ChainFind.js +0 -327
  225. package/lib/orm/ChainInstance.d.ts +0 -6
  226. package/lib/orm/ChainInstance.js +0 -73
  227. package/lib/orm/Debug.d.ts +0 -2
  228. package/lib/orm/Debug.js +0 -17
  229. package/lib/orm/Drivers/DB/base.d.ts +0 -3
  230. package/lib/orm/Drivers/DB/base.js +0 -3
  231. package/lib/orm/Drivers/DB/dm.d.ts +0 -11
  232. package/lib/orm/Drivers/DB/dm.js +0 -23
  233. package/lib/orm/Drivers/DB/mysql.d.ts +0 -11
  234. package/lib/orm/Drivers/DB/mysql.js +0 -23
  235. package/lib/orm/Drivers/DB/postgres.d.ts +0 -11
  236. package/lib/orm/Drivers/DB/postgres.js +0 -22
  237. package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -16
  238. package/lib/orm/Drivers/DB/sqlite3.js +0 -39
  239. package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
  240. package/lib/orm/Drivers/DML/_ddl-sql.js +0 -51
  241. package/lib/orm/Drivers/DML/_dml-helpers.d.ts +0 -19
  242. package/lib/orm/Drivers/DML/_dml-helpers.js +0 -51
  243. package/lib/orm/Drivers/DML/_shared.d.ts +0 -9
  244. package/lib/orm/Drivers/DML/_shared.js +0 -38
  245. package/lib/orm/Drivers/DML/_utils.d.ts +0 -8
  246. package/lib/orm/Drivers/DML/_utils.js +0 -67
  247. package/lib/orm/Drivers/DML/constants.d.ts +0 -3
  248. package/lib/orm/Drivers/DML/constants.js +0 -2
  249. package/lib/orm/Drivers/DML/dm.d.ts +0 -2
  250. package/lib/orm/Drivers/DML/index.d.ts +0 -4
  251. package/lib/orm/Drivers/DML/index.js +0 -6
  252. package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
  253. package/lib/orm/Drivers/DML/mysql.js +0 -251
  254. package/lib/orm/Drivers/DML/postgres.d.ts +0 -3
  255. package/lib/orm/Drivers/DML/postgres.js +0 -276
  256. package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
  257. package/lib/orm/Drivers/DML/sqlite.js +0 -266
  258. package/lib/orm/Error.d.ts +0 -11
  259. package/lib/orm/Error.js +0 -40
  260. package/lib/orm/Helpers.d.ts +0 -35
  261. package/lib/orm/Helpers.js +0 -233
  262. package/lib/orm/Hook.d.ts +0 -13
  263. package/lib/orm/Hook.js +0 -99
  264. package/lib/orm/Instance.d.ts +0 -2
  265. package/lib/orm/Instance.js +0 -697
  266. package/lib/orm/LazyLoad.d.ts +0 -4
  267. package/lib/orm/LazyLoad.js +0 -76
  268. package/lib/orm/Model.d.ts +0 -7
  269. package/lib/orm/Model.js +0 -971
  270. package/lib/orm/ORM.d.ts +0 -37
  271. package/lib/orm/ORM.js +0 -241
  272. package/lib/orm/Patch/fib-cache.js +0 -2
  273. package/lib/orm/Patch/plugin.d.ts +0 -4
  274. package/lib/orm/Patch/plugin.js +0 -13
  275. package/lib/orm/Property.d.ts +0 -9
  276. package/lib/orm/Property.js +0 -71
  277. package/lib/orm/Settings.d.ts +0 -42
  278. package/lib/orm/Settings.js +0 -119
  279. package/lib/orm/Singleton.d.ts +0 -5
  280. package/lib/orm/Singleton.js +0 -72
  281. package/lib/orm/Typo/Adapter.d.ts +0 -5
  282. package/lib/orm/Typo/Adapter.js +0 -1
  283. package/lib/orm/Typo/DMLDriver.d.ts +0 -210
  284. package/lib/orm/Typo/DMLDriver.js +0 -1
  285. package/lib/orm/Typo/Db.d.ts +0 -38
  286. package/lib/orm/Typo/Db.js +0 -1
  287. package/lib/orm/Typo/Error.d.ts +0 -31
  288. package/lib/orm/Typo/Error.js +0 -1
  289. package/lib/orm/Typo/ORM.d.ts +0 -233
  290. package/lib/orm/Typo/ORM.js +0 -3
  291. package/lib/orm/Typo/Validators.d.ts +0 -32
  292. package/lib/orm/Typo/Validators.js +0 -2
  293. package/lib/orm/Typo/_common.d.ts +0 -38
  294. package/lib/orm/Typo/_common.js +0 -1
  295. package/lib/orm/Typo/assoc.d.ts +0 -221
  296. package/lib/orm/Typo/assoc.js +0 -1
  297. package/lib/orm/Typo/hook.d.ts +0 -42
  298. package/lib/orm/Typo/hook.js +0 -1
  299. package/lib/orm/Typo/instance.d.ts +0 -157
  300. package/lib/orm/Typo/instance.js +0 -1
  301. package/lib/orm/Typo/model.js +0 -6
  302. package/lib/orm/Typo/patch.d.ts +0 -31
  303. package/lib/orm/Typo/patch.js +0 -1
  304. package/lib/orm/Typo/property.d.ts +0 -57
  305. package/lib/orm/Typo/property.js +0 -1
  306. package/lib/orm/Typo/query.d.ts +0 -216
  307. package/lib/orm/Typo/query.js +0 -1
  308. package/lib/orm/Typo/settings.js +0 -5
  309. package/lib/orm/Typo/synchronous.js +0 -1
  310. package/lib/orm/Utilities.d.ts +0 -179
  311. package/lib/orm/Utilities.js +0 -975
  312. package/lib/orm/Validators.d.ts +0 -34
  313. package/lib/orm/Validators.js +0 -100
  314. package/lib/orm/Where/common.d.ts +0 -1
  315. package/lib/orm/Where/common.js +0 -7
  316. package/lib/orm/Where/filterDate.d.ts +0 -11
  317. package/lib/orm/Where/filterDate.js +0 -58
  318. package/lib/orm/index.d.ts +0 -68
  319. package/lib/orm/index.js +0 -157
  320. package/lib/orm-core/callback.d.ts +0 -12
  321. package/lib/orm-core/callback.js +0 -1
  322. package/lib/orm-core/dialect.js +0 -1
  323. package/lib/orm-core/error.d.ts +0 -16
  324. package/lib/orm-core/error.js +0 -29
  325. package/lib/orm-core/index.js +0 -6
  326. package/lib/orm-core/sync.d.ts +0 -12
  327. package/lib/orm-core/sync.js +0 -1
  328. package/lib/orm-core/utils.d.ts +0 -1
  329. package/lib/orm-core/utils.js +0 -5
  330. package/lib/orm-property/Property.d.ts +0 -78
  331. package/lib/orm-property/Property.js +0 -1
  332. package/lib/orm-property/Utils.d.ts +0 -9
  333. package/lib/orm-property/Utils.js +0 -13
  334. package/lib/orm-property/customTypes.d.ts +0 -2
  335. package/lib/orm-property/customTypes.js +0 -13
  336. package/lib/orm-property/index.d.ts +0 -10
  337. package/lib/orm-property/index.js +0 -22
  338. package/lib/orm-property/transformer.d.ts +0 -5
  339. package/lib/orm-property/transformer.js +0 -10
  340. package/lib/orm-property/transformers/dm.d.ts +0 -29
  341. package/lib/orm-property/transformers/index.d.ts +0 -4
  342. package/lib/orm-property/transformers/index.js +0 -5
  343. package/lib/orm-property/transformers/mysql.d.ts +0 -102
  344. package/lib/orm-property/transformers/mysql.js +0 -261
  345. package/lib/orm-property/transformers/postgresql.d.ts +0 -54
  346. package/lib/orm-property/transformers/postgresql.js +0 -189
  347. package/lib/orm-property/transformers/sqlite.d.ts +0 -19
  348. package/lib/orm-property/transformers/sqlite.js +0 -171
  349. package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -40
  350. package/lib/sql-ddl-sync/Dialects/dm.js +0 -296
  351. package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -7
  352. package/lib/sql-ddl-sync/Dialects/index.js +0 -7
  353. package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -39
  354. package/lib/sql-ddl-sync/Dialects/mysql.js +0 -240
  355. package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -40
  356. package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -286
  357. package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -44
  358. package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -256
  359. package/lib/sql-ddl-sync/SQL.d.ts +0 -12
  360. package/lib/sql-ddl-sync/SQL.js +0 -108
  361. package/lib/sql-ddl-sync/Typo/Collection.d.ts +0 -13
  362. package/lib/sql-ddl-sync/Typo/Collection.js +0 -1
  363. package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
  364. package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -1
  365. package/lib/sql-ddl-sync/Typo/Dialect.js +0 -1
  366. package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
  367. package/lib/sql-ddl-sync/Typo/Driver.js +0 -1
  368. package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
  369. package/lib/sql-ddl-sync/Typo/Query.js +0 -1
  370. package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
  371. package/lib/sql-ddl-sync/Typo/SQL.js +0 -1
  372. package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
  373. package/lib/sql-ddl-sync/Typo/_common.js +0 -1
  374. package/lib/sql-ddl-sync/Utils.d.ts +0 -40
  375. package/lib/sql-ddl-sync/Utils.js +0 -217
  376. package/lib/sql-ddl-sync/index.d.ts +0 -87
  377. package/lib/sql-ddl-sync/index.js +0 -371
  378. package/lib/sql-query/Comparators.d.ts +0 -3
  379. package/lib/sql-query/Comparators.js +0 -94
  380. package/lib/sql-query/Create.d.ts +0 -35
  381. package/lib/sql-query/Create.js +0 -77
  382. package/lib/sql-query/Dialects/dm.d.ts +0 -3
  383. package/lib/sql-query/Dialects/index.js +0 -12
  384. package/lib/sql-query/Dialects/mssql.d.ts +0 -3
  385. package/lib/sql-query/Dialects/mssql.js +0 -73
  386. package/lib/sql-query/Dialects/mysql.d.ts +0 -3
  387. package/lib/sql-query/Dialects/mysql.js +0 -100
  388. package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
  389. package/lib/sql-query/Dialects/postgresql.js +0 -76
  390. package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
  391. package/lib/sql-query/Dialects/sqlite.js +0 -61
  392. package/lib/sql-query/Helpers.d.ts +0 -38
  393. package/lib/sql-query/Helpers.js +0 -259
  394. package/lib/sql-query/Insert.d.ts +0 -12
  395. package/lib/sql-query/Insert.js +0 -33
  396. package/lib/sql-query/Query.d.ts +0 -29
  397. package/lib/sql-query/Query.js +0 -119
  398. package/lib/sql-query/Remove.d.ts +0 -16
  399. package/lib/sql-query/Remove.js +0 -93
  400. package/lib/sql-query/Select.d.ts +0 -62
  401. package/lib/sql-query/Select.js +0 -533
  402. package/lib/sql-query/Set.d.ts +0 -4
  403. package/lib/sql-query/Set.js +0 -16
  404. package/lib/sql-query/Typo/Aggregation.d.ts +0 -32
  405. package/lib/sql-query/Typo/Aggregation.js +0 -1
  406. package/lib/sql-query/Typo/Comparators.d.ts +0 -140
  407. package/lib/sql-query/Typo/Comparators.js +0 -1
  408. package/lib/sql-query/Typo/Dialect.d.ts +0 -39
  409. package/lib/sql-query/Typo/Dialect.js +0 -1
  410. package/lib/sql-query/Typo/Field.d.ts +0 -8
  411. package/lib/sql-query/Typo/Field.js +0 -1
  412. package/lib/sql-query/Typo/Helper.d.ts +0 -4
  413. package/lib/sql-query/Typo/Helper.js +0 -1
  414. package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
  415. package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -1
  416. package/lib/sql-query/Typo/Query.d.ts +0 -34
  417. package/lib/sql-query/Typo/Query.js +0 -16
  418. package/lib/sql-query/Typo/Sql.d.ts +0 -143
  419. package/lib/sql-query/Typo/Sql.js +0 -1
  420. package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
  421. package/lib/sql-query/Typo/SubQuery.js +0 -1
  422. package/lib/sql-query/Typo/index.js +0 -1
  423. package/lib/sql-query/Update.d.ts +0 -15
  424. package/lib/sql-query/Update.js +0 -38
  425. package/lib/sql-query/Where.d.ts +0 -4
  426. package/lib/sql-query/Where.js +0 -280
  427. /package/{lib → src}/codepoints-map.json +0 -0
@@ -0,0 +1,599 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ import * as FxORMCore from '../orm-core/index';
4
+ const util = require('util');
5
+ import type { FxOrmSqlDDLSync__Collection } from "./Typo/Collection";
6
+ import type { FxOrmSqlDDLSync__DbIndex } from "./Typo/DbIndex";
7
+ import type { FxOrmSqlDDLSync__Dialect } from "./Typo/Dialect";
8
+ import type { FxOrmSqlDDLSync__Driver } from "./Typo/Driver";
9
+ import type { FxOrmSqlDDLSync } from "./Typo/_common";
10
+ import {
11
+ getSqlQueryDialect,
12
+ logJson,
13
+ getCollectionMapsTo_PropertyNameDict,
14
+ filterPropertyDefaultValue,
15
+ filterSyncStrategy,
16
+ filterSuppressColumnDrop,
17
+ psqlRepairEnumTypes,
18
+ extractCollectionIndexes,
19
+ normalizeDefinedProperty,
20
+ } from './Utils';
21
+ import type { FxOrmCoreCallbackNS } from '../orm-core/index';
22
+
23
+ import "./Dialects";
24
+ import {type IProperty, transformer} from '../orm-property/index';
25
+ import type { IDbDriver } from "../db-driver/index";
26
+ import { ALTER_TABLE_COMMENT } from "./SQL";
27
+ import * as Dialects from './Dialects';
28
+
29
+ const noOp = () => {};
30
+
31
+ export function dialect (name: FxOrmSqlDDLSync__Dialect.DialectType | 'psql') {
32
+ switch (name) {
33
+ case 'psql':
34
+ case 'postgresql':
35
+ return Dialects['postgresql'];
36
+ case 'sqlite':
37
+ case 'mssql':
38
+ case 'mysql':
39
+ case 'dm':
40
+ return Dialects[name];
41
+ default:
42
+ throw new Error(`no dialect with name '${name}'`)
43
+ }
44
+ }
45
+
46
+ function alterCollectionComment<T extends IDbDriver.ISQLConn = IDbDriver.ISQLConn>(
47
+ collection: FxOrmSqlDDLSync__Collection.Collection,
48
+ dbdriver: IDbDriver.ITypedDriver<T>,
49
+ ) {
50
+ if (dbdriver.type === 'sqlite') return ;
51
+
52
+ // don't remove old comment if not provided
53
+ if (!collection.comment) return '';
54
+
55
+ dbdriver.execute(
56
+ ALTER_TABLE_COMMENT(dbdriver.type, collection.name, collection.comment)
57
+ );
58
+ }
59
+
60
+ function updateColumnsComment<T extends IDbDriver.ISQLConn = IDbDriver.ISQLConn>(this: any,
61
+ collection: FxOrmSqlDDLSync__Collection.Collection,
62
+ dbdriver: IDbDriver.ITypedDriver<T>,
63
+ remote_properties: FxOrmSqlDDLSync__Collection.Collection['properties'],
64
+ ) {
65
+ if (dbdriver.type !== 'psql' && dbdriver.type !== 'dm' && dbdriver.type !== 'mssql') return ;
66
+
67
+ // TODO: support mysql also
68
+ const dialect = getSqlQueryDialect(dbdriver.type);
69
+
70
+ for (let k in collection.properties) {
71
+ const prop = collection.properties[k];
72
+ if (!prop.comment) continue ;
73
+
74
+ const remote_prop = remote_properties[k];
75
+ const mapsTo = prop.mapsTo || k;
76
+ if (!mapsTo) {
77
+ this.debug(`[updateColumnsComment] No mapsTo for property '${k}' in collection '${collection.name}'`);
78
+ continue ;
79
+ }
80
+
81
+ if (remote_prop.comment === prop.comment) continue ;
82
+
83
+ if (dbdriver.type === 'mssql') {
84
+ const nv = (value: string) => `N'${String(value).replace(/'/g, "''")}'`;
85
+ const args = [
86
+ `@name=N'MS_Description'`,
87
+ `@value=${nv(prop.comment)}`,
88
+ `@level0type=N'SCHEMA'`,
89
+ `@level0name=@schema`,
90
+ `@level1type=N'TABLE'`,
91
+ `@level1name=${nv(collection.name)}`,
92
+ `@level2type=N'COLUMN'`,
93
+ `@level2name=${nv(mapsTo)}`
94
+ ].join(', ');
95
+
96
+ dbdriver.execute(
97
+ `DECLARE @schema sysname = SCHEMA_NAME(); BEGIN TRY EXEC sp_updateextendedproperty ${args} END TRY BEGIN CATCH EXEC sp_addextendedproperty ${args} END CATCH`
98
+ );
99
+ continue ;
100
+ }
101
+
102
+ dbdriver.execute(
103
+ dialect.escape(
104
+ `comment on column ??.?? is ?`,
105
+ [ collection.name, mapsTo, prop.comment ]
106
+ )
107
+ );
108
+ }
109
+ }
110
+
111
+ /**
112
+ * @description iterate collection, create property's column which didn't exist.
113
+ *
114
+ * @param collection
115
+ * @param force_sync (dangerous) if force re-syncing property to column
116
+ */
117
+ function processCollection(
118
+ syncInstnace: Sync,
119
+ collection: FxOrmSqlDDLSync__Collection.Collection,
120
+ opts?: {
121
+ force_sync?: boolean,
122
+ strategy?: FxOrmSqlDDLSync.SyncCollectionOptions['strategy']
123
+ }
124
+ ) {
125
+ let has: boolean;
126
+ let is_processed: boolean = false;
127
+
128
+ has = syncInstnace.Dialect.hasCollectionSync(syncInstnace.dbdriver, collection.name)
129
+
130
+ if (!has) {
131
+ syncInstnace.createCollection(collection)
132
+ is_processed = true;
133
+ }
134
+
135
+ const { strategy = syncInstnace.strategy } = opts || {};
136
+
137
+ alterCollectionComment(collection, syncInstnace.dbdriver);
138
+
139
+ switch (strategy) {
140
+ case 'soft':
141
+ return is_processed
142
+ case 'mixed':
143
+ case 'hard':
144
+ break
145
+ }
146
+
147
+ syncInstnace.syncCollection(collection, { strategy })
148
+
149
+ return true;
150
+ }
151
+
152
+ /**
153
+ * @param collection_name table where column created
154
+ * @param prop column's property
155
+ */
156
+ function getColumnTypeRaw (
157
+ syncInstance: Sync,
158
+ collection_name: FxOrmSqlDDLSync.TableName,
159
+ prop: IProperty,
160
+ opts?: {
161
+ for?: FxOrmSqlDDLSync__Dialect.PurposeToGetRawType
162
+ }
163
+ ): false | FxOrmSqlDDLSync__Dialect.DialectResult {
164
+ let type: false | string | FxOrmSqlDDLSync__Dialect.TypeResult;
165
+
166
+ /**
167
+ * get type, customTypes first
168
+ */
169
+ if (syncInstance.types.hasOwnProperty(prop.type)) {
170
+ type = syncInstance.types[prop.type].datastoreType(prop);
171
+ } else { // fallback to driver's types
172
+ const { for: _for = 'create_table' } = opts || {};
173
+
174
+ const dbtype = syncInstance.dbdriver.type;
175
+ type = transformer(dbtype as any).toStorageType(prop, {
176
+ collection: collection_name!,
177
+ customTypes: syncInstance.dbdriver?.customTypes,
178
+ escapeVal: getSqlQueryDialect(dbtype).escapeVal,
179
+ userOptions: {
180
+ useDefaultValue: _for === 'create_table' || (
181
+ dbtype === 'sqlite' && ['add_column', 'alter_column'].includes(_for)
182
+ ),
183
+ }
184
+ }).typeValue;
185
+
186
+ }
187
+
188
+ if (!type)
189
+ return false;
190
+
191
+ if (typeof type == "string") {
192
+ type = { value : type };
193
+ }
194
+
195
+ if (prop.mapsTo === undefined)
196
+ throw new Error("undefined prop.mapsTo" + JSON.stringify(prop))
197
+
198
+ return {
199
+ value: getSqlQueryDialect(syncInstance.dbdriver.type).escapeId(prop.mapsTo) + " " + type.value,
200
+ };
201
+ }
202
+
203
+ export class Sync<T extends IDbDriver.ISQLConn = IDbDriver.ISQLConn> {
204
+ strategy: FxOrmSqlDDLSync.SyncCollectionOptions['strategy'] = 'soft'
205
+ /**
206
+ * @description total changes count in this time `Sync`
207
+ * @deprecated
208
+ */
209
+ total_changes!: number
210
+
211
+ readonly collections!: FxOrmSqlDDLSync__Collection.Collection[]
212
+
213
+ readonly dbdriver!: IDbDriver.ITypedDriver<T>
214
+ readonly Dialect!: FxOrmSqlDDLSync__Dialect.Dialect<T>
215
+ /**
216
+ * @description customTypes
217
+ */
218
+ readonly types!: Record<string, FxOrmSqlDDLSync__Driver.CustomPropertyType<T>>
219
+
220
+ private suppressColumnDrop: boolean
221
+ private debug!: (msg: string) => any
222
+
223
+ constructor (options: FxOrmSqlDDLSync.SyncOptions<T>) {
224
+ const dbdriver = options.dbdriver
225
+
226
+ this.suppressColumnDrop = filterSuppressColumnDrop(options.suppressColumnDrop !== false, dbdriver.type)
227
+ this.strategy = filterSyncStrategy(options.syncStrategy)
228
+
229
+ this.debug = (typeof options.debug === 'function' ? options.debug : noOp) as any
230
+
231
+ Object.defineProperty(this, 'types', { value: {}, writable: false })
232
+ Object.defineProperty(this, 'collections', { value: [], writable: false })
233
+ Object.defineProperty(this, 'dbdriver', { value: dbdriver, writable: false })
234
+ Object.defineProperty(this, 'Dialect', { value: dialect(dbdriver.type as any), writable: false })
235
+ }
236
+
237
+ [sync_method: string]: any
238
+
239
+ defineCollection (
240
+ collection_name: string,
241
+ properties: FxOrmSqlDDLSync__Collection.Collection['properties'],
242
+ options?: {
243
+ comment: FxOrmSqlDDLSync__Collection.Collection['comment']
244
+ }
245
+ ): this {
246
+ let collectionIdx = this.collections.findIndex(collection => collection.name === collection_name)
247
+ if (collectionIdx >= 0)
248
+ this.collections.splice(collectionIdx, 1)
249
+
250
+ properties = { ...properties };
251
+
252
+ let index_defs: FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[] = [];
253
+ for (let k in properties) {
254
+ // reassign it
255
+ properties[k] = { ...properties[k] };
256
+ properties[k].mapsTo = properties[k].mapsTo || k;
257
+ extractCollectionIndexes(collection_name, k, properties[k], this.dbdriver.type, index_defs);
258
+ normalizeDefinedProperty(properties[k], this.dbdriver.type);
259
+ }
260
+
261
+ if (typeof this.Dialect.convertIndexes === 'function') {
262
+ index_defs = this.Dialect.convertIndexes(collection_name, index_defs);
263
+ }
264
+
265
+ this.collections.push({
266
+ name: collection_name,
267
+ properties,
268
+ index_defs,
269
+ comment: options?.comment as any,
270
+ });
271
+
272
+ return this;
273
+ }
274
+
275
+ findCollection (collection_name: string): FxOrmSqlDDLSync__Collection.Collection {
276
+ return (this.collections.find(collection => collection.name === collection_name) || null) as any
277
+ }
278
+
279
+ defineType (type: string, proto: FxOrmSqlDDLSync__Driver.CustomPropertyType<T>): this {
280
+ this.types[type] = proto;
281
+ return this;
282
+ }
283
+
284
+ /**
285
+ * @description
286
+ * create collection in db if it doesn't exist, then sync all columns for it.
287
+ *
288
+ * @param collection collection relation to create
289
+ */
290
+ createCollection <T = any> (collection: FxOrmSqlDDLSync__Collection.Collection): T {
291
+ const columns: string[] = [];
292
+
293
+ let keys: string[] = [];
294
+
295
+ for (let k in collection.properties) {
296
+ let property: IProperty = collection.properties[k],
297
+ col: false | FxOrmSqlDDLSync__Dialect.DialectResult;
298
+
299
+ col = getColumnTypeRaw(this as any, collection.name, property, { for: 'create_table' });
300
+
301
+ if (col === false) {
302
+ logJson('createCollection', property);
303
+ throw new Error(`Invalid type definition for property '${k}'.`);
304
+ }
305
+
306
+ if (property.key) keys.push(property.mapsTo!);
307
+ columns.push(col.value);
308
+ }
309
+
310
+ this.debug("Creating " + collection.name);
311
+
312
+ // ? TODO: what it means?
313
+ if (typeof this.Dialect.processKeys === "function")
314
+ keys = (this.Dialect.processKeys as (...args: any[]) => any)(keys);
315
+
316
+ this.total_changes += 1;
317
+
318
+ if (this.dbdriver.type === 'psql') {
319
+ psqlRepairEnumTypes(collection.properties, collection.name, this.dbdriver);
320
+ }
321
+
322
+ const result_1 = this.Dialect.createCollectionSync(
323
+ this.dbdriver,
324
+ collection.name, columns, keys, { comment: collection.comment }
325
+ );
326
+
327
+ this.syncIndexes(collection.name, collection.index_defs);
328
+ updateColumnsComment(collection, this.dbdriver, this.Dialect.getCollectionPropertiesSync(this.dbdriver, collection.name));
329
+
330
+ return result_1;
331
+ }
332
+
333
+ /**
334
+ * @description
335
+ * compare/diff properties between definition ones and the real ones,
336
+ * then sync column in definition but missing in the real
337
+ *
338
+ * @param collection collection properties user provided
339
+ * @param opts
340
+ * - opts.columns: properties from user(default from db)
341
+ * - opts.strategy: (default soft) strategy when conflict between local and remote db, see details below
342
+ *
343
+ * @strategy
344
+ * - 'soft': no change
345
+ * - 'mixed': add missing columns, but never change existed column in db
346
+ * - 'hard': modify existed columns in db
347
+ */
348
+ syncCollection (
349
+ _collection: string | FxOrmSqlDDLSync__Collection.Collection,
350
+ opts?: FxOrmSqlDDLSync.SyncCollectionOptions
351
+ ): void {
352
+ const collection = typeof _collection === 'string' ? this.findCollection(_collection) : _collection;
353
+
354
+ if (!collection)
355
+ throw new Error('[syncCollection] invalid collection')
356
+
357
+ let {
358
+ columns = this.Dialect.getCollectionPropertiesSync(this.dbdriver, collection.name),
359
+ strategy = this.strategy,
360
+ suppressColumnDrop = this.suppressColumnDrop
361
+ } = opts || {};
362
+ suppressColumnDrop = filterSuppressColumnDrop(suppressColumnDrop, this.dbdriver.type)
363
+
364
+ strategy = filterSyncStrategy(strategy)
365
+
366
+ let last_k: string = null as any;
367
+
368
+ this.debug("Synchronizing " + collection.name);
369
+
370
+ if (strategy !== 'soft') {
371
+ for (let k in collection.properties) {
372
+ const prop = collection.properties[k];
373
+ if (!columns.hasOwnProperty(k)) {
374
+ prop.mapsTo = prop.mapsTo || k;
375
+
376
+ const col = getColumnTypeRaw(this as any, collection.name, prop, { for: 'add_column' });
377
+
378
+ if (col === false) {
379
+ logJson('syncCollection', prop);
380
+ throw new Error(`Invalid type definition for property '${k}'.`);
381
+ }
382
+
383
+ this.debug("Adding column " + collection.name + "." + k + ": " + col.value);
384
+
385
+ // check existence again
386
+ if (!this.Dialect.hasCollectionColumnsSync(this.dbdriver, collection.name, prop.mapsTo!)) {
387
+ this.Dialect.addCollectionColumnSync(
388
+ this.dbdriver,
389
+ collection.name,
390
+ col.value,
391
+ // for sqlite, added column must be the last one,
392
+ // we pass empty string to make `addCollectionColumnSync`
393
+ // find last column automatically
394
+ this.dbdriver.type === 'sqlite' ? '' : last_k,
395
+ )
396
+
397
+ this.total_changes += 1;
398
+ }
399
+ } else if (
400
+ strategy === 'hard' &&
401
+ this.dbdriver.type !== 'sqlite'
402
+ && this.needDefinitionToColumn(prop, columns[k], { collection: collection.name })
403
+ ) {
404
+ const col = getColumnTypeRaw(this as any, collection.name, prop, { for: 'alter_column' });
405
+
406
+ if (col === false) {
407
+ logJson('syncCollection', prop);
408
+ throw new Error(`Invalid type definition for property '${k}'.`);
409
+ }
410
+
411
+ this.debug("Modifying column " + collection.name + "." + k + ": " + col.value);
412
+
413
+ // check existence again
414
+ if (this.Dialect.hasCollectionColumnsSync(this.dbdriver, collection.name, prop.mapsTo!)) {
415
+ this.Dialect.modifyCollectionColumnSync(
416
+ this.dbdriver,
417
+ collection.name,
418
+ col.value
419
+ );
420
+
421
+ this.total_changes += 1;
422
+ }
423
+ }
424
+
425
+ last_k = k;
426
+ }
427
+
428
+ if ( strategy === 'hard' && !suppressColumnDrop ) {
429
+ const hash = getCollectionMapsTo_PropertyNameDict(collection)
430
+ for (let colname in columns) {
431
+ if (collection.properties.hasOwnProperty(colname)) continue ;
432
+ /* colname maybe mapsTo */
433
+ if (hash.hasOwnProperty(colname)) continue ;
434
+
435
+ this.debug(`Dropping column ${collection.name}.${colname}`);
436
+
437
+ this.total_changes += 1;
438
+
439
+ this.Dialect.dropCollectionColumnSync(this.dbdriver, collection.name, colname);
440
+ }
441
+ }
442
+ }
443
+
444
+ this.syncIndexes(collection.name, collection.index_defs);
445
+ }
446
+
447
+ syncIndexes (
448
+ collection_name: string,
449
+ index_defs: FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[]
450
+ ): void {
451
+ if (index_defs.length == 0) return ;
452
+
453
+ const db_indexes = this.Dialect.getCollectionIndexesSync(this.dbdriver, collection_name);
454
+
455
+ for (let i = 0; i < index_defs.length; i++) {
456
+ if (!db_indexes.hasOwnProperty(index_defs[i].name)) {
457
+ this.debug("Adding index " + collection_name + "." + index_defs[i].name + " (" + index_defs[i].columns.join(", ") + ")");
458
+
459
+ this.total_changes += 1;
460
+
461
+ const index = index_defs[i];
462
+ this.Dialect.addIndexSync(this.dbdriver, index.name, index.unique, collection_name, index.columns as string[]);
463
+ continue;
464
+ } else if (!db_indexes[index_defs[i].name].unique != !index_defs[i].unique) {
465
+ this.debug("Replacing index " + collection_name + "." + index_defs[i].name);
466
+
467
+ this.total_changes += 1;
468
+
469
+ const index = index_defs[i];
470
+ this.Dialect.removeIndexSync(this.dbdriver, index.name, collection_name);
471
+ this.Dialect.addIndexSync(this.dbdriver, index.name, index.unique, collection_name, index.columns as string[]);
472
+ }
473
+ delete db_indexes[index_defs[i].name];
474
+ }
475
+
476
+ for (let idx in db_indexes) {
477
+ this.debug("Removing index " + collection_name + "." + idx);
478
+
479
+ this.total_changes += 1;
480
+
481
+ this.Dialect.removeIndexSync(this.dbdriver, collection_name, idx);
482
+ }
483
+ }
484
+
485
+ /**
486
+ * @description
487
+ * sync all collections to db (if not existing), with initializing ones' properties.
488
+ *
489
+ * @callbackable
490
+ */
491
+ sync (cb: FxOrmCoreCallbackNS.ExecutionCallback<FxOrmSqlDDLSync.SyncResult>): void
492
+ sync (): FxOrmSqlDDLSync.SyncResult
493
+ sync (cb?: FxOrmCoreCallbackNS.ExecutionCallback<FxOrmSqlDDLSync.SyncResult>) {
494
+ const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod<FxOrmSqlDDLSync.SyncResult>(
495
+ () => {
496
+ this.total_changes = 0;
497
+ this.collections.forEach(collection => processCollection(this as any, collection, { strategy: this.strategy }))
498
+
499
+ return {
500
+ changes: this.total_changes
501
+ };
502
+ }
503
+ )
504
+ FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: !!cb, callback: cb });
505
+
506
+ return exposedErrResults.result;
507
+ };
508
+
509
+ /**
510
+ * @description
511
+ * sync all collections to db whatever it existed,
512
+ * with sync ones' properties whatever the property existed.
513
+ *
514
+ * @callbackable
515
+ */
516
+ forceSync (cb: FxOrmCoreCallbackNS.ExecutionCallback<FxOrmSqlDDLSync.SyncResult>): void
517
+ forceSync (): FxOrmSqlDDLSync.SyncResult
518
+ forceSync (cb?: FxOrmCoreCallbackNS.ExecutionCallback<FxOrmSqlDDLSync.SyncResult>) {
519
+ const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod<FxOrmSqlDDLSync.SyncResult>(
520
+ () => {
521
+ this.total_changes = 0;
522
+ this.collections.forEach(collection => processCollection(this as any, collection, { strategy: 'hard' }))
523
+
524
+ return {
525
+ changes: this.total_changes
526
+ };
527
+ }
528
+ )
529
+ FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: !!cb, callback: cb });
530
+
531
+ return exposedErrResults.result;
532
+ };
533
+
534
+ /**
535
+ * @description if sync one column
536
+ *
537
+ * @param property existed property in collection
538
+ * @param column column expected to be synced
539
+ */
540
+ needDefinitionToColumn (
541
+ property: IProperty,
542
+ column: IProperty,
543
+ options?: {
544
+ collection?: string
545
+ }
546
+ ): boolean {
547
+ if (property.serial && property.type === "number") {
548
+ property.type = "serial";
549
+ }
550
+
551
+ /* if type not equal, sync is required */
552
+ if (property.type != column.type) {
553
+ if (typeof this.Dialect.supportsType !== "function") {
554
+ return true;
555
+ }
556
+ if (this.Dialect.supportsType(property.type) !== column.type) {
557
+ return true;
558
+ }
559
+ }
560
+
561
+ /* deal with type which maybe require sync as type equals between two sides :start */
562
+ if (property.type === 'serial') {
563
+ return false; // serial columns have a fixed form, nothing more to check
564
+ }
565
+ if (property.required !== column.required && !property.key) {
566
+ return true;
567
+ }
568
+
569
+ const { collection: collection_name = undefined } = options || {}
570
+ if (
571
+ property.hasOwnProperty('defaultValue')
572
+ && filterPropertyDefaultValue(property, {
573
+ collection: collection_name!,
574
+ property,
575
+ driver: this.dbdriver
576
+ }) != column.defaultValue
577
+ ) {
578
+ return true;
579
+ }
580
+ if (property.type === 'number' || property.type === 'integer') {
581
+ if (column.hasOwnProperty('size') && (property.size || 4) != column.size) {
582
+ return true;
583
+ }
584
+ }
585
+ if (property.type === 'enum' && column.type === 'enum') {
586
+ if (util.difference(property.values, column.values).length > 0
587
+ || util.difference(column.values, property.values).length > 0) {
588
+ return true;
589
+ }
590
+ }
591
+ /* deal with type which maybe require sync as type equals between two sides :end */
592
+
593
+ return false;
594
+ }
595
+ }
596
+
597
+ export type { FxOrmSqlDDLSync } from "./Typo/_common";
598
+ export type { FxOrmSqlDDLSync__Driver } from "./Typo/Driver";
599
+ export type { FxOrmSqlDDLSync__Dialect } from "./Typo/Dialect";
@@ -0,0 +1,115 @@
1
+ import type { FxSqlQueryComparator, FxSqlQueryComparatorFunction } from "./Typo/Comparators";
2
+
3
+ type FuncOpts = FxSqlQueryComparatorFunction.__Options;
4
+ type between = FxSqlQueryComparatorFunction.between
5
+ function between (a: string, b: string, opts?: FuncOpts) {
6
+ return createSpecialObject({
7
+ from: a, to: b, asIdentifier: !!opts?.asIdentifier
8
+ }, 'between');
9
+ };
10
+
11
+ type not_between = FxSqlQueryComparatorFunction.not_between
12
+ function not_between (a: string, b: string, opts?: FuncOpts) {
13
+ return createSpecialObject({
14
+ from: a, to: b, asIdentifier: !!opts?.asIdentifier
15
+ }, 'not_between');
16
+ };
17
+
18
+ type like = FxSqlQueryComparatorFunction.like
19
+ function like (expr: FxSqlQueryComparator.QueryComparatorExprType, opts?: FuncOpts) {
20
+ return createSpecialObject({
21
+ expr: expr, asIdentifier: !!opts?.asIdentifier
22
+ }, 'like');
23
+ };
24
+
25
+ type not_like = FxSqlQueryComparatorFunction.not_like
26
+ function not_like (expr: FxSqlQueryComparator.QueryComparatorExprType, opts?: FuncOpts) {
27
+ return createSpecialObject({
28
+ expr: expr, asIdentifier: !!opts?.asIdentifier
29
+ }, 'not_like');
30
+ };
31
+
32
+
33
+ type eq = FxSqlQueryComparatorFunction.eq
34
+ function eq (v: any, opts?: FuncOpts) {
35
+ return createSpecialObject({
36
+ val: v, asIdentifier: !!opts?.asIdentifier
37
+ }, 'eq');
38
+ };
39
+
40
+ type ne = FxSqlQueryComparatorFunction.ne
41
+ function ne (v: any, opts?: FuncOpts) {
42
+ return createSpecialObject({
43
+ val: v, asIdentifier: !!opts?.asIdentifier
44
+ }, 'ne');
45
+ };
46
+
47
+ type gt = FxSqlQueryComparatorFunction.gt
48
+ function gt (v: any, opts?: FuncOpts) {
49
+ return createSpecialObject({
50
+ val: v, asIdentifier: !!opts?.asIdentifier
51
+ }, 'gt');
52
+ };
53
+
54
+ type gte = FxSqlQueryComparatorFunction.gte
55
+ function gte (v: any, opts?: FuncOpts) {
56
+ return createSpecialObject({
57
+ val: v, asIdentifier: !!opts?.asIdentifier
58
+ }, 'gte');
59
+ };
60
+
61
+ type lt = FxSqlQueryComparatorFunction.lt
62
+ function lt (v: any, opts?: FuncOpts) {
63
+ return createSpecialObject({
64
+ val: v, asIdentifier: !!opts?.asIdentifier
65
+ }, 'lt');
66
+ };
67
+
68
+ type lte = FxSqlQueryComparatorFunction.lte
69
+ function lte (v: any, opts?: FuncOpts) {
70
+ return createSpecialObject({
71
+ val: v, asIdentifier: !!opts?.asIdentifier
72
+ }, 'lte');
73
+ };
74
+
75
+ type _in = FxSqlQueryComparatorFunction.not_in
76
+ function _in (v: any, opts?: FuncOpts) {
77
+ return createSpecialObject({
78
+ val: v, asIdentifier: !!opts?.asIdentifier
79
+ }, 'in');
80
+ };
81
+
82
+ type not_in = FxSqlQueryComparatorFunction.not_in
83
+ function not_in (v: any, opts?: FuncOpts) {
84
+ return createSpecialObject({
85
+ val: v, asIdentifier: !!opts?.asIdentifier
86
+ }, 'not_in');
87
+ };
88
+
89
+ export default {
90
+ between,
91
+ not_between,
92
+ like,
93
+ not_like,
94
+ eq,
95
+ ne,
96
+ gt,
97
+ gte,
98
+ lt,
99
+ lte,
100
+ in: _in,
101
+ not_in,
102
+ } as FxSqlQueryComparator.ComparatorHash
103
+
104
+ function createSpecialObject(
105
+ obj: object,
106
+ tag: FxSqlQueryComparator.QueryComparatorType,
107
+ ): FxSqlQueryComparator.QueryComparatorObject {
108
+ Object.defineProperty(obj, "sql_comparator", {
109
+ configurable : false,
110
+ enumerable : false,
111
+ value : function () { return tag; }
112
+ });
113
+
114
+ return obj as FxSqlQueryComparator.QueryComparatorObject;
115
+ }