pure-orm 4.0.0-6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -20
- package/coverage/clover.xml +377 -583
- 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 +285 -198
- 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 +427 -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 +720 -1153
- 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} +48 -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} +99 -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
|
* [
|
|
@@ -388,360 +434,75 @@ export const create = ({
|
|
|
388
434
|
}, {});
|
|
389
435
|
};
|
|
390
436
|
|
|
391
|
-
const createFromDatabase = <T extends ICollection<IModel>>(
|
|
392
|
-
|
|
393
|
-
): T | undefined => {
|
|
394
|
-
if (!_result || !_result.length) {
|
|
395
|
-
return void 0;
|
|
396
|
-
}
|
|
397
|
-
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];
|
|
398
439
|
const objectified = result.map(objectifyDatabaseResult);
|
|
399
440
|
const boified = objectified.map(mapToBos);
|
|
400
441
|
const clumps = clumpIntoGroups(boified);
|
|
401
442
|
const nested = clumps.map(nestClump);
|
|
402
443
|
const models = nested.map((n) => Object.values(n)[0]);
|
|
403
444
|
const Collection = getEntityByModel(models[0]).Collection;
|
|
404
|
-
return
|
|
445
|
+
return <T>new Collection({ models });
|
|
446
|
+
};
|
|
447
|
+
|
|
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);
|
|
405
460
|
};
|
|
406
461
|
|
|
407
|
-
const createOneFromDatabase = <T extends IModel>(
|
|
408
|
-
|
|
409
|
-
if (!collection) {
|
|
462
|
+
const createOneFromDatabase = <T extends IModel>(rows: any): T => {
|
|
463
|
+
if (!rows || !rows.length) {
|
|
410
464
|
throw Error('Did not get one.');
|
|
411
465
|
}
|
|
412
|
-
|
|
466
|
+
const collection = createFromDatabase<ICollection<IModel>>(rows);
|
|
467
|
+
if (!collection || !collection.models || collection.models.length === 0) {
|
|
413
468
|
throw Error('Did not get one.');
|
|
414
469
|
} else if (collection.models.length > 1) {
|
|
415
470
|
throw Error('Got more than one.');
|
|
416
471
|
}
|
|
417
|
-
return collection.models[0]
|
|
472
|
+
return <T>collection.models[0];
|
|
418
473
|
};
|
|
419
474
|
|
|
420
475
|
const createOneOrNoneFromDatabase = <T extends IModel>(
|
|
421
|
-
|
|
476
|
+
rows: any
|
|
422
477
|
): T | void => {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
throw Error('Got more than one.');
|
|
478
|
+
if (!rows || !rows.length) {
|
|
479
|
+
return void 0;
|
|
426
480
|
}
|
|
427
|
-
return
|
|
481
|
+
return <T>createOneFromDatabase(rows);
|
|
428
482
|
};
|
|
429
483
|
|
|
430
484
|
const createManyFromDatabase = <T extends ICollection<IModel>>(
|
|
431
|
-
|
|
485
|
+
rows: any
|
|
432
486
|
): T => {
|
|
433
|
-
|
|
434
|
-
if (!collection || collection.models.length === 0) {
|
|
487
|
+
if (!rows || !rows.length) {
|
|
435
488
|
throw Error('Did not get at least one.');
|
|
436
489
|
}
|
|
437
|
-
return
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
const getSqlInsertParts = (model: IModel) => {
|
|
441
|
-
const columns = getEntityByModel(model)
|
|
442
|
-
.columnNames.filter(
|
|
443
|
-
(column: string, index: number) =>
|
|
444
|
-
model[
|
|
445
|
-
getEntityByModel(model).propertyNames[index] as keyof typeof model
|
|
446
|
-
] !== void 0
|
|
447
|
-
)
|
|
448
|
-
.map((col: string) => `"${col}"`)
|
|
449
|
-
.join(', ');
|
|
450
|
-
const values = getEntityByModel(model)
|
|
451
|
-
.propertyNames.map(
|
|
452
|
-
(property: string) => model[property as keyof typeof model]
|
|
453
|
-
)
|
|
454
|
-
.filter((value: any) => value !== void 0);
|
|
455
|
-
const valuesVar = values.map(
|
|
456
|
-
(value: any, index: number) => `$${index + 1}`
|
|
457
|
-
);
|
|
458
|
-
return { columns, values, valuesVar };
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
const getSqlUpdateParts = (model: IModel, on = 'id') => {
|
|
462
|
-
const clauseArray = getEntityByModel(model)
|
|
463
|
-
.columnNames.filter(
|
|
464
|
-
(sqlColumn: string, index: number) =>
|
|
465
|
-
model[
|
|
466
|
-
getEntityByModel(model).propertyNames[index] as keyof typeof model
|
|
467
|
-
] !== void 0
|
|
468
|
-
)
|
|
469
|
-
.map(
|
|
470
|
-
(sqlColumn: string, index: number) => `"${sqlColumn}" = $${index + 1}`
|
|
471
|
-
);
|
|
472
|
-
const clause = clauseArray.join(', ');
|
|
473
|
-
const idVar = `$${clauseArray.length + 1}`;
|
|
474
|
-
const _values = getEntityByModel(model)
|
|
475
|
-
.propertyNames.map(
|
|
476
|
-
(property: string) => model[property as keyof typeof model]
|
|
477
|
-
)
|
|
478
|
-
.filter((value: any) => value !== void 0);
|
|
479
|
-
const values = [..._values, model[on as keyof typeof model]];
|
|
480
|
-
return { clause, idVar, values };
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
const getMatchingParts = (model: IModel) => {
|
|
484
|
-
const whereClause = getEntityByModel(model)
|
|
485
|
-
.propertyNames.map((property: string, index: number) =>
|
|
486
|
-
model[property as keyof typeof model] != null
|
|
487
|
-
? `"${getEntityByModel(model).tableName}"."${
|
|
488
|
-
getEntityByModel(model).columnNames[index]
|
|
489
|
-
}"`
|
|
490
|
-
: null
|
|
491
|
-
)
|
|
492
|
-
.filter((x: string | null) => x != null)
|
|
493
|
-
.map((x: string | null, i: number) => `${x} = $${i + 1}`)
|
|
494
|
-
.join(' AND ');
|
|
495
|
-
const values = getEntityByModel(model)
|
|
496
|
-
.propertyNames.map((property: string) =>
|
|
497
|
-
model[property as keyof typeof model] != null
|
|
498
|
-
? model[property as keyof typeof model]
|
|
499
|
-
: null
|
|
500
|
-
)
|
|
501
|
-
.filter((x: any) => x != null);
|
|
502
|
-
return { whereClause, values };
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
// This one returns an object, which allows it to be more versatile.
|
|
506
|
-
// To-do: make this one even better and use it instead of the one above.
|
|
507
|
-
const getMatchingPartsObject = (model: IModel) => {
|
|
508
|
-
const whereClause = getEntityByModel(model)
|
|
509
|
-
.propertyNames.map((property: string, index: number) =>
|
|
510
|
-
model[property as keyof typeof model] != null
|
|
511
|
-
? `"${getEntityByModel(model).tableName}"."${
|
|
512
|
-
getEntityByModel(model).columnNames[index]
|
|
513
|
-
}"`
|
|
514
|
-
: null
|
|
515
|
-
)
|
|
516
|
-
.filter((x: string | null) => x != null)
|
|
517
|
-
.map((x: string | null, i: number) => `${x} = $(${i + 1})`)
|
|
518
|
-
.join(' AND ');
|
|
519
|
-
const values = getEntityByModel(model)
|
|
520
|
-
.propertyNames.map((property: string) =>
|
|
521
|
-
model[property as keyof typeof model] != null
|
|
522
|
-
? model[property as keyof typeof model]
|
|
523
|
-
: null
|
|
524
|
-
)
|
|
525
|
-
.filter((x: any) => x != null)
|
|
526
|
-
.reduce(
|
|
527
|
-
(accum: any, val: any, index: number) =>
|
|
528
|
-
Object.assign({}, accum, { [index + 1]: val }),
|
|
529
|
-
{}
|
|
530
|
-
);
|
|
531
|
-
return { whereClause, values };
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
const getNewWith = (model: IModel, sqlColumns: any, values: any) => {
|
|
535
|
-
const Constructor = model.constructor as any;
|
|
536
|
-
const modelKeys = sqlColumns.map(
|
|
537
|
-
(key: string) =>
|
|
538
|
-
getEntityByModel(model).propertyNames[
|
|
539
|
-
getEntityByModel(model).columnNames.indexOf(key)
|
|
540
|
-
]
|
|
541
|
-
);
|
|
542
|
-
const modelData = modelKeys.reduce(
|
|
543
|
-
(data: any, key: string, index: number) => {
|
|
544
|
-
data[key] = values[index];
|
|
545
|
-
return data;
|
|
546
|
-
},
|
|
547
|
-
{}
|
|
548
|
-
);
|
|
549
|
-
return new Constructor(modelData);
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
const getValueBySqlColumn = (model: IModel, sqlColumn: string) => {
|
|
553
|
-
return model[
|
|
554
|
-
getEntityByModel(model).propertyNames[
|
|
555
|
-
getEntityByModel(model).columnNames.indexOf(sqlColumn)
|
|
556
|
-
] as keyof typeof model
|
|
557
|
-
];
|
|
558
|
-
};
|
|
559
|
-
/* ------------------------------------------------------------------------*/
|
|
560
|
-
/* Query functions --------------------------------------------------------*/
|
|
561
|
-
/* ------------------------------------------------------------------------*/
|
|
562
|
-
|
|
563
|
-
const one = <T extends IModel>(
|
|
564
|
-
query: string,
|
|
565
|
-
values?: object,
|
|
566
|
-
errorHandler = defaultErrorHandler
|
|
567
|
-
): T => {
|
|
568
|
-
return db
|
|
569
|
-
.many(query, values)
|
|
570
|
-
.then((rows: any) => createOneFromDatabase(rows))
|
|
571
|
-
.catch(errorHandler);
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
const oneOrNone = <T extends IModel>(
|
|
575
|
-
query: string,
|
|
576
|
-
values?: object,
|
|
577
|
-
errorHandler = defaultErrorHandler
|
|
578
|
-
): T | void => {
|
|
579
|
-
return db
|
|
580
|
-
.any(query, values)
|
|
581
|
-
.then((rows: any) => createOneOrNoneFromDatabase(rows))
|
|
582
|
-
.catch(errorHandler);
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
const many = <T extends ICollection<IModel>>(
|
|
586
|
-
query: string,
|
|
587
|
-
values?: object,
|
|
588
|
-
errorHandler = defaultErrorHandler
|
|
589
|
-
): T => {
|
|
590
|
-
return db
|
|
591
|
-
.any(query, values)
|
|
592
|
-
.then((rows: any) => createManyFromDatabase(rows))
|
|
593
|
-
.catch(errorHandler);
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
const any = <T extends ICollection<IModel>>(
|
|
597
|
-
query: string,
|
|
598
|
-
values?: object,
|
|
599
|
-
errorHandler = defaultErrorHandler
|
|
600
|
-
): T | void => {
|
|
601
|
-
return db
|
|
602
|
-
.any(query, values)
|
|
603
|
-
.then((rows: any) => createFromDatabase(rows))
|
|
604
|
-
.catch(errorHandler);
|
|
605
|
-
};
|
|
606
|
-
|
|
607
|
-
const none = (
|
|
608
|
-
query: string,
|
|
609
|
-
values?: object,
|
|
610
|
-
errorHandler = defaultErrorHandler
|
|
611
|
-
): void => {
|
|
612
|
-
return db
|
|
613
|
-
.none(query, values)
|
|
614
|
-
.then(() => null)
|
|
615
|
-
.catch(errorHandler);
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
/* ------------------------------------------------------------------------*/
|
|
619
|
-
/* Built-in basic CRUD functions ------------------------------------------*/
|
|
620
|
-
/* ------------------------------------------------------------------------*/
|
|
621
|
-
|
|
622
|
-
// Standard create
|
|
623
|
-
const create = <T extends IModel>(model: T): T => {
|
|
624
|
-
const { columns, values, valuesVar } = getSqlInsertParts(model);
|
|
625
|
-
const query = `
|
|
626
|
-
INSERT INTO "${getEntityByModel(model).tableName}" ( ${columns} )
|
|
627
|
-
VALUES ( ${valuesVar} )
|
|
628
|
-
RETURNING ${getEntityByModel(model).selectColumnsClause};
|
|
629
|
-
`;
|
|
630
|
-
return one<T>(query, values);
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
// Standard update
|
|
634
|
-
const update = <T extends IModel>(model: T, { on = 'id' } = {}): T => {
|
|
635
|
-
const { clause, idVar, values } = getSqlUpdateParts(model, on);
|
|
636
|
-
const query = `
|
|
637
|
-
UPDATE "${getEntityByModel(model).tableName}"
|
|
638
|
-
SET ${clause}
|
|
639
|
-
WHERE "${getEntityByModel(model).tableName}".${on} = ${idVar}
|
|
640
|
-
RETURNING ${getEntityByModel(model).selectColumnsClause};
|
|
641
|
-
`;
|
|
642
|
-
return one<T>(query, values);
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
// Standard delete
|
|
646
|
-
const _delete = <T extends IModel>(model: T): void => {
|
|
647
|
-
const id = (model as any).id;
|
|
648
|
-
const query = `
|
|
649
|
-
DELETE FROM "${getEntityByModel(model).tableName}"
|
|
650
|
-
WHERE "${getEntityByModel(model).tableName}".id = $(id)
|
|
651
|
-
`;
|
|
652
|
-
return none(query, { id });
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
const deleteMatching = <T extends IModel>(model: T) => {
|
|
656
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
657
|
-
const query = `
|
|
658
|
-
DELETE FROM "${getEntityByModel(model).tableName}"
|
|
659
|
-
WHERE ${whereClause};
|
|
660
|
-
`;
|
|
661
|
-
return none(query, values);
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
const getMatching = <T extends IModel>(model: T): T => {
|
|
665
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
666
|
-
const query = `
|
|
667
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
668
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
669
|
-
WHERE ${whereClause};
|
|
670
|
-
`;
|
|
671
|
-
return one<T>(query, values);
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
const getOneOrNoneMatching = <T extends IModel>(model: T): T | void => {
|
|
675
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
676
|
-
const query = `
|
|
677
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
678
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
679
|
-
WHERE ${whereClause};
|
|
680
|
-
`;
|
|
681
|
-
return oneOrNone<T>(query, values);
|
|
682
|
-
};
|
|
683
|
-
|
|
684
|
-
const getAnyMatching = <T extends ICollection<IModel>>(
|
|
685
|
-
model: IModel
|
|
686
|
-
): T | void => {
|
|
687
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
688
|
-
const query = `
|
|
689
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
690
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
691
|
-
WHERE ${whereClause};
|
|
692
|
-
`;
|
|
693
|
-
return any<T>(query, values);
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
const getAllMatching = <T extends ICollection<IModel>>(model: IModel): T => {
|
|
697
|
-
const { whereClause, values } = getMatchingParts(model);
|
|
698
|
-
const query = `
|
|
699
|
-
SELECT ${getEntityByModel(model).selectColumnsClause}
|
|
700
|
-
FROM "${getEntityByModel(model).tableName}"
|
|
701
|
-
WHERE ${whereClause};
|
|
702
|
-
`;
|
|
703
|
-
return many<T>(query, values);
|
|
490
|
+
return <T>createFromDatabase(rows);
|
|
704
491
|
};
|
|
705
492
|
|
|
706
493
|
return {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
clumpIntoGroups,
|
|
710
|
-
mapToBos,
|
|
711
|
-
objectifyDatabaseResult,
|
|
494
|
+
getEntityByModel,
|
|
495
|
+
getEntityByTableName,
|
|
712
496
|
createFromDatabase,
|
|
497
|
+
createAnyFromDatabase,
|
|
713
498
|
createOneFromDatabase,
|
|
714
499
|
createOneOrNoneFromDatabase,
|
|
715
500
|
createManyFromDatabase,
|
|
716
|
-
getSqlInsertParts,
|
|
717
|
-
getSqlUpdateParts,
|
|
718
|
-
getMatchingParts,
|
|
719
|
-
getMatchingPartsObject,
|
|
720
|
-
getNewWith,
|
|
721
|
-
getValueBySqlColumn,
|
|
722
|
-
// Query Functions
|
|
723
|
-
one,
|
|
724
|
-
oneOrNone,
|
|
725
|
-
many,
|
|
726
|
-
any,
|
|
727
|
-
none,
|
|
728
|
-
// Built-in basic CRUD functions
|
|
729
|
-
create,
|
|
730
|
-
update,
|
|
731
|
-
delete: _delete,
|
|
732
|
-
deleteMatching,
|
|
733
|
-
getMatching,
|
|
734
|
-
getOneOrNoneMatching,
|
|
735
|
-
getAnyMatching,
|
|
736
|
-
getAllMatching,
|
|
737
|
-
// tables property for access to select columns clause string
|
|
738
501
|
tables: entities.reduce((accum: any, data: IEntityInternal<IModel>) => {
|
|
739
502
|
accum[data.displayName] = {
|
|
740
503
|
columns: data.selectColumnsClause
|
|
741
504
|
};
|
|
742
505
|
return accum;
|
|
743
|
-
}, {})
|
|
744
|
-
// provide direct access to db
|
|
745
|
-
db
|
|
506
|
+
}, {})
|
|
746
507
|
};
|
|
747
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