fib-orm 1.4.1 → 2.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 (295) hide show
  1. package/License +1 -1
  2. package/README.md +53 -0
  3. package/lib/cli/commands/ddlFrom.d.ts +2 -0
  4. package/lib/cli/commands/ddlFrom.js +74 -0
  5. package/lib/cli/commands/dumpModel.d.ts +2 -0
  6. package/lib/cli/commands/dumpModel.js +106 -0
  7. package/lib/cli/commands/escape.d.ts +2 -0
  8. package/lib/cli/commands/escape.js +68 -0
  9. package/lib/cli/commands/spinner.d.ts +2 -0
  10. package/lib/cli/commands/spinner.js +36 -0
  11. package/lib/cli/commands/upgrade.d.ts +2 -0
  12. package/lib/cli/commands/upgrade.js +65 -0
  13. package/lib/cli/helpers/ddl.d.ts +17 -0
  14. package/lib/cli/helpers/ddl.js +55 -0
  15. package/lib/cli/helpers/package.d.ts +26 -0
  16. package/lib/cli/helpers/package.js +56 -0
  17. package/lib/cli/index.d.ts +2 -0
  18. package/lib/cli/index.js +18 -0
  19. package/lib/codepoints-map.json +762 -0
  20. package/lib/db-driver/Typo.d.ts +112 -0
  21. package/lib/db-driver/Typo.js +1 -0
  22. package/lib/db-driver/built-ins/base.class.d.ts +96 -0
  23. package/lib/db-driver/built-ins/base.class.js +186 -0
  24. package/lib/db-driver/built-ins/driver-dm.d.ts +18 -0
  25. package/lib/db-driver/built-ins/driver-dm.js +53 -0
  26. package/lib/db-driver/built-ins/driver-mongodb.d.ts +24 -0
  27. package/lib/db-driver/built-ins/driver-mongodb.js +46 -0
  28. package/lib/db-driver/built-ins/driver-mysql.d.ts +18 -0
  29. package/lib/db-driver/built-ins/driver-mysql.js +37 -0
  30. package/lib/db-driver/built-ins/driver-postgresql.d.ts +22 -0
  31. package/lib/db-driver/built-ins/driver-postgresql.js +76 -0
  32. package/lib/db-driver/built-ins/driver-redis.d.ts +12 -0
  33. package/lib/db-driver/built-ins/driver-redis.js +35 -0
  34. package/lib/db-driver/built-ins/driver-sqlite.d.ts +17 -0
  35. package/lib/db-driver/built-ins/driver-sqlite.js +34 -0
  36. package/lib/db-driver/index.d.ts +3 -0
  37. package/lib/db-driver/index.js +4 -0
  38. package/lib/db-driver/utils.d.ts +14 -0
  39. package/lib/db-driver/utils.js +187 -0
  40. package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +12 -0
  41. package/lib/knex/deps/tarn/dist/PendingOperation.js +48 -0
  42. package/lib/knex/deps/tarn/dist/Pool.d.ts +97 -0
  43. package/lib/knex/deps/tarn/dist/Pool.js +516 -0
  44. package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +16 -0
  45. package/lib/knex/deps/tarn/dist/PromiseInspection.js +21 -0
  46. package/lib/knex/deps/tarn/dist/Resource.d.ts +9 -0
  47. package/lib/knex/deps/tarn/dist/Resource.js +19 -0
  48. package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +2 -0
  49. package/lib/knex/deps/tarn/dist/TimeoutError.js +5 -0
  50. package/lib/knex/deps/tarn/dist/tarn.d.ts +3 -0
  51. package/lib/knex/deps/tarn/dist/tarn.js +10 -0
  52. package/lib/knex/deps/tarn/dist/utils.d.ts +14 -0
  53. package/lib/knex/deps/tarn/dist/utils.js +60 -0
  54. package/lib/knex/knex.d.ts +2 -0
  55. package/lib/knex/knex.js +3 -0
  56. package/lib/knex/sandbox.d.ts +4 -0
  57. package/lib/knex/sandbox.js +22 -0
  58. package/lib/orm/Adapters.d.ts +3 -0
  59. package/lib/orm/Adapters.js +44 -0
  60. package/lib/orm/AggregateFunctions.d.ts +3 -0
  61. package/lib/orm/AggregateFunctions.js +176 -0
  62. package/lib/orm/Associations/Extend.d.ts +22 -0
  63. package/lib/orm/Associations/Extend.js +274 -0
  64. package/lib/orm/Associations/Many.d.ts +17 -0
  65. package/lib/orm/Associations/Many.js +569 -0
  66. package/lib/orm/Associations/One.d.ts +16 -0
  67. package/lib/orm/Associations/One.js +310 -0
  68. package/lib/orm/Associations/_utils.d.ts +15 -0
  69. package/lib/orm/Associations/_utils.js +52 -0
  70. package/lib/orm/ChainFind.d.ts +3 -0
  71. package/lib/orm/ChainFind.js +327 -0
  72. package/lib/orm/ChainInstance.d.ts +6 -0
  73. package/lib/orm/ChainInstance.js +73 -0
  74. package/lib/orm/Debug.d.ts +2 -0
  75. package/lib/orm/Debug.js +17 -0
  76. package/lib/orm/Drivers/DB/base.d.ts +3 -0
  77. package/lib/orm/Drivers/DB/base.js +3 -0
  78. package/lib/orm/Drivers/DB/dm.d.ts +11 -0
  79. package/lib/orm/Drivers/DB/dm.js +23 -0
  80. package/lib/orm/Drivers/DB/mysql.d.ts +11 -0
  81. package/lib/orm/Drivers/DB/mysql.js +23 -0
  82. package/lib/orm/Drivers/DB/postgres.d.ts +11 -0
  83. package/lib/orm/Drivers/DB/postgres.js +22 -0
  84. package/lib/orm/Drivers/DB/sqlite3.d.ts +16 -0
  85. package/lib/orm/Drivers/DB/sqlite3.js +39 -0
  86. package/lib/orm/Drivers/DML/_ddl-sql.d.ts +3 -0
  87. package/lib/orm/Drivers/DML/_ddl-sql.js +51 -0
  88. package/lib/orm/Drivers/DML/_dml-helpers.d.ts +19 -0
  89. package/lib/orm/Drivers/DML/_dml-helpers.js +51 -0
  90. package/lib/orm/Drivers/DML/_shared.d.ts +9 -0
  91. package/lib/orm/Drivers/DML/_shared.js +38 -0
  92. package/lib/orm/Drivers/DML/_utils.d.ts +8 -0
  93. package/lib/orm/Drivers/DML/_utils.js +67 -0
  94. package/lib/orm/Drivers/DML/constants.d.ts +3 -0
  95. package/lib/orm/Drivers/DML/constants.js +2 -0
  96. package/lib/orm/Drivers/DML/dm.d.ts +2 -0
  97. package/lib/orm/Drivers/DML/dm.js +293 -0
  98. package/lib/orm/Drivers/DML/index.d.ts +4 -0
  99. package/lib/orm/Drivers/DML/index.js +6 -0
  100. package/lib/orm/Drivers/DML/mysql.d.ts +2 -0
  101. package/lib/orm/Drivers/DML/mysql.js +251 -0
  102. package/lib/orm/Drivers/DML/postgres.d.ts +3 -0
  103. package/lib/orm/Drivers/DML/postgres.js +276 -0
  104. package/lib/orm/Drivers/DML/sqlite.d.ts +2 -0
  105. package/lib/orm/Drivers/DML/sqlite.js +266 -0
  106. package/lib/orm/Error.d.ts +11 -0
  107. package/lib/orm/Error.js +40 -0
  108. package/lib/orm/Helpers.d.ts +35 -0
  109. package/lib/orm/Helpers.js +233 -0
  110. package/lib/orm/Hook.d.ts +13 -0
  111. package/lib/orm/Hook.js +99 -0
  112. package/lib/orm/Instance.d.ts +2 -0
  113. package/lib/orm/Instance.js +697 -0
  114. package/lib/orm/LazyLoad.d.ts +4 -0
  115. package/lib/orm/LazyLoad.js +76 -0
  116. package/lib/orm/Model.d.ts +7 -0
  117. package/lib/orm/Model.js +971 -0
  118. package/lib/orm/ORM.d.ts +37 -0
  119. package/lib/orm/ORM.js +241 -0
  120. package/lib/orm/Patch/fib-cache.d.ts +40 -0
  121. package/lib/orm/Patch/fib-cache.js +2 -0
  122. package/lib/orm/Patch/plugin.d.ts +4 -0
  123. package/lib/orm/Patch/plugin.js +13 -0
  124. package/lib/orm/Property.d.ts +9 -0
  125. package/lib/orm/Property.js +71 -0
  126. package/lib/orm/Settings.d.ts +42 -0
  127. package/lib/orm/Settings.js +119 -0
  128. package/lib/orm/Singleton.d.ts +5 -0
  129. package/lib/orm/Singleton.js +72 -0
  130. package/lib/orm/Typo/Adapter.d.ts +5 -0
  131. package/lib/orm/Typo/Adapter.js +1 -0
  132. package/lib/orm/Typo/DMLDriver.d.ts +210 -0
  133. package/lib/orm/Typo/DMLDriver.js +1 -0
  134. package/lib/orm/Typo/Db.d.ts +38 -0
  135. package/lib/orm/Typo/Db.js +1 -0
  136. package/lib/orm/Typo/Error.d.ts +31 -0
  137. package/lib/orm/Typo/Error.js +1 -0
  138. package/lib/orm/Typo/ORM.d.ts +233 -0
  139. package/lib/orm/Typo/ORM.js +3 -0
  140. package/lib/orm/Typo/Validators.d.ts +32 -0
  141. package/lib/orm/Typo/Validators.js +2 -0
  142. package/lib/orm/Typo/_common.d.ts +38 -0
  143. package/lib/orm/Typo/_common.js +1 -0
  144. package/lib/orm/Typo/assoc.d.ts +221 -0
  145. package/lib/orm/Typo/assoc.js +1 -0
  146. package/lib/orm/Typo/hook.d.ts +42 -0
  147. package/lib/orm/Typo/hook.js +1 -0
  148. package/lib/orm/Typo/instance.d.ts +157 -0
  149. package/lib/orm/Typo/instance.js +1 -0
  150. package/lib/orm/Typo/model.d.ts +313 -0
  151. package/lib/orm/Typo/model.js +6 -0
  152. package/lib/orm/Typo/patch.d.ts +31 -0
  153. package/lib/orm/Typo/patch.js +1 -0
  154. package/lib/orm/Typo/property.d.ts +57 -0
  155. package/lib/orm/Typo/property.js +1 -0
  156. package/lib/orm/Typo/query.d.ts +216 -0
  157. package/lib/orm/Typo/query.js +1 -0
  158. package/lib/orm/Typo/settings.d.ts +35 -0
  159. package/lib/orm/Typo/settings.js +5 -0
  160. package/lib/orm/Typo/synchronous.d.ts +47 -0
  161. package/lib/orm/Typo/synchronous.js +1 -0
  162. package/lib/orm/Utilities.d.ts +179 -0
  163. package/lib/orm/Utilities.js +975 -0
  164. package/lib/orm/Validators.d.ts +34 -0
  165. package/lib/orm/Validators.js +100 -0
  166. package/lib/orm/Where/common.d.ts +1 -0
  167. package/lib/orm/Where/common.js +7 -0
  168. package/lib/orm/Where/filterDate.d.ts +11 -0
  169. package/lib/orm/Where/filterDate.js +58 -0
  170. package/lib/orm/index.d.ts +68 -0
  171. package/lib/orm/index.js +157 -0
  172. package/lib/orm-core/callback.d.ts +12 -0
  173. package/lib/orm-core/callback.js +1 -0
  174. package/lib/orm-core/dialect.d.ts +80 -0
  175. package/lib/orm-core/dialect.js +1 -0
  176. package/lib/orm-core/error.d.ts +16 -0
  177. package/lib/orm-core/error.js +29 -0
  178. package/lib/orm-core/index.d.ts +6 -0
  179. package/lib/orm-core/index.js +6 -0
  180. package/lib/orm-core/sync.d.ts +12 -0
  181. package/lib/orm-core/sync.js +1 -0
  182. package/lib/orm-core/utils.d.ts +1 -0
  183. package/lib/orm-core/utils.js +5 -0
  184. package/lib/orm-property/Property.d.ts +78 -0
  185. package/lib/orm-property/Property.js +1 -0
  186. package/lib/orm-property/Utils.d.ts +9 -0
  187. package/lib/orm-property/Utils.js +13 -0
  188. package/lib/orm-property/customTypes.d.ts +2 -0
  189. package/lib/orm-property/customTypes.js +13 -0
  190. package/lib/orm-property/index.d.ts +10 -0
  191. package/lib/orm-property/index.js +22 -0
  192. package/lib/orm-property/transformer.d.ts +5 -0
  193. package/lib/orm-property/transformer.js +10 -0
  194. package/lib/orm-property/transformers/dm.d.ts +29 -0
  195. package/lib/orm-property/transformers/dm.js +237 -0
  196. package/lib/orm-property/transformers/index.d.ts +4 -0
  197. package/lib/orm-property/transformers/index.js +5 -0
  198. package/lib/orm-property/transformers/mysql.d.ts +102 -0
  199. package/lib/orm-property/transformers/mysql.js +261 -0
  200. package/lib/orm-property/transformers/postgresql.d.ts +54 -0
  201. package/lib/orm-property/transformers/postgresql.js +189 -0
  202. package/lib/orm-property/transformers/sqlite.d.ts +19 -0
  203. package/lib/orm-property/transformers/sqlite.js +171 -0
  204. package/lib/sql-ddl-sync/Dialects/dm.d.ts +40 -0
  205. package/lib/sql-ddl-sync/Dialects/dm.js +296 -0
  206. package/lib/sql-ddl-sync/Dialects/index.d.ts +7 -0
  207. package/lib/sql-ddl-sync/Dialects/index.js +7 -0
  208. package/lib/sql-ddl-sync/Dialects/mysql.d.ts +39 -0
  209. package/lib/sql-ddl-sync/Dialects/mysql.js +240 -0
  210. package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +40 -0
  211. package/lib/sql-ddl-sync/Dialects/postgresql.js +286 -0
  212. package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +44 -0
  213. package/lib/sql-ddl-sync/Dialects/sqlite.js +256 -0
  214. package/lib/sql-ddl-sync/SQL.d.ts +12 -0
  215. package/lib/sql-ddl-sync/SQL.js +108 -0
  216. package/lib/sql-ddl-sync/Typo/Collection.d.ts +13 -0
  217. package/lib/sql-ddl-sync/Typo/Collection.js +1 -0
  218. package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +13 -0
  219. package/lib/sql-ddl-sync/Typo/DbIndex.js +1 -0
  220. package/lib/sql-ddl-sync/Typo/Dialect.d.ts +81 -0
  221. package/lib/sql-ddl-sync/Typo/Dialect.js +1 -0
  222. package/lib/sql-ddl-sync/Typo/Driver.d.ts +53 -0
  223. package/lib/sql-ddl-sync/Typo/Driver.js +1 -0
  224. package/lib/sql-ddl-sync/Typo/Query.d.ts +7 -0
  225. package/lib/sql-ddl-sync/Typo/Query.js +1 -0
  226. package/lib/sql-ddl-sync/Typo/SQL.d.ts +31 -0
  227. package/lib/sql-ddl-sync/Typo/SQL.js +1 -0
  228. package/lib/sql-ddl-sync/Typo/_common.d.ts +29 -0
  229. package/lib/sql-ddl-sync/Typo/_common.js +1 -0
  230. package/lib/sql-ddl-sync/Utils.d.ts +40 -0
  231. package/lib/sql-ddl-sync/Utils.js +217 -0
  232. package/lib/sql-ddl-sync/index.d.ts +87 -0
  233. package/lib/sql-ddl-sync/index.js +371 -0
  234. package/lib/sql-query/Comparators.d.ts +3 -0
  235. package/lib/sql-query/Comparators.js +94 -0
  236. package/lib/sql-query/Create.d.ts +35 -0
  237. package/lib/sql-query/Create.js +77 -0
  238. package/lib/sql-query/Dialects/dm.d.ts +3 -0
  239. package/lib/sql-query/Dialects/dm.js +74 -0
  240. package/lib/sql-query/Dialects/index.d.ts +10 -0
  241. package/lib/sql-query/Dialects/index.js +12 -0
  242. package/lib/sql-query/Dialects/mssql.d.ts +3 -0
  243. package/lib/sql-query/Dialects/mssql.js +73 -0
  244. package/lib/sql-query/Dialects/mysql.d.ts +3 -0
  245. package/lib/sql-query/Dialects/mysql.js +100 -0
  246. package/lib/sql-query/Dialects/postgresql.d.ts +3 -0
  247. package/lib/sql-query/Dialects/postgresql.js +76 -0
  248. package/lib/sql-query/Dialects/sqlite.d.ts +3 -0
  249. package/lib/sql-query/Dialects/sqlite.js +61 -0
  250. package/lib/sql-query/Helpers.d.ts +38 -0
  251. package/lib/sql-query/Helpers.js +259 -0
  252. package/lib/sql-query/Insert.d.ts +12 -0
  253. package/lib/sql-query/Insert.js +33 -0
  254. package/lib/sql-query/Query.d.ts +29 -0
  255. package/lib/sql-query/Query.js +119 -0
  256. package/lib/sql-query/Remove.d.ts +16 -0
  257. package/lib/sql-query/Remove.js +93 -0
  258. package/lib/sql-query/Select.d.ts +62 -0
  259. package/lib/sql-query/Select.js +533 -0
  260. package/lib/sql-query/Set.d.ts +4 -0
  261. package/lib/sql-query/Set.js +16 -0
  262. package/lib/sql-query/Typo/Aggregation.d.ts +32 -0
  263. package/lib/sql-query/Typo/Aggregation.js +1 -0
  264. package/lib/sql-query/Typo/Comparators.d.ts +140 -0
  265. package/lib/sql-query/Typo/Comparators.js +1 -0
  266. package/lib/sql-query/Typo/Dialect.d.ts +39 -0
  267. package/lib/sql-query/Typo/Dialect.js +1 -0
  268. package/lib/sql-query/Typo/Field.d.ts +8 -0
  269. package/lib/sql-query/Typo/Field.js +1 -0
  270. package/lib/sql-query/Typo/Helper.d.ts +4 -0
  271. package/lib/sql-query/Typo/Helper.js +1 -0
  272. package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +80 -0
  273. package/lib/sql-query/Typo/Query-ChainBuilder.js +1 -0
  274. package/lib/sql-query/Typo/Query.d.ts +34 -0
  275. package/lib/sql-query/Typo/Query.js +16 -0
  276. package/lib/sql-query/Typo/Sql.d.ts +143 -0
  277. package/lib/sql-query/Typo/Sql.js +1 -0
  278. package/lib/sql-query/Typo/SubQuery.d.ts +39 -0
  279. package/lib/sql-query/Typo/SubQuery.js +1 -0
  280. package/lib/sql-query/Typo/index.d.ts +9 -0
  281. package/lib/sql-query/Typo/index.js +1 -0
  282. package/lib/sql-query/Update.d.ts +15 -0
  283. package/lib/sql-query/Update.js +38 -0
  284. package/lib/sql-query/Where.d.ts +4 -0
  285. package/lib/sql-query/Where.js +280 -0
  286. package/package.json +72 -36
  287. package/.travis.yml +0 -14
  288. package/@types/index.d.ts +0 -193
  289. package/@types/orm_mirror/orm.d.ts +0 -275
  290. package/@types/orm_mirror/sql-query.d.ts +0 -79
  291. package/Readme.md +0 -843
  292. package/lib/index.js +0 -13
  293. package/lib/modules/mysql.js +0 -35
  294. package/lib/modules/sqlite3.js +0 -27
  295. package/lib/patch.js +0 -271
