fib-orm 1.4.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/License +1 -1
  2. package/README.md +53 -0
  3. package/lib/cli/commands/ddlFrom.d.ts +2 -0
  4. package/lib/cli/commands/ddlFrom.js +74 -0
  5. package/lib/cli/commands/dumpModel.d.ts +2 -0
  6. package/lib/cli/commands/dumpModel.js +106 -0
  7. package/lib/cli/commands/escape.d.ts +2 -0
  8. package/lib/cli/commands/escape.js +68 -0
  9. package/lib/cli/commands/spinner.d.ts +2 -0
  10. package/lib/cli/commands/spinner.js +36 -0
  11. package/lib/cli/commands/upgrade.d.ts +2 -0
  12. package/lib/cli/commands/upgrade.js +65 -0
  13. package/lib/cli/helpers/ddl.d.ts +17 -0
  14. package/lib/cli/helpers/ddl.js +55 -0
  15. package/lib/cli/helpers/package.d.ts +26 -0
  16. package/lib/cli/helpers/package.js +56 -0
  17. package/lib/cli/index.d.ts +2 -0
  18. package/lib/cli/index.js +18 -0
  19. package/lib/codepoints-map.json +762 -0
  20. package/lib/db-driver/Typo.d.ts +112 -0
  21. package/lib/db-driver/Typo.js +1 -0
  22. package/lib/db-driver/built-ins/base.class.d.ts +96 -0
  23. package/lib/db-driver/built-ins/base.class.js +186 -0
  24. package/lib/db-driver/built-ins/driver-dm.d.ts +18 -0
  25. package/lib/db-driver/built-ins/driver-dm.js +53 -0
  26. package/lib/db-driver/built-ins/driver-mongodb.d.ts +24 -0
  27. package/lib/db-driver/built-ins/driver-mongodb.js +46 -0
  28. package/lib/db-driver/built-ins/driver-mysql.d.ts +18 -0
  29. package/lib/db-driver/built-ins/driver-mysql.js +37 -0
  30. package/lib/db-driver/built-ins/driver-postgresql.d.ts +22 -0
  31. package/lib/db-driver/built-ins/driver-postgresql.js +76 -0
  32. package/lib/db-driver/built-ins/driver-redis.d.ts +12 -0
  33. package/lib/db-driver/built-ins/driver-redis.js +35 -0
  34. package/lib/db-driver/built-ins/driver-sqlite.d.ts +17 -0
  35. package/lib/db-driver/built-ins/driver-sqlite.js +34 -0
  36. package/lib/db-driver/index.d.ts +3 -0
  37. package/lib/db-driver/index.js +4 -0
  38. package/lib/db-driver/utils.d.ts +14 -0
  39. package/lib/db-driver/utils.js +187 -0
  40. package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +12 -0
  41. package/lib/knex/deps/tarn/dist/PendingOperation.js +48 -0
  42. package/lib/knex/deps/tarn/dist/Pool.d.ts +97 -0
  43. package/lib/knex/deps/tarn/dist/Pool.js +516 -0
  44. package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +16 -0
  45. package/lib/knex/deps/tarn/dist/PromiseInspection.js +21 -0
  46. package/lib/knex/deps/tarn/dist/Resource.d.ts +9 -0
  47. package/lib/knex/deps/tarn/dist/Resource.js +19 -0
  48. package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +2 -0
  49. package/lib/knex/deps/tarn/dist/TimeoutError.js +5 -0
  50. package/lib/knex/deps/tarn/dist/tarn.d.ts +3 -0
  51. package/lib/knex/deps/tarn/dist/tarn.js +10 -0
  52. package/lib/knex/deps/tarn/dist/utils.d.ts +14 -0
  53. package/lib/knex/deps/tarn/dist/utils.js +60 -0
  54. package/lib/knex/knex.d.ts +2 -0
  55. package/lib/knex/knex.js +3 -0
  56. package/lib/knex/sandbox.d.ts +4 -0
  57. package/lib/knex/sandbox.js +22 -0
  58. package/lib/orm/Adapters.d.ts +3 -0
  59. package/lib/orm/Adapters.js +44 -0
  60. package/lib/orm/AggregateFunctions.d.ts +3 -0
  61. package/lib/orm/AggregateFunctions.js +176 -0
  62. package/lib/orm/Associations/Extend.d.ts +22 -0
  63. package/lib/orm/Associations/Extend.js +274 -0
  64. package/lib/orm/Associations/Many.d.ts +17 -0
  65. package/lib/orm/Associations/Many.js +569 -0
  66. package/lib/orm/Associations/One.d.ts +16 -0
  67. package/lib/orm/Associations/One.js +310 -0
  68. package/lib/orm/Associations/_utils.d.ts +15 -0
  69. package/lib/orm/Associations/_utils.js +52 -0
  70. package/lib/orm/ChainFind.d.ts +3 -0
  71. package/lib/orm/ChainFind.js +327 -0
  72. package/lib/orm/ChainInstance.d.ts +6 -0
  73. package/lib/orm/ChainInstance.js +73 -0
  74. package/lib/orm/Debug.d.ts +2 -0
  75. package/lib/orm/Debug.js +17 -0
  76. package/lib/orm/Drivers/DB/base.d.ts +3 -0
  77. package/lib/orm/Drivers/DB/base.js +3 -0
  78. package/lib/orm/Drivers/DB/dm.d.ts +11 -0
  79. package/lib/orm/Drivers/DB/dm.js +23 -0
  80. package/lib/orm/Drivers/DB/mysql.d.ts +11 -0
  81. package/lib/orm/Drivers/DB/mysql.js +23 -0
  82. package/lib/orm/Drivers/DB/postgres.d.ts +11 -0
  83. package/lib/orm/Drivers/DB/postgres.js +22 -0
  84. package/lib/orm/Drivers/DB/sqlite3.d.ts +16 -0
  85. package/lib/orm/Drivers/DB/sqlite3.js +39 -0
  86. package/lib/orm/Drivers/DML/_ddl-sql.d.ts +3 -0
  87. package/lib/orm/Drivers/DML/_ddl-sql.js +51 -0
  88. package/lib/orm/Drivers/DML/_dml-helpers.d.ts +19 -0
  89. package/lib/orm/Drivers/DML/_dml-helpers.js +51 -0
  90. package/lib/orm/Drivers/DML/_shared.d.ts +9 -0
  91. package/lib/orm/Drivers/DML/_shared.js +38 -0
  92. package/lib/orm/Drivers/DML/_utils.d.ts +8 -0
  93. package/lib/orm/Drivers/DML/_utils.js +67 -0
  94. package/lib/orm/Drivers/DML/constants.d.ts +3 -0
  95. package/lib/orm/Drivers/DML/constants.js +2 -0
  96. package/lib/orm/Drivers/DML/dm.d.ts +2 -0
  97. package/lib/orm/Drivers/DML/dm.js +293 -0
  98. package/lib/orm/Drivers/DML/index.d.ts +4 -0
  99. package/lib/orm/Drivers/DML/index.js +6 -0
  100. package/lib/orm/Drivers/DML/mysql.d.ts +2 -0
  101. package/lib/orm/Drivers/DML/mysql.js +251 -0
  102. package/lib/orm/Drivers/DML/postgres.d.ts +3 -0
  103. package/lib/orm/Drivers/DML/postgres.js +276 -0
  104. package/lib/orm/Drivers/DML/sqlite.d.ts +2 -0
  105. package/lib/orm/Drivers/DML/sqlite.js +266 -0
  106. package/lib/orm/Error.d.ts +11 -0
  107. package/lib/orm/Error.js +40 -0
  108. package/lib/orm/Helpers.d.ts +35 -0
  109. package/lib/orm/Helpers.js +233 -0
  110. package/lib/orm/Hook.d.ts +13 -0
  111. package/lib/orm/Hook.js +99 -0
  112. package/lib/orm/Instance.d.ts +2 -0
  113. package/lib/orm/Instance.js +697 -0
  114. package/lib/orm/LazyLoad.d.ts +4 -0
  115. package/lib/orm/LazyLoad.js +76 -0
  116. package/lib/orm/Model.d.ts +7 -0
  117. package/lib/orm/Model.js +971 -0
  118. package/lib/orm/ORM.d.ts +37 -0
  119. package/lib/orm/ORM.js +241 -0
  120. package/lib/orm/Patch/fib-cache.d.ts +40 -0
  121. package/lib/orm/Patch/fib-cache.js +2 -0
  122. package/lib/orm/Patch/plugin.d.ts +4 -0
  123. package/lib/orm/Patch/plugin.js +13 -0
  124. package/lib/orm/Property.d.ts +9 -0
  125. package/lib/orm/Property.js +71 -0
  126. package/lib/orm/Settings.d.ts +42 -0
  127. package/lib/orm/Settings.js +119 -0
  128. package/lib/orm/Singleton.d.ts +5 -0
  129. package/lib/orm/Singleton.js +72 -0
  130. package/lib/orm/Typo/Adapter.d.ts +5 -0
  131. package/lib/orm/Typo/Adapter.js +1 -0
  132. package/lib/orm/Typo/DMLDriver.d.ts +210 -0
  133. package/lib/orm/Typo/DMLDriver.js +1 -0
  134. package/lib/orm/Typo/Db.d.ts +38 -0
  135. package/lib/orm/Typo/Db.js +1 -0
  136. package/lib/orm/Typo/Error.d.ts +31 -0
  137. package/lib/orm/Typo/Error.js +1 -0
  138. package/lib/orm/Typo/ORM.d.ts +233 -0
  139. package/lib/orm/Typo/ORM.js +3 -0
  140. package/lib/orm/Typo/Validators.d.ts +32 -0
  141. package/lib/orm/Typo/Validators.js +2 -0
  142. package/lib/orm/Typo/_common.d.ts +38 -0
  143. package/lib/orm/Typo/_common.js +1 -0
  144. package/lib/orm/Typo/assoc.d.ts +221 -0
  145. package/lib/orm/Typo/assoc.js +1 -0
  146. package/lib/orm/Typo/hook.d.ts +42 -0
  147. package/lib/orm/Typo/hook.js +1 -0
  148. package/lib/orm/Typo/instance.d.ts +157 -0
  149. package/lib/orm/Typo/instance.js +1 -0
  150. package/lib/orm/Typo/model.d.ts +313 -0
  151. package/lib/orm/Typo/model.js +6 -0
  152. package/lib/orm/Typo/patch.d.ts +31 -0
  153. package/lib/orm/Typo/patch.js +1 -0
  154. package/lib/orm/Typo/property.d.ts +57 -0
  155. package/lib/orm/Typo/property.js +1 -0
  156. package/lib/orm/Typo/query.d.ts +216 -0
  157. package/lib/orm/Typo/query.js +1 -0
  158. package/lib/orm/Typo/settings.d.ts +35 -0
  159. package/lib/orm/Typo/settings.js +5 -0
  160. package/lib/orm/Typo/synchronous.d.ts +47 -0
  161. package/lib/orm/Typo/synchronous.js +1 -0
  162. package/lib/orm/Utilities.d.ts +179 -0
  163. package/lib/orm/Utilities.js +975 -0
  164. package/lib/orm/Validators.d.ts +34 -0
  165. package/lib/orm/Validators.js +100 -0
  166. package/lib/orm/Where/common.d.ts +1 -0
  167. package/lib/orm/Where/common.js +7 -0
  168. package/lib/orm/Where/filterDate.d.ts +11 -0
  169. package/lib/orm/Where/filterDate.js +58 -0
  170. package/lib/orm/index.d.ts +68 -0
  171. package/lib/orm/index.js +157 -0
  172. package/lib/orm-core/callback.d.ts +12 -0
  173. package/lib/orm-core/callback.js +1 -0
  174. package/lib/orm-core/dialect.d.ts +80 -0
  175. package/lib/orm-core/dialect.js +1 -0
  176. package/lib/orm-core/error.d.ts +16 -0
  177. package/lib/orm-core/error.js +29 -0
  178. package/lib/orm-core/index.d.ts +6 -0
  179. package/lib/orm-core/index.js +6 -0
  180. package/lib/orm-core/sync.d.ts +12 -0
  181. package/lib/orm-core/sync.js +1 -0
  182. package/lib/orm-core/utils.d.ts +1 -0
  183. package/lib/orm-core/utils.js +5 -0
  184. package/lib/orm-property/Property.d.ts +78 -0
  185. package/lib/orm-property/Property.js +1 -0
  186. package/lib/orm-property/Utils.d.ts +9 -0
  187. package/lib/orm-property/Utils.js +13 -0
  188. package/lib/orm-property/customTypes.d.ts +2 -0
  189. package/lib/orm-property/customTypes.js +13 -0
  190. package/lib/orm-property/index.d.ts +10 -0
  191. package/lib/orm-property/index.js +22 -0
  192. package/lib/orm-property/transformer.d.ts +5 -0
  193. package/lib/orm-property/transformer.js +10 -0
  194. package/lib/orm-property/transformers/dm.d.ts +29 -0
  195. package/lib/orm-property/transformers/dm.js +237 -0
  196. package/lib/orm-property/transformers/index.d.ts +4 -0
  197. package/lib/orm-property/transformers/index.js +5 -0
  198. package/lib/orm-property/transformers/mysql.d.ts +102 -0
  199. package/lib/orm-property/transformers/mysql.js +261 -0
  200. package/lib/orm-property/transformers/postgresql.d.ts +54 -0
  201. package/lib/orm-property/transformers/postgresql.js +189 -0
  202. package/lib/orm-property/transformers/sqlite.d.ts +19 -0
  203. package/lib/orm-property/transformers/sqlite.js +171 -0
  204. package/lib/sql-ddl-sync/Dialects/dm.d.ts +40 -0
  205. package/lib/sql-ddl-sync/Dialects/dm.js +296 -0
  206. package/lib/sql-ddl-sync/Dialects/index.d.ts +7 -0
  207. package/lib/sql-ddl-sync/Dialects/index.js +7 -0
  208. package/lib/sql-ddl-sync/Dialects/mysql.d.ts +39 -0
  209. package/lib/sql-ddl-sync/Dialects/mysql.js +240 -0
  210. package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +40 -0
  211. package/lib/sql-ddl-sync/Dialects/postgresql.js +286 -0
  212. package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +44 -0
  213. package/lib/sql-ddl-sync/Dialects/sqlite.js +256 -0
  214. package/lib/sql-ddl-sync/SQL.d.ts +12 -0
  215. package/lib/sql-ddl-sync/SQL.js +108 -0
  216. package/lib/sql-ddl-sync/Typo/Collection.d.ts +13 -0
  217. package/lib/sql-ddl-sync/Typo/Collection.js +1 -0
  218. package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +13 -0
  219. package/lib/sql-ddl-sync/Typo/DbIndex.js +1 -0
  220. package/lib/sql-ddl-sync/Typo/Dialect.d.ts +81 -0
  221. package/lib/sql-ddl-sync/Typo/Dialect.js +1 -0
  222. package/lib/sql-ddl-sync/Typo/Driver.d.ts +53 -0
  223. package/lib/sql-ddl-sync/Typo/Driver.js +1 -0
  224. package/lib/sql-ddl-sync/Typo/Query.d.ts +7 -0
  225. package/lib/sql-ddl-sync/Typo/Query.js +1 -0
  226. package/lib/sql-ddl-sync/Typo/SQL.d.ts +31 -0
  227. package/lib/sql-ddl-sync/Typo/SQL.js +1 -0
  228. package/lib/sql-ddl-sync/Typo/_common.d.ts +29 -0
  229. package/lib/sql-ddl-sync/Typo/_common.js +1 -0
  230. package/lib/sql-ddl-sync/Utils.d.ts +40 -0
  231. package/lib/sql-ddl-sync/Utils.js +217 -0
  232. package/lib/sql-ddl-sync/index.d.ts +87 -0
  233. package/lib/sql-ddl-sync/index.js +371 -0
  234. package/lib/sql-query/Comparators.d.ts +3 -0
  235. package/lib/sql-query/Comparators.js +94 -0
  236. package/lib/sql-query/Create.d.ts +35 -0
  237. package/lib/sql-query/Create.js +77 -0
  238. package/lib/sql-query/Dialects/dm.d.ts +3 -0
  239. package/lib/sql-query/Dialects/dm.js +74 -0
  240. package/lib/sql-query/Dialects/index.d.ts +10 -0
  241. package/lib/sql-query/Dialects/index.js +12 -0
  242. package/lib/sql-query/Dialects/mssql.d.ts +3 -0
  243. package/lib/sql-query/Dialects/mssql.js +73 -0
  244. package/lib/sql-query/Dialects/mysql.d.ts +3 -0
  245. package/lib/sql-query/Dialects/mysql.js +100 -0
  246. package/lib/sql-query/Dialects/postgresql.d.ts +3 -0
  247. package/lib/sql-query/Dialects/postgresql.js +76 -0
  248. package/lib/sql-query/Dialects/sqlite.d.ts +3 -0
  249. package/lib/sql-query/Dialects/sqlite.js +61 -0
  250. package/lib/sql-query/Helpers.d.ts +38 -0
  251. package/lib/sql-query/Helpers.js +259 -0
  252. package/lib/sql-query/Insert.d.ts +12 -0
  253. package/lib/sql-query/Insert.js +33 -0
  254. package/lib/sql-query/Query.d.ts +29 -0
  255. package/lib/sql-query/Query.js +119 -0
  256. package/lib/sql-query/Remove.d.ts +16 -0
  257. package/lib/sql-query/Remove.js +93 -0
  258. package/lib/sql-query/Select.d.ts +62 -0
  259. package/lib/sql-query/Select.js +533 -0
  260. package/lib/sql-query/Set.d.ts +4 -0
  261. package/lib/sql-query/Set.js +16 -0
  262. package/lib/sql-query/Typo/Aggregation.d.ts +32 -0
  263. package/lib/sql-query/Typo/Aggregation.js +1 -0
  264. package/lib/sql-query/Typo/Comparators.d.ts +140 -0
  265. package/lib/sql-query/Typo/Comparators.js +1 -0
  266. package/lib/sql-query/Typo/Dialect.d.ts +39 -0
  267. package/lib/sql-query/Typo/Dialect.js +1 -0
  268. package/lib/sql-query/Typo/Field.d.ts +8 -0
  269. package/lib/sql-query/Typo/Field.js +1 -0
  270. package/lib/sql-query/Typo/Helper.d.ts +4 -0
  271. package/lib/sql-query/Typo/Helper.js +1 -0
  272. package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +80 -0
  273. package/lib/sql-query/Typo/Query-ChainBuilder.js +1 -0
  274. package/lib/sql-query/Typo/Query.d.ts +34 -0
  275. package/lib/sql-query/Typo/Query.js +16 -0
  276. package/lib/sql-query/Typo/Sql.d.ts +143 -0
  277. package/lib/sql-query/Typo/Sql.js +1 -0
  278. package/lib/sql-query/Typo/SubQuery.d.ts +39 -0
  279. package/lib/sql-query/Typo/SubQuery.js +1 -0
  280. package/lib/sql-query/Typo/index.d.ts +9 -0
  281. package/lib/sql-query/Typo/index.js +1 -0
  282. package/lib/sql-query/Update.d.ts +15 -0
  283. package/lib/sql-query/Update.js +38 -0
  284. package/lib/sql-query/Where.d.ts +4 -0
  285. package/lib/sql-query/Where.js +280 -0
  286. package/package.json +72 -36
  287. package/.travis.yml +0 -14
  288. package/@types/index.d.ts +0 -193
  289. package/@types/orm_mirror/orm.d.ts +0 -275
  290. package/@types/orm_mirror/sql-query.d.ts +0 -79
  291. package/Readme.md +0 -843
  292. package/lib/index.js +0 -13
  293. package/lib/modules/mysql.js +0 -35
  294. package/lib/modules/sqlite3.js +0 -27
  295. package/lib/patch.js +0 -271
@@ -0,0 +1,78 @@
1
+ export type __StringType<ENUM_T = string> = string | ENUM_T;
2
+ export type ColumnType = __StringType;
3
+ export interface IProperty {
4
+ type: __StringType<PropertyType>;
5
+ key?: boolean;
6
+ mapsTo?: string;
7
+ unique?: boolean | string | string[];
8
+ index?: boolean | string | string[];
9
+ serial?: boolean;
10
+ unsigned?: boolean;
11
+ primary?: boolean;
12
+ required?: boolean;
13
+ defaultValue?: ((ctx?: ITransformCtx) => any) | any;
14
+ size?: number | string;
15
+ rational?: boolean;
16
+ time?: boolean;
17
+ big?: boolean;
18
+ values?: any[];
19
+ /**
20
+ * @description for some db backends, comment is the description of the column
21
+ */
22
+ comment?: string;
23
+ [ext_k: string]: any;
24
+ }
25
+ /**
26
+ * @description
27
+ * all standard property types should be supported by transformer
28
+ */
29
+ export type PropertyType = 'text' | 'integer' | 'number' | 'serial' | 'boolean' | 'date' | 'binary' | 'object' | 'enum' | 'point';
30
+ export type ICustomPropertyType = {
31
+ datastoreType(prop: IProperty, ctx: ITransformCtx): string;
32
+ };
33
+ export type ITransformCtx = {
34
+ /**
35
+ * @description database's type
36
+ */
37
+ type?: string;
38
+ /**
39
+ * @description database's version
40
+ */
41
+ version?: string;
42
+ /**
43
+ * @description collection name
44
+ */
45
+ collection?: string;
46
+ userOptions?: Record<string, any>;
47
+ };
48
+ export interface IPropTransformer<TCol extends object> {
49
+ /**
50
+ * @description filter column information, some input data would be dirty.
51
+ *
52
+ * e.g. the type of field in TCol is Class_Buffer, we need to convert it to string.
53
+ *
54
+ */
55
+ filterRawColumns?(column: TCol): TCol;
56
+ /**
57
+ * @description transform database's type raw information to property
58
+ */
59
+ rawToProperty(column: TCol, ctx?: ITransformCtx): {
60
+ raw: TCol;
61
+ property: IProperty;
62
+ };
63
+ /**
64
+ * @description transform property to database's type
65
+ */
66
+ toStorageType(property: IProperty, ctx: ITransformCtx & {
67
+ /**
68
+ * @description custom types
69
+ */
70
+ customTypes?: Record<string, ICustomPropertyType>;
71
+ escapeVal(val: any): string;
72
+ }): {
73
+ isCustom: boolean;
74
+ property: IProperty;
75
+ typeValue: string;
76
+ };
77
+ }
78
+ export type ExtractColumnInfo<T extends any> = T extends IPropTransformer<infer U> ? U : never;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { IProperty, ITransformCtx } from "./Property";
2
+ export declare function filterPropertyDefaultValue(property: IProperty, ctx: ITransformCtx): any;
3
+ export declare const enum COLUMN_NUMER_TYPE_IDX {
4
+ SHORT = 2,
5
+ INTEGER = 4,
6
+ LONG = 8,
7
+ FLOAT = 4,
8
+ DOUBLE = 8
9
+ }
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.filterPropertyDefaultValue = void 0;
3
+ function filterPropertyDefaultValue(property, ctx) {
4
+ let _dftValue;
5
+ if (property.hasOwnProperty('defaultValue'))
6
+ if (typeof property.defaultValue === 'function') {
7
+ _dftValue = property.defaultValue(ctx);
8
+ }
9
+ else
10
+ _dftValue = property.defaultValue;
11
+ return _dftValue;
12
+ }
13
+ exports.filterPropertyDefaultValue = filterPropertyDefaultValue;
@@ -0,0 +1,2 @@
1
+ import { ICustomPropertyType } from "./Property";
2
+ export declare function defineCustomType(opts: Partial<ICustomPropertyType>): ICustomPropertyType;
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.defineCustomType = void 0;
3
+ const DEFAULT_DATASTORE_TYPE = function (prop, ctx) {
4
+ return prop.type.toUpperCase();
5
+ };
6
+ function defineCustomType(opts) {
7
+ opts = Object.assign({}, opts);
8
+ if (typeof opts.datastoreType !== 'function') {
9
+ opts.datastoreType = DEFAULT_DATASTORE_TYPE.bind(null);
10
+ }
11
+ return opts;
12
+ }
13
+ exports.defineCustomType = defineCustomType;
@@ -0,0 +1,10 @@
1
+ import * as Transformers from './transformers';
2
+ export { Transformers };
3
+ export type { IProperty } from './Property';
4
+ export declare function transformer(type: 'mysql'): typeof Transformers['mysql'];
5
+ export declare function transformer(type: 'psql'): typeof Transformers['postgresql'];
6
+ export declare function transformer(type: 'postgresql'): typeof Transformers['postgresql'];
7
+ export declare function transformer(type: 'sqlite'): typeof Transformers['sqlite'];
8
+ export declare function transformer(type: 'dm'): typeof Transformers['dm'];
9
+ export { defineCustomType } from './customTypes';
10
+ export { ExtractColumnInfo } from './Property';
@@ -0,0 +1,22 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.defineCustomType = exports.transformer = exports.Transformers = void 0;
3
+ const Transformers = require("./transformers");
4
+ exports.Transformers = Transformers;
5
+ function transformer(type) {
6
+ switch (type) {
7
+ case 'psql':
8
+ case 'postgres':
9
+ return Transformers['postgresql'];
10
+ case 'dm':
11
+ return Transformers['dm'];
12
+ case 'postgresql':
13
+ case 'mysql':
14
+ case 'sqlite':
15
+ return Transformers[type];
16
+ default:
17
+ throw new Error('Unknown database type');
18
+ }
19
+ }
20
+ exports.transformer = transformer;
21
+ var customTypes_1 = require("./customTypes");
22
+ Object.defineProperty(exports, "defineCustomType", { enumerable: true, get: function () { return customTypes_1.defineCustomType; } });
@@ -0,0 +1,5 @@
1
+ import { IPropTransformer } from "./Property";
2
+ export declare function defineTransformer<T extends object>(opts: {
3
+ rawToProperty: IPropTransformer<T>['rawToProperty'];
4
+ toStorageType: IPropTransformer<T>['toStorageType'];
5
+ }): IPropTransformer<T>;
@@ -0,0 +1,10 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.defineTransformer = void 0;
3
+ function defineTransformer(opts) {
4
+ const { rawToProperty, toStorageType, } = opts;
5
+ return {
6
+ rawToProperty,
7
+ toStorageType,
8
+ };
9
+ }
10
+ exports.defineTransformer = defineTransformer;
@@ -0,0 +1,29 @@
1
+ import { IPropTransformer, PropertyType, __StringType } from "../Property";
2
+ export type ColumnType_DM = PropertyType;
3
+ export interface ColumnInfoDM {
4
+ COLUMN_NAME?: string;
5
+ DATA_TYPE?: string;
6
+ DATA_LENGTH?: number | string;
7
+ DATA_PRECISION?: number | string;
8
+ DATA_SCALE?: number | string;
9
+ NULLABLE?: __StringType<'Y' | 'N' | 'YES' | 'NO'>;
10
+ DATA_DEFAULT?: any;
11
+ CHAR_LENGTH?: number | string;
12
+ IDENTITY_COLUMN?: __StringType<'YES' | 'NO' | 'Y' | 'N'>;
13
+ IS_IDENTITY?: __StringType<'YES' | 'NO' | 'Y' | 'N'>;
14
+ COMMENT?: string;
15
+ column_name?: string;
16
+ data_type?: string;
17
+ data_length?: number | string;
18
+ data_precision?: number | string;
19
+ data_scale?: number | string;
20
+ nullable?: __StringType<'Y' | 'N' | 'YES' | 'NO'>;
21
+ data_default?: any;
22
+ char_length?: number | string;
23
+ identity_column?: __StringType<'YES' | 'NO' | 'Y' | 'N'>;
24
+ is_identity?: __StringType<'YES' | 'NO' | 'Y' | 'N'>;
25
+ comment?: string;
26
+ }
27
+ export declare const rawToProperty: IPropTransformer<ColumnInfoDM>['rawToProperty'];
28
+ export declare const toStorageType: IPropTransformer<ColumnInfoDM>['toStorageType'];
29
+ export declare const filterRawColumns: IPropTransformer<ColumnInfoDM>['filterRawColumns'];
@@ -0,0 +1,237 @@
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 normalizeColInfo(colInfo) {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
17
+ const normalized = Object.assign({}, colInfo);
18
+ normalized.COLUMN_NAME = ((_a = normalized.COLUMN_NAME) !== null && _a !== void 0 ? _a : normalized.column_name);
19
+ normalized.DATA_TYPE = ((_b = normalized.DATA_TYPE) !== null && _b !== void 0 ? _b : normalized.data_type);
20
+ normalized.DATA_LENGTH = ((_c = normalized.DATA_LENGTH) !== null && _c !== void 0 ? _c : normalized.data_length);
21
+ normalized.DATA_PRECISION = ((_d = normalized.DATA_PRECISION) !== null && _d !== void 0 ? _d : normalized.data_precision);
22
+ normalized.DATA_SCALE = ((_e = normalized.DATA_SCALE) !== null && _e !== void 0 ? _e : normalized.data_scale);
23
+ normalized.NULLABLE = ((_f = normalized.NULLABLE) !== null && _f !== void 0 ? _f : normalized.nullable);
24
+ normalized.DATA_DEFAULT = ((_g = normalized.DATA_DEFAULT) !== null && _g !== void 0 ? _g : normalized.data_default);
25
+ normalized.CHAR_LENGTH = ((_h = normalized.CHAR_LENGTH) !== null && _h !== void 0 ? _h : normalized.char_length);
26
+ normalized.IDENTITY_COLUMN = ((_l = (_k = (_j = normalized.IDENTITY_COLUMN) !== null && _j !== void 0 ? _j : normalized.identity_column) !== null && _k !== void 0 ? _k : normalized.IS_IDENTITY) !== null && _l !== void 0 ? _l : normalized.is_identity);
27
+ normalized.COMMENT = ((_p = (_o = (_m = normalized.COMMENT) !== null && _m !== void 0 ? _m : normalized.comment) !== null && _o !== void 0 ? _o : normalized.COMMENTS) !== null && _p !== void 0 ? _p : normalized.comments);
28
+ normalized.COLUMN_NAME = normalized.COLUMN_NAME ? normalized.COLUMN_NAME.toString() : '';
29
+ normalized.DATA_TYPE = normalized.DATA_TYPE ? normalized.DATA_TYPE.toString() : '';
30
+ normalized.DATA_LENGTH = normalized.DATA_LENGTH ? normalized.DATA_LENGTH.toString() : '';
31
+ normalized.DATA_PRECISION = normalized.DATA_PRECISION ? normalized.DATA_PRECISION.toString() : '';
32
+ normalized.DATA_SCALE = normalized.DATA_SCALE ? normalized.DATA_SCALE.toString() : '';
33
+ normalized.NULLABLE = normalized.NULLABLE ? normalized.NULLABLE.toString() : '';
34
+ normalized.DATA_DEFAULT = normalized.DATA_DEFAULT !== undefined ? normalized.DATA_DEFAULT.toString() : normalized.DATA_DEFAULT;
35
+ normalized.CHAR_LENGTH = normalized.CHAR_LENGTH ? normalized.CHAR_LENGTH.toString() : '';
36
+ normalized.IDENTITY_COLUMN = normalized.IDENTITY_COLUMN ? normalized.IDENTITY_COLUMN.toString() : '';
37
+ normalized.COMMENT = normalized.COMMENT ? normalized.COMMENT.toString() : '';
38
+ return normalized;
39
+ }
40
+ function isIdentityColumn(colInfo) {
41
+ const v = colInfo.IDENTITY_COLUMN ? colInfo.IDENTITY_COLUMN.toString().toUpperCase() : '';
42
+ return v === 'YES' || v === 'Y' || v === 'TRUE' || v === '1';
43
+ }
44
+ function colInfoToProperty(colInfo) {
45
+ const property = {};
46
+ const col = normalizeColInfo(colInfo);
47
+ const type = col.DATA_TYPE.toUpperCase();
48
+ if (isIdentityColumn(col)) {
49
+ property.serial = true;
50
+ property.key = true;
51
+ property.primary = true;
52
+ }
53
+ if (col.NULLABLE && (col.NULLABLE.toUpperCase() === 'N' || col.NULLABLE.toUpperCase() === 'NO')) {
54
+ property.required = true;
55
+ }
56
+ if (col.DATA_DEFAULT !== 'null' && col.DATA_DEFAULT !== undefined && col.DATA_DEFAULT !== null) {
57
+ property.defaultValue = col.DATA_DEFAULT;
58
+ }
59
+ switch (type) {
60
+ case 'SMALLINT':
61
+ case 'INTEGER':
62
+ case 'INT':
63
+ case 'BIGINT':
64
+ case 'TINYINT':
65
+ property.type = 'integer';
66
+ property.size = 4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */;
67
+ for (let k in columnSizes.integer) {
68
+ if (columnSizes.integer[k] === type) {
69
+ property.size = parseInt(k, 10);
70
+ break;
71
+ }
72
+ }
73
+ break;
74
+ case 'FLOAT':
75
+ case 'DOUBLE':
76
+ case 'REAL':
77
+ case 'NUMERIC':
78
+ case 'DECIMAL':
79
+ property.type = 'number';
80
+ property.rational = true;
81
+ property.size = 8 /* COLUMN_NUMER_TYPE_IDX.DOUBLE */;
82
+ if (type === 'FLOAT' || type === 'REAL') {
83
+ property.size = 4 /* COLUMN_NUMER_TYPE_IDX.FLOAT */;
84
+ }
85
+ break;
86
+ case 'BIT':
87
+ property.type = 'boolean';
88
+ break;
89
+ case 'DATE':
90
+ property.type = 'date';
91
+ break;
92
+ case 'DATETIME':
93
+ case 'TIMESTAMP':
94
+ property.type = 'date';
95
+ property.time = true;
96
+ break;
97
+ case 'CHAR':
98
+ case 'VARCHAR':
99
+ case 'VARCHAR2':
100
+ case 'NCHAR':
101
+ case 'NVARCHAR':
102
+ property.type = 'text';
103
+ if (col.CHAR_LENGTH) {
104
+ property.size = parseInt(String(col.CHAR_LENGTH), 10);
105
+ }
106
+ else if (col.DATA_LENGTH) {
107
+ property.size = parseInt(String(col.DATA_LENGTH), 10);
108
+ }
109
+ break;
110
+ case 'TEXT':
111
+ case 'CLOB':
112
+ case 'LONG':
113
+ case 'LONGVARCHAR':
114
+ property.type = 'text';
115
+ property.big = true;
116
+ break;
117
+ case 'BLOB':
118
+ case 'IMAGE':
119
+ case 'LONGVARBINARY':
120
+ case 'VARBINARY':
121
+ case 'BINARY':
122
+ case 'RAW':
123
+ property.type = 'binary';
124
+ break;
125
+ default:
126
+ throw new Error(`Unknown property type '${type}'`);
127
+ }
128
+ if (property.serial) {
129
+ property.type = 'serial';
130
+ }
131
+ property.mapsTo = col.COLUMN_NAME;
132
+ if (col.COMMENT) {
133
+ property.comment = col.COMMENT;
134
+ }
135
+ return property;
136
+ }
137
+ const rawToProperty = function (colInfo, ctx) {
138
+ return {
139
+ raw: colInfo,
140
+ property: colInfoToProperty(colInfo)
141
+ };
142
+ };
143
+ exports.rawToProperty = rawToProperty;
144
+ const toStorageType = function (inputProperty, ctx) {
145
+ var _a;
146
+ const property = Object.assign({}, inputProperty);
147
+ const result = {
148
+ isCustom: false,
149
+ property,
150
+ typeValue: '',
151
+ };
152
+ if (property.type == 'number' && property.rational === false) {
153
+ property.type = 'integer';
154
+ delete property.rational;
155
+ }
156
+ switch (property.type) {
157
+ case 'text':
158
+ if (property.big) {
159
+ result.typeValue = 'TEXT';
160
+ }
161
+ else {
162
+ const size = Math.min(Math.max(parseInt(property.size, 10) || 255, 1), 32767);
163
+ result.typeValue = `VARCHAR(${size})`;
164
+ }
165
+ break;
166
+ case 'integer':
167
+ result.typeValue = columnSizes.integer[property.size] || columnSizes.integer[4 /* COLUMN_NUMER_TYPE_IDX.INTEGER */];
168
+ break;
169
+ case 'number':
170
+ result.typeValue = columnSizes.floating[property.size] || columnSizes.floating[8 /* COLUMN_NUMER_TYPE_IDX.DOUBLE */];
171
+ break;
172
+ case 'serial':
173
+ property.type = 'number';
174
+ property.serial = true;
175
+ property.key = true;
176
+ result.typeValue = 'INT';
177
+ break;
178
+ case 'boolean':
179
+ result.typeValue = 'BIT';
180
+ break;
181
+ case 'datetime':
182
+ property.type = 'date';
183
+ property.time = true;
184
+ case 'date':
185
+ result.typeValue = property.time ? 'DATETIME' : 'DATE';
186
+ break;
187
+ case 'binary':
188
+ result.typeValue = 'BLOB';
189
+ break;
190
+ case 'object':
191
+ result.typeValue = 'TEXT';
192
+ break;
193
+ case 'point':
194
+ result.typeValue = 'TEXT';
195
+ break;
196
+ case 'enum':
197
+ result.typeValue = 'VARCHAR(255)';
198
+ break;
199
+ case 'point':
200
+ default:
201
+ result.isCustom = true;
202
+ break;
203
+ }
204
+ if (!result.typeValue && !result.isCustom)
205
+ return result;
206
+ if (property.required) {
207
+ result.typeValue += ' NOT NULL';
208
+ }
209
+ if (property.serial) {
210
+ if (!property.required) {
211
+ result.typeValue += ' NOT NULL';
212
+ }
213
+ result.typeValue += ' IDENTITY(1,1)';
214
+ }
215
+ if (result.isCustom) {
216
+ if ((_a = ctx.customTypes) === null || _a === void 0 ? void 0 : _a[property.type]) {
217
+ result.typeValue = ctx.customTypes[property.type].datastoreType(property, ctx);
218
+ }
219
+ }
220
+ else if (property.hasOwnProperty('defaultValue') && property.defaultValue !== undefined) {
221
+ const defaultValue = property.type === 'date' && property.defaultValue === Date.now
222
+ ? 'CURRENT_TIMESTAMP'
223
+ : (0, Utils_1.filterPropertyDefaultValue)(property, ctx);
224
+ result.typeValue += ` DEFAULT ${property.type === 'date' && (['CURRENT_TIMESTAMP'].includes(defaultValue))
225
+ ? defaultValue
226
+ : ctx.escapeVal(defaultValue)}`;
227
+ }
228
+ if (property.comment) {
229
+ result.typeValue += ` COMMENT ${ctx.escapeVal(property.comment)}`;
230
+ }
231
+ return result;
232
+ };
233
+ exports.toStorageType = toStorageType;
234
+ const filterRawColumns = function (col) {
235
+ return normalizeColInfo(col);
236
+ };
237
+ exports.filterRawColumns = filterRawColumns;
@@ -0,0 +1,4 @@
1
+ export import mysql = require('./mysql');
2
+ export import sqlite = require('./sqlite');
3
+ export import postgresql = require('./postgresql');
4
+ export import dm = require('./dm');
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.mysql = require("./mysql");
3
+ exports.sqlite = require("./sqlite");
4
+ exports.postgresql = require("./postgresql");
5
+ exports.dm = require("./dm");
@@ -0,0 +1,102 @@
1
+ /// <reference types="@fibjs/types" />
2
+ import { IPropTransformer, PropertyType, __StringType } from "../Property";
3
+ export type ColumnType_MySQL = PropertyType;
4
+ /**
5
+ * result from:
6
+ * 1. SHOW COLUMN FROM ??;
7
+ * 1. SHOW FULL COLUMN FROM ??;
8
+ *
9
+ * there're extra fields in the result of sql 2: Collation, Comment, Privileges
10
+ *
11
+ */
12
+ export interface ColumnInfoMySQL {
13
+ Field: string;
14
+ Type: Class_Buffer | __StringType<'smallint' | 'integer' | 'bigint' | 'int' | 'float' | 'double' | 'tinyint' | 'datetime' | 'date' | 'longblob' | 'blob' | 'varchar'>;
15
+ Size: number | string;
16
+ /**
17
+ * extra description such as `AUTO_INCREMENT`
18
+ */
19
+ Extra: string;
20
+ /**
21
+ * @example `PRI`
22
+ */
23
+ Key: __StringType<'PRI' | 'MUL'>;
24
+ /**
25
+ * @example `NO`
26
+ */
27
+ Null: __StringType<'NO' | 'YES'>;
28
+ /**
29
+ * @deprecated
30
+ */
31
+ SubType?: string[];
32
+ /**
33
+ * @example null
34
+ */
35
+ Default?: any;
36
+ /**
37
+ * @example `utf8mb4_unicode_ci`
38
+ */
39
+ Collation?: string;
40
+ /**
41
+ * @example `select,insert,update,references`
42
+ * type IPrivileges = "select" | "insert" | "update" | "references";
43
+ */
44
+ Privileges?: string;
45
+ Comment?: string;
46
+ }
47
+ export interface ColumnInfoMySQL {
48
+ Field: string;
49
+ Type: Class_Buffer | __StringType<'smallint' | 'integer' | 'bigint' | 'int' | 'float' | 'double' | 'tinyint' | 'datetime' | 'date' | 'longblob' | 'blob' | 'varchar'>;
50
+ Size: number | string;
51
+ /**
52
+ * extra description such as `AUTO_INCREMENT`
53
+ */
54
+ Extra: string;
55
+ /**
56
+ * @example `PRI`
57
+ */
58
+ Key: __StringType<'PRI' | 'MUL'>;
59
+ /**
60
+ * @example `NO`
61
+ */
62
+ Null: __StringType<'NO' | 'YES'>;
63
+ SubType?: string[];
64
+ /**
65
+ * @example null
66
+ */
67
+ Default?: any;
68
+ }
69
+ type DB_INTEGER = number;
70
+ type DB_UNSIGNED_INT = DB_INTEGER;
71
+ type DB_BIGINT = number | bigint;
72
+ type DB_UNSIGNED_BIGINT = DB_BIGINT;
73
+ type DB_TEXT = string;
74
+ type DB_VARCHAR<T extends number = 255> = string;
75
+ export interface SchemaColumnInfoMySQL {
76
+ TABLE_CATALOG: DB_VARCHAR<64>;
77
+ TABLE_SCHEMA: DB_VARCHAR<64>;
78
+ TABLE_NAME: DB_VARCHAR<64>;
79
+ COLUMN_NAME: DB_VARCHAR<64>;
80
+ ORDINAL_POSITION: DB_UNSIGNED_INT;
81
+ COLUMN_DEFAULT: DB_TEXT;
82
+ IS_NULLABLE: DB_VARCHAR<3> | 'NO' | 'YES';
83
+ DATA_TYPE: DB_TEXT;
84
+ CHARACTER_MAXIMUM_LENGTH: DB_BIGINT;
85
+ CHARACTER_OCTET_LENGTH: DB_BIGINT;
86
+ NUMERIC_PRECISION: DB_UNSIGNED_BIGINT;
87
+ NUMERIC_SCALE: DB_UNSIGNED_BIGINT;
88
+ DATETIME_PRECISION: DB_UNSIGNED_INT;
89
+ CHARACTER_SET_NAME: DB_VARCHAR;
90
+ COLLATION_NAME: DB_TEXT;
91
+ COLUMN_TYPE: DB_TEXT;
92
+ COLUMN_KEY: '' | 'PRI' | 'UNI' | 'MUL';
93
+ EXTRA: DB_VARCHAR<256>;
94
+ PRIVILEGES: DB_VARCHAR<154>;
95
+ COLUMN_COMMENT: DB_TEXT;
96
+ GENERATION_EXPRESSION: DB_TEXT;
97
+ SRS_ID: DB_UNSIGNED_INT;
98
+ }
99
+ export declare const rawToProperty: IPropTransformer<ColumnInfoMySQL>['rawToProperty'];
100
+ export declare const toStorageType: IPropTransformer<ColumnInfoMySQL>['toStorageType'];
101
+ export declare const filterRawColumns: IPropTransformer<ColumnInfoMySQL>['filterRawColumns'];
102
+ export {};