pure-orm 4.0.0-4 → 4.0.0-7
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 +11 -11
- package/coverage/clover.xml +367 -581
- package/coverage/coverage-final.json +18 -20
- package/coverage/lcov-report/dist/src/core.js.html +1014 -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 +298 -187
- 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 +1527 -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 +448 -247
- 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 +713 -1142
- package/dist/example/factories/orm.d.ts +1 -46
- 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} +43 -240
- 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} +86 -339
- 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 -99
- package/dist/test-utils/blog/orm.d.ts +0 -2
- package/dist/test-utils/five/orm.d.ts +0 -47
- package/dist/test-utils/nine/orm.d.ts +0 -47
- 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 -47
- package/dist/test-utils/order-more/orm.d.ts +0 -47
- package/dist/test-utils/six/orm.d.ts +0 -47
- package/dist/test-utils/thirteen/orm.d.ts +0 -47
- package/dist/test-utils/twelve/orm.d.ts +0 -47
- 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,19 +54,52 @@ export interface IEntityInternal<T extends IModel> {
|
|
|
54
54
|
}
|
|
55
55
|
export type IEntitiesInternal<T extends IModel> = Array<IEntityInternal<T>>;
|
|
56
56
|
|
|
57
|
-
export interface
|
|
58
|
-
entities: IEntities<
|
|
59
|
-
db: any;
|
|
60
|
-
logError?: (err: Error) => void;
|
|
57
|
+
export interface ICreateCoreOptions {
|
|
58
|
+
entities: IEntities<IModel>;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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 => {
|
|
101
|
+
const entities: IEntitiesInternal<IModel> = externalEntities.map(
|
|
102
|
+
(d: IEntity<IModel>) => {
|
|
70
103
|
const tableName = d.tableName;
|
|
71
104
|
const displayName = d.displayName || camelCase(d.tableName);
|
|
72
105
|
const collectionDisplayName =
|
|
@@ -146,7 +179,7 @@ export const create = ({
|
|
|
146
179
|
}
|
|
147
180
|
);
|
|
148
181
|
|
|
149
|
-
const getEntityByTableName = (tableName: string): IEntityInternal<
|
|
182
|
+
const getEntityByTableName = (tableName: string): IEntityInternal<IModel> => {
|
|
150
183
|
const entity = entities.find((data) => data.tableName == tableName);
|
|
151
184
|
if (!entity) {
|
|
152
185
|
throw new Error(`Could not find entity for table ${tableName}`);
|
|
@@ -154,7 +187,7 @@ export const create = ({
|
|
|
154
187
|
return entity;
|
|
155
188
|
};
|
|
156
189
|
|
|
157
|
-
const getEntityByModel = (model: IModel): IEntityInternal<
|
|
190
|
+
const getEntityByModel = (model: IModel): IEntityInternal<IModel> => {
|
|
158
191
|
const entity = entities.find((data) => data.Model == model.constructor);
|
|
159
192
|
if (!entity) {
|
|
160
193
|
throw new Error(`Could not find entity for class ${model.constructor}`);
|
|
@@ -162,15 +195,6 @@ export const create = ({
|
|
|
162
195
|
return entity;
|
|
163
196
|
};
|
|
164
197
|
|
|
165
|
-
const defaultErrorHandler = (err: Error) => {
|
|
166
|
-
if (!(err.name === 'QueryResultError')) {
|
|
167
|
-
if (logError) {
|
|
168
|
-
logError(err);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
throw err;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
198
|
/*
|
|
175
199
|
* In:
|
|
176
200
|
* [
|
|
@@ -379,360 +403,83 @@ export const create = ({
|
|
|
379
403
|
return Object.keys(result).reduce((obj: any, text: string) => {
|
|
380
404
|
const tableName = text.split('#')[0];
|
|
381
405
|
const column = text.split('#')[1];
|
|
406
|
+
if (!tableName || !column) {
|
|
407
|
+
throw new Error('Column names must be namespaced to table');
|
|
408
|
+
}
|
|
382
409
|
obj[tableName] = obj[tableName] || {};
|
|
383
410
|
obj[tableName][column] = result[text as keyof typeof result];
|
|
384
411
|
return obj;
|
|
385
412
|
}, {});
|
|
386
413
|
};
|
|
387
414
|
|
|
388
|
-
const createFromDatabase = <T extends ICollection<IModel>>(
|
|
389
|
-
|
|
390
|
-
): T | undefined => {
|
|
391
|
-
const result = Array.isArray(_result) ? _result : [_result];
|
|
415
|
+
const createFromDatabase = <T extends ICollection<IModel>>(rows: any): T => {
|
|
416
|
+
const result = Array.isArray(rows) ? rows : [rows];
|
|
392
417
|
const objectified = result.map(objectifyDatabaseResult);
|
|
393
418
|
const boified = objectified.map(mapToBos);
|
|
394
419
|
const clumps = clumpIntoGroups(boified);
|
|
395
420
|
const nested = clumps.map(nestClump);
|
|
396
421
|
const models = nested.map((n) => Object.values(n)[0]);
|
|
397
422
|
const Collection = getEntityByModel(models[0]).Collection;
|
|
398
|
-
return
|
|
423
|
+
return <T>new Collection({ models });
|
|
399
424
|
};
|
|
400
425
|
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
426
|
+
const createAnyFromDatabase = <T extends ICollection<IModel>>(
|
|
427
|
+
rows: any,
|
|
428
|
+
rootKey: string | IModel
|
|
429
|
+
): T => {
|
|
430
|
+
if (!rows || !rows.length) {
|
|
431
|
+
const Collection =
|
|
432
|
+
typeof rootKey === 'string'
|
|
433
|
+
? getEntityByTableName(rootKey).Collection
|
|
434
|
+
: getEntityByModel(rootKey).Collection;
|
|
435
|
+
return new Collection({ models: [] }) as T;
|
|
436
|
+
}
|
|
437
|
+
return <T>createFromDatabase<T>(rows);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
const createOneFromDatabase = <T extends IModel>(rows: any): T => {
|
|
441
|
+
if (!rows || !rows.length) {
|
|
404
442
|
throw Error('Did not get one.');
|
|
405
443
|
}
|
|
406
|
-
|
|
444
|
+
const collection = createFromDatabase<ICollection<IModel>>(rows);
|
|
445
|
+
if (!collection || !collection.models || collection.models.length === 0) {
|
|
407
446
|
throw Error('Did not get one.');
|
|
408
447
|
} else if (collection.models.length > 1) {
|
|
409
448
|
throw Error('Got more than one.');
|
|
410
449
|
}
|
|
411
|
-
return collection.models[0]
|
|
450
|
+
return <T>collection.models[0];
|
|
412
451
|
};
|
|
413
452
|
|
|
414
453
|
const createOneOrNoneFromDatabase = <T extends IModel>(
|
|
415
|
-
|
|
454
|
+
rows: any
|
|
416
455
|
): 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.');
|
|
456
|
+
if (!rows || !rows.length) {
|
|
457
|
+
return void 0;
|
|
423
458
|
}
|
|
424
|
-
return
|
|
459
|
+
return <T>createOneFromDatabase(rows);
|
|
425
460
|
};
|
|
426
461
|
|
|
427
462
|
const createManyFromDatabase = <T extends ICollection<IModel>>(
|
|
428
|
-
|
|
463
|
+
rows: any
|
|
429
464
|
): T => {
|
|
430
|
-
|
|
431
|
-
if (!collection || collection.models.length === 0) {
|
|
465
|
+
if (!rows || !rows.length) {
|
|
432
466
|
throw Error('Did not get at least one.');
|
|
433
467
|
}
|
|
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);
|
|
468
|
+
return <T>createFromDatabase(rows);
|
|
701
469
|
};
|
|
702
470
|
|
|
703
471
|
return {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
clumpIntoGroups,
|
|
707
|
-
mapToBos,
|
|
708
|
-
objectifyDatabaseResult,
|
|
472
|
+
getEntityByModel,
|
|
473
|
+
getEntityByTableName,
|
|
709
474
|
createFromDatabase,
|
|
475
|
+
createAnyFromDatabase,
|
|
710
476
|
createOneFromDatabase,
|
|
711
477
|
createOneOrNoneFromDatabase,
|
|
712
478
|
createManyFromDatabase,
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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: entities.reduce((accum: any, data: IEntityInternal<any>) => {
|
|
735
|
-
accum[data.displayName] = data.selectColumnsClause;
|
|
479
|
+
tables: entities.reduce((accum: any, data: IEntityInternal<IModel>) => {
|
|
480
|
+
accum[data.displayName] = {
|
|
481
|
+
columns: data.selectColumnsClause
|
|
482
|
+
};
|
|
736
483
|
return accum;
|
|
737
484
|
}, {})
|
|
738
485
|
};
|
|
@@ -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