@uql/core 1.0.12 → 3.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 (464) hide show
  1. package/CHANGELOG.md +254 -0
  2. package/LICENSE.md +2 -2
  3. package/dist/browser/http/bus.d.ts +3 -0
  4. package/dist/browser/http/bus.js +14 -0
  5. package/dist/browser/http/http.d.ts +6 -0
  6. package/dist/browser/http/http.js +45 -0
  7. package/dist/browser/http/index.d.ts +2 -0
  8. package/dist/browser/http/index.js +3 -0
  9. package/dist/browser/index.d.ts +4 -0
  10. package/dist/browser/index.js +5 -0
  11. package/dist/browser/options.d.ts +4 -0
  12. package/dist/browser/options.js +14 -0
  13. package/dist/browser/querier/genericClientRepository.d.ts +17 -0
  14. package/dist/browser/querier/genericClientRepository.js +39 -0
  15. package/dist/browser/querier/httpQuerier.d.ts +20 -0
  16. package/dist/browser/querier/httpQuerier.js +71 -0
  17. package/dist/browser/querier/index.d.ts +3 -0
  18. package/dist/browser/querier/index.js +4 -0
  19. package/dist/browser/querier/querier.util.d.ts +2 -0
  20. package/dist/browser/querier/querier.util.js +17 -0
  21. package/dist/browser/type/clientQuerier.d.ts +16 -0
  22. package/dist/browser/type/clientQuerier.js +2 -0
  23. package/dist/browser/type/clientQuerierPool.d.ts +4 -0
  24. package/dist/browser/type/clientQuerierPool.js +2 -0
  25. package/dist/browser/type/clientRepository.d.ts +13 -0
  26. package/dist/browser/type/clientRepository.js +2 -0
  27. package/dist/browser/type/index.d.ts +4 -0
  28. package/dist/browser/type/index.js +5 -0
  29. package/dist/browser/type/request.d.ts +28 -0
  30. package/dist/browser/type/request.js +2 -0
  31. package/dist/browser/uql-browser.min.js +2150 -0
  32. package/dist/browser/uql-browser.min.js.map +1 -0
  33. package/dist/dialect/abstractDialect.d.ts +16 -0
  34. package/dist/dialect/abstractDialect.js +28 -0
  35. package/dist/dialect/abstractSqlDialect.d.ts +47 -0
  36. package/dist/dialect/abstractSqlDialect.js +650 -0
  37. package/dist/dialect/index.d.ts +3 -0
  38. package/dist/dialect/index.js +4 -0
  39. package/dist/dialect/queryContext.d.ts +48 -0
  40. package/dist/dialect/queryContext.js +65 -0
  41. package/{entity → dist/entity}/decorator/definition.d.ts +3 -3
  42. package/dist/entity/decorator/definition.js +214 -0
  43. package/{entity → dist/entity}/decorator/entity.d.ts +1 -1
  44. package/dist/entity/decorator/entity.js +7 -0
  45. package/{entity → dist/entity}/decorator/field.d.ts +1 -1
  46. package/dist/entity/decorator/field.js +8 -0
  47. package/{entity → dist/entity}/decorator/id.d.ts +1 -1
  48. package/dist/entity/decorator/id.js +8 -0
  49. package/dist/entity/decorator/index.d.ts +5 -0
  50. package/dist/entity/decorator/index.js +6 -0
  51. package/{entity → dist/entity}/decorator/relation.d.ts +1 -1
  52. package/dist/entity/decorator/relation.js +20 -0
  53. package/dist/entity/index.d.ts +1 -0
  54. package/dist/entity/index.js +2 -0
  55. package/dist/express/index.d.ts +2 -0
  56. package/dist/express/index.js +3 -0
  57. package/dist/express/querierMiddleware.d.ts +26 -0
  58. package/dist/express/querierMiddleware.js +190 -0
  59. package/dist/express/query.util.d.ts +2 -0
  60. package/dist/express/query.util.js +19 -0
  61. package/dist/index.d.ts +9 -0
  62. package/dist/index.js +10 -0
  63. package/dist/maria/index.d.ts +3 -0
  64. package/dist/maria/index.js +4 -0
  65. package/dist/maria/mariaDialect.d.ts +8 -0
  66. package/dist/maria/mariaDialect.js +38 -0
  67. package/dist/maria/mariaQuerierPool.test.d.ts +5 -0
  68. package/dist/maria/mariaQuerierPool.test.js +19 -0
  69. package/dist/maria/mariadbQuerier.d.ts +17 -0
  70. package/dist/maria/mariadbQuerier.js +39 -0
  71. package/dist/maria/mariadbQuerier.test.d.ts +4 -0
  72. package/dist/maria/mariadbQuerier.test.js +19 -0
  73. package/dist/maria/mariadbQuerierPool.d.ts +10 -0
  74. package/dist/maria/mariadbQuerierPool.js +17 -0
  75. package/dist/migrate/cli.d.ts +2 -0
  76. package/dist/migrate/cli.js +254 -0
  77. package/dist/migrate/generator/index.d.ts +4 -0
  78. package/dist/migrate/generator/index.js +5 -0
  79. package/dist/migrate/generator/mongoSchemaGenerator.d.ts +12 -0
  80. package/dist/migrate/generator/mongoSchemaGenerator.js +100 -0
  81. package/dist/migrate/generator/mysqlSchemaGenerator.d.ts +14 -0
  82. package/dist/migrate/generator/mysqlSchemaGenerator.js +81 -0
  83. package/dist/migrate/generator/postgresSchemaGenerator.d.ts +18 -0
  84. package/dist/migrate/generator/postgresSchemaGenerator.js +111 -0
  85. package/dist/migrate/generator/sqliteSchemaGenerator.d.ts +14 -0
  86. package/dist/migrate/generator/sqliteSchemaGenerator.js +68 -0
  87. package/dist/migrate/index.d.ts +12 -0
  88. package/dist/migrate/index.js +17 -0
  89. package/dist/migrate/introspection/index.d.ts +4 -0
  90. package/dist/migrate/introspection/index.js +5 -0
  91. package/dist/migrate/introspection/mongoIntrospector.d.ts +8 -0
  92. package/dist/migrate/introspection/mongoIntrospector.js +46 -0
  93. package/dist/migrate/introspection/mysqlIntrospector.d.ts +25 -0
  94. package/dist/migrate/introspection/mysqlIntrospector.js +220 -0
  95. package/dist/migrate/introspection/postgresIntrospector.d.ts +21 -0
  96. package/dist/migrate/introspection/postgresIntrospector.js +269 -0
  97. package/dist/migrate/introspection/sqliteIntrospector.d.ts +23 -0
  98. package/dist/migrate/introspection/sqliteIntrospector.js +212 -0
  99. package/dist/migrate/migrator-mongo.test.d.ts +1 -0
  100. package/dist/migrate/migrator-mongo.test.js +54 -0
  101. package/dist/migrate/migrator.d.ts +133 -0
  102. package/dist/migrate/migrator.js +600 -0
  103. package/dist/migrate/migrator.test.d.ts +1 -0
  104. package/dist/migrate/migrator.test.js +106 -0
  105. package/dist/migrate/schemaGenerator.d.ts +78 -0
  106. package/dist/migrate/schemaGenerator.js +363 -0
  107. package/dist/migrate/storage/databaseStorage.d.ts +24 -0
  108. package/dist/migrate/storage/databaseStorage.js +77 -0
  109. package/dist/migrate/storage/index.d.ts +2 -0
  110. package/dist/migrate/storage/index.js +3 -0
  111. package/dist/migrate/storage/jsonStorage.d.ts +15 -0
  112. package/dist/migrate/storage/jsonStorage.js +51 -0
  113. package/dist/migrate/type.d.ts +1 -0
  114. package/dist/migrate/type.js +2 -0
  115. package/dist/mongo/index.d.ts +3 -0
  116. package/dist/mongo/index.js +4 -0
  117. package/dist/mongo/mongoDialect.d.ts +34 -0
  118. package/dist/mongo/mongoDialect.js +163 -0
  119. package/dist/mongo/mongodbQuerier.d.ts +28 -0
  120. package/dist/mongo/mongodbQuerier.js +204 -0
  121. package/dist/mongo/mongodbQuerier.test.d.ts +1 -0
  122. package/dist/mongo/mongodbQuerier.test.js +36 -0
  123. package/dist/mongo/mongodbQuerierPool.d.ts +10 -0
  124. package/dist/mongo/mongodbQuerierPool.js +20 -0
  125. package/dist/mongo/mongodbQuerierPool.test.d.ts +1 -0
  126. package/dist/mongo/mongodbQuerierPool.test.js +21 -0
  127. package/dist/mysql/index.d.ts +3 -0
  128. package/dist/mysql/index.js +4 -0
  129. package/dist/mysql/mysql2Querier.d.ts +17 -0
  130. package/dist/mysql/mysql2Querier.js +43 -0
  131. package/dist/mysql/mysql2Querier.test.d.ts +4 -0
  132. package/dist/mysql/mysql2Querier.test.js +16 -0
  133. package/dist/mysql/mysql2QuerierPool.d.ts +10 -0
  134. package/dist/mysql/mysql2QuerierPool.js +17 -0
  135. package/dist/mysql/mysql2QuerierPool.test.d.ts +5 -0
  136. package/dist/mysql/mysql2QuerierPool.test.js +16 -0
  137. package/dist/mysql/mysqlDialect.d.ts +5 -0
  138. package/dist/mysql/mysqlDialect.js +15 -0
  139. package/dist/namingStrategy/defaultNamingStrategy.d.ts +9 -0
  140. package/dist/namingStrategy/defaultNamingStrategy.js +15 -0
  141. package/dist/namingStrategy/index.d.ts +2 -0
  142. package/dist/namingStrategy/index.js +3 -0
  143. package/dist/namingStrategy/snakeCaseNamingStrategy.d.ts +8 -0
  144. package/dist/namingStrategy/snakeCaseNamingStrategy.js +14 -0
  145. package/{options.d.ts → dist/options.d.ts} +1 -1
  146. package/dist/options.js +14 -0
  147. package/dist/package.json +131 -0
  148. package/dist/postgres/index.d.ts +3 -0
  149. package/dist/postgres/index.js +4 -0
  150. package/dist/postgres/pgQuerier.d.ts +17 -0
  151. package/dist/postgres/pgQuerier.js +39 -0
  152. package/dist/postgres/pgQuerier.test.d.ts +4 -0
  153. package/dist/postgres/pgQuerier.test.js +20 -0
  154. package/dist/postgres/pgQuerierPool.d.ts +10 -0
  155. package/dist/postgres/pgQuerierPool.js +17 -0
  156. package/dist/postgres/pgQuerierPool.test.d.ts +5 -0
  157. package/dist/postgres/pgQuerierPool.test.js +23 -0
  158. package/dist/postgres/postgresDialect.d.ts +13 -0
  159. package/dist/postgres/postgresDialect.js +110 -0
  160. package/dist/querier/abstractQuerier-test.d.ts +45 -0
  161. package/dist/querier/abstractQuerier-test.js +461 -0
  162. package/dist/querier/abstractQuerier.d.ts +50 -0
  163. package/dist/querier/abstractQuerier.js +278 -0
  164. package/dist/querier/abstractQuerierPool-test.d.ts +9 -0
  165. package/dist/querier/abstractQuerierPool-test.js +18 -0
  166. package/dist/querier/abstractQuerierPool.d.ts +14 -0
  167. package/dist/querier/abstractQuerierPool.js +9 -0
  168. package/dist/querier/abstractSqlQuerier-test.d.ts +9 -0
  169. package/dist/querier/abstractSqlQuerier-test.js +16 -0
  170. package/dist/querier/abstractSqlQuerier.d.ts +28 -0
  171. package/dist/querier/abstractSqlQuerier.js +133 -0
  172. package/dist/querier/decorator/index.d.ts +3 -0
  173. package/dist/querier/decorator/index.js +4 -0
  174. package/dist/querier/decorator/injectQuerier.d.ts +3 -0
  175. package/dist/querier/decorator/injectQuerier.js +33 -0
  176. package/dist/querier/decorator/serialized.d.ts +6 -0
  177. package/dist/querier/decorator/serialized.js +14 -0
  178. package/{querier → dist/querier}/decorator/transactional.d.ts +1 -1
  179. package/dist/querier/decorator/transactional.js +48 -0
  180. package/dist/querier/index.d.ts +4 -0
  181. package/dist/querier/index.js +5 -0
  182. package/dist/repository/genericRepository.d.ts +20 -0
  183. package/dist/repository/genericRepository.js +51 -0
  184. package/dist/repository/index.d.ts +1 -0
  185. package/dist/repository/index.js +2 -0
  186. package/dist/sqlite/index.d.ts +3 -0
  187. package/dist/sqlite/index.js +4 -0
  188. package/dist/sqlite/sqliteDialect.d.ts +10 -0
  189. package/dist/sqlite/sqliteDialect.js +48 -0
  190. package/dist/sqlite/sqliteQuerier.d.ts +15 -0
  191. package/dist/sqlite/sqliteQuerier.js +33 -0
  192. package/dist/sqlite/sqliteQuerier.test.d.ts +5 -0
  193. package/dist/sqlite/sqliteQuerier.test.js +19 -0
  194. package/dist/sqlite/sqliteQuerierPool.d.ts +14 -0
  195. package/dist/sqlite/sqliteQuerierPool.js +34 -0
  196. package/dist/sqlite/sqliteQuerierPool.test.d.ts +5 -0
  197. package/dist/sqlite/sqliteQuerierPool.test.js +10 -0
  198. package/dist/test/entityMock.d.ts +164 -0
  199. package/dist/test/entityMock.js +554 -0
  200. package/dist/test/index.d.ts +3 -0
  201. package/dist/test/index.js +4 -0
  202. package/dist/test/it.util.d.ts +4 -0
  203. package/dist/test/it.util.js +55 -0
  204. package/dist/test/spec.util.d.ts +14 -0
  205. package/dist/test/spec.util.js +50 -0
  206. package/{type → dist/type}/entity.d.ts +97 -4
  207. package/dist/type/entity.js +5 -0
  208. package/dist/type/index.d.ts +9 -0
  209. package/dist/type/index.js +10 -0
  210. package/dist/type/migration.d.ts +213 -0
  211. package/dist/type/migration.js +2 -0
  212. package/dist/type/namingStrategy.d.ts +17 -0
  213. package/dist/type/namingStrategy.js +2 -0
  214. package/dist/type/querier.d.ts +96 -0
  215. package/dist/type/querier.js +11 -0
  216. package/{type → dist/type}/querierPool.d.ts +7 -3
  217. package/dist/type/querierPool.js +2 -0
  218. package/{type → dist/type}/query.d.ts +170 -108
  219. package/dist/type/query.js +9 -0
  220. package/{type → dist/type}/repository.d.ts +42 -35
  221. package/dist/type/repository.js +2 -0
  222. package/{type → dist/type}/universalQuerier.d.ts +50 -28
  223. package/dist/type/universalQuerier.js +2 -0
  224. package/dist/type/utility.d.ts +13 -0
  225. package/dist/type/utility.js +2 -0
  226. package/dist/util/dialect.util.d.ts +12 -0
  227. package/dist/util/dialect.util.js +93 -0
  228. package/dist/util/index.d.ts +5 -0
  229. package/dist/util/index.js +6 -0
  230. package/dist/util/object.util.d.ts +7 -0
  231. package/dist/util/object.util.js +19 -0
  232. package/dist/util/raw.d.ts +8 -0
  233. package/dist/util/raw.js +11 -0
  234. package/dist/util/sql.util.d.ts +13 -0
  235. package/dist/util/sql.util.js +78 -0
  236. package/{util → dist/util}/string.util.d.ts +1 -0
  237. package/dist/util/string.util.js +34 -0
  238. package/package.json +85 -17
  239. package/src/@types/index.d.ts +1 -0
  240. package/src/@types/jest.d.ts +6 -0
  241. package/src/browser/http/bus.spec.ts +22 -0
  242. package/src/browser/http/bus.ts +17 -0
  243. package/src/browser/http/http.spec.ts +70 -0
  244. package/src/browser/http/http.ts +55 -0
  245. package/src/browser/http/index.ts +2 -0
  246. package/src/browser/index.ts +4 -0
  247. package/src/browser/options.spec.ts +37 -0
  248. package/src/browser/options.ts +18 -0
  249. package/src/browser/querier/genericClientRepository.spec.ts +105 -0
  250. package/src/browser/querier/genericClientRepository.ts +49 -0
  251. package/src/browser/querier/httpQuerier.ts +82 -0
  252. package/src/browser/querier/index.ts +3 -0
  253. package/src/browser/querier/querier.util.spec.ts +35 -0
  254. package/src/browser/querier/querier.util.ts +18 -0
  255. package/src/browser/type/clientQuerier.ts +45 -0
  256. package/src/browser/type/clientQuerierPool.ts +5 -0
  257. package/src/browser/type/clientRepository.ts +22 -0
  258. package/src/browser/type/index.ts +4 -0
  259. package/src/browser/type/request.ts +25 -0
  260. package/src/dialect/abstractDialect.ts +28 -0
  261. package/src/dialect/abstractSqlDialect-spec.ts +1309 -0
  262. package/src/dialect/abstractSqlDialect.ts +805 -0
  263. package/src/dialect/index.ts +3 -0
  264. package/src/dialect/namingStrategy.spec.ts +52 -0
  265. package/src/dialect/queryContext.ts +69 -0
  266. package/src/entity/decorator/definition.spec.ts +736 -0
  267. package/src/entity/decorator/definition.ts +265 -0
  268. package/src/entity/decorator/entity.ts +8 -0
  269. package/src/entity/decorator/field.ts +9 -0
  270. package/src/entity/decorator/id.ts +9 -0
  271. package/src/entity/decorator/index.ts +5 -0
  272. package/src/entity/decorator/relation.spec.ts +41 -0
  273. package/src/entity/decorator/relation.ts +34 -0
  274. package/src/entity/index.ts +1 -0
  275. package/src/express/@types/express.d.ts +8 -0
  276. package/src/express/@types/index.d.ts +1 -0
  277. package/src/express/index.ts +2 -0
  278. package/src/express/querierMiddleware.ts +217 -0
  279. package/src/express/query.util.spec.ts +40 -0
  280. package/src/express/query.util.ts +21 -0
  281. package/src/index.ts +9 -0
  282. package/src/maria/index.ts +3 -0
  283. package/src/maria/mariaDialect.spec.ts +207 -0
  284. package/src/maria/mariaDialect.ts +42 -0
  285. package/src/maria/mariaQuerierPool.test.ts +23 -0
  286. package/src/maria/mariadbQuerier.test.ts +23 -0
  287. package/src/maria/mariadbQuerier.ts +45 -0
  288. package/src/maria/mariadbQuerierPool.ts +21 -0
  289. package/src/migrate/cli.ts +301 -0
  290. package/src/migrate/generator/index.ts +4 -0
  291. package/src/migrate/generator/mongoSchemaGenerator.spec.ts +112 -0
  292. package/src/migrate/generator/mongoSchemaGenerator.ts +115 -0
  293. package/src/migrate/generator/mysqlSchemaGenerator.spec.ts +34 -0
  294. package/src/migrate/generator/mysqlSchemaGenerator.ts +92 -0
  295. package/src/migrate/generator/postgresSchemaGenerator.spec.ts +44 -0
  296. package/src/migrate/generator/postgresSchemaGenerator.ts +127 -0
  297. package/src/migrate/generator/sqliteSchemaGenerator.spec.ts +33 -0
  298. package/src/migrate/generator/sqliteSchemaGenerator.ts +81 -0
  299. package/src/migrate/index.ts +41 -0
  300. package/src/migrate/introspection/index.ts +4 -0
  301. package/src/migrate/introspection/mongoIntrospector.spec.ts +75 -0
  302. package/src/migrate/introspection/mongoIntrospector.ts +47 -0
  303. package/src/migrate/introspection/mysqlIntrospector.spec.ts +113 -0
  304. package/src/migrate/introspection/mysqlIntrospector.ts +278 -0
  305. package/src/migrate/introspection/postgresIntrospector.spec.ts +112 -0
  306. package/src/migrate/introspection/postgresIntrospector.ts +329 -0
  307. package/src/migrate/introspection/sqliteIntrospector.spec.ts +112 -0
  308. package/src/migrate/introspection/sqliteIntrospector.ts +296 -0
  309. package/src/migrate/migrator-mongo.test.ts +54 -0
  310. package/src/migrate/migrator.spec.ts +255 -0
  311. package/src/migrate/migrator.test.ts +94 -0
  312. package/src/migrate/migrator.ts +719 -0
  313. package/src/migrate/namingStrategy.spec.ts +22 -0
  314. package/src/migrate/schemaGenerator-advanced.spec.ts +138 -0
  315. package/src/migrate/schemaGenerator.spec.ts +190 -0
  316. package/src/migrate/schemaGenerator.ts +478 -0
  317. package/src/migrate/storage/databaseStorage.spec.ts +69 -0
  318. package/src/migrate/storage/databaseStorage.ts +100 -0
  319. package/src/migrate/storage/index.ts +2 -0
  320. package/src/migrate/storage/jsonStorage.ts +58 -0
  321. package/src/migrate/type.ts +1 -0
  322. package/src/mongo/index.ts +3 -0
  323. package/src/mongo/mongoDialect.spec.ts +251 -0
  324. package/src/mongo/mongoDialect.ts +238 -0
  325. package/src/mongo/mongodbQuerier.test.ts +45 -0
  326. package/src/mongo/mongodbQuerier.ts +256 -0
  327. package/src/mongo/mongodbQuerierPool.test.ts +25 -0
  328. package/src/mongo/mongodbQuerierPool.ts +24 -0
  329. package/src/mysql/index.ts +3 -0
  330. package/src/mysql/mysql2Querier.test.ts +20 -0
  331. package/src/mysql/mysql2Querier.ts +49 -0
  332. package/src/mysql/mysql2QuerierPool.test.ts +20 -0
  333. package/src/mysql/mysql2QuerierPool.ts +21 -0
  334. package/src/mysql/mysqlDialect.spec.ts +20 -0
  335. package/src/mysql/mysqlDialect.ts +16 -0
  336. package/src/namingStrategy/defaultNamingStrategy.ts +18 -0
  337. package/src/namingStrategy/index.spec.ts +36 -0
  338. package/src/namingStrategy/index.ts +2 -0
  339. package/src/namingStrategy/snakeCaseNamingStrategy.ts +15 -0
  340. package/src/options.spec.ts +41 -0
  341. package/src/options.ts +18 -0
  342. package/src/postgres/index.ts +3 -0
  343. package/src/postgres/manual-types.d.ts +4 -0
  344. package/src/postgres/pgQuerier.test.ts +25 -0
  345. package/src/postgres/pgQuerier.ts +45 -0
  346. package/src/postgres/pgQuerierPool.test.ts +28 -0
  347. package/src/postgres/pgQuerierPool.ts +21 -0
  348. package/src/postgres/postgresDialect.spec.ts +428 -0
  349. package/src/postgres/postgresDialect.ts +144 -0
  350. package/src/querier/abstractQuerier-test.ts +584 -0
  351. package/src/querier/abstractQuerier.ts +353 -0
  352. package/src/querier/abstractQuerierPool-test.ts +20 -0
  353. package/src/querier/abstractQuerierPool.ts +18 -0
  354. package/src/querier/abstractSqlQuerier-spec.ts +979 -0
  355. package/src/querier/abstractSqlQuerier-test.ts +21 -0
  356. package/src/querier/abstractSqlQuerier.ts +138 -0
  357. package/src/querier/decorator/index.ts +3 -0
  358. package/src/querier/decorator/injectQuerier.spec.ts +74 -0
  359. package/src/querier/decorator/injectQuerier.ts +45 -0
  360. package/src/querier/decorator/serialized.spec.ts +98 -0
  361. package/src/querier/decorator/serialized.ts +13 -0
  362. package/src/querier/decorator/transactional.spec.ts +240 -0
  363. package/src/querier/decorator/transactional.ts +56 -0
  364. package/src/querier/index.ts +4 -0
  365. package/src/repository/genericRepository.spec.ts +111 -0
  366. package/src/repository/genericRepository.ts +74 -0
  367. package/src/repository/index.ts +1 -0
  368. package/src/sqlite/index.ts +3 -0
  369. package/src/sqlite/manual-types.d.ts +4 -0
  370. package/src/sqlite/sqliteDialect.spec.ts +155 -0
  371. package/src/sqlite/sqliteDialect.ts +76 -0
  372. package/src/sqlite/sqliteQuerier.spec.ts +36 -0
  373. package/src/sqlite/sqliteQuerier.test.ts +21 -0
  374. package/src/sqlite/sqliteQuerier.ts +37 -0
  375. package/src/sqlite/sqliteQuerierPool.test.ts +12 -0
  376. package/src/sqlite/sqliteQuerierPool.ts +38 -0
  377. package/src/test/entityMock.ts +375 -0
  378. package/src/test/index.ts +3 -0
  379. package/src/test/it.util.ts +69 -0
  380. package/src/test/spec.util.ts +57 -0
  381. package/src/type/entity.ts +218 -0
  382. package/src/type/index.ts +9 -0
  383. package/src/type/migration.ts +241 -0
  384. package/src/type/namingStrategy.ts +17 -0
  385. package/src/type/querier.ts +143 -0
  386. package/src/type/querierPool.ts +26 -0
  387. package/src/type/query.ts +506 -0
  388. package/src/type/repository.ts +142 -0
  389. package/src/type/universalQuerier.ts +133 -0
  390. package/src/type/utility.ts +21 -0
  391. package/src/util/dialect.util-extra.spec.ts +96 -0
  392. package/src/util/dialect.util.spec.ts +23 -0
  393. package/src/util/dialect.util.ts +134 -0
  394. package/src/util/index.ts +5 -0
  395. package/src/util/object.util.spec.ts +29 -0
  396. package/src/util/object.util.ts +27 -0
  397. package/src/util/raw.ts +11 -0
  398. package/src/util/sql.util-extra.spec.ts +17 -0
  399. package/src/util/sql.util.spec.ts +208 -0
  400. package/src/util/sql.util.ts +104 -0
  401. package/src/util/string.util.spec.ts +46 -0
  402. package/src/util/string.util.ts +35 -0
  403. package/tsconfig.build.json +5 -0
  404. package/tsconfig.json +8 -0
  405. package/README.md +0 -177
  406. package/dialect/abstractSqlDialect.d.ts +0 -30
  407. package/dialect/abstractSqlDialect.js +0 -365
  408. package/dialect/index.d.ts +0 -4
  409. package/dialect/index.js +0 -8
  410. package/dialect/mysqlDialect.d.ts +0 -6
  411. package/dialect/mysqlDialect.js +0 -21
  412. package/dialect/postgresDialect.d.ts +0 -8
  413. package/dialect/postgresDialect.js +0 -44
  414. package/dialect/sqliteDialect.d.ts +0 -4
  415. package/dialect/sqliteDialect.js +0 -11
  416. package/entity/decorator/definition.js +0 -223
  417. package/entity/decorator/entity.js +0 -11
  418. package/entity/decorator/field.js +0 -12
  419. package/entity/decorator/id.js +0 -12
  420. package/entity/decorator/index.d.ts +0 -5
  421. package/entity/decorator/index.js +0 -12
  422. package/entity/decorator/relation.js +0 -27
  423. package/entity/index.d.ts +0 -1
  424. package/entity/index.js +0 -5
  425. package/index.d.ts +0 -1
  426. package/index.js +0 -5
  427. package/options.js +0 -20
  428. package/querier/abstractQuerier.d.ts +0 -30
  429. package/querier/abstractQuerier.js +0 -230
  430. package/querier/abstractSqlQuerier.d.ts +0 -27
  431. package/querier/abstractSqlQuerier.js +0 -88
  432. package/querier/decorator/index.d.ts +0 -2
  433. package/querier/decorator/index.js +0 -6
  434. package/querier/decorator/injectQuerier.d.ts +0 -3
  435. package/querier/decorator/injectQuerier.js +0 -39
  436. package/querier/decorator/transactional.js +0 -52
  437. package/querier/index.d.ts +0 -3
  438. package/querier/index.js +0 -7
  439. package/repository/genericRepository.d.ts +0 -19
  440. package/repository/genericRepository.js +0 -52
  441. package/repository/index.d.ts +0 -1
  442. package/repository/index.js +0 -5
  443. package/type/entity.js +0 -5
  444. package/type/index.d.ts +0 -7
  445. package/type/index.js +0 -11
  446. package/type/querier.d.ts +0 -53
  447. package/type/querier.js +0 -3
  448. package/type/querierPool.js +0 -3
  449. package/type/query.js +0 -13
  450. package/type/repository.js +0 -3
  451. package/type/universalQuerier.js +0 -3
  452. package/type/utility.d.ts +0 -12
  453. package/type/utility.js +0 -3
  454. package/util/dialect.util.d.ts +0 -17
  455. package/util/dialect.util.js +0 -114
  456. package/util/index.d.ts +0 -5
  457. package/util/index.js +0 -9
  458. package/util/object.util.d.ts +0 -3
  459. package/util/object.util.js +0 -22
  460. package/util/raw.d.ts +0 -2
  461. package/util/raw.js +0 -9
  462. package/util/sql.util.d.ts +0 -2
  463. package/util/sql.util.js +0 -55
  464. package/util/string.util.js +0 -20
@@ -0,0 +1,208 @@
1
+ import { expect, it } from 'bun:test';
2
+ import type { Item, ItemAdjustment, Storehouse } from '../test/index.js';
3
+ import type { QuerySortMap } from '../type/index.js';
4
+ import { escapeSqlId, flatObject, obtainAttrsPaths, unflatObjects } from './sql.util.js';
5
+
6
+ it('flatObject', () => {
7
+ expect(flatObject(undefined)).toEqual({});
8
+ expect(flatObject(null)).toEqual({});
9
+ expect(flatObject({})).toEqual({});
10
+ const sort: QuerySortMap<Item> = {
11
+ name: 1,
12
+ measureUnit: { name: -1, category: { creator: { profile: { picture: 1 } } } },
13
+ };
14
+ expect(flatObject(sort)).toEqual<Record<string, number>>({
15
+ name: 1,
16
+ 'measureUnit.name': -1,
17
+ 'measureUnit.category.creator.profile.picture': 1,
18
+ });
19
+ });
20
+
21
+ it('unflatObjects - empty', () => {
22
+ const res1 = unflatObjects(undefined);
23
+ expect(res1).toBe(undefined);
24
+ const res2 = unflatObjects([]);
25
+ expect(res2).toEqual([]);
26
+ });
27
+
28
+ it('unflatObjects', () => {
29
+ const source: Storehouse[] = [
30
+ {
31
+ id: 1,
32
+ name: 'Auxiliar',
33
+ address: null,
34
+ description: null,
35
+ createdAt: 1,
36
+ updatedAt: null,
37
+ creatorId: 1,
38
+ companyId: 1,
39
+ },
40
+ {
41
+ id: 2,
42
+ name: 'Principal',
43
+ address: null,
44
+ description: null,
45
+ createdAt: 1,
46
+ updatedAt: 1578759519913,
47
+ creatorId: 1,
48
+ companyId: 1,
49
+ },
50
+ ];
51
+ const result = unflatObjects(source);
52
+ const expected: Storehouse[] = [
53
+ {
54
+ id: 1,
55
+ name: 'Auxiliar',
56
+ address: null,
57
+ description: null,
58
+ createdAt: 1,
59
+ updatedAt: null,
60
+ creatorId: 1,
61
+ companyId: 1,
62
+ },
63
+ {
64
+ id: 2,
65
+ name: 'Principal',
66
+ address: null,
67
+ description: null,
68
+ createdAt: 1,
69
+ updatedAt: 1578759519913,
70
+ creatorId: 1,
71
+ companyId: 1,
72
+ },
73
+ ];
74
+ expect(result).toEqual(expected);
75
+ });
76
+
77
+ it('unflatObjects deep', () => {
78
+ const source = [
79
+ {
80
+ id: 9,
81
+ buyPrice: 1000,
82
+ number: 10,
83
+ 'item.id': 1,
84
+ 'item.name': 'Arepa de Yuca y Queso x 6',
85
+ 'item.createdAt': 1,
86
+ 'item.buyLedgerAccount': 1,
87
+ 'item.saleLedgerAccount': 1,
88
+ 'item.tax': 1,
89
+ 'item.companyId': 1,
90
+ 'item.measureUnit': 1,
91
+ 'item.inventoryable': 1,
92
+ 'item.buyLedgerAccount.id': 1,
93
+ 'item.buyLedgerAccount.name': 'Ventas',
94
+ 'item.saleLedgerAccount.id': 1,
95
+ 'item.saleLedgerAccount.name': 'Ventas',
96
+ 'item.tax.id': 1,
97
+ 'item.tax.name': 'IVA 0%',
98
+ 'item.tax.percentage': 0,
99
+ 'item.tax.category.pk': '1',
100
+ 'item.tax.category.name': 'Impuestos',
101
+ 'item.tax.category.description': 'Nacionales',
102
+ 'item.measureUnit.id': 1,
103
+ 'item.measureUnit.name': 'Unidad',
104
+ 'item.creatorId': null as string,
105
+ 'item.creator.id': null as string,
106
+ 'item.creator.name': null as string,
107
+ },
108
+ {
109
+ id: 15,
110
+ buyPrice: 2000,
111
+ number: 20,
112
+ 'item.id': 2,
113
+ 'item.name': 'Pony Malta 2 litros',
114
+ 'item.createdAt': 1,
115
+ 'item.companyId': 1,
116
+ 'item.creatorId': 5,
117
+ 'item.creator.id': 5,
118
+ 'item.creator.name': 'Roshi Master',
119
+ },
120
+ ];
121
+ const result = unflatObjects(source as Item[]);
122
+ const expected: ItemAdjustment[] = [
123
+ {
124
+ id: 9,
125
+ buyPrice: 1000,
126
+ number: 10,
127
+ item: {
128
+ id: 1,
129
+ name: 'Arepa de Yuca y Queso x 6',
130
+ createdAt: 1,
131
+ buyLedgerAccount: {
132
+ id: 1,
133
+ name: 'Ventas',
134
+ },
135
+ saleLedgerAccount: {
136
+ id: 1,
137
+ name: 'Ventas',
138
+ },
139
+ tax: {
140
+ id: 1,
141
+ name: 'IVA 0%',
142
+ percentage: 0,
143
+ category: {
144
+ pk: '1',
145
+ name: 'Impuestos',
146
+ description: 'Nacionales',
147
+ },
148
+ },
149
+ companyId: 1,
150
+ measureUnit: {
151
+ id: 1,
152
+ name: 'Unidad',
153
+ },
154
+ inventoryable: 1 as any as boolean,
155
+ },
156
+ },
157
+ {
158
+ id: 15,
159
+ buyPrice: 2000,
160
+ number: 20,
161
+ item: {
162
+ id: 2,
163
+ name: 'Pony Malta 2 litros',
164
+ createdAt: 1,
165
+ companyId: 1,
166
+ creatorId: 5,
167
+ creator: {
168
+ id: 5,
169
+ name: 'Roshi Master',
170
+ },
171
+ },
172
+ },
173
+ ];
174
+ expect(result).toEqual(expected);
175
+ });
176
+
177
+ it('obtainAttrsPaths - empty', () => {
178
+ const res1 = obtainAttrsPaths(undefined);
179
+ expect(res1).toEqual({});
180
+ const res2 = obtainAttrsPaths({});
181
+ expect(res2).toEqual({});
182
+ });
183
+
184
+ it('obtainAttrsPaths - object', () => {
185
+ const res1 = obtainAttrsPaths({
186
+ 'prop1.a.b': 1,
187
+ 'prop2.c.d': 2,
188
+ });
189
+ console.log('***** res1', res1);
190
+ expect(res1).toEqual({
191
+ 'prop1.a.b': ['prop1', 'a', 'b'],
192
+ 'prop2.c.d': ['prop2', 'c', 'd'],
193
+ });
194
+ });
195
+
196
+ it('escapeSqlId', () => {
197
+ expect(escapeSqlId('table')).toBe('`table`');
198
+ expect(escapeSqlId('table', '"')).toBe('"table"');
199
+ expect(escapeSqlId('table', '`')).toBe('`table`');
200
+ expect(escapeSqlId('my"table', '"')).toBe('"my""table"');
201
+ expect(escapeSqlId('my`table', '`')).toBe('`my``table`');
202
+ expect(escapeSqlId('schema.table')).toBe('`schema`.`table`');
203
+ expect(escapeSqlId('schema.table', '"')).toBe('"schema"."table"');
204
+ expect(escapeSqlId('schema.table', '"', true)).toBe('"schema.table"');
205
+ expect(escapeSqlId('table', '`', false, true)).toBe('`table`.');
206
+ expect(escapeSqlId('')).toBe('');
207
+ expect(escapeSqlId(undefined)).toBe('');
208
+ });
@@ -0,0 +1,104 @@
1
+ import type { FieldValue, Key } from '../type/index.js';
2
+ import { getKeys, hasKeys } from './object.util.js';
3
+
4
+ export function flatObject<E>(obj: E, pre?: string): E {
5
+ return getKeys(obj).reduce(
6
+ (acc, key) => flatObjectEntry(acc, key, obj[key as Key<E>], typeof obj[key as Key<E>] === 'object' ? '' : pre),
7
+ {} as E,
8
+ );
9
+ }
10
+
11
+ function flatObjectEntry<E>(map: E, key: string, val: any, pre?: string): E {
12
+ const prefix = pre ? `${pre}.${key}` : key;
13
+ return typeof val === 'object'
14
+ ? getKeys(val).reduce((acc, prop) => flatObjectEntry(acc, prop, val[prop], prefix), map)
15
+ : { ...map, [prefix]: val };
16
+ }
17
+
18
+ export function unflatObjects<T>(objects: T[]): T[] {
19
+ if (!Array.isArray(objects) || !objects.length) {
20
+ return objects;
21
+ }
22
+
23
+ const attrsPaths = obtainAttrsPaths(objects[0]);
24
+
25
+ if (!hasKeys(attrsPaths)) {
26
+ return objects;
27
+ }
28
+
29
+ return objects.map((row) => {
30
+ const dto = {} as T;
31
+
32
+ for (const col in row) {
33
+ if (row[col] === null) {
34
+ continue;
35
+ }
36
+ const attrPath = attrsPaths[col];
37
+ if (attrPath) {
38
+ const target = attrPath.slice(0, -1).reduce(
39
+ (acc, key) => {
40
+ if (typeof acc[key as Key<T>] !== 'object') {
41
+ acc[key as Key<T>] = {} as FieldValue<T>;
42
+ }
43
+ return acc[key as Key<T>];
44
+ },
45
+ dto as Record<string, any>,
46
+ );
47
+ target[attrPath[attrPath.length - 1]] = row[col];
48
+ } else {
49
+ dto[col] = row[col];
50
+ }
51
+ }
52
+
53
+ return dto;
54
+ });
55
+ }
56
+
57
+ export function obtainAttrsPaths<T>(row: T) {
58
+ return getKeys(row).reduce(
59
+ (acc, col) => {
60
+ // Support both dot notation (legacy) and underscore notation (new)
61
+ if (col.includes('.')) {
62
+ acc[col] = col.split('.');
63
+ } else if (col.includes('_') && col !== col.toUpperCase()) {
64
+ // Convert underscore to dot notation for nested paths
65
+ // Skip all-uppercase (like UPPER_CASE constants)
66
+ acc[col] = col.split('_');
67
+ }
68
+ return acc;
69
+ },
70
+ {} as { [k: string]: string[] },
71
+ );
72
+ }
73
+
74
+ /**
75
+ * Escape a SQL identifier (table name, column name, etc.)
76
+ * @param val the identifier to escape
77
+ * @param escapeIdChar the escape character to use (e.g. ` or ")
78
+ * @param forbidQualified whether to forbid qualified identifiers (containing dots)
79
+ * @param addDot whether to add a dot suffix
80
+ */
81
+ export function escapeSqlId(
82
+ val: string,
83
+ escapeIdChar: '`' | '"' = '`',
84
+ forbidQualified?: boolean,
85
+ addDot?: boolean,
86
+ ): string {
87
+ if (!val) {
88
+ return '';
89
+ }
90
+
91
+ if (!forbidQualified && val.includes('.')) {
92
+ const result = val
93
+ .split('.')
94
+ .map((it) => escapeSqlId(it, escapeIdChar, true))
95
+ .join('.');
96
+ return addDot ? result + '.' : result;
97
+ }
98
+
99
+ const escaped = escapeIdChar + val.replace(new RegExp(escapeIdChar, 'g'), escapeIdChar + escapeIdChar) + escapeIdChar;
100
+
101
+ const suffix = addDot ? '.' : '';
102
+
103
+ return escaped + suffix;
104
+ }
@@ -0,0 +1,46 @@
1
+ import { expect, it } from 'bun:test';
2
+ import { kebabCase, lowerFirst, snakeCase, upperFirst } from './string.util.js';
3
+
4
+ it('kebabCase', () => {
5
+ const res1 = kebabCase('SomeWordsAndMore');
6
+ expect(res1).toBe('some-words-and-more');
7
+ const res2 = kebabCase('someWordsAndMore');
8
+ expect(res2).toBe('some-words-and-more');
9
+ });
10
+
11
+ it('upperFirst', () => {
12
+ const res1 = upperFirst('id');
13
+ expect(res1).toBe('Id');
14
+ const res2 = upperFirst('Id');
15
+ expect(res2).toBe('Id');
16
+ const res3 = upperFirst('idSomething');
17
+ expect(res3).toBe('IdSomething');
18
+ });
19
+
20
+ it('lowerFirst', () => {
21
+ const res1 = lowerFirst('id');
22
+ expect(res1).toBe('id');
23
+ const res2 = lowerFirst('Id');
24
+ expect(res2).toBe('id');
25
+ const res3 = lowerFirst('IdSomething');
26
+ expect(res3).toBe('idSomething');
27
+ });
28
+
29
+ it('snakeCase', () => {
30
+ const res1 = snakeCase('SomeWordsAndMore');
31
+ expect(res1).toBe('some_words_and_more');
32
+ const res2 = snakeCase('someWordsAndMore');
33
+ expect(res2).toBe('some_words_and_more');
34
+ const res3 = snakeCase('simple');
35
+ expect(res3).toBe('simple');
36
+ const res4 = snakeCase('ID');
37
+ expect(res4).toBe('i_d');
38
+ const res5 = snakeCase('already_snake');
39
+ expect(res5).toBe('already_snake');
40
+ const res6 = snakeCase('');
41
+ expect(res6).toBe('');
42
+ const res7 = snakeCase(undefined);
43
+ expect(res7).toBe(undefined);
44
+ const res8 = snakeCase(null);
45
+ expect(res8).toBe(null);
46
+ });
@@ -0,0 +1,35 @@
1
+ export function kebabCase(val: string): string {
2
+ let resp = val.charAt(0).toLowerCase();
3
+ for (let i = 1; i < val.length; ++i) {
4
+ resp += val[i] === val[i].toUpperCase() ? '-' + val[i].toLowerCase() : val[i];
5
+ }
6
+ return resp;
7
+ }
8
+
9
+ export function upperFirst(text: string): string {
10
+ return text[0].toUpperCase() + text.slice(1);
11
+ }
12
+
13
+ export function lowerFirst(text: string): string {
14
+ return text[0].toLowerCase() + text.slice(1);
15
+ }
16
+
17
+ export function snakeCase(val: string): string {
18
+ if (val === undefined || val === null) {
19
+ return val;
20
+ }
21
+ if (!val) {
22
+ return '';
23
+ }
24
+ let resp = val.charAt(0).toLowerCase();
25
+ for (let i = 1; i < val.length; ++i) {
26
+ const char = val[i];
27
+ const charLower = char.toLowerCase();
28
+ if (char !== charLower && char === char.toUpperCase()) {
29
+ resp += '_' + charLower;
30
+ } else {
31
+ resp += char;
32
+ }
33
+ }
34
+ return resp;
35
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.json",
4
+ "exclude": ["node_modules", "dist", "**/*/*.spec.ts", "**/*/*-spec.ts", "**/*/*.it.ts", "**/*/*-it.ts", "**/*/test"]
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"]
8
+ }
package/README.md DELETED
@@ -1,177 +0,0 @@
1
- # [uql](https://nukak.org) &middot; [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/rogerpadilla/uql/blob/main/LICENSE) [![tests](https://github.com/rogerpadilla/uql/actions/workflows/tests.yml/badge.svg)](https://github.com/rogerpadilla/uql) [![coverage status](https://coveralls.io/repos/rogerpadilla/uql/badge.svg?branch=main)](https://coveralls.io/r/rogerpadilla/uql?branch=main) [![npm version](https://badge.fury.io/js/%40uql%2Fcore.svg)](https://badge.fury.io/js/%40uql%2Fcore)
2
-
3
- ## Quick Start
4
-
5
- `uql` is a flexible and efficient `ORM`, with declarative `JSON` syntax and really smart type-safety.
6
-
7
- The `uql` queries can be safely written in the frontend (browser/mobile) and sent to the backend; or only use `uql` in the backend, or even in a mobile app with an embedded database (like `sqlite`).
8
-
9
- ### <a name="features"></a> Features
10
-
11
- - `JSON` (serializable) syntax for all the [queries](https://nukak.org/docs/querying-logical-operators).
12
- - uses the power of `TypeScript` to get smart type-safety [everywhere](https://nukak.org/docs/api-repository).
13
- - the generated queries are [performant](https://nukak.org/docs/querying-retrieve-relations), safe, and human-readable.
14
- - `$project`, `$filter`, `$sort`, `$limit` works at [multiple levels](https://nukak.org/docs/querying-retrieve-relations) (including deep relations and their fields).
15
- - [declarative](https://nukak.org/docs/transactions-declarative) and [imperative](https://nukak.org/docs/transactions-imperative) `transactions`.
16
- - [soft-delete](https://nukak.org/docs/entities-soft-delete), [virtual fields](https://nukak.org/docs/entities-virtual-fields), [repositories](https://nukak.org/docs/api-repository), `connection pooling`.
17
- - transparent support for [inheritance](https://nukak.org/docs/entities-advanced) between entities.
18
- - supports `Postgres`, `MySQL`, `MariaDB`, `SQLite`, `MongoDB`.
19
-
20
- ### <a name="installation"></a> Installation
21
-
22
- 1. Install the core package:
23
-
24
- ```sh
25
- npm install @uql/core --save
26
- ```
27
-
28
- or
29
-
30
- ```sh
31
- yarn add @uql/core
32
- ```
33
-
34
- 2. Install one of the specific packages according to your database:
35
-
36
- | Database | Package |
37
- | ------------ | --------------- |
38
- | `MySQL` | `@uql/mysql` |
39
- | `PostgreSQL` | `@uql/postgres` |
40
- | `MariaDB` | `@uql/maria` |
41
- | `MongoDB` | `@uql/mongo` |
42
- | `SQLite` | `@uql/sqlite` |
43
-
44
- E.g. for `PostgreSQL`
45
-
46
- ```sh
47
- npm install @uql/postgres --save
48
- ```
49
-
50
- or with _yarn_
51
-
52
- ```sh
53
- yarn add @uql/postgres
54
- ```
55
-
56
- 3. Additionally, your `tsconfig.json` may need the following flags:
57
-
58
- ```json
59
- "target": "es2020",
60
- "experimentalDecorators": true,
61
- "emitDecoratorMetadata": true
62
- ```
63
-
64
- ### <a name="configuration"></a> Configuration
65
-
66
- A default querier-pool can be set in any of the bootstrap files of your app (e.g. in the `server.ts`).
67
-
68
- ```ts
69
- import { setQuerierPool } from '@uql/core';
70
- import { PgQuerierPool } from '@uql/postgres';
71
-
72
- const querierPool = new PgQuerierPool(
73
- {
74
- host: 'localhost',
75
- user: 'theUser',
76
- password: 'thePassword',
77
- database: 'theDatabase',
78
- },
79
- // a logger can optionally be passed so the SQL queries are logged
80
- console.log
81
- );
82
-
83
- setQuerierPool(querierPool);
84
- ```
85
-
86
- ### <a name="definition-of-entities"></a> Definition of Entities
87
-
88
- Take any dump class (aka DTO) and annotate it with the decorators from `'@uql/core/entity'`.
89
-
90
- ```ts
91
- import { v4 as uuidv4 } from 'uuid';
92
- import { Field, ManyToOne, Id, OneToMany, Entity, OneToOne, ManyToMany } from '@uql/core/entity';
93
-
94
- @Entity()
95
- export class Profile {
96
- /**
97
- * primary-key.
98
- * the `onInsert` callback can be used to specify a custom mechanism for auto-generating
99
- * the default value of a field when inserting a new record.
100
- */
101
- @Id({ onInsert: uuidv4 })
102
- id?: string;
103
- @Field()
104
- picture?: string;
105
- /**
106
- * foreign-keys are really simple to specify.
107
- */
108
- @Field({ reference: () => User })
109
- creatorId?: string;
110
- }
111
-
112
- @Entity()
113
- export class User {
114
- @Id({ onInsert: uuidv4 })
115
- id?: string;
116
- @Field()
117
- name?: string;
118
- @Field()
119
- email?: string;
120
- @Field()
121
- password?: string;
122
- /**
123
- * `mappedBy` can be a callback or a string (callback is useful for auto-refactoring).
124
- */
125
- @OneToOne({ entity: () => Profile, mappedBy: (profile) => profile.creatorId, cascade: true })
126
- profile?: Profile;
127
- }
128
-
129
- @Entity()
130
- export class MeasureUnitCategory {
131
- @Id({ onInsert: uuidv4 })
132
- id?: string;
133
- @Field()
134
- name?: string;
135
- @OneToMany({ entity: () => MeasureUnit, mappedBy: (measureUnit) => measureUnit.category })
136
- measureUnits?: MeasureUnit[];
137
- }
138
-
139
- @Entity()
140
- export class MeasureUnit {
141
- @Id({ onInsert: uuidv4 })
142
- id?: string;
143
- @Field()
144
- name?: string;
145
- @Field({ reference: () => MeasureUnitCategory })
146
- categoryId?: string;
147
- @ManyToOne({ cascade: 'persist' })
148
- category?: MeasureUnitCategory;
149
- }
150
- ```
151
-
152
- ### <a name="query-data"></a> Query the data
153
-
154
- ```ts
155
- import { getQuerier } from '@uql/core';
156
- import { User } from './entity';
157
-
158
- const querier = await getQuerier();
159
-
160
- const id = await this.querier.insertOne(User, {
161
- email: 'lorem@example.com',
162
- profile: { picture: 'ipsum.jpg' },
163
- });
164
-
165
- const users = await querier.findMany(User, {
166
- $project: { id: true, email: true, profile: ['picture'] },
167
- $filter: { email: { $iendsWith: '@google.com' } },
168
- $sort: { createdAt: -1 },
169
- $limit: 100,
170
- });
171
-
172
- await querier.release();
173
- ```
174
-
175
- ---
176
-
177
- See more in https://nukak.org :high_brightness:
@@ -1,30 +0,0 @@
1
- import { QueryFilter, Query, Scalar, QueryFilterFieldOperatorMap, QuerySort, QueryPager, FieldKey, QueryProject, Type, QueryCriteria, QueryOptions, QueryDialect, QueryFilterOptions, QueryComparisonOptions, QueryFilterMap, QuerySearch, QueryProjectOptions } from '../type';
2
- export declare abstract class AbstractSqlDialect implements QueryDialect {
3
- readonly escapeIdChar: '`' | '"';
4
- readonly beginTransactionCommand: string;
5
- readonly escapeIdRegex: RegExp;
6
- constructor(escapeIdChar: '`' | '"', beginTransactionCommand: string);
7
- criteria<E>(entity: Type<E>, qm: Query<E>, opts?: QueryOptions): string;
8
- projectFields<E>(entity: Type<E>, project: QueryProject<E>, opts?: QueryProjectOptions): string;
9
- projectRelations<E>(entity: Type<E>, project?: QueryProject<E>, { prefix }?: {
10
- prefix?: string;
11
- }): {
12
- fields: string;
13
- tables: string;
14
- };
15
- select<E>(entity: Type<E>, qm: Query<E>, opts?: QueryOptions): string;
16
- where<E>(entity: Type<E>, filter?: QueryFilter<E>, opts?: QueryFilterOptions): string;
17
- compare<E, K extends keyof QueryFilterMap<E>>(entity: Type<E>, key: K, val: QueryFilterMap<E>[K], opts?: QueryComparisonOptions): string;
18
- compareFieldOperator<E, K extends keyof QueryFilterFieldOperatorMap<E>>(entity: Type<E>, key: FieldKey<E>, op: K, val: QueryFilterFieldOperatorMap<E>[K], opts?: QueryOptions): string;
19
- getComparisonKey<E>(entity: Type<E>, key: FieldKey<E>, { prefix }?: QueryOptions): Scalar;
20
- group<E>(entity: Type<E>, fields: readonly FieldKey<E>[], opts?: QueryOptions): string;
21
- sort<E>(entity: Type<E>, sort: QuerySort<E>, { prefix }?: QueryOptions): string;
22
- pager(opts: QueryPager): string;
23
- count<E>(entity: Type<E>, qm: QuerySearch<E>, opts?: QueryOptions): string;
24
- find<E>(entity: Type<E>, qm: Query<E>, opts?: QueryOptions): string;
25
- insert<E>(entity: Type<E>, payload: E | E[]): string;
26
- update<E>(entity: Type<E>, qm: QueryCriteria<E>, payload: E, opts?: QueryOptions): string;
27
- delete<E>(entity: Type<E>, qm: QueryCriteria<E>, opts?: QueryOptions): string;
28
- escapeId(val: string, forbidQualified?: boolean, addDot?: boolean): string;
29
- escape(value: any): Scalar;
30
- }