@@ -0,0 +1,280 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.build = void 0;
3
+ const Helpers = require("./Helpers");
4
+ const ComparatorsHash = require("./Comparators");
5
+ function build(knexQueryBuilder, Dialect, whereList, opts) {
6
+ if (whereList.length === 0) {
7
+ return;
8
+ }
9
+ for (let i = 0; i < whereList.length; i++) {
10
+ buildOrGroup(knexQueryBuilder, Dialect, whereList[i], opts);
11
+ }
12
+ }
13
+ exports.build = build;
14
+ ;
15
+ const WHERE_CONJUNCTIONS = ["or", "and", "not_or", "not_and", "not"];
16
+ const NOT_PREFIX_LEN = 'not_'.length;
17
+ function isKeyConjunctionNot(k) {
18
+ return k.indexOf("_") >= 0;
19
+ }
20
+ function buildOrGroup(knexQueryBuilder, Dialect, where, opts, nextPrefixedOpWord, innerInfo) {
21
+ opts = opts || {};
22
+ if (where.exists) {
23
+ buildExistsSqlFragments(knexQueryBuilder, Dialect, where, opts);
24
+ return;
25
+ }
26
+ let query = [], op, transformed_result_op = op;
27
+ for (let k in where.wheres) {
28
+ let where_conditem_value = where.wheres[k];
29
+ if (where_conditem_value === null || where_conditem_value === undefined) {
30
+ // ? in subquery
31
+ knexQueryBuilder.whereNull(k);
32
+ continue;
33
+ }
34
+ // `not` is an alias for `not_and`
35
+ if (isConjunctionWhereConditionInput(k, where_conditem_value)) {
36
+ let conjunctionWord = k.toLocaleLowerCase();
37
+ /**
38
+ * @values FxSqlQueryComparator.QueryConjunctionWord
39
+ */
40
+ transformed_result_op = (k == "not" ? "and" : (isKeyConjunctionNot(k) ? k.substr(NOT_PREFIX_LEN) : k)).toUpperCase();
41
+ const conjunction_where_list = where_conditem_value;
42
+ let { nextOperator: parentConjuncWhereClosureOperator, } = selectWhereOperatorByCtx(nextPrefixedOpWord);
43
+ let { nextOperator: wrapperConjuncWhereClosureOperator, conjunction: innerConjunction, suffix: innerSuffix, } = selectWhereOperatorByCtx(conjunctionWord);
44
+ if (wrapperConjuncWhereClosureOperator === 'whereNot')
45
+ wrapperConjuncWhereClosureOperator = selectWhereOperatorByCtx('not', innerSuffix, innerConjunction).nextOperator;
46
+ const p_call = function (cb) {
47
+ knexQueryBuilder[parentConjuncWhereClosureOperator].call(knexQueryBuilder, cb);
48
+ };
49
+ const loop_inner_call = function () {
50
+ const innerOperator = selectWhereOperatorByCtx(undefined, innerSuffix, innerConjunction).nextOperator;
51
+ for (let j = 0; j < conjunction_where_list.length; j++) {
52
+ const conj_c = conjunction_where_list[j];
53
+ this[wrapperConjuncWhereClosureOperator].call(this, function () {
54
+ buildOrGroup(this, Dialect, { table: where.table, wheres: conj_c }, opts, null, {
55
+ innerOperator: j === 0 ? undefined : innerOperator
56
+ });
57
+ });
58
+ }
59
+ };
60
+ p_call(loop_inner_call);
61
+ continue;
62
+ }
63
+ let { innerOperator = 'where', } = innerInfo || {};
64
+ const normalizedKey = getComparisonKey(Dialect, where.table, k);
65
+ let non_conj_where_conditem_value = transformSqlComparatorLiteralObject(where_conditem_value) || where_conditem_value;
66
+ if (isSqlComparatorPayload(non_conj_where_conditem_value)) {
67
+ op = non_conj_where_conditem_value.sql_comparator();
68
+ switch (op) {
69
+ case "between":
70
+ innerOperator = selectWhereOperatorByCtx(nextPrefixedOpWord, 'between').nextOperator;
71
+ knexQueryBuilder[innerOperator].call(knexQueryBuilder, normalizedKey, [non_conj_where_conditem_value.from, non_conj_where_conditem_value.to]);
72
+ break;
73
+ case "not_between":
74
+ innerOperator = selectWhereOperatorByCtx(nextPrefixedOpWord, 'notBetween').nextOperator;
75
+ knexQueryBuilder[innerOperator].call(knexQueryBuilder, normalizedKey, [non_conj_where_conditem_value.from, non_conj_where_conditem_value.to]);
76
+ break;
77
+ case "like":
78
+ innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator;
79
+ knexQueryBuilder[innerOperator].call(knexQueryBuilder, normalizedKey, 'like', Helpers.escapeValForKnex(non_conj_where_conditem_value.expr, Dialect, opts));
80
+ break;
81
+ case "not_like":
82
+ innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator;
83
+ knexQueryBuilder[innerOperator].call(knexQueryBuilder, normalizedKey, 'not like', Helpers.escapeValForKnex(non_conj_where_conditem_value.expr, Dialect, opts));
84
+ break;
85
+ case "eq":
86
+ case "ne":
87
+ case "gt":
88
+ case "gte":
89
+ case "lt":
90
+ case "lte":
91
+ case "in":
92
+ case "not_in":
93
+ switch (op) {
94
+ case "eq":
95
+ transformed_result_op = (non_conj_where_conditem_value.val === null ? "IS" : "=");
96
+ break;
97
+ case "ne":
98
+ transformed_result_op = (non_conj_where_conditem_value.val === null ? "IS NOT" : "<>");
99
+ break;
100
+ case "gt":
101
+ transformed_result_op = ">";
102
+ break;
103
+ case "gte":
104
+ transformed_result_op = ">=";
105
+ break;
106
+ case "lt":
107
+ transformed_result_op = "<";
108
+ break;
109
+ case "lte":
110
+ transformed_result_op = "<=";
111
+ break;
112
+ case "in":
113
+ transformed_result_op = "IN";
114
+ break;
115
+ case "not_in":
116
+ transformed_result_op = "NOT IN";
117
+ break;
118
+ }
119
+ let val = non_conj_where_conditem_value.val;
120
+ innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator;
121
+ if (!isInStyleOperator(op, non_conj_where_conditem_value)
122
+ && val !== null
123
+ && non_conj_where_conditem_value.asIdentifier) {
124
+ val = Dialect.knex.ref(val);
125
+ }
126
+ knexQueryBuilder[innerOperator].call(knexQueryBuilder, normalizedKey, transformed_result_op, Helpers.escapeValForKnex(val, Dialect, opts));
127
+ break;
128
+ }
129
+ continue;
130
+ }
131
+ if (isUnderscoreSqlInput(k, non_conj_where_conditem_value)) {
132
+ if (!Array.isArray(non_conj_where_conditem_value)
133
+ || (non_conj_where_conditem_value[0] && non_conj_where_conditem_value[0].length < 1)) {
134
+ throw new Error(`invalid value for ${k}, expected its 2 dimension array like __sql: [ ['expr with ? or ??', ['value', 'id']], ['SQL'], ... ]`);
135
+ }
136
+ for (let i = 0; i < non_conj_where_conditem_value.length; i++) {
137
+ knexQueryBuilder.whereRaw(normalizeSqlConditions(Dialect, non_conj_where_conditem_value[i]));
138
+ }
139
+ }
140
+ else {
141
+ /**
142
+ * array as 'IN'
143
+ */
144
+ if (Array.isArray(non_conj_where_conditem_value)) {
145
+ innerOperator = selectWhereOperatorByCtx(nextPrefixedOpWord, 'in').nextOperator;
146
+ knexQueryBuilder[innerOperator].call(knexQueryBuilder, normalizedKey, Helpers.escapeValForKnex(non_conj_where_conditem_value, Dialect, opts));
147
+ }
148
+ else { // finally, simplest where-equal
149
+ const simple_value = non_conj_where_conditem_value;
150
+ innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator;
151
+ knexQueryBuilder[innerOperator].call(knexQueryBuilder, normalizedKey, Helpers.escapeValForKnex(simple_value, Dialect, opts));
152
+ }
153
+ }
154
+ }
155
+ if (query.length === 0) {
156
+ return false;
157
+ }
158
+ return query.join(" AND ");
159
+ }
160
+ function selectWhereOperatorByCtx(conjunctionWord, suffix, prefix) {
161
+ const result = {
162
+ nextOperator: 'where',
163
+ conjunction: 'and',
164
+ suffix: undefined,
165
+ prefix: undefined,
166
+ };
167
+ switch (conjunctionWord) {
168
+ case 'not_and':
169
+ case 'not':
170
+ result.nextOperator = 'whereNot';
171
+ result.conjunction = 'and';
172
+ break;
173
+ case 'and':
174
+ result.nextOperator = 'where';
175
+ break;
176
+ case 'or':
177
+ result.nextOperator = 'orWhere';
178
+ result.conjunction = 'or';
179
+ break;
180
+ case 'not_or':
181
+ result.nextOperator = 'whereNot';
182
+ result.conjunction = 'or';
183
+ break;
184
+ default:
185
+ result.nextOperator = 'where';
186
+ break;
187
+ }
188
+ if (result.suffix = suffix)
189
+ result.nextOperator = `${result.nextOperator}${Helpers.ucfirst(suffix)}`;
190
+ if (result.prefix = prefix)
191
+ result.nextOperator = `${prefix}${Helpers.ucfirst(result.nextOperator)}`;
192
+ return result;
193
+ }
194
+ function buildExistsSqlFragments(knexQueryBuilder, Dialect, where, opts) {
195
+ /* start of deal with case `whereExists` */
196
+ const link_table = where.exists.table_linked;
197
+ knexQueryBuilder.whereExists(function () {
198
+ this.select('*')
199
+ .from(where.exists.table);
200
+ /**
201
+ * @example whereExists('table2', 'table1', [['fid1', 'fid2'], ['id1', 'id2']], { col1: 1, col2: 2 })
202
+ */
203
+ if (Array.isArray(where.exists.link_info[0]) && Array.isArray(where.exists.link_info[1])) {
204
+ const col_tuple_for_aligning_from = where.exists.link_info[0];
205
+ const col_tuple_for_aligning_to = where.exists.link_info[1];
206
+ for (let i = 0; i < col_tuple_for_aligning_from.length; i++) {
207
+ this.where(
208
+ // `${col_tuple_for_aligning_from}.${col_tuple_for_aligning_from[i]}`,
209
+ `${col_tuple_for_aligning_from[i]}`, Dialect.knex.ref(col_tuple_for_aligning_to[i]).withSchema(link_table));
210
+ }
211
+ }
212
+ else {
213
+ const [table_from, table_to] = where.exists.link_info;
214
+ /**
215
+ * @example whereExists('table2', 'table1', ['fid', 'id'], { col1: 1, col2: 2 })
216
+ */
217
+ if (table_from && table_to) {
218
+ this.where(
219
+ // `${where.exists.table}.${table_from}`,
220
+ `${table_from}`, Dialect.knex.ref(table_to).withSchema(link_table));
221
+ }
222
+ }
223
+ buildOrGroup(this, Dialect, { table: null, wheres: where.wheres }, opts);
224
+ });
225
+ }
226
+ function getComparisonKey(Dialect, table, column) {
227
+ if (!table)
228
+ return column;
229
+ return Dialect.knex.ref(column).withSchema(table);
230
+ }
231
+ function normalizeSqlConditions(Dialect, queryArray) {
232
+ if (queryArray.length == 1) {
233
+ return queryArray[0];
234
+ }
235
+ return Helpers.escapeQuery(Dialect, queryArray[0], queryArray[1]);
236
+ }
237
+ function isSqlComparatorPayload(non_special_kv) {
238
+ if (typeof non_special_kv !== 'object')
239
+ return false;
240
+ if (!('sql_comparator' in non_special_kv))
241
+ return false;
242
+ return typeof non_special_kv.sql_comparator === "function";
243
+ }
244
+ function transformSqlComparatorLiteralObject(non_special_kv) {
245
+ if (typeof non_special_kv !== 'object')
246
+ return false;
247
+ const keys = Object.keys(non_special_kv);
248
+ const op = keys.find(k => k in ComparatorsHash);
249
+ if (!op)
250
+ return false;
251
+ const literal_kv = non_special_kv;
252
+ const modifiers = literal_kv.modifiers = literal_kv.modifiers || {};
253
+ const fn = ComparatorsHash[op];
254
+ let input = literal_kv[op];
255
+ // non in-style tuple op contains: `between`, `not_between`
256
+ const is_in_style = ['not_in', 'in'].includes(op);
257
+ const in_input_arr = Array.isArray(input);
258
+ if (modifiers.is_date) {
259
+ let to_filter = in_input_arr ? input : [input];
260
+ const args_0 = (to_filter)
261
+ .map((x) => new Date(x))
262
+ .filter((x) => x + '' !== 'Invalid Date');
263
+ if (args_0.length === to_filter.length) {
264
+ to_filter = args_0;
265
+ input = in_input_arr ? to_filter : to_filter[0];
266
+ }
267
+ }
268
+ const apply_args = in_input_arr && !is_in_style ? input : [input];
269
+ const result = fn.apply(null, apply_args);
270
+ return result;
271
+ }
272
+ function isConjunctionWhereConditionInput(k, where_conditem_value) {
273
+ return WHERE_CONJUNCTIONS.indexOf(k) >= 0;
274
+ }
275
+ function isUnderscoreSqlInput(k, where_conditem_value) {
276
+ return k === '__sql';
277
+ }
278
+ function isInStyleOperator(op, where_conditem_value) {
279
+ return !!~['in', 'not_in'].indexOf(op);
280
+ }
package/package.json CHANGED
@@ -1,38 +1,74 @@
1
1
  {
2
- "name": "fib-orm",
3
- "version": "1.4.1",
4
- "description": "Object Relational Mapping for fibjs",
5
- "main": "lib/index.js",
6
- "types": "@types/index.d.ts",
7
- "repository": "git://github.com/fibjs/fib-orm.git",
8
- "author": "Liu Hu <lion@9465.net>",
9
- "homepage": "https://github.com/fibjs/fib-orm",
10
- "license": "MIT",
11
- "keywords": [
12
- "orm",
13
- "database",
14
- "fibjs"
15
- ],
16
- "scripts": {
17
- "ci": "fibjs test",
18
- "bundle": "fibjs ./build/bundle"
19
- },
20
- "ci": {
21
- "type": "travis",
22
- "version": [
23
- "0.21.0",
24
- "0.22.0",
25
- "0.23.0",
26
- "0.24.0"
27
- ]
28
- },
29
- "dependencies": {
30
- "orm": "^3.2.2"
31
- },
32
- "devDependencies": {
33
- "@fibjs/ci": "^2.0.0",
34
- "@types/fibjs": "github:fibjs/fib-types#v1.0.4",
35
- "fib-typify": "^0.1.0",
36
- "lodash": "^4.17.4"
37
- }
2
+ "name": "fib-orm",
3
+ "version": "2.0.0",
4
+ "description": "ORM for fibjs - unified package",
5
+ "main": "lib/orm/index.js",
6
+ "types": "lib/orm/index.d.ts",
7
+ "exports": {
8
+ ".": "./lib/orm/index.js",
9
+ "./cli": "./lib/cli/index.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/fibjs/fib-orm.git"
14
+ },
15
+ "author": "fibjs",
16
+ "homepage": "https://github.com/fibjs/fib-orm",
17
+ "license": "ISC",
18
+ "keywords": [
19
+ "orm",
20
+ "database",
21
+ "fibjs",
22
+ "mysql",
23
+ "sqlite",
24
+ "postgres",
25
+ "redis"
26
+ ],
27
+ "scripts": {
28
+ "build": "rm -rf ./lib && ftsc $(find src -name '*.ts' ! -name '*.d.ts' ! -path '*/plugins/*' | sort) --outDir ./lib && cp src/codepoints-map.json lib/codepoints-map.json && cp -r src/knex/deps lib/knex/deps",
29
+ "test": "fibjs test",
30
+ "ci": "npm run ci-sqlite",
31
+ "ci-mysql": "npm run build && cross-env ORM_PROTOCOL=mysql npm run test",
32
+ "ci-sqlite": "npm run build && cross-env ORM_PROTOCOL=sqlite npm run test",
33
+ "ci-postgres": "npm run build && cross-env ORM_PROTOCOL=postgres npm run test"
34
+ },
35
+ "dependencies": {
36
+ "@fibjs/enforce": "^0.1.1",
37
+ "@fibcli/make-cli": "^0.1.6",
38
+ "@fibcli/ora": "^0.1.0",
39
+ "@fibjs/chalk": "^1.0.0",
40
+ "@types/knex": "^0.16.1",
41
+ "fib-cache": "^1.1.0",
42
+ "fib-kv": "^1.3.1",
43
+ "knex": "^2.5.1",
44
+ "lodash.clonedeep": "^4.5.0",
45
+ "lodash.flatten": "^4.4.0",
46
+ "lodash.merge": "^4.6.1",
47
+ "parse-querystring-dotkey": "^1.0.3",
48
+ "rxjs": "^6.5.2",
49
+ "@types/diff": "^5.0.2",
50
+ "@types/semver": "^7.3.10",
51
+ "diff": "^5.1.0",
52
+ "semver": "^7.3.7"
53
+ },
54
+ "devDependencies": {
55
+ "@fibjs/types": "^0.35.0",
56
+ "@types/lodash.clonedeep": "^4.5.6",
57
+ "@types/lodash.flatten": "^4.4.6",
58
+ "@types/lodash.merge": "^4.6.6",
59
+ "cross-env": "^5.2.0",
60
+ "fib-typify": "^0.11.3",
61
+ "rimraf": "^3.0.2",
62
+ "ts-expect": "^1.3.0"
63
+ },
64
+ "engines": {
65
+ "fibjs": ">= 0.33.0"
66
+ },
67
+ "private": false,
68
+ "files": [
69
+ "lib"
70
+ ],
71
+ "publishConfig": {
72
+ "access": "public"
73
+ }
38
74
  }
package/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: node_js
2
- node_js: '6'
3
- env:
4
- - VERSION=0.21.0
5
- - VERSION=0.22.0
6
- - VERSION=0.23.0
7
- - VERSION=0.24.0
8
- script:
9
- - npm i
10
- - mkdir -p ./node_modules/.bin
11
- - curl -SL "https://github.com/fibjs/fibjs/releases/download/v${VERSION}/fibjs-v${VERSION}-linux-x64.xz" -o ./node_modules/.bin/fibjs.xz
12
- - xz -d ./node_modules/.bin/fibjs.xz
13
- - chmod a+x ./node_modules/.bin/fibjs
14
- - npm run ci
package/@types/index.d.ts DELETED
@@ -1,193 +0,0 @@
1
- /// <reference path="./orm_mirror/orm.d.ts" />
2
-
3
- import OrmNS = require('orm')
4
- import SqlQueryNS from 'sqlquery'
5
-
6
- declare module "orm" {
7
- /* Connection About Patch :start */
8
-
9
- /**
10
- * it should be defined in 'orm' but there is not, so we should fix it
11
- */
12
- interface ConnInstanceInOrmConnDriverDB {
13
- begin: () => any
14
- commit: () => any
15
- rollback: () => any
16
- trans: (func: Function) => any
17
- execute: Function;
18
- close: Function;
19
- }
20
-
21
- interface DbInstanceInOrmConnDriver {
22
- conn: ConnInstanceInOrmConnDriverDB
23
- }
24
- export interface OrigOrmExecQueryOpts {
25
- [key: string]: any;
26
- }
27
- export interface OrigOrmConnDriver {
28
- // dialog type
29
- dialect: string;
30
- propertyToValue: Function;
31
- valueToProperty: Function;
32
- insert: Function;
33
- db: DbInstanceInOrmConnDriver
34
- }
35
- /**
36
- * then we should patch still
37
- */
38
- export interface PatchedOrmConnDriver extends OrigOrmConnDriver {
39
- execQuerySync: (query: SqlQueryNS.Query, opt: OrigOrmExecQueryOpts) => any
40
- }
41
-
42
- export interface OrmConnectionOpts {
43
- }
44
- /* Connection About Patch :end */
45
-
46
- export interface FibORM extends OrmNS.ORM {
47
- driver: PatchedOrmConnDriver
48
- begin: () => any
49
- commit: () => any
50
- rollback: () => any
51
- trans: (func: Function) => any
52
-
53
- syncSync(): void;
54
- }
55
- // bad annotation but 'db' is used as like 'orm' ever, so we use 'FibOrmDB' to substitute FibORM
56
- type FibOrmDB = FibORM
57
-
58
- export function connectSync(opts: OrmNS.FibORMIConnectionOptions | string): FibOrmDB;
59
-
60
- export interface FibORMIConnectionOptions extends OrmNS.IConnectionOptions {
61
- timezone: string;
62
- }
63
-
64
- interface InstanceAssociationItem {
65
- name: string;
66
- field: OrigModelProperty
67
- // funcname = string;
68
- getAccessor: string;
69
- setAccessor: string;
70
- hasAccessor: string;
71
- delAccessor: string;
72
- addAccessor: string;
73
- }
74
-
75
- interface InstanceOptions extends OrmNS.ModelOptions {
76
- one_associations: InstanceAssociationItem[]
77
- many_associations: InstanceAssociationItem[]
78
- extend_associations: InstanceAssociationItem[]
79
- association_properties: any
80
- fieldToPropertyMap: any
81
- }
82
-
83
- interface PatchedSyncfiedModelOrInstance {
84
- /**
85
- * @important
86
- *
87
- * methods patchSyncfied by 'fib-orm'
88
- */
89
- countSync: Function;
90
- firstSync: Function;
91
- lastSync: Function;
92
- allSync: Function;
93
- whereSync: Function;
94
- findSync: Function;
95
- removeSync: Function;
96
- runSync: Function;
97
- }
98
-
99
- interface PatchedSyncfiedInstanceWithDbWriteOperation extends PatchedSyncfiedModelOrInstance {
100
- saveSync: Function;
101
- removeSync: Function;
102
- validateSync: Function;
103
- modelSync: Function;
104
- }
105
- interface PatchedSyncfiedInstanceWithAssociations {
106
- /**
107
- * generated by association, but you don't know what it is
108
- */
109
- /* getXxx: Function; */
110
- /* setXxx: Function; */
111
- /* removeXxx: Function; */
112
-
113
- /* findByXxx: Function; */
114
- [associationFunc: string]: Function;
115
- }
116
-
117
- // keep compatible to orig one in 'orm'
118
- interface OrigModelProperty extends OrmNS.Property {
119
- /**
120
- * text | number | integer | boolean | date | enum | object | <del>point</del> | binary | serial
121
- * view details in https://github.com/dresende/node-orm2/wiki/Model-Properties
122
- */
123
- type: string
124
- }
125
- type OrigAggreteGenerator = (...args: any[]) => OrmNS.IAggregated
126
- interface OrigHooks extends OrmNS.Hooks {
127
- afterAutoFetch?: (next?) => void
128
- }
129
-
130
- export interface FibOrmFixedModel extends OrmNS.Model, OrigHooks, PatchedSyncfiedModelOrInstance {
131
- new (): FibOrmFixedModelInstance;
132
- new (...ids: any[]): FibOrmFixedModelInstance;
133
-
134
- allProperties: {
135
- [key: string]: OrigModelProperty
136
- }
137
-
138
- find(): any /* OrmNS.Model|OrmNS.IChainFind */;
139
-
140
- /**
141
- * methods used to add associations
142
- */
143
- hasOne: (...args: any[]) => any;
144
- hasMany: (...args: any[]) => any;
145
- extendsTo: (...args: any[]) => OrmNS.Model;
146
- }
147
-
148
- export interface FibOrmFindLikeQueryObject {
149
- [key: string]: any;
150
- }
151
-
152
- // patch the missing field defined in orm/lib/Instance.js (such as defined by Object.defineProperty)
153
- export interface FibOrmFixedModelInstance extends OrmNS.Instance {
154
- /**
155
- * default property but some has been declared in OrmNS.Instance,
156
- * so we comment it(e.g. `on: Function`)
157
- */
158
- /**(defined) on: Function; */
159
- /**(defined) save: Function; */
160
- saved: boolean;
161
- /**(defined) remove: Function; */
162
- set: Function;
163
- markAsDirty: Function;
164
- dirtyProperties: object;
165
- isInstance: boolean;
166
- isPersisted: boolean;
167
- isShell: boolean;
168
- /**(defined) validate: Function; */
169
- __singleton_uid: string | number;
170
- __opts?: InstanceOptions;
171
- model: OrmNS.Model;
172
-
173
- [extraProperty: string]: any;
174
- }
175
-
176
- export interface FibOrmPatchedSyncfiedInstantce extends PatchedSyncfiedInstanceWithDbWriteOperation, PatchedSyncfiedInstanceWithAssociations {
177
- }
178
-
179
- export interface FibOrmPatchedSyncfiedDueToAggregationInstance {
180
- /* function getXxx() */
181
- }
182
-
183
- // export type FibOrmObjectToPatch =
184
- // FibOrmFixedModel | FibOrmFixedModelInstance
185
- // | FibOrmPatchedSyncfiedInstantce | PatchedSyncfiedInstanceWithDbWriteOperation | PatchedSyncfiedInstanceWithAssociations
186
-
187
- export interface IChainFibORMFind extends PatchedSyncfiedModelOrInstance, SqlQueryNS.SelectQuery {
188
- only(args: string[]): IChainFibORMFind;
189
- only(...args: string[]): IChainFibORMFind;
190
- order(...order: string[]): IChainFibORMFind;
191
- }
192
- /* Orm About Patch :end */
193
- }