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