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,262 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterRawColumns = exports.toStorageType = exports.rawToProperty = void 0;
4
+ const Utils_1 = require("../Utils");
5
+ const columnSizes = {
6
+ integer: {
7
+ [2 /* COLUMN_NUMER_TYPE_IDX.SHORT */]: 'SMALLINT',
8
+ [4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */]: 'INTEGER',
9
+ [8 /* COLUMN_NUMER_TYPE_IDX.LONG */]: 'BIGINT'
10
+ },
11
+ floating: {
12
+ [4 /* COLUMN_NUMER_TYPE_IDX.FLOAT */]: 'FLOAT',
13
+ [8 /* COLUMN_NUMER_TYPE_IDX.DOUBLE */]: 'DOUBLE'
14
+ }
15
+ };
16
+ function colInfoToProperty(colInfo) {
17
+ var _a, _b;
18
+ const property = {};
19
+ colInfo = Object.assign({}, colInfo);
20
+ (0, exports.filterRawColumns)(colInfo);
21
+ let Type = colInfo.Type + '';
22
+ const spaceIdx = Type.indexOf(" ");
23
+ if (spaceIdx > 0) {
24
+ colInfo.SubType = Type.slice(spaceIdx + 1).split(/\s+/);
25
+ Type = Type.slice(0, spaceIdx);
26
+ }
27
+ // match_result
28
+ let [_, _type, _size] = Type.match(/^(.+)\((\d+)\)$/) || [];
29
+ if (_)
30
+ colInfo.Size = parseInt(_size, 10);
31
+ const narrowType = !_ ? Type.toUpperCase() : _type.toUpperCase();
32
+ if (colInfo.Extra.toUpperCase() == "AUTO_INCREMENT") {
33
+ property.serial = true;
34
+ property.key = true;
35
+ property.unsigned = true;
36
+ }
37
+ if (colInfo.Key === "PRI") {
38
+ property.primary = true;
39
+ property.key = true;
40
+ }
41
+ if (colInfo.Null.toUpperCase() == "NO") {
42
+ property.required = true;
43
+ }
44
+ if (colInfo.Default !== "null") {
45
+ property.defaultValue = colInfo.Default;
46
+ }
47
+ switch (narrowType) {
48
+ case "SMALLINT":
49
+ case "INTEGER":
50
+ case "BIGINT":
51
+ case "INT":
52
+ property.type = "integer";
53
+ property.size = 4; // INT
54
+ if ((_a = colInfo.SubType) === null || _a === void 0 ? void 0 : _a.includes('unsigned'))
55
+ property.unsigned = true;
56
+ for (let k in columnSizes.integer) {
57
+ if (columnSizes.integer[k] == narrowType) {
58
+ property.size = k;
59
+ break;
60
+ }
61
+ }
62
+ break;
63
+ case "FLOAT":
64
+ case "DOUBLE":
65
+ property.type = "number";
66
+ property.rational = true;
67
+ if ((_b = colInfo.SubType) === null || _b === void 0 ? void 0 : _b.includes('unsigned'))
68
+ property.unsigned = true;
69
+ for (let k in columnSizes.floating) {
70
+ if (columnSizes.floating[k] == narrowType) {
71
+ property.size = k;
72
+ break;
73
+ }
74
+ }
75
+ break;
76
+ case "TINYINT":
77
+ if (colInfo.Size == 1) {
78
+ property.type = "boolean";
79
+ }
80
+ else {
81
+ property.type = "integer";
82
+ }
83
+ break;
84
+ case "DATETIME":
85
+ property.time = true;
86
+ case "DATE":
87
+ property.type = "date";
88
+ break;
89
+ case "LONGBLOB":
90
+ property.big = true;
91
+ case "BLOB":
92
+ property.type = "binary";
93
+ break;
94
+ case "VARCHAR":
95
+ property.type = "text";
96
+ if (colInfo.Size) {
97
+ property.size = colInfo.Size;
98
+ }
99
+ break;
100
+ case "TEXT":
101
+ property.type = "text";
102
+ break;
103
+ case "LONGTEXT":
104
+ property.type = "longtext";
105
+ break;
106
+ case "POINT":
107
+ property.type = "point";
108
+ break;
109
+ default:
110
+ let [_2, _enum_value_str] = narrowType.toLowerCase().match(/^enum\('(.+)'\)$/) || [];
111
+ if (_2) {
112
+ property.type = "enum";
113
+ property.values = _enum_value_str.split(/'\s*,\s*'/);
114
+ break;
115
+ }
116
+ throw new Error(`Unknown property type '${narrowType}'`);
117
+ }
118
+ if (property.serial) {
119
+ property.type = "serial";
120
+ }
121
+ property.mapsTo = colInfo.Field;
122
+ if (colInfo.Comment)
123
+ property.comment = colInfo.Comment;
124
+ return property;
125
+ }
126
+ function schemaColInfoToProperty(colInfo) {
127
+ throw new Error('Not implemented');
128
+ }
129
+ const rawToProperty = function (colInfo, ctx) {
130
+ return {
131
+ raw: colInfo,
132
+ property: colInfoToProperty(colInfo)
133
+ };
134
+ };
135
+ exports.rawToProperty = rawToProperty;
136
+ const toStorageType = function (inputProperty, ctx) {
137
+ var _a;
138
+ const property = Object.assign({}, inputProperty);
139
+ const result = {
140
+ isCustom: false,
141
+ property,
142
+ typeValue: '',
143
+ };
144
+ if (property.type == 'number' && property.rational === false) {
145
+ property.type = 'integer';
146
+ delete property.rational;
147
+ }
148
+ switch (property.type) {
149
+ case "text":
150
+ if (property.big) {
151
+ result.typeValue = "LONGTEXT";
152
+ }
153
+ else {
154
+ result.typeValue = "VARCHAR(" + Math.min(Math.max(parseInt(property.size, 10) || 255, 1), 65535) + ")";
155
+ }
156
+ break;
157
+ case "integer":
158
+ result.typeValue = columnSizes.integer[property.size] || columnSizes.integer[4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */];
159
+ if (property.unsigned) {
160
+ result.typeValue += " UNSIGNED";
161
+ }
162
+ break;
163
+ /**
164
+ * @notice As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE, and DECIMAL (and any synonyms); you should expect support for it to be removed in a future version of MySQL. Consider using a simple CHECK constraint instead for such columns.
165
+ *
166
+ * @see https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html
167
+ */
168
+ case "number":
169
+ result.typeValue = columnSizes.floating[property.size] || columnSizes.floating[4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */];
170
+ if (property.unsigned) {
171
+ result.typeValue += " UNSIGNED";
172
+ }
173
+ break;
174
+ case "serial":
175
+ property.type = "number";
176
+ property.serial = true;
177
+ property.key = true;
178
+ result.typeValue = `INT(${property.size || 11})`;
179
+ break;
180
+ case "boolean":
181
+ result.typeValue = "TINYINT(1)";
182
+ break;
183
+ case "datetime":
184
+ property.type = "date";
185
+ property.time = true;
186
+ case "date":
187
+ if (!property.time) {
188
+ result.typeValue = "DATE";
189
+ }
190
+ else {
191
+ result.typeValue = "DATETIME";
192
+ }
193
+ break;
194
+ case "binary":
195
+ case "object":
196
+ if (property.big === true) {
197
+ result.typeValue = "LONGBLOB";
198
+ }
199
+ else {
200
+ result.typeValue = "BLOB";
201
+ }
202
+ break;
203
+ case "enum":
204
+ result.typeValue = "ENUM (" + property.values.map((val) => ctx.escapeVal(val)) + ")";
205
+ break;
206
+ case "point":
207
+ result.typeValue = "POINT";
208
+ break;
209
+ default:
210
+ result.isCustom = true;
211
+ break;
212
+ }
213
+ if (!result.typeValue && !result.isCustom)
214
+ return result;
215
+ if (property.required) {
216
+ result.typeValue += " NOT NULL";
217
+ }
218
+ if (property.serial) {
219
+ if (!property.required) {
220
+ // append if not set
221
+ result.typeValue += " NOT NULL";
222
+ }
223
+ result.typeValue += " AUTO_INCREMENT";
224
+ }
225
+ if (result.isCustom) {
226
+ if ((_a = ctx.customTypes) === null || _a === void 0 ? void 0 : _a[property.type]) {
227
+ result.typeValue = ctx.customTypes[property.type].datastoreType(property, ctx);
228
+ }
229
+ }
230
+ else if (property.hasOwnProperty("defaultValue") && property.defaultValue !== undefined) {
231
+ const defaultValue = property.type === 'date' && property.defaultValue === Date.now
232
+ ? 'CURRENT_TIMESTAMP'
233
+ : (0, Utils_1.filterPropertyDefaultValue)(property, ctx);
234
+ result.typeValue += ` DEFAULT ${property.type === 'date' && (['CURRENT_TIMESTAMP'].includes(defaultValue))
235
+ ? defaultValue
236
+ : ctx.escapeVal(defaultValue)}`;
237
+ }
238
+ if (property.comment) {
239
+ result.typeValue += ` COMMENT ${ctx.escapeVal(property.comment)}`;
240
+ }
241
+ return result;
242
+ };
243
+ exports.toStorageType = toStorageType;
244
+ function isSimpleColumnInfo(input) {
245
+ return input.hasOwnProperty('Type');
246
+ }
247
+ const filterRawColumns = function (col) {
248
+ if (isSimpleColumnInfo(col)) {
249
+ col.Type = col.Type ? col.Type.toString() : '';
250
+ col.Size = col.Size ? col.Size.toString() : '';
251
+ col.Extra = col.Extra ? col.Extra.toString() : '';
252
+ col.Key = col.Key ? col.Key.toString() : '';
253
+ col.Null = col.Null ? col.Null.toString() : '';
254
+ col.Default = col.Default ? col.Default.toString() : '';
255
+ col.Collation = col.Collation ? col.Collation.toString() : '';
256
+ col.Privileges = col.Privileges ? col.Privileges.toString() : '';
257
+ col.Comment = col.Comment ? col.Comment.toString() : '';
258
+ return col;
259
+ }
260
+ return col;
261
+ };
262
+ exports.filterRawColumns = filterRawColumns;
@@ -0,0 +1,54 @@
1
+ import { IPropTransformer, __StringType } from "../Property";
2
+ type AllNinable<T extends object> = {
3
+ [P in keyof T]: null | T[P];
4
+ };
5
+ type PostgreSQLTypeValueBool = 'NO' | 'YES';
6
+ export type ColumnInfoPostgreSQL = AllNinable<{
7
+ table_catalog: string;
8
+ table_schema: string;
9
+ table_name: string;
10
+ column_name: string;
11
+ ordinal_position: string;
12
+ column_default: string;
13
+ is_nullable: PostgreSQLTypeValueBool;
14
+ data_type: __StringType<'smallint' | 'integer' | 'bigint' | 'real' | 'double precision' | 'boolean' | 'timestamp with time zone' | 'timestamp without time zone' | 'date' | 'bytea' | 'text' | 'character varying' | 'user-defined'>;
15
+ character_maximum_length: number;
16
+ character_octet_length: number;
17
+ numeric_precision: string;
18
+ numeric_precision_radix: string;
19
+ numeric_scale: string;
20
+ datetime_precision: string;
21
+ interval_type: string;
22
+ interval_precision: string;
23
+ character_set_catalog: string;
24
+ character_set_schema: string;
25
+ character_set_name: string;
26
+ collation_catalog: string;
27
+ collation_schema: string;
28
+ collation_name: string;
29
+ domain_catalog: string;
30
+ domain_schema: string;
31
+ domain_name: string;
32
+ udt_catalog: string;
33
+ udt_schema: string;
34
+ udt_name: string;
35
+ scope_catalog: string;
36
+ scope_schema: string;
37
+ scope_name: string;
38
+ maximum_cardinality: string;
39
+ dtd_identifier: string;
40
+ is_self_referencing: PostgreSQLTypeValueBool;
41
+ is_identity: PostgreSQLTypeValueBool;
42
+ identity_generation: string;
43
+ identity_start: string;
44
+ identity_increment: string;
45
+ identity_maximum: string;
46
+ identity_minimum: string;
47
+ identity_cycle: string;
48
+ is_generated: PostgreSQLTypeValueBool;
49
+ generation_expression: string;
50
+ is_updatable: PostgreSQLTypeValueBool;
51
+ }>;
52
+ export declare const rawToProperty: IPropTransformer<ColumnInfoPostgreSQL>['rawToProperty'];
53
+ export declare const toStorageType: IPropTransformer<ColumnInfoPostgreSQL>['toStorageType'];
54
+ export {};
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toStorageType = exports.rawToProperty = void 0;
4
+ const Utils_1 = require("../Utils");
5
+ function psqlGetEnumTypeName(collection_name, column_name) {
6
+ return `${collection_name}_enum_${column_name.toLowerCase()}`;
7
+ }
8
+ const columnSizes = {
9
+ integer: {
10
+ [2 /* COLUMN_NUMER_TYPE_IDX.SHORT */]: 'SMALLINT',
11
+ [4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */]: 'INTEGER',
12
+ [8 /* COLUMN_NUMER_TYPE_IDX.LONG */]: 'BIGINT'
13
+ },
14
+ floating: {
15
+ [4 /* COLUMN_NUMER_TYPE_IDX.FLOAT */]: 'REAL',
16
+ [8 /* COLUMN_NUMER_TYPE_IDX.DOUBLE */]: 'DOUBLE PRECISION'
17
+ },
18
+ };
19
+ const rawToProperty = function (dCol, ctx) {
20
+ var _a;
21
+ let property = {};
22
+ if (dCol.is_nullable.toUpperCase() == "NO") {
23
+ property.required = true;
24
+ }
25
+ if (dCol.column_default !== null) {
26
+ let m = dCol.column_default.match(/^'(.+)'::/);
27
+ if (m) {
28
+ property.defaultValue = m[1];
29
+ }
30
+ else {
31
+ property.defaultValue = dCol.column_default;
32
+ }
33
+ }
34
+ switch (dCol.data_type.toUpperCase()) {
35
+ case "SMALLINT":
36
+ case "INTEGER":
37
+ case "BIGINT":
38
+ if (typeof dCol.column_default == 'string' && dCol.column_default.indexOf('nextval(') == 0) {
39
+ property.type = "serial";
40
+ property.key = true;
41
+ property.serial = true;
42
+ }
43
+ else {
44
+ property.type = "integer";
45
+ }
46
+ for (let k in columnSizes.integer) {
47
+ if (columnSizes.integer[k] == dCol.data_type.toUpperCase()) {
48
+ property.size = k;
49
+ break;
50
+ }
51
+ }
52
+ break;
53
+ case "REAL":
54
+ case "DOUBLE PRECISION":
55
+ property.type = "number";
56
+ property.rational = true;
57
+ for (let k in columnSizes.floating) {
58
+ if (columnSizes.floating[k] == dCol.data_type.toUpperCase()) {
59
+ property.size = k;
60
+ break;
61
+ }
62
+ }
63
+ break;
64
+ case "BOOLEAN":
65
+ property.type = "boolean";
66
+ break;
67
+ case "TIMESTAMP WITH TIME ZONE":
68
+ property.time = true;
69
+ property.type = "date";
70
+ break;
71
+ case "TIMESTAMP WITHOUT TIME ZONE":
72
+ property.time = false;
73
+ property.type = "date";
74
+ break;
75
+ case "DATE":
76
+ property.type = "date";
77
+ break;
78
+ case "BYTEA":
79
+ property.type = "binary";
80
+ break;
81
+ case "TEXT":
82
+ property.type = "text";
83
+ break;
84
+ case "CHARACTER VARYING":
85
+ property.type = "text";
86
+ if (dCol.character_maximum_length) {
87
+ property.size = dCol.character_maximum_length;
88
+ }
89
+ break;
90
+ case "USER-DEFINED":
91
+ if (dCol.udt_name.match(/_enum_/)) {
92
+ property.type = "enum";
93
+ property.values = ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.userOptions) === null || _a === void 0 ? void 0 : _a.enumValues) || [];
94
+ break;
95
+ }
96
+ case "POINT":
97
+ property.type = "point";
98
+ break;
99
+ default:
100
+ throw new Error("Unknown column type '" + dCol.data_type + "'");
101
+ }
102
+ property.mapsTo = dCol.column_name;
103
+ return {
104
+ raw: dCol,
105
+ property
106
+ };
107
+ };
108
+ exports.rawToProperty = rawToProperty;
109
+ const toStorageType = function (inputProperty, ctx) {
110
+ var _a, _b, _c;
111
+ const property = Object.assign({}, inputProperty);
112
+ const result = {
113
+ isCustom: false,
114
+ property,
115
+ typeValue: '',
116
+ };
117
+ if (property.serial) {
118
+ result.typeValue = 'SERIAL';
119
+ return result;
120
+ }
121
+ if (property.type == 'number' && property.rational === false) {
122
+ property.type = 'integer';
123
+ delete property.rational;
124
+ }
125
+ switch (property.type) {
126
+ case "text":
127
+ result.typeValue = "TEXT";
128
+ break;
129
+ case "integer":
130
+ result.typeValue = columnSizes.integer[property.size] || columnSizes.integer[4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */];
131
+ break;
132
+ case "number":
133
+ result.typeValue = columnSizes.floating[property.size] || columnSizes.floating[4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */];
134
+ break;
135
+ case "serial":
136
+ property.serial = true;
137
+ property.key = true;
138
+ result.typeValue = "SERIAL";
139
+ break;
140
+ case "boolean":
141
+ result.typeValue = "BOOLEAN";
142
+ break;
143
+ case "datetime":
144
+ property.type = "date";
145
+ property.time = true;
146
+ case "date":
147
+ if (!property.time) {
148
+ result.typeValue = "DATE";
149
+ }
150
+ else {
151
+ result.typeValue = "TIMESTAMP WITHOUT TIME ZONE";
152
+ }
153
+ break;
154
+ case "binary":
155
+ case "object":
156
+ result.typeValue = "BYTEA";
157
+ break;
158
+ case "enum":
159
+ const collection = ((ctx === null || ctx === void 0 ? void 0 : ctx.collection) || '');
160
+ result.typeValue = psqlGetEnumTypeName(collection, ((_a = property.mapsTo) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '');
161
+ break;
162
+ case "point":
163
+ result.typeValue = "POINT";
164
+ break;
165
+ default:
166
+ result.isCustom = true;
167
+ break;
168
+ }
169
+ if (!result.typeValue && !result.isCustom)
170
+ return result;
171
+ if (property.required) {
172
+ result.typeValue += " NOT NULL";
173
+ }
174
+ if (result.isCustom) {
175
+ if ((_b = ctx.customTypes) === null || _b === void 0 ? void 0 : _b[property.type]) {
176
+ result.typeValue = (_c = ctx.customTypes) === null || _c === void 0 ? void 0 : _c[property.type].datastoreType(property, ctx);
177
+ }
178
+ }
179
+ else if (property.hasOwnProperty("defaultValue") && property.defaultValue !== undefined) {
180
+ if (property.type === 'date' && property.defaultValue === Date.now) {
181
+ result.typeValue += " DEFAULT now()";
182
+ }
183
+ else {
184
+ const defaultValue = (0, Utils_1.filterPropertyDefaultValue)(property, ctx);
185
+ result.typeValue += " DEFAULT " + ctx.escapeVal(defaultValue);
186
+ }
187
+ }
188
+ return result;
189
+ };
190
+ exports.toStorageType = toStorageType;
@@ -0,0 +1,19 @@
1
+ import { IPropTransformer, IProperty, __StringType } from "../Property";
2
+ export interface ColumnInfoSQLite {
3
+ cid: number;
4
+ dflt_value: string;
5
+ name: string;
6
+ notnull: 1 | 0;
7
+ pk: 1 | 0;
8
+ type: ColumnType_SQLite;
9
+ }
10
+ type ColumnType_SQLite = __StringType<'TEXT' | 'INTEGER' | 'REAL' | 'SERIAL' | 'INTEGER UNSIGNED' | 'DATE' | 'DATETIME' | 'BLOB' | 'ENUM' | 'POINT'>;
11
+ export interface PropertySQLite extends IProperty {
12
+ key?: boolean;
13
+ before?: string;
14
+ after?: string;
15
+ }
16
+ type ITransformers = IPropTransformer<ColumnInfoSQLite>;
17
+ export declare const rawToProperty: ITransformers['rawToProperty'];
18
+ export declare const toStorageType: ITransformers['toStorageType'];
19
+ export {};
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toStorageType = exports.rawToProperty = void 0;
4
+ const Utils_1 = require("../Utils");
5
+ const rawToProperty = function (dCol, ctx) {
6
+ const prop = {};
7
+ if (dCol.pk) {
8
+ prop.key = true;
9
+ }
10
+ if (dCol.notnull) {
11
+ prop.required = true;
12
+ }
13
+ if (dCol.dflt_value) {
14
+ const m = dCol.dflt_value.match(/^'(.*)'$/);
15
+ if (m) {
16
+ prop.defaultValue = m[1];
17
+ }
18
+ else {
19
+ prop.defaultValue = null;
20
+ }
21
+ }
22
+ switch (dCol.type.toUpperCase()) {
23
+ case "INTEGER":
24
+ // In sqlite land, integer primary keys are autoincrement by default
25
+ // weather you asked for this behaviour or not.
26
+ // http://www.sqlite.org/faq.html#q1
27
+ if (dCol.pk == 1) {
28
+ prop.type = "serial";
29
+ prop.serial = true;
30
+ prop.key = true;
31
+ }
32
+ else {
33
+ prop.type = "integer";
34
+ }
35
+ break;
36
+ case "INTEGER UNSIGNED":
37
+ prop.type = "boolean";
38
+ break;
39
+ case "REAL":
40
+ prop.type = "number";
41
+ prop.rational = true;
42
+ break;
43
+ case "DATETIME":
44
+ prop.type = "date";
45
+ prop.time = true;
46
+ break;
47
+ case "BLOB":
48
+ prop.type = "binary";
49
+ prop.big = true;
50
+ break;
51
+ case "TEXT":
52
+ prop.type = "text";
53
+ break;
54
+ case "POINT":
55
+ prop.type = "point";
56
+ break;
57
+ default:
58
+ let [_, type, _before, field] = dCol.type.toUpperCase().match(/(.*)\s(AFTER|BEFORE)\s`(.*)`$/) || [];
59
+ if (_) {
60
+ switch (_before && field) {
61
+ case 'BEFORE':
62
+ prop.before = field;
63
+ case 'AFTER':
64
+ prop.after = field;
65
+ break;
66
+ }
67
+ prop.type = type;
68
+ break;
69
+ }
70
+ throw new Error(`Unknown prop type '${dCol.type}'`);
71
+ }
72
+ prop.mapsTo = dCol.name;
73
+ return {
74
+ raw: dCol,
75
+ property: prop
76
+ };
77
+ };
78
+ exports.rawToProperty = rawToProperty;
79
+ const toStorageType = function (inputProperty, ctx) {
80
+ var _a, _b;
81
+ const property = Object.assign({}, inputProperty);
82
+ const result = {
83
+ isCustom: false,
84
+ property,
85
+ typeValue: '',
86
+ };
87
+ if (property.type == 'number' && property.rational === false) {
88
+ property.type = 'integer';
89
+ delete property.rational;
90
+ }
91
+ switch (property.type) {
92
+ case "text":
93
+ result.typeValue = "TEXT";
94
+ break;
95
+ case "integer":
96
+ result.typeValue = "INTEGER";
97
+ break;
98
+ case "number":
99
+ result.typeValue = "REAL";
100
+ break;
101
+ case "serial":
102
+ property.serial = true;
103
+ property.key = true;
104
+ result.typeValue = "INTEGER";
105
+ break;
106
+ case "boolean":
107
+ result.typeValue = "INTEGER UNSIGNED";
108
+ break;
109
+ case "datetime":
110
+ property.type = "date";
111
+ property.time = true;
112
+ case "date":
113
+ result.typeValue = "DATETIME";
114
+ break;
115
+ case "binary":
116
+ case "object":
117
+ result.typeValue = "BLOB";
118
+ break;
119
+ case "enum":
120
+ result.typeValue = "INTEGER";
121
+ break;
122
+ case "point":
123
+ result.typeValue = "POINT";
124
+ break;
125
+ default:
126
+ result.isCustom = true;
127
+ break;
128
+ }
129
+ if (!result.typeValue && !result.isCustom)
130
+ return result;
131
+ if (property.required) {
132
+ result.typeValue += " NOT NULL";
133
+ }
134
+ if (property.key) {
135
+ if (!property.required) {
136
+ // append if not set
137
+ result.typeValue += " NOT NULL";
138
+ }
139
+ if (property.serial) {
140
+ result.typeValue += " PRIMARY KEY";
141
+ }
142
+ }
143
+ if (property.serial) {
144
+ if (!property.key) {
145
+ result.typeValue += " PRIMARY KEY";
146
+ }
147
+ result.typeValue += " AUTOINCREMENT";
148
+ }
149
+ if (result.isCustom) {
150
+ if ((_a = ctx.customTypes) === null || _a === void 0 ? void 0 : _a[property.type]) {
151
+ result.typeValue = (_b = ctx.customTypes) === null || _b === void 0 ? void 0 : _b[property.type].datastoreType(property, ctx);
152
+ }
153
+ }
154
+ else if (property.hasOwnProperty("defaultValue") && property.defaultValue !== undefined) {
155
+ let defaultValue = property.type === 'date' && property.defaultValue === Date.now
156
+ ? ctx.escapeVal('CURRENT_TIMESTAMP')
157
+ : ctx.escapeVal((0, Utils_1.filterPropertyDefaultValue)(property, ctx));
158
+ const { useDefaultValue = true } = ctx.userOptions || {};
159
+ /**
160
+ * @description
161
+ * sqlite doens't support alter column's datetime default value,
162
+ * you should alter table's schema to change `datetime` type column's default value
163
+ *
164
+ * @see https://stackoverflow.com/questions/2614483/how-to-create-a-datetime-column-with-default-value-in-sqlite3
165
+ * @see https://stackoverflow.com/questions/25911191/altering-a-sqlite-table-to-add-a-timestamp-column-with-default-value
166
+ */
167
+ if (defaultValue && useDefaultValue)
168
+ result.typeValue += ` DEFAULT ${defaultValue} `;
169
+ }
170
+ return result;
171
+ };
172
+ exports.toStorageType = toStorageType;