fib-orm 1.4.2 → 2.1.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 +75 -0
  5. package/lib/cli/commands/dumpModel.d.ts +2 -0
  6. package/lib/cli/commands/dumpModel.js +107 -0
  7. package/lib/cli/commands/escape.d.ts +2 -0
  8. package/lib/cli/commands/escape.js +69 -0
  9. package/lib/cli/commands/spinner.d.ts +2 -0
  10. package/lib/cli/commands/spinner.js +37 -0
  11. package/lib/cli/commands/upgrade.d.ts +2 -0
  12. package/lib/cli/commands/upgrade.js +66 -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 +25 -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 +19 -0
  19. package/lib/codepoints-map.json +762 -0
  20. package/lib/db-driver/Typo.d.ts +111 -0
  21. package/lib/db-driver/Typo.js +2 -0
  22. package/lib/db-driver/built-ins/base.class.d.ts +91 -0
  23. package/lib/db-driver/built-ins/base.class.js +187 -0
  24. package/lib/db-driver/built-ins/driver-dm.d.ts +17 -0
  25. package/lib/db-driver/built-ins/driver-dm.js +54 -0
  26. package/lib/db-driver/built-ins/driver-mongodb.d.ts +23 -0
  27. package/lib/db-driver/built-ins/driver-mongodb.js +47 -0
  28. package/lib/db-driver/built-ins/driver-mysql.d.ts +17 -0
  29. package/lib/db-driver/built-ins/driver-mysql.js +38 -0
  30. package/lib/db-driver/built-ins/driver-postgresql.d.ts +21 -0
  31. package/lib/db-driver/built-ins/driver-postgresql.js +77 -0
  32. package/lib/db-driver/built-ins/driver-redis.d.ts +11 -0
  33. package/lib/db-driver/built-ins/driver-redis.js +36 -0
  34. package/lib/db-driver/built-ins/driver-sqlite.d.ts +16 -0
  35. package/lib/db-driver/built-ins/driver-sqlite.js +35 -0
  36. package/lib/db-driver/index.d.ts +3 -0
  37. package/lib/db-driver/index.js +5 -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 +4 -0
  56. package/lib/knex/sandbox.d.ts +4 -0
  57. package/lib/knex/sandbox.js +23 -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 +177 -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 +16 -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 +14 -0
  69. package/lib/orm/Associations/_utils.js +53 -0
  70. package/lib/orm/ChainFind.d.ts +3 -0
  71. package/lib/orm/ChainFind.js +328 -0
  72. package/lib/orm/ChainInstance.d.ts +6 -0
  73. package/lib/orm/ChainInstance.js +74 -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 +2 -0
  77. package/lib/orm/Drivers/DB/base.js +4 -0
  78. package/lib/orm/Drivers/DB/dm.d.ts +9 -0
  79. package/lib/orm/Drivers/DB/dm.js +24 -0
  80. package/lib/orm/Drivers/DB/mysql.d.ts +9 -0
  81. package/lib/orm/Drivers/DB/mysql.js +24 -0
  82. package/lib/orm/Drivers/DB/postgres.d.ts +9 -0
  83. package/lib/orm/Drivers/DB/postgres.js +23 -0
  84. package/lib/orm/Drivers/DB/sqlite3.d.ts +14 -0
  85. package/lib/orm/Drivers/DB/sqlite3.js +40 -0
  86. package/lib/orm/Drivers/DML/_ddl-sql.d.ts +3 -0
  87. package/lib/orm/Drivers/DML/_ddl-sql.js +52 -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 +39 -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 +3 -0
  96. package/lib/orm/Drivers/DML/dm.d.ts +2 -0
  97. package/lib/orm/Drivers/DML/dm.js +294 -0
  98. package/lib/orm/Drivers/DML/index.d.ts +4 -0
  99. package/lib/orm/Drivers/DML/index.js +7 -0
  100. package/lib/orm/Drivers/DML/mysql.d.ts +2 -0
  101. package/lib/orm/Drivers/DML/mysql.js +252 -0
  102. package/lib/orm/Drivers/DML/postgres.d.ts +2 -0
  103. package/lib/orm/Drivers/DML/postgres.js +277 -0
  104. package/lib/orm/Drivers/DML/sqlite.d.ts +2 -0
  105. package/lib/orm/Drivers/DML/sqlite.js +267 -0
  106. package/lib/orm/Error.d.ts +11 -0
  107. package/lib/orm/Error.js +41 -0
  108. package/lib/orm/Helpers.d.ts +35 -0
  109. package/lib/orm/Helpers.js +234 -0
  110. package/lib/orm/Hook.d.ts +13 -0
  111. package/lib/orm/Hook.js +100 -0
  112. package/lib/orm/Instance.d.ts +2 -0
  113. package/lib/orm/Instance.js +698 -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 +6 -0
  117. package/lib/orm/Model.js +974 -0
  118. package/lib/orm/ORM.d.ts +37 -0
  119. package/lib/orm/ORM.js +242 -0
  120. package/lib/orm/Patch/fib-cache.d.ts +39 -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 +14 -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 +120 -0
  128. package/lib/orm/Singleton.d.ts +5 -0
  129. package/lib/orm/Singleton.js +73 -0
  130. package/lib/orm/Typo/Adapter.d.ts +5 -0
  131. package/lib/orm/Typo/Adapter.js +2 -0
  132. package/lib/orm/Typo/DMLDriver.d.ts +209 -0
  133. package/lib/orm/Typo/DMLDriver.js +2 -0
  134. package/lib/orm/Typo/Db.d.ts +35 -0
  135. package/lib/orm/Typo/Db.js +2 -0
  136. package/lib/orm/Typo/Error.d.ts +29 -0
  137. package/lib/orm/Typo/Error.js +2 -0
  138. package/lib/orm/Typo/ORM.d.ts +231 -0
  139. package/lib/orm/Typo/ORM.js +4 -0
  140. package/lib/orm/Typo/Validators.d.ts +31 -0
  141. package/lib/orm/Typo/Validators.js +3 -0
  142. package/lib/orm/Typo/_common.d.ts +37 -0
  143. package/lib/orm/Typo/_common.js +2 -0
  144. package/lib/orm/Typo/assoc.d.ts +221 -0
  145. package/lib/orm/Typo/assoc.js +2 -0
  146. package/lib/orm/Typo/hook.d.ts +42 -0
  147. package/lib/orm/Typo/hook.js +2 -0
  148. package/lib/orm/Typo/instance.d.ts +156 -0
  149. package/lib/orm/Typo/instance.js +2 -0
  150. package/lib/orm/Typo/model.d.ts +311 -0
  151. package/lib/orm/Typo/model.js +7 -0
  152. package/lib/orm/Typo/patch.d.ts +31 -0
  153. package/lib/orm/Typo/patch.js +2 -0
  154. package/lib/orm/Typo/property.d.ts +57 -0
  155. package/lib/orm/Typo/property.js +2 -0
  156. package/lib/orm/Typo/query.d.ts +216 -0
  157. package/lib/orm/Typo/query.js +2 -0
  158. package/lib/orm/Typo/settings.d.ts +35 -0
  159. package/lib/orm/Typo/settings.js +6 -0
  160. package/lib/orm/Typo/synchronous.d.ts +47 -0
  161. package/lib/orm/Typo/synchronous.js +2 -0
  162. package/lib/orm/Utilities.d.ts +178 -0
  163. package/lib/orm/Utilities.js +975 -0
  164. package/lib/orm/Validators.d.ts +33 -0
  165. package/lib/orm/Validators.js +101 -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 +67 -0
  171. package/lib/orm/index.js +158 -0
  172. package/lib/orm-core/callback.d.ts +12 -0
  173. package/lib/orm-core/callback.js +2 -0
  174. package/lib/orm-core/dialect.d.ts +80 -0
  175. package/lib/orm-core/dialect.js +2 -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 +7 -0
  180. package/lib/orm-core/sync.d.ts +12 -0
  181. package/lib/orm-core/sync.js +2 -0
  182. package/lib/orm-core/utils.d.ts +1 -0
  183. package/lib/orm-core/utils.js +6 -0
  184. package/lib/orm-property/Property.d.ts +78 -0
  185. package/lib/orm-property/Property.js +2 -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 +23 -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 +238 -0
  196. package/lib/orm-property/transformers/index.d.ts +4 -0
  197. package/lib/orm-property/transformers/index.js +6 -0
  198. package/lib/orm-property/transformers/mysql.d.ts +101 -0
  199. package/lib/orm-property/transformers/mysql.js +262 -0
  200. package/lib/orm-property/transformers/postgresql.d.ts +54 -0
  201. package/lib/orm-property/transformers/postgresql.js +190 -0
  202. package/lib/orm-property/transformers/sqlite.d.ts +19 -0
  203. package/lib/orm-property/transformers/sqlite.js +172 -0
  204. package/lib/sql-ddl-sync/Dialects/dm.d.ts +39 -0
  205. package/lib/sql-ddl-sync/Dialects/dm.js +297 -0
  206. package/lib/sql-ddl-sync/Dialects/index.d.ts +6 -0
  207. package/lib/sql-ddl-sync/Dialects/index.js +8 -0
  208. package/lib/sql-ddl-sync/Dialects/mysql.d.ts +38 -0
  209. package/lib/sql-ddl-sync/Dialects/mysql.js +241 -0
  210. package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +39 -0
  211. package/lib/sql-ddl-sync/Dialects/postgresql.js +287 -0
  212. package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +43 -0
  213. package/lib/sql-ddl-sync/Dialects/sqlite.js +257 -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 +2 -0
  218. package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +13 -0
  219. package/lib/sql-ddl-sync/Typo/DbIndex.js +2 -0
  220. package/lib/sql-ddl-sync/Typo/Dialect.d.ts +81 -0
  221. package/lib/sql-ddl-sync/Typo/Dialect.js +2 -0
  222. package/lib/sql-ddl-sync/Typo/Driver.d.ts +53 -0
  223. package/lib/sql-ddl-sync/Typo/Driver.js +2 -0
  224. package/lib/sql-ddl-sync/Typo/Query.d.ts +7 -0
  225. package/lib/sql-ddl-sync/Typo/Query.js +2 -0
  226. package/lib/sql-ddl-sync/Typo/SQL.d.ts +31 -0
  227. package/lib/sql-ddl-sync/Typo/SQL.js +2 -0
  228. package/lib/sql-ddl-sync/Typo/_common.d.ts +29 -0
  229. package/lib/sql-ddl-sync/Typo/_common.js +2 -0
  230. package/lib/sql-ddl-sync/Utils.d.ts +39 -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 +372 -0
  234. package/lib/sql-query/Comparators.d.ts +3 -0
  235. package/lib/sql-query/Comparators.js +95 -0
  236. package/lib/sql-query/Create.d.ts +35 -0
  237. package/lib/sql-query/Create.js +78 -0
  238. package/lib/sql-query/Dialects/dm.d.ts +3 -0
  239. package/lib/sql-query/Dialects/dm.js +75 -0
  240. package/lib/sql-query/Dialects/index.d.ts +10 -0
  241. package/lib/sql-query/Dialects/index.js +13 -0
  242. package/lib/sql-query/Dialects/mssql.d.ts +3 -0
  243. package/lib/sql-query/Dialects/mssql.js +74 -0
  244. package/lib/sql-query/Dialects/mysql.d.ts +3 -0
  245. package/lib/sql-query/Dialects/mysql.js +101 -0
  246. package/lib/sql-query/Dialects/postgresql.d.ts +3 -0
  247. package/lib/sql-query/Dialects/postgresql.js +77 -0
  248. package/lib/sql-query/Dialects/sqlite.d.ts +3 -0
  249. package/lib/sql-query/Dialects/sqlite.js +62 -0
  250. package/lib/sql-query/Helpers.d.ts +37 -0
  251. package/lib/sql-query/Helpers.js +260 -0
  252. package/lib/sql-query/Insert.d.ts +12 -0
  253. package/lib/sql-query/Insert.js +34 -0
  254. package/lib/sql-query/Query.d.ts +28 -0
  255. package/lib/sql-query/Query.js +120 -0
  256. package/lib/sql-query/Remove.d.ts +16 -0
  257. package/lib/sql-query/Remove.js +94 -0
  258. package/lib/sql-query/Select.d.ts +62 -0
  259. package/lib/sql-query/Select.js +534 -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 +2 -0
  264. package/lib/sql-query/Typo/Comparators.d.ts +140 -0
  265. package/lib/sql-query/Typo/Comparators.js +2 -0
  266. package/lib/sql-query/Typo/Dialect.d.ts +39 -0
  267. package/lib/sql-query/Typo/Dialect.js +2 -0
  268. package/lib/sql-query/Typo/Field.d.ts +8 -0
  269. package/lib/sql-query/Typo/Field.js +2 -0
  270. package/lib/sql-query/Typo/Helper.d.ts +4 -0
  271. package/lib/sql-query/Typo/Helper.js +2 -0
  272. package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +80 -0
  273. package/lib/sql-query/Typo/Query-ChainBuilder.js +2 -0
  274. package/lib/sql-query/Typo/Query.d.ts +34 -0
  275. package/lib/sql-query/Typo/Query.js +17 -0
  276. package/lib/sql-query/Typo/Sql.d.ts +143 -0
  277. package/lib/sql-query/Typo/Sql.js +2 -0
  278. package/lib/sql-query/Typo/SubQuery.d.ts +39 -0
  279. package/lib/sql-query/Typo/SubQuery.js +2 -0
  280. package/lib/sql-query/Typo/index.d.ts +9 -0
  281. package/lib/sql-query/Typo/index.js +2 -0
  282. package/lib/sql-query/Update.d.ts +15 -0
  283. package/lib/sql-query/Update.js +39 -0
  284. package/lib/sql-query/Where.d.ts +4 -0
  285. package/lib/sql-query/Where.js +280 -0
  286. package/package.json +71 -36
  287. package/.travis.yml +0 -14
  288. package/@types/index.d.ts +0 -254
  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,19 @@
1
+ import { FxSqlQueryColumns } from "../../../sql-query/Query";
2
+ import { FxOrmDMLDriver } from "../../Typo/DMLDriver";
3
+ import { FxOrmInstance } from "../../Typo/instance";
4
+ import { FxOrmProperty } from "../../Typo/property";
5
+ export declare function safeParseJson<T extends object>(input: string | T, fallbackValue?: any): T;
6
+ export declare function normalizePropertyValueOnFound(data: FxOrmInstance.InstanceDataPayload, property: FxOrmProperty.NormalizedProperty, ctx: {
7
+ driver: FxOrmDMLDriver.DMLDriver;
8
+ }): FxOrmInstance.InstanceDataPayload;
9
+ export declare function pickPointTypeFields(dmlDriver: FxOrmDMLDriver.DMLDriver, modelProperties: Record<string, FxOrmProperty.NormalizedProperty>): string[];
10
+ export declare function filterFieldsOnFind(ctx: {
11
+ dmlDriver: FxOrmDMLDriver.DMLDriver;
12
+ pointPropertiesMapsTo: string[];
13
+ }, ret: {
14
+ selectFields: FxSqlQueryColumns.SelectInputArgType[];
15
+ }): void;
16
+ /**
17
+ * @description for point from sqlite, which stored as text actually
18
+ */
19
+ export declare function unwrapQuote(stringVal: string): string;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safeParseJson = safeParseJson;
4
+ exports.normalizePropertyValueOnFound = normalizePropertyValueOnFound;
5
+ exports.pickPointTypeFields = pickPointTypeFields;
6
+ exports.filterFieldsOnFind = filterFieldsOnFind;
7
+ exports.unwrapQuote = unwrapQuote;
8
+ function safeParseJson(input, fallbackValue = {}) {
9
+ if (typeof input !== 'string') {
10
+ return input;
11
+ }
12
+ try {
13
+ return JSON.parse(input);
14
+ }
15
+ catch (e) {
16
+ return fallbackValue;
17
+ }
18
+ }
19
+ function normalizePropertyValueOnFound(data, property, ctx) {
20
+ if (ctx.driver.db.type !== 'mysql')
21
+ return;
22
+ if (property.type === 'point') {
23
+ }
24
+ return data;
25
+ }
26
+ function pickPointTypeFields(dmlDriver, modelProperties) {
27
+ if (!['mysql', 'sqlite', 'dm'].includes(dmlDriver.db.type))
28
+ return [];
29
+ return Object.values(modelProperties)
30
+ .filter(p => p.type === 'point')
31
+ .map(p => p.mapsTo);
32
+ }
33
+ function filterFieldsOnFind(ctx, ret) {
34
+ if (ctx.dmlDriver.db.type !== 'mysql')
35
+ return;
36
+ ctx.pointPropertiesMapsTo.forEach(mapsTo => {
37
+ const idx = ret.selectFields.indexOf(mapsTo);
38
+ if (idx === -1)
39
+ return;
40
+ ret.selectFields[idx] = {
41
+ sql: `CONCAT('{','\"x\":', ST_X(${mapsTo}), ',','\"y\":', ST_Y(${mapsTo}),'}')`,
42
+ as: mapsTo,
43
+ };
44
+ });
45
+ }
46
+ /**
47
+ * @description for point from sqlite, which stored as text actually
48
+ */
49
+ function unwrapQuote(stringVal) {
50
+ return stringVal.replace(/(?:^\'|\'$)/g, '');
51
+ }
@@ -0,0 +1,9 @@
1
+ import type { FxSqlQuerySql } from '../../../sql-query/Query';
2
+ import type { FxOrmAssociation } from '../../Typo/assoc';
3
+ import type { FxOrmDMLDriver } from '../../Typo/DMLDriver';
4
+ import type { FxOrmQuery } from '../../Typo/query';
5
+ import type { FxOrmCommon } from '../../Typo/_common';
6
+ export declare function execQuery<T = any>(this: FxOrmDMLDriver.DMLDriver): T;
7
+ export declare function eagerQuery<T = any>(this: FxOrmDMLDriver.DMLDriver, association: FxOrmAssociation.InstanceAssociationItem, opts: FxOrmQuery.ChainFindOptions, keys: string[], cb: FxOrmCommon.ExecutionCallback<T>): T;
8
+ export declare const poolQuery: FxOrmDMLDriver.DMLDriver['poolQuery'];
9
+ export declare function execQuerySync(this: FxOrmDMLDriver.DMLDriver, query: string, opt: FxSqlQuerySql.SqlEscapeArgType[]): any;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.poolQuery = void 0;
4
+ exports.execQuery = execQuery;
5
+ exports.eagerQuery = eagerQuery;
6
+ exports.execQuerySync = execQuerySync;
7
+ const util = require("util");
8
+ function execQuery() {
9
+ var query, cb;
10
+ const args = Array.prototype.slice.apply(arguments);
11
+ if (typeof util.last(args) === 'function')
12
+ cb = args.pop();
13
+ query = this.query.escape.apply(this.query, args);
14
+ return this.execSimpleQuery(query, cb);
15
+ }
16
+ function eagerQuery(association, opts, keys, cb) {
17
+ var desiredKey = Object.keys(association.field);
18
+ var assocKey = Object.keys(association.mergeAssocId);
19
+ var where = {};
20
+ // TODO: what if $p has composite association keys?
21
+ where[desiredKey[0]] = keys;
22
+ var query = this.query.select()
23
+ .from(association.model.table)
24
+ .select(opts.only)
25
+ .from(association.mergeTable, assocKey, opts.keys)
26
+ .select(desiredKey).as("$p")
27
+ .where(association.mergeTable, where)
28
+ .build();
29
+ return this.execSimpleQuery(query, cb);
30
+ }
31
+ const poolQuery = function (query, cb) {
32
+ return this.db.query(query, cb);
33
+ };
34
+ exports.poolQuery = poolQuery;
35
+ function execQuerySync(query, opt) {
36
+ if (arguments.length == 2)
37
+ query = this.query.escape(query, opt);
38
+ return this.db.execute(query);
39
+ }
@@ -0,0 +1,8 @@
1
+ import type { FxSqlQueryChainBuilder, FxSqlQuerySubQuery } from "../../../sql-query/Query";
2
+ import type { FxOrmDMLDriver } from "../../Typo/DMLDriver";
3
+ export declare function buildBaseConditionsToQuery(this: FxOrmDMLDriver.DMLDriver, q: FxSqlQueryChainBuilder.ChainBuilder__Select, base_table: string, base_conditions?: FxSqlQuerySubQuery.SubQueryConditions, top_conditions?: FxSqlQuerySubQuery.SubQueryConditions): FxSqlQueryChainBuilder.ChainBuilder__Select;
4
+ export declare function buildMergeToQuery(this: FxOrmDMLDriver.DMLDriver, q: FxSqlQueryChainBuilder.ChainBuilder__Select, merges: FxOrmDMLDriver.DMLDriver_FindOptions['merge']): FxSqlQueryChainBuilder.ChainBuilder__Select;
5
+ export declare function buildExistsToQuery(this: FxOrmDMLDriver.DMLDriver, q: FxSqlQueryChainBuilder.ChainBuilder__Select, table_alias: string, exists: FxOrmDMLDriver.DMLDriver_FindOptions['exists']): void;
6
+ export declare function buildOrderToQuery(this: FxOrmDMLDriver.DMLDriver, q: FxSqlQueryChainBuilder.ChainBuilder__Select, order: FxOrmDMLDriver.DMLDriver_FindOptions['order']): void;
7
+ export declare function getKnexInstance(driver: FxOrmDMLDriver.DMLDriver): void;
8
+ export declare function buildMergeToKnex(this: FxOrmDMLDriver.DMLDriver, knex: import("../../../knex/types").Knex, merges: FxOrmDMLDriver.DMLDriver_FindOptions['merge'], conditions: FxSqlQuerySubQuery.SubQueryConditions): void;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildBaseConditionsToQuery = buildBaseConditionsToQuery;
4
+ exports.buildMergeToQuery = buildMergeToQuery;
5
+ exports.buildExistsToQuery = buildExistsToQuery;
6
+ exports.buildOrderToQuery = buildOrderToQuery;
7
+ exports.getKnexInstance = getKnexInstance;
8
+ exports.buildMergeToKnex = buildMergeToKnex;
9
+ function buildBaseConditionsToQuery(q, base_table, base_conditions, top_conditions) {
10
+ if (top_conditions && Object.keys(top_conditions).length) {
11
+ q = q.where(null, top_conditions);
12
+ }
13
+ if (base_conditions && Object.keys(base_conditions).length) {
14
+ q = q.where(base_table, base_conditions);
15
+ }
16
+ return q;
17
+ }
18
+ function buildMergeToQuery(q, merges) {
19
+ if (merges === null || merges === void 0 ? void 0 : merges.length) {
20
+ merges.forEach(merge => {
21
+ /**
22
+ * you should always pass alias as `merge.from.table` --- it's need indicate where base_conditions;
23
+ * you dont need pass alias as `merge.to.table` --- it's dont need indicate where base_conditions;
24
+ */
25
+ q
26
+ .from(merge.from.table, merge.from.field, merge.to.table, merge.to.field)
27
+ .select(merge.select);
28
+ /**
29
+ * this means merge where base_conditions is not empty
30
+ *
31
+ * merge.where[0] is aliased table name,
32
+ * merge.where[1] is where base_conditions
33
+ */
34
+ if (merge.where && Object.keys(merge.where[1]).length) {
35
+ q = q.where(merge.where[0], merge.where[1]);
36
+ }
37
+ });
38
+ }
39
+ return q;
40
+ }
41
+ function buildExistsToQuery(q, table_alias, exists) {
42
+ if (exists) {
43
+ for (let k in exists) {
44
+ const exist_item = exists[k];
45
+ q.whereExists(exist_item.table, table_alias, exist_item.link, exist_item.conditions);
46
+ }
47
+ }
48
+ }
49
+ function buildOrderToQuery(q, order) {
50
+ if (order) {
51
+ for (let i = 0; i < order.length; i++) {
52
+ q.order(order[i][0], order[i][1]);
53
+ }
54
+ }
55
+ }
56
+ function getKnexInstance(driver) {
57
+ if (!driver.query.knex)
58
+ throw new Error(`[getKnexInstance] driver.query.knex must be init firstly!`);
59
+ Object.defineProperty(driver, 'knex', {
60
+ get() {
61
+ return driver.getQuery().knex;
62
+ },
63
+ configurable: false,
64
+ });
65
+ }
66
+ function buildMergeToKnex(knex, merges, conditions) {
67
+ }
@@ -0,0 +1,3 @@
1
+ export declare const enum SpecialFieldsReason {
2
+ MYSQL_POINT = 0
3
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
@@ -0,0 +1,2 @@
1
+ import type { FxOrmDMLDriver } from "../../Typo/DMLDriver";
2
+ export declare const Driver: FxOrmDMLDriver.DMLDriverConstructor;
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Driver = void 0;
4
+ const util = require("util");
5
+ const dm_1 = require("../DB/dm");
6
+ const shared = require("./_shared");
7
+ const DDL = require("./_ddl-sql");
8
+ const Query_1 = require("../../../sql-query/Query");
9
+ const Sync = require("../../../sql-ddl-sync/index");
10
+ const utils = require("./_utils");
11
+ const Utilities = require("../../Utilities");
12
+ const _dml_helpers_1 = require("./_dml-helpers");
13
+ exports.Driver = function (config, connection, opts) {
14
+ this.dialect = 'dm';
15
+ this.opts = opts || {};
16
+ this.customTypes = {};
17
+ Object.defineProperty(this, 'db', {
18
+ value: connection || new dm_1.Database(config),
19
+ writable: false
20
+ });
21
+ Object.defineProperty(this, 'sqlDriver', {
22
+ value: this.db,
23
+ writable: false
24
+ });
25
+ Object.defineProperty(this, 'config', {
26
+ value: this.db.config,
27
+ writable: false
28
+ });
29
+ if (!this.config.timezone)
30
+ this.config.timezone = "local";
31
+ Object.defineProperty(this, 'ddlSync', {
32
+ value: Sync.dialect(this.dialect),
33
+ writable: false
34
+ });
35
+ Object.defineProperty(this, 'query', {
36
+ value: new Query_1.Query({ dialect: this.dialect, timezone: this.config.timezone }),
37
+ writable: false
38
+ });
39
+ utils.getKnexInstance(this);
40
+ this.aggregate_functions = ["ABS", "CEIL", "FLOOR", "ROUND",
41
+ "AVG", "MIN", "MAX",
42
+ "LOG", "LOG2", "LOG10", "EXP", "POWER",
43
+ "ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN",
44
+ "CONV", ["RANDOM", "RAND"], "RADIANS", "DEGREES",
45
+ "SUM", "COUNT",
46
+ "DISTINCT"];
47
+ };
48
+ util.extend(exports.Driver.prototype, shared, DDL);
49
+ exports.Driver.prototype.ping = function (cb) {
50
+ this.db.ping();
51
+ if (cb)
52
+ setImmediate(cb);
53
+ return this;
54
+ };
55
+ exports.Driver.prototype.on = function (ev, cb) {
56
+ if (ev == "error") {
57
+ this.db.eventor.on("error", cb);
58
+ this.db.eventor.on("unhandledError", cb);
59
+ }
60
+ return this;
61
+ };
62
+ exports.Driver.prototype.connect = function (cb) {
63
+ const syncResponse = Utilities.catchBlocking(() => {
64
+ return this.db.connect();
65
+ });
66
+ Utilities.takeAwayResult(syncResponse, { callback: cb });
67
+ return syncResponse.result;
68
+ };
69
+ exports.Driver.prototype.reconnect = function (cb) {
70
+ const connOpts = this.config.href || this.config;
71
+ this.db = new dm_1.Database(connOpts);
72
+ const syncResponse = Utilities.catchBlocking(() => {
73
+ return this.connect();
74
+ });
75
+ if (typeof cb === 'function')
76
+ cb(null, syncResponse.result);
77
+ return syncResponse.result;
78
+ };
79
+ exports.Driver.prototype.close = function (cb) {
80
+ const errResults = Utilities.catchBlocking(() => this.db.close());
81
+ Utilities.takeAwayResult(errResults, { no_throw: !!cb, callback: cb });
82
+ return errResults.result;
83
+ };
84
+ exports.Driver.prototype.getQuery = function () {
85
+ return this.query;
86
+ };
87
+ exports.Driver.prototype.execSimpleQuery = function (query, cb) {
88
+ if (this.opts.debug) {
89
+ require("../../Debug").sql('dm', query);
90
+ }
91
+ return this.db.query(query, cb);
92
+ };
93
+ exports.Driver.prototype.find = function (selectFields, table, conditions, opts) {
94
+ const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
95
+ const __pointTypeMapsTo = opts.__pointTypeMapsTo || [];
96
+ (0, _dml_helpers_1.filterFieldsOnFind)({
97
+ dmlDriver: this,
98
+ pointPropertiesMapsTo: __pointTypeMapsTo,
99
+ }, {
100
+ selectFields,
101
+ });
102
+ const ctx = {
103
+ table,
104
+ fromTuple: from_tuple,
105
+ selectFields,
106
+ selectVirtualFields: opts.selectVirtualFields || []
107
+ };
108
+ let q = this.query.select();
109
+ q = typeof (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect) === 'function' ? (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect.call(this, ctx, q)) || q : Utilities.DEFAULT_GENERATE_SQL_QUERY_SELECT.call(this, ctx, q);
110
+ if (opts.offset) {
111
+ q.offset(opts.offset);
112
+ }
113
+ if (typeof opts.limit == "number") {
114
+ q.limit(opts.limit);
115
+ }
116
+ else if (opts.offset) {
117
+ q.limit('18446744073709551615');
118
+ }
119
+ utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions, opts.topConditions]);
120
+ utils.buildOrderToQuery.apply(this, [q, opts.order]);
121
+ utils.buildMergeToQuery.apply(this, [q, opts.merge, conditions]);
122
+ utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
123
+ const results = this.execSimpleQuery(q.build());
124
+ if (__pointTypeMapsTo.length > 0 && Array.isArray(results)) {
125
+ results.forEach(item => {
126
+ __pointTypeMapsTo.forEach(field => {
127
+ item[field] = (0, _dml_helpers_1.safeParseJson)(item[field]);
128
+ });
129
+ });
130
+ }
131
+ return results;
132
+ };
133
+ exports.Driver.prototype.count = function (table, conditions, opts, cb) {
134
+ const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
135
+ const q = this.query.select()
136
+ .from(from_tuple)
137
+ .count(null, 'c');
138
+ utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions]);
139
+ utils.buildMergeToQuery.apply(this, [q, opts.merge, conditions]);
140
+ utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
141
+ return this.execSimpleQuery(q.build(), cb);
142
+ };
143
+ exports.Driver.prototype.insert = function (table, data, keyProperties, cb) {
144
+ const q = this.query.insert()
145
+ .into(table)
146
+ .set(data)
147
+ .build();
148
+ const syncResponse = Utilities.catchBlocking(() => {
149
+ let info;
150
+ const singleKeyProp = keyProperties && keyProperties.length === 1 ? keyProperties[0] : null;
151
+ const isIdentityKey = !!(singleKeyProp && (singleKeyProp.serial || singleKeyProp.type === 'serial'));
152
+ const explicitIdentity = !!(isIdentityKey && data[singleKeyProp.mapsTo] !== undefined && data[singleKeyProp.mapsTo] !== null);
153
+ if (explicitIdentity) {
154
+ this.execSimpleQuery(`SET IDENTITY_INSERT ${this.query.escapeId(table)} ON`);
155
+ try {
156
+ info = this.execSimpleQuery(q);
157
+ }
158
+ finally {
159
+ this.execSimpleQuery(`SET IDENTITY_INSERT ${this.query.escapeId(table)} OFF`);
160
+ }
161
+ }
162
+ else {
163
+ info = this.execSimpleQuery(q);
164
+ }
165
+ const ids = {};
166
+ if (keyProperties) {
167
+ if (keyProperties.length == 1) {
168
+ const keyProp = keyProperties[0];
169
+ const isIdentityKey = !!(keyProp.serial || keyProp.type === 'serial');
170
+ if (isIdentityKey) {
171
+ if (info && info.hasOwnProperty("insertId") && info.insertId !== 0) {
172
+ ids[keyProp.name] = info.insertId;
173
+ }
174
+ else {
175
+ let identityRes = null;
176
+ try {
177
+ identityRes = this.execSimpleQuery('SELECT @@IDENTITY as id');
178
+ }
179
+ catch (e) { }
180
+ if (identityRes && identityRes[0] && identityRes[0].id !== undefined && identityRes[0].id !== null) {
181
+ ids[keyProp.name] = identityRes[0].id;
182
+ }
183
+ else {
184
+ ids[keyProp.name] = data[keyProp.mapsTo];
185
+ }
186
+ }
187
+ }
188
+ else {
189
+ ids[keyProp.name] = data[keyProp.mapsTo];
190
+ }
191
+ }
192
+ else {
193
+ for (let i = 0, prop; i < keyProperties.length; i++) {
194
+ prop = keyProperties[i];
195
+ ids[prop.name] = data[prop.mapsTo];
196
+ }
197
+ }
198
+ }
199
+ return ids;
200
+ });
201
+ Utilities.takeAwayResult(syncResponse, { callback: cb });
202
+ return syncResponse.result;
203
+ };
204
+ exports.Driver.prototype.update = function (table, changes, conditions, cb) {
205
+ var q = this.query.update()
206
+ .into(table)
207
+ .set(changes)
208
+ .where(conditions)
209
+ .build();
210
+ return this.execSimpleQuery(q, cb);
211
+ };
212
+ exports.Driver.prototype.remove = function (table, conditions, cb) {
213
+ var q = this.query.remove()
214
+ .from(table)
215
+ .where(conditions)
216
+ .build();
217
+ return this.execSimpleQuery(q, cb);
218
+ };
219
+ exports.Driver.prototype.clear = function (table, cb) {
220
+ var q = "TRUNCATE TABLE " + this.query.escapeId(table);
221
+ return this.execSimpleQuery(q, cb);
222
+ };
223
+ exports.Driver.prototype.valueToProperty = function (value, property) {
224
+ var customType;
225
+ switch (property.type) {
226
+ case "point":
227
+ if (typeof value === 'string') {
228
+ value = (0, _dml_helpers_1.safeParseJson)(value, null);
229
+ }
230
+ break;
231
+ case "date":
232
+ if (util.isNumber(value) || util.isString(value))
233
+ value = new Date(value);
234
+ break;
235
+ case "boolean":
236
+ value = !!value;
237
+ break;
238
+ case "object":
239
+ if (typeof value == "object" && !Buffer.isBuffer(value)) {
240
+ break;
241
+ }
242
+ try {
243
+ value = JSON.parse(value);
244
+ }
245
+ catch (e) {
246
+ value = null;
247
+ }
248
+ break;
249
+ case "binary": {
250
+ if (value && value.type === 'Buffer' && Array.isArray(value.data)) {
251
+ value = Buffer.from(value.data);
252
+ }
253
+ break;
254
+ }
255
+ default:
256
+ customType = this.customTypes[property.type];
257
+ if (customType && 'valueToProperty' in customType) {
258
+ value = customType.valueToProperty(value, property);
259
+ }
260
+ }
261
+ return value;
262
+ };
263
+ exports.Driver.prototype.propertyToValue = function (value, property) {
264
+ var customType;
265
+ switch (property.type) {
266
+ case "point":
267
+ if (value !== null && value !== undefined) {
268
+ value = JSON.stringify(value);
269
+ }
270
+ break;
271
+ case "object":
272
+ if (value !== null) {
273
+ if (!Buffer.isBuffer(value))
274
+ value = JSON.stringify(value);
275
+ }
276
+ break;
277
+ case "date":
278
+ if (util.isNumber(value) || util.isString(value))
279
+ value = new Date(value);
280
+ break;
281
+ case "boolean":
282
+ value = !!value;
283
+ break;
284
+ default:
285
+ customType = this.customTypes[property.type];
286
+ if (customType && 'propertyToValue' in customType) {
287
+ value = customType.propertyToValue(value, property);
288
+ }
289
+ }
290
+ return value;
291
+ };
292
+ Object.defineProperty(exports.Driver.prototype, "isSql", {
293
+ value: true
294
+ });
@@ -0,0 +1,4 @@
1
+ export * as mysql from "./mysql";
2
+ export * as postgres from "./postgres";
3
+ export * as sqlite from "./sqlite";
4
+ export * as dm from "./dm";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dm = exports.sqlite = exports.postgres = exports.mysql = void 0;
4
+ exports.mysql = require("./mysql");
5
+ exports.postgres = require("./postgres");
6
+ exports.sqlite = require("./sqlite");
7
+ exports.dm = require("./dm");
@@ -0,0 +1,2 @@
1
+ import type { FxOrmDMLDriver } from "../../Typo/DMLDriver";
2
+ export declare const Driver: FxOrmDMLDriver.DMLDriverConstructor_MySQL;