pure-orm 4.0.0-5 → 4.0.0-8
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.
- package/README.md +14 -20
- package/coverage/clover.xml +375 -577
- package/coverage/coverage-final.json +18 -20
- package/coverage/lcov-report/dist/src/core.js.html +1038 -0
- package/coverage/lcov-report/dist/src/drivers/index.html +97 -0
- package/coverage/lcov-report/dist/src/drivers/pgp.js.html +240 -0
- package/coverage/lcov-report/dist/src/factory.js.html +293 -197
- package/coverage/lcov-report/dist/src/index.html +20 -33
- package/coverage/lcov-report/dist/src/index.js.html +16 -10
- package/coverage/lcov-report/dist/src/orm.js.html +645 -0
- package/coverage/lcov-report/dist/test-utils/blog/entities.js.html +108 -0
- package/coverage/lcov-report/dist/test-utils/blog/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/blog/models/article.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/article_tag.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/person.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/tag.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/entities.js.html +114 -0
- package/coverage/lcov-report/dist/test-utils/five/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/five/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/parcel-event.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/parcel-line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/parcel.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/entities.js.html +84 -0
- package/coverage/lcov-report/dist/test-utils/nine/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/nine/models/feature-switch.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/entities.js.html +114 -0
- package/coverage/lcov-report/dist/test-utils/order/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/order/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/product.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/utm-source.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/entities.js.html +204 -0
- package/coverage/lcov-report/dist/test-utils/order-more/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/order-more/models/actual-product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/color.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/customer.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/gender.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/inventory-level.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-event.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/physical-address.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant-image.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/product.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/refund.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/shipment-actual-product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/shipment.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/size.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/utm-medium.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/utm-source.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/entities.js.html +114 -0
- package/coverage/lcov-report/dist/test-utils/six/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/six/models/customer.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/parcel-line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/parcel.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/entities.js.html +132 -0
- package/coverage/lcov-report/dist/test-utils/thirteen/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/thirteen/models/audience.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/brand.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/category.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/member.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/passion.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/product.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation-audience.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/three/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/three/results.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/entities.js.html +87 -0
- package/coverage/lcov-report/dist/test-utils/twelve/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/twelve/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/models/member.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/models/prompt.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/two/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/two/results.js.html +1 -1
- package/coverage/lcov-report/index.html +47 -47
- package/coverage/lcov-report/src/core.ts.html +1593 -0
- package/coverage/lcov-report/src/drivers/index.html +97 -0
- package/coverage/lcov-report/src/drivers/pgp.ts.html +516 -0
- package/coverage/lcov-report/src/factory.ts.html +436 -250
- package/coverage/lcov-report/src/index.html +20 -33
- package/coverage/lcov-report/src/index.ts.html +23 -5
- package/coverage/lcov-report/src/orm.ts.html +954 -0
- package/coverage/lcov-report/test-utils/blog/entities.ts.html +102 -0
- package/coverage/lcov-report/test-utils/blog/index.html +6 -6
- package/coverage/lcov-report/test-utils/blog/models/article.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/article_tag.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/person.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/tag.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/entities.ts.html +105 -0
- package/coverage/lcov-report/test-utils/five/index.html +2 -2
- package/coverage/lcov-report/test-utils/five/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/parcel-event.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/parcel-line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/parcel.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/nine/entities.ts.html +75 -0
- package/coverage/lcov-report/test-utils/nine/index.html +2 -2
- package/coverage/lcov-report/test-utils/nine/models/feature-switch.ts.html +1 -1
- package/coverage/lcov-report/test-utils/nine/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/nine/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/entities.ts.html +108 -0
- package/coverage/lcov-report/test-utils/order/index.html +2 -2
- package/coverage/lcov-report/test-utils/order/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/product.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/utm-source.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/entities.ts.html +198 -0
- package/coverage/lcov-report/test-utils/order-more/index.html +2 -2
- package/coverage/lcov-report/test-utils/order-more/models/actual-product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/color.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/customer.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/gender.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/inventory-level.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/parcel-event.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/parcel-line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/parcel.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/physical-address.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/product-variant-image.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/product.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/refund.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/shipment-actual-product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/shipment.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/size.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/utm-medium.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/utm-source.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/entities.ts.html +105 -0
- package/coverage/lcov-report/test-utils/six/index.html +2 -2
- package/coverage/lcov-report/test-utils/six/models/customer.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/parcel-line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/parcel.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/entities.ts.html +123 -0
- package/coverage/lcov-report/test-utils/thirteen/index.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/models/audience.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/brand.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/category.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/member.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/passion.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/product.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/recommendation-audience.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/recommendation.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/three/index.html +1 -1
- package/coverage/lcov-report/test-utils/three/results.js.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/entities.ts.html +78 -0
- package/coverage/lcov-report/test-utils/twelve/index.html +2 -2
- package/coverage/lcov-report/test-utils/twelve/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/models/member.ts.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/models/prompt.ts.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/two/index.html +1 -1
- package/coverage/lcov-report/test-utils/two/results.js.html +1 -1
- package/coverage/lcov.info +726 -1143
- package/dist/example/factories/orm.d.ts +1 -47
- package/dist/example/models/employer.d.ts +1 -1
- package/dist/example/models/job.d.ts +1 -1
- package/dist/example/models/person.d.ts +1 -1
- package/dist/src/core.d.ts +66 -0
- package/dist/src/{factory.js → core.js} +51 -245
- package/dist/src/{factory.spec.d.ts → core.spec.d.ts} +0 -0
- package/dist/src/{factory.spec.js → core.spec.js} +56 -43
- package/dist/src/driver-integrations/index.d.ts +13 -0
- package/dist/src/driver-integrations/index.js +2 -0
- package/dist/src/driver-integrations/pgp.d.ts +2 -0
- package/dist/src/driver-integrations/pgp.js +57 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +5 -3
- package/dist/src/orm.d.ts +20 -0
- package/dist/src/orm.js +190 -0
- package/dist/test-utils/blog/entities.d.ts +1 -0
- package/dist/test-utils/blog/{orm.js → entities.js} +7 -6
- package/dist/test-utils/blog/{orm.ts → entities.ts} +6 -6
- package/dist/test-utils/blog/models/article.d.ts +1 -1
- package/dist/test-utils/blog/models/article_tag.d.ts +1 -1
- package/dist/test-utils/blog/models/person.d.ts +1 -1
- package/dist/test-utils/blog/models/tag.d.ts +1 -1
- package/dist/test-utils/five/entities.d.ts +6 -0
- package/dist/test-utils/five/{orm.js → entities.js} +8 -12
- package/dist/test-utils/five/{orm.ts → entities.ts} +7 -12
- package/dist/test-utils/five/models/line-item.d.ts +1 -1
- package/dist/test-utils/five/models/order.d.ts +1 -1
- package/dist/test-utils/five/models/parcel-event.d.ts +1 -1
- package/dist/test-utils/five/models/parcel-line-item.d.ts +1 -1
- package/dist/test-utils/five/models/parcel.d.ts +1 -1
- package/dist/test-utils/nine/entities.d.ts +6 -0
- package/dist/test-utils/nine/entities.js +5 -0
- package/dist/test-utils/nine/entities.ts +2 -0
- package/dist/test-utils/nine/models/feature-switch.d.ts +1 -1
- package/dist/test-utils/order/entities.d.ts +26 -0
- package/dist/test-utils/order/{orm.js → entities.js} +8 -12
- package/{test-utils/order/orm.ts → dist/test-utils/order/entities.ts} +7 -12
- package/dist/test-utils/order/models/line-item.d.ts +1 -1
- package/dist/test-utils/order/models/order.d.ts +1 -1
- package/dist/test-utils/order/models/product-variant.d.ts +1 -1
- package/dist/test-utils/order/models/product.d.ts +1 -1
- package/dist/test-utils/order/models/utm-source.d.ts +1 -1
- package/dist/test-utils/order-more/entities.d.ts +6 -0
- package/dist/test-utils/order-more/{orm.js → entities.js} +23 -27
- package/dist/test-utils/order-more/{orm.ts → entities.ts} +22 -27
- package/dist/test-utils/order-more/models/actual-product-variant.d.ts +1 -1
- package/dist/test-utils/order-more/models/color.d.ts +1 -1
- package/dist/test-utils/order-more/models/customer.d.ts +1 -1
- package/dist/test-utils/order-more/models/gender.d.ts +1 -1
- package/dist/test-utils/order-more/models/inventory-level.d.ts +1 -1
- package/dist/test-utils/order-more/models/line-item.d.ts +1 -1
- package/dist/test-utils/order-more/models/order.d.ts +1 -1
- package/dist/test-utils/order-more/models/parcel-event.d.ts +1 -1
- package/dist/test-utils/order-more/models/parcel-line-item.d.ts +1 -1
- package/dist/test-utils/order-more/models/parcel.d.ts +1 -1
- package/dist/test-utils/order-more/models/physical-address.d.ts +1 -1
- package/dist/test-utils/order-more/models/product-variant-image.d.ts +1 -1
- package/dist/test-utils/order-more/models/product-variant.d.ts +1 -1
- package/dist/test-utils/order-more/models/product.d.ts +1 -1
- package/dist/test-utils/order-more/models/refund.d.ts +1 -1
- package/dist/test-utils/order-more/models/shipment-actual-product-variant.d.ts +1 -1
- package/dist/test-utils/order-more/models/shipment.d.ts +1 -1
- package/dist/test-utils/order-more/models/size.d.ts +1 -1
- package/dist/test-utils/order-more/models/utm-medium.d.ts +1 -1
- package/dist/test-utils/order-more/models/utm-source.d.ts +1 -1
- package/dist/test-utils/six/entities.d.ts +6 -0
- package/dist/test-utils/six/{orm.js → entities.js} +8 -12
- package/{test-utils/six/orm.ts → dist/test-utils/six/entities.ts} +7 -12
- package/dist/test-utils/six/models/customer.d.ts +1 -1
- package/dist/test-utils/six/models/line-item.d.ts +1 -1
- package/dist/test-utils/six/models/order.d.ts +1 -1
- package/dist/test-utils/six/models/parcel-line-item.d.ts +1 -1
- package/dist/test-utils/six/models/parcel.d.ts +1 -1
- package/dist/test-utils/thirteen/entities.d.ts +6 -0
- package/dist/test-utils/thirteen/{orm.js → entities.js} +11 -15
- package/dist/test-utils/thirteen/{orm.ts → entities.ts} +10 -15
- package/dist/test-utils/thirteen/models/audience.d.ts +1 -1
- package/dist/test-utils/thirteen/models/brand.d.ts +1 -1
- package/dist/test-utils/thirteen/models/category.d.ts +1 -1
- package/dist/test-utils/thirteen/models/member.d.ts +1 -1
- package/dist/test-utils/thirteen/models/passion.d.ts +1 -1
- package/dist/test-utils/thirteen/models/product.d.ts +1 -1
- package/dist/test-utils/thirteen/models/recommendation-audience.d.ts +1 -1
- package/dist/test-utils/thirteen/models/recommendation.d.ts +1 -1
- package/dist/test-utils/twelve/entities.d.ts +6 -0
- package/dist/test-utils/twelve/entities.js +6 -0
- package/dist/test-utils/twelve/entities.ts +3 -0
- package/dist/test-utils/twelve/models/member.d.ts +1 -1
- package/dist/test-utils/twelve/models/prompt.d.ts +1 -1
- package/package.json +4 -3
- package/src/{factory.spec.ts → core.spec.ts} +55 -41
- package/src/{factory.ts → core.ts} +102 -338
- package/src/driver-integrations/index.ts +56 -0
- package/src/driver-integrations/pgp.ts +92 -0
- package/src/index.ts +5 -3
- package/src/orm.ts +291 -0
- package/test-utils/blog/{orm.ts → entities.ts} +6 -6
- package/test-utils/five/{orm.ts → entities.ts} +7 -12
- package/test-utils/nine/entities.ts +2 -0
- package/{dist/test-utils/order/orm.ts → test-utils/order/entities.ts} +7 -12
- package/test-utils/order-more/{orm.ts → entities.ts} +22 -27
- package/{dist/test-utils/six/orm.ts → test-utils/six/entities.ts} +7 -12
- package/test-utils/thirteen/{orm.ts → entities.ts} +10 -15
- package/test-utils/twelve/entities.ts +3 -0
- package/dist/src/factory.d.ts +0 -100
- package/dist/test-utils/blog/orm.d.ts +0 -2
- package/dist/test-utils/five/orm.d.ts +0 -48
- package/dist/test-utils/nine/orm.d.ts +0 -48
- package/dist/test-utils/nine/orm.js +0 -9
- package/dist/test-utils/nine/orm.ts +0 -7
- package/dist/test-utils/order/orm.d.ts +0 -48
- package/dist/test-utils/order-more/orm.d.ts +0 -48
- package/dist/test-utils/six/orm.d.ts +0 -48
- package/dist/test-utils/thirteen/orm.d.ts +0 -48
- package/dist/test-utils/twelve/orm.d.ts +0 -48
- package/dist/test-utils/twelve/orm.js +0 -10
- package/dist/test-utils/twelve/orm.ts +0 -8
- package/test-utils/nine/orm.ts +0 -7
- package/test-utils/twelve/orm.ts +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import camelCase from 'camelcase';
|
|
2
2
|
|
|
3
3
|
export interface IColumnData {
|
|
4
4
|
column: string;
|
|
@@ -54,17 +54,50 @@ export interface IEntityInternal<T extends IModel> {
|
|
|
54
54
|
}
|
|
55
55
|
export type IEntitiesInternal<T extends IModel> = Array<IEntityInternal<T>>;
|
|
56
56
|
|
|
57
|
-
export interface
|
|
57
|
+
export interface ICreateCoreOptions {
|
|
58
58
|
entities: IEntities<IModel>;
|
|
59
|
-
db: any;
|
|
60
|
-
logError?: (err: Error) => void;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
export interface ICore {
|
|
62
|
+
/* ------------------------------------------------------------------------*/
|
|
63
|
+
/* Object Relational Mapping methods --------------------------------------*/
|
|
64
|
+
/* ------------------------------------------------------------------------*/
|
|
65
|
+
|
|
66
|
+
/* Note these construction methods ensure their count against the number of
|
|
67
|
+
* generated top level business objects - independent of the number of
|
|
68
|
+
* relational rows passed in as a result from a database driver query.
|
|
69
|
+
* Thus, for example, `one` understands that there may be multiple result
|
|
70
|
+
* rows (which a database driver's `one` query method would throw at) but
|
|
71
|
+
* which correctly nest into one Model.)
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
createFromDatabase: <T extends ICollection<IModel>>(rows: any) => T;
|
|
75
|
+
createAnyFromDatabase: <T extends ICollection<IModel>>(
|
|
76
|
+
rows: any,
|
|
77
|
+
rootKey: string | IModel
|
|
78
|
+
) => T;
|
|
79
|
+
createOneFromDatabase: <T extends IModel>(rows: any) => T;
|
|
80
|
+
createOneOrNoneFromDatabase: <T extends IModel>(rows: any) => T | void;
|
|
81
|
+
createManyFromDatabase: <T extends ICollection<IModel>>(rows: any) => T;
|
|
82
|
+
|
|
83
|
+
/* ------------------------------------------------------------------------*/
|
|
84
|
+
/* Helpful Properties -----------------------------------------------------*/
|
|
85
|
+
/* ------------------------------------------------------------------------*/
|
|
86
|
+
|
|
87
|
+
/* The tables property gives access to the sql select clause string for
|
|
88
|
+
* each entity based on it's `displayName`. This property can be used when
|
|
89
|
+
* writing raw SQL as the select clause, which handles quoting column names
|
|
90
|
+
* and namespacing them to the table to avoid collisions and as required
|
|
91
|
+
* for PureORM mapping.
|
|
92
|
+
*/
|
|
93
|
+
tables: { [key: string]: { columns: string } };
|
|
94
|
+
getEntityByModel: (model: IModel) => IEntityInternal<IModel>;
|
|
95
|
+
getEntityByTableName: (tableName: string) => IEntityInternal<IModel>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const createCore = ({
|
|
99
|
+
entities: externalEntities
|
|
100
|
+
}: ICreateCoreOptions): ICore => {
|
|
68
101
|
const entities: IEntitiesInternal<IModel> = externalEntities.map(
|
|
69
102
|
(d: IEntity<IModel>) => {
|
|
70
103
|
const tableName = d.tableName;
|
|
@@ -146,31 +179,44 @@ export const create = ({
|
|
|
146
179
|
}
|
|
147
180
|
);
|
|
148
181
|
|
|
182
|
+
const tableNameToEntityMap = entities.reduce(
|
|
183
|
+
(
|
|
184
|
+
map: Map<string, IEntityInternal<IModel>>,
|
|
185
|
+
entity: IEntityInternal<IModel>
|
|
186
|
+
) => {
|
|
187
|
+
map.set(entity.tableName, entity);
|
|
188
|
+
return map;
|
|
189
|
+
},
|
|
190
|
+
new Map()
|
|
191
|
+
);
|
|
192
|
+
|
|
149
193
|
const getEntityByTableName = (tableName: string): IEntityInternal<IModel> => {
|
|
150
|
-
const entity =
|
|
194
|
+
const entity = tableNameToEntityMap.get(tableName);
|
|
151
195
|
if (!entity) {
|
|
152
196
|
throw new Error(`Could not find entity for table ${tableName}`);
|
|
153
197
|
}
|
|
154
198
|
return entity;
|
|
155
199
|
};
|
|
156
200
|
|
|
201
|
+
const modelToEntityMap = entities.reduce(
|
|
202
|
+
(
|
|
203
|
+
map: Map<IModel, IEntityInternal<IModel>>,
|
|
204
|
+
entity: IEntityInternal<IModel>
|
|
205
|
+
) => {
|
|
206
|
+
map.set(entity.Model, entity);
|
|
207
|
+
return map;
|
|
208
|
+
},
|
|
209
|
+
new Map()
|
|
210
|
+
);
|
|
211
|
+
|
|
157
212
|
const getEntityByModel = (model: IModel): IEntityInternal<IModel> => {
|
|
158
|
-
const entity =
|
|
213
|
+
const entity = modelToEntityMap.get(model.constructor);
|
|
159
214
|
if (!entity) {
|
|
160
215
|
throw new Error(`Could not find entity for class ${model.constructor}`);
|
|
161
216
|
}
|
|
162
217
|
return entity;
|
|
163
218
|
};
|
|
164
219
|
|
|
165
|
-
const defaultErrorHandler = (err: Error) => {
|
|
166
|
-
if (!(err.name === 'QueryResultError')) {
|
|
167
|
-
if (logError) {
|
|
168
|
-
logError(err);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
throw err;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
220
|
/*
|
|
175
221
|
* In:
|
|
176
222
|
* [
|
|
@@ -379,366 +425,84 @@ export const create = ({
|
|
|
379
425
|
return Object.keys(result).reduce((obj: any, text: string) => {
|
|
380
426
|
const tableName = text.split('#')[0];
|
|
381
427
|
const column = text.split('#')[1];
|
|
428
|
+
if (!tableName || !column) {
|
|
429
|
+
throw new Error('Column names must be namespaced to table');
|
|
430
|
+
}
|
|
382
431
|
obj[tableName] = obj[tableName] || {};
|
|
383
432
|
obj[tableName][column] = result[text as keyof typeof result];
|
|
384
433
|
return obj;
|
|
385
434
|
}, {});
|
|
386
435
|
};
|
|
387
436
|
|
|
388
|
-
const createFromDatabase = <T extends ICollection<IModel>>(
|
|
389
|
-
|
|
390
|
-
): T | undefined => {
|
|
391
|
-
const result = Array.isArray(_result) ? _result : [_result];
|
|
437
|
+
const createFromDatabase = <T extends ICollection<IModel>>(rows: any): T => {
|
|
438
|
+
const result = Array.isArray(rows) ? rows : [rows];
|
|
392
439
|
const objectified = result.map(objectifyDatabaseResult);
|
|
393
440
|
const boified = objectified.map(mapToBos);
|
|
394
441
|
const clumps = clumpIntoGroups(boified);
|
|
395
442
|
const nested = clumps.map(nestClump);
|
|
396
443
|
const models = nested.map((n) => Object.values(n)[0]);
|
|
397
444
|
const Collection = getEntityByModel(models[0]).Collection;
|
|
398
|
-
return
|
|
445
|
+
return <T>new Collection({ models });
|
|
399
446
|
};
|
|
400
447
|
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
448
|
+
const createAnyFromDatabase = <T extends ICollection<IModel>>(
|
|
449
|
+
rows: any,
|
|
450
|
+
rootKey: string | IModel
|
|
451
|
+
): T => {
|
|
452
|
+
if (!rows || !rows.length) {
|
|
453
|
+
const Collection =
|
|
454
|
+
typeof rootKey === 'string'
|
|
455
|
+
? getEntityByTableName(rootKey).Collection
|
|
456
|
+
: getEntityByModel(rootKey).Collection;
|
|
457
|
+
return new Collection({ models: [] }) as T;
|
|
458
|
+
}
|
|
459
|
+
return <T>createFromDatabase<T>(rows);
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
const createOneFromDatabase = <T extends IModel>(rows: any): T => {
|
|
463
|
+
if (!rows || !rows.length) {
|
|
404
464
|
throw Error('Did not get one.');
|
|
405
465
|
}
|
|
406
|
-
|
|
466
|
+
const collection = createFromDatabase<ICollection<IModel>>(rows);
|
|
467
|
+
if (!collection || !collection.models || collection.models.length === 0) {
|
|
407
468
|
throw Error('Did not get one.');
|
|
408
469
|
} else if (collection.models.length > 1) {
|
|
409
470
|
throw Error('Got more than one.');
|
|
410
471
|
}
|
|
411
|
-
return collection.models[0]
|
|
472
|
+
return <T>collection.models[0];
|
|
412
473
|
};
|
|
413
474
|
|
|
414
475
|
const createOneOrNoneFromDatabase = <T extends IModel>(
|
|
415
|
-
|
|
476
|
+
rows: any
|
|
416
477
|
): T | void => {
|
|
417
|
-
if (!
|
|
418
|
-
return
|
|
419
|
-
}
|
|
420
|
-
const collection = createFromDatabase(_result);
|
|
421
|
-
if (collection && collection.models.length > 1) {
|
|
422
|
-
throw Error('Got more than one.');
|
|
478
|
+
if (!rows || !rows.length) {
|
|
479
|
+
return void 0;
|
|
423
480
|
}
|
|
424
|
-
return
|
|
481
|
+
return <T>createOneFromDatabase(rows);
|
|
425
482
|
};
|
|
426
483
|
|
|
427
484
|
const createManyFromDatabase = <T extends ICollection<IModel>>(
|
|
428
|
-
|
|
485
|
+
rows: any
|
|
429
486
|
): T => {
|
|
430
|
-
|
|
431
|
-
if (!collection || collection.models.length === 0) {
|
|
487
|
+
if (!rows || !rows.length) {
|
|
432
488
|
throw Error('Did not get at least one.');
|
|
433
489
|
}
|
|
434
|
-
return
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
const getSqlInsertParts = (model: IModel) => {
|
|
438
|
-
const columns = getEntityByModel(model)
|
|
439
|
-
.columnNames.filter(
|
|
440
|
-
(column: string, index: number) =>
|
|
441
|
-
model[
|
|
442
|
-
getEntityByModel(model).propertyNames[index] as keyof typeof model
|
|
443
|
-
] !== void 0
|
|
444
|
-
)
|
|
445
|
-
.map((col: string) => `"${col}"`)
|
|
446
|
-
.join(', ');
|
|
447
|
-
const values = getEntityByModel(model)
|
|
448
|
-
.propertyNames.map(
|
|
449
|
-
(property: string) => model[property as keyof typeof model]
|
|
450
|
-
)
|
|
451
|
-
.filter((value: any) => value !== void 0);
|
|
452
|
-
const valuesVar = values.map(
|
|
453
|
-
(value: any, index: number) => `$${index + 1}`
|
|
454
|
-
);
|
|
455
|
-
return { columns, values, valuesVar };
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
const getSqlUpdateParts = (model: IModel, on = 'id') => {
|
|
459
|
-
const clauseArray = getEntityByModel(model)
|
|
460
|
-
.columnNames.filter(
|
|
461
|
-
(sqlColumn: string, index: number) =>
|
|
462
|
-
model[
|
|
463
|
-
getEntityByModel(model).propertyNames[index] as keyof typeof model
|
|
464
|
-
] !== void 0
|
|
465
|
-
)
|
|
466
|
-
.map(
|
|
467
|
-
(sqlColumn: string, index: number) => `"${sqlColumn}" = $${index + 1}`
|
|
468
|
-
);
|
|
469
|
-
const clause = clauseArray.join(', ');
|
|
470
|
-
const idVar = `$${clauseArray.length + 1}`;
|
|
471
|
-
const _values = getEntityByModel(model)
|
|
472
|
-
.propertyNames.map(
|
|
473
|
-
(property: string) => model[property as keyof typeof model]
|
|
474
|
-
)
|
|
475
|
-
.filter((value: any) => value !== void 0);
|
|
476
|
-
const values = [..._values, model[on as keyof typeof model]];
|
|
477
|
-
return { clause, idVar, values };
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
const getMatchingParts = (model: IModel) => {
|
|
481
|
-
const whereClause = getEntityByModel(model)
|
|
482
|
-
.propertyNames.map((property: string, index: number) =>
|
|
483
|
-
model[property as keyof typeof model] != null
|
|
484
|
-
? `"${getEntityByModel(model).tableName}"."${
|
|
485
|
-
getEntityByModel(model).columnNames[index]
|
|
486
|
-
}"`
|
|
487
|
-
: null
|
|
488
|
-
)
|
|
489
|
-
.filter((x: string | null) => x != null)
|
|
490
|
-
.map((x: string | null, i: number) => `${x} = $${i + 1}`)
|
|
491
|
-
.join(' AND ');
|
|
492
|
-
const values = getEntityByModel(model)
|
|
493
|
-
.propertyNames.map((property: string) =>
|
|
494
|
-
model[property as keyof typeof model] != null
|
|
495
|
-
? model[property as keyof typeof model]
|
|
496
|
-
: null
|
|
497
|
-
)
|
|
498
|
-
.filter((x: any) => x != null);
|
|
499
|
-
return { whereClause, values };
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
// This one returns an object, which allows it to be more versatile.
|
|
503
|
-
// To-do: make this one even better and use it instead of the one above.
|
|
504
|
-
const getMatchingPartsObject = (model: IModel) => {
|
|
505
|
-
const whereClause = getEntityByModel(model)
|
|
506
|
-
.propertyNames.map((property: string, index: number) =>
|
|
507
|
-
model[property as keyof typeof model] != null
|
|
508
|
-
? `"${getEntityByModel(model).tableName}"."${
|
|
509
|
-
getEntityByModel(model).columnNames[index]
|
|
510
|
-
}"`
|
|
511
|
-
: null
|
|
512
|
-
)
|
|
513
|
-
.filter((x: string | null) => x != null)
|
|
514
|
-
.map((x: string | null, i: number) => `${x} = $(${i + 1})`)
|
|
515
|
-
.join(' AND ');
|
|
516
|
-
const values = getEntityByModel(model)
|
|
517
|
-
.propertyNames.map((property: string) =>
|
|
518
|
-
model[property as keyof typeof model] != null
|
|
519
|
-
? model[property as keyof typeof model]
|
|
520
|
-
: null
|
|
521
|
-
)
|
|
522
|
-
.filter((x: any) => x != null)
|
|
523
|
-
.reduce(
|
|
524
|
-
(accum: any, val: any, index: number) =>
|
|
525
|
-
Object.assign({}, accum, { [index + 1]: val }),
|
|
526
|
-
{}
|
|
527
|
-
);
|
|
528
|
-
return { whereClause, values };
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
const getNewWith = (model: IModel, sqlColumns: any, values: any) => {
|
|
532
|
-
const Constructor = model.constructor as any;
|
|
533
|
-
const modelKeys = sqlColumns.map(
|
|
534
|
-
(key: string) =>
|
|
535
|
-
getEntityByModel(model).propertyNames[
|
|
536
|
-
getEntityByModel(model).columnNames.indexOf(key)
|
|
537
|
-
]
|
|
538
|
-
);
|
|
539
|
-
const modelData = modelKeys.reduce(
|
|
540
|
-
(data: any, key: string, index: number) => {
|
|
541
|
-
data[key] = values[index];
|
|
542
|
-
return data;
|
|
543
|
-
},
|
|
544
|
-
{}
|
|
545
|
-
);
|
|
546
|
-
return new Constructor(modelData);
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
const getValueBySqlColumn = (model: IModel, sqlColumn: string) => {
|
|
550
|
-
return model[
|
|
551
|
-
getEntityByModel(model).propertyNames[
|
|
552
|
-
getEntityByModel(model).columnNames.indexOf(sqlColumn)
|
|
553
|
-
] as keyof typeof model
|
|
554
|
-
];
|
|
555
|
-
};
|
|
556
|
-
/* ------------------------------------------------------------------------*/
|
|
557
|
-
/* Query functions --------------------------------------------------------*/
|
|
558
|
-
/* ------------------------------------------------------------------------*/
|
|
559
|
-
|
|
560
|
-
const one = <T extends IModel>(
|
|
561
|
-
query: string,
|
|
562
|
-
values?: object,
|
|
563
|
-
errorHandler = defaultErrorHandler
|
|
564
|
-
): T => {
|
|
565
|
-
return db
|
|
566
|
-
.many(query, values)
|
|
567
|
-
.then((rows: any) => createOneFromDatabase(rows))
|
|
568
|
-
.catch(errorHandler);
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
const oneOrNone = <T extends IModel>(
|
|
572
|
-
query: string,
|
|
573
|
-
values?: object,
|
|
574
|
-
errorHandler = defaultErrorHandler
|
|
575
|
-
): T | void => {
|
|
576
|
-
return db
|
|
577
|
-
.any(query, values)
|
|
578
|
-
.then((rows: any) => createOneOrNoneFromDatabase(rows))
|
|
579
|
-
.catch(errorHandler);
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
const many = <T extends ICollection<IModel>>(
|
|
583
|
-
query: string,
|
|
584
|
-
values?: object,
|
|
585
|
-
errorHandler = defaultErrorHandler
|
|
586
|
-
): T => {
|
|
587
|
-
return db
|
|
588
|
-
.any(query, values)
|
|
589
|
-
.then((rows: any) => createManyFromDatabase(rows))
|
|
590
|
-
.catch(errorHandler);
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
const any = <T extends ICollection<IModel>>(
|
|
594
|
-
query: string,
|
|
595
|
-
values?: object,
|
|
596
|
-
errorHandler = defaultErrorHandler
|
|
597
|
-
): T | void => {
|
|
598
|
-
return db
|
|
599
|
-
.any(query, values)
|
|
600
|
-
.then((rows: any) => createFromDatabase(rows))
|
|
601
|
-
.catch(errorHandler);
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
const none = (
|
|
605
|
-
query: string,
|
|
606
|
-
values?: object,
|
|
607
|
-
errorHandler = defaultErrorHandler
|
|
608
|
-
): void => {
|
|
609
|
-
return db
|
|
610
|
-
.none(query, values)
|
|
611
|
-
.then(() => null)
|
|
612
|
-
.catch(errorHandler);
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
/* ------------------------------------------------------------------------*/
|
|
616
|
-
/* Built-in basic CRUD functions ------------------------------------------*/
|
|
617
|
-
/* ------------------------------------------------------------------------*/
|
|
618
|
-
|
|
619
|
-
// Standard create
|
|
620
|
-
const create = <T extends IModel>(model: T): T => {
|
|
621
|
-
const { columns, values, valuesVar } = getSqlInsertParts(model);
|
|
622
|
-
const query = `
|
|
623
|
-
INSERT INTO "${getEntityByModel(model).tableName}" ( ${columns} )
|
|
624
|
-
VALUES ( ${valuesVar} )
|
|
625
|
-
RETURNING ${getEntityByModel(model).selectColumnsClause};
|
|
626
|
-
`;
|
|
627
|
-
return one<T>(query, values);
|
|
628
|
-
};
|
|
629
|
-
|
|
630
|
-
// Standard update
|
|
631
|
-
const update = <T extends IModel>(model: T, { on = 'id' } = {}): T => {
|
|
632
|
-
const { clause, idVar, values } = getSqlUpdateParts(model, on);
|
|
633
|
-
const query = `
|
|
634
|
-
UPDATE "${getEntityByModel(model).tableName}"
|
|
635
|
-
SET ${clause}
|
|
636
|
-
WHERE "${getEntityByModel(model).tableName}".${on} = ${idVar}
|
|
637
|
-
RETURNING ${getEntityByModel(model).selectColumnsClause};
|
|
638
|
-
`;
|
|
639
|
-
return one<T>(query, values);
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
// Standard delete
|
|
643
|
-
const _delete = <T extends IModel>(model: T): void => {
|
|
644
|
-
const id = (model as any).id;
|
|
645
|
-
const query = `
|
|
646
|
-
DELETE FROM "${getEntityByModel(model).tableName}"
|
|
647
|
-
WHERE "${getEntityByModel(model).tableName}".id = $(id)
|
|
648
|
-
`;
|
|
649
|
-
return none(query, { id });
|
|
650
|
-
};
|
|
651
|
-
|
|
652
|
-
const deleteMatching = <T extends IModel>(model: T) => {
|
|
653
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
654
|
-
const query = `
|
|
655
|
-
DELETE FROM "${getEntityByModel(model).tableName}"
|
|
656
|
-
WHERE ${whereClause};
|
|
657
|
-
`;
|
|
658
|
-
return none(query, values);
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
const getMatching = <T extends IModel>(model: T): T => {
|
|
662
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
663
|
-
const query = `
|
|
664
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
665
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
666
|
-
WHERE ${whereClause};
|
|
667
|
-
`;
|
|
668
|
-
return one<T>(query, values);
|
|
669
|
-
};
|
|
670
|
-
|
|
671
|
-
const getOneOrNoneMatching = <T extends IModel>(model: T): T | void => {
|
|
672
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
673
|
-
const query = `
|
|
674
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
675
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
676
|
-
WHERE ${whereClause};
|
|
677
|
-
`;
|
|
678
|
-
return oneOrNone<T>(query, values);
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
const getAnyMatching = <T extends ICollection<IModel>>(
|
|
682
|
-
model: IModel
|
|
683
|
-
): T | void => {
|
|
684
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
685
|
-
const query = `
|
|
686
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
687
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
688
|
-
WHERE ${whereClause};
|
|
689
|
-
`;
|
|
690
|
-
return any<T>(query, values);
|
|
691
|
-
};
|
|
692
|
-
|
|
693
|
-
const getAllMatching = <T extends ICollection<IModel>>(model: IModel): T => {
|
|
694
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
695
|
-
const query = `
|
|
696
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
697
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
698
|
-
WHERE ${whereClause};
|
|
699
|
-
`;
|
|
700
|
-
return many<T>(query, values);
|
|
490
|
+
return <T>createFromDatabase(rows);
|
|
701
491
|
};
|
|
702
492
|
|
|
703
493
|
return {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
clumpIntoGroups,
|
|
707
|
-
mapToBos,
|
|
708
|
-
objectifyDatabaseResult,
|
|
494
|
+
getEntityByModel,
|
|
495
|
+
getEntityByTableName,
|
|
709
496
|
createFromDatabase,
|
|
497
|
+
createAnyFromDatabase,
|
|
710
498
|
createOneFromDatabase,
|
|
711
499
|
createOneOrNoneFromDatabase,
|
|
712
500
|
createManyFromDatabase,
|
|
713
|
-
getSqlInsertParts,
|
|
714
|
-
getSqlUpdateParts,
|
|
715
|
-
getMatchingParts,
|
|
716
|
-
getMatchingPartsObject,
|
|
717
|
-
getNewWith,
|
|
718
|
-
getValueBySqlColumn,
|
|
719
|
-
// Query Functions
|
|
720
|
-
one,
|
|
721
|
-
oneOrNone,
|
|
722
|
-
many,
|
|
723
|
-
any,
|
|
724
|
-
none,
|
|
725
|
-
// Built-in basic CRUD functions
|
|
726
|
-
create,
|
|
727
|
-
update,
|
|
728
|
-
delete: _delete,
|
|
729
|
-
deleteMatching,
|
|
730
|
-
getMatching,
|
|
731
|
-
getOneOrNoneMatching,
|
|
732
|
-
getAnyMatching,
|
|
733
|
-
getAllMatching,
|
|
734
|
-
// tables property for access to select columns clause string
|
|
735
501
|
tables: entities.reduce((accum: any, data: IEntityInternal<IModel>) => {
|
|
736
502
|
accum[data.displayName] = {
|
|
737
503
|
columns: data.selectColumnsClause
|
|
738
504
|
};
|
|
739
505
|
return accum;
|
|
740
|
-
}, {})
|
|
741
|
-
// provide direct access to db
|
|
742
|
-
db
|
|
506
|
+
}, {})
|
|
743
507
|
};
|
|
744
508
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ICore, IModel, ICollection } from '../core';
|
|
2
|
+
|
|
3
|
+
export interface ICreateForDriverOptions {
|
|
4
|
+
core: ICore;
|
|
5
|
+
db: any;
|
|
6
|
+
logError?: (err: Error) => never;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ICoreIntegratedDriver extends ICore {
|
|
10
|
+
/* ------------------------------------------------------------------------*/
|
|
11
|
+
/* Query methods ----------------------------------------------------------*/
|
|
12
|
+
/* ------------------------------------------------------------------------*/
|
|
13
|
+
|
|
14
|
+
/* Note these query methods ensure their count against the number of
|
|
15
|
+
* generated top level business objects which are created - not the number
|
|
16
|
+
* of relational rows returned from the database driver! Thus, for example,
|
|
17
|
+
* `one` understands that there may be multiple result rows (which a
|
|
18
|
+
* database driver's `one` query method would throw at) but which correctly
|
|
19
|
+
* nest into one Model.)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// Execute a query returning a single model, or throws.
|
|
23
|
+
one: <T extends IModel>(
|
|
24
|
+
query: string,
|
|
25
|
+
values?: object,
|
|
26
|
+
errorHandler?: (err: Error) => never
|
|
27
|
+
) => T;
|
|
28
|
+
|
|
29
|
+
// Execute a query returning either single model or undefined, or throws.
|
|
30
|
+
oneOrNone: <T extends IModel>(
|
|
31
|
+
query: string,
|
|
32
|
+
values?: object,
|
|
33
|
+
errorHandler?: (err: Error) => never
|
|
34
|
+
) => T | void;
|
|
35
|
+
|
|
36
|
+
// Execute a query returning a Collection with at least one model, or throws.
|
|
37
|
+
many: <T extends ICollection<IModel>>(
|
|
38
|
+
query: string,
|
|
39
|
+
values?: object,
|
|
40
|
+
errorHandler?: (err: Error) => never
|
|
41
|
+
) => T;
|
|
42
|
+
|
|
43
|
+
// Execute a query returning a Collection.
|
|
44
|
+
any: <T extends ICollection<IModel>>(
|
|
45
|
+
query: string,
|
|
46
|
+
values?: object,
|
|
47
|
+
errorHandler?: (err: Error) => never
|
|
48
|
+
) => T | void;
|
|
49
|
+
|
|
50
|
+
// Execute a query returning null.
|
|
51
|
+
none: (
|
|
52
|
+
query: string,
|
|
53
|
+
values?: object,
|
|
54
|
+
errorHandler?: (err: Error) => never
|
|
55
|
+
) => void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { IModel, ICollection } from '../core';
|
|
2
|
+
import { ICreateForDriverOptions, ICoreIntegratedDriver } from './index';
|
|
3
|
+
|
|
4
|
+
export const createForPGP = ({
|
|
5
|
+
core,
|
|
6
|
+
db,
|
|
7
|
+
logError
|
|
8
|
+
}: ICreateForDriverOptions): ICoreIntegratedDriver => {
|
|
9
|
+
const defaultErrorHandler = (err: Error) => {
|
|
10
|
+
if (!(err.name === 'QueryResultError')) {
|
|
11
|
+
if (logError) {
|
|
12
|
+
logError(err);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
throw err;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/* ------------------------------------------------------------------------*/
|
|
19
|
+
/* Query functions --------------------------------------------------------*/
|
|
20
|
+
/* ------------------------------------------------------------------------*/
|
|
21
|
+
|
|
22
|
+
const one = <T extends IModel>(
|
|
23
|
+
query: string,
|
|
24
|
+
values?: object,
|
|
25
|
+
errorHandler = defaultErrorHandler
|
|
26
|
+
): T => {
|
|
27
|
+
return db
|
|
28
|
+
.many(query, values)
|
|
29
|
+
.then((rows: any) => core.createOneFromDatabase(rows))
|
|
30
|
+
.catch(errorHandler);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const oneOrNone = <T extends IModel>(
|
|
34
|
+
query: string,
|
|
35
|
+
values?: object,
|
|
36
|
+
errorHandler = defaultErrorHandler
|
|
37
|
+
): T | void => {
|
|
38
|
+
return db
|
|
39
|
+
.any(query, values)
|
|
40
|
+
.then((rows: any) => core.createOneOrNoneFromDatabase(rows))
|
|
41
|
+
.catch(errorHandler);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const many = <T extends ICollection<IModel>>(
|
|
45
|
+
query: string,
|
|
46
|
+
values?: object,
|
|
47
|
+
errorHandler = defaultErrorHandler
|
|
48
|
+
): T => {
|
|
49
|
+
return db
|
|
50
|
+
.any(query, values)
|
|
51
|
+
.then((rows: any) => core.createManyFromDatabase(rows))
|
|
52
|
+
.catch(errorHandler);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const any = <T extends ICollection<IModel>>(
|
|
56
|
+
query: string,
|
|
57
|
+
values?: object,
|
|
58
|
+
errorHandler = defaultErrorHandler
|
|
59
|
+
): T | void => {
|
|
60
|
+
return db
|
|
61
|
+
.result(query, values)
|
|
62
|
+
.then((result: any) =>
|
|
63
|
+
core.createAnyFromDatabase(
|
|
64
|
+
result.rows,
|
|
65
|
+
result.fields[0].name.split('#')[0]
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
.catch(errorHandler);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const none = (
|
|
72
|
+
query: string,
|
|
73
|
+
values?: object,
|
|
74
|
+
errorHandler = defaultErrorHandler
|
|
75
|
+
): void => {
|
|
76
|
+
return db
|
|
77
|
+
.none(query, values)
|
|
78
|
+
.then(() => null)
|
|
79
|
+
.catch(errorHandler);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return Object.assign({}, core, {
|
|
83
|
+
// Query Functions
|
|
84
|
+
one,
|
|
85
|
+
oneOrNone,
|
|
86
|
+
many,
|
|
87
|
+
any,
|
|
88
|
+
none,
|
|
89
|
+
// provide direct access to db
|
|
90
|
+
db
|
|
91
|
+
});
|
|
92
|
+
};
|
package/src/index.ts
CHANGED