pure-orm 4.0.0-5 → 4.0.0-8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -20
- package/coverage/clover.xml +375 -577
- package/coverage/coverage-final.json +18 -20
- package/coverage/lcov-report/dist/src/core.js.html +1038 -0
- package/coverage/lcov-report/dist/src/drivers/index.html +97 -0
- package/coverage/lcov-report/dist/src/drivers/pgp.js.html +240 -0
- package/coverage/lcov-report/dist/src/factory.js.html +293 -197
- package/coverage/lcov-report/dist/src/index.html +20 -33
- package/coverage/lcov-report/dist/src/index.js.html +16 -10
- package/coverage/lcov-report/dist/src/orm.js.html +645 -0
- package/coverage/lcov-report/dist/test-utils/blog/entities.js.html +108 -0
- package/coverage/lcov-report/dist/test-utils/blog/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/blog/models/article.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/article_tag.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/person.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/tag.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/entities.js.html +114 -0
- package/coverage/lcov-report/dist/test-utils/five/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/five/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/parcel-event.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/parcel-line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/parcel.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/entities.js.html +84 -0
- package/coverage/lcov-report/dist/test-utils/nine/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/nine/models/feature-switch.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/entities.js.html +114 -0
- package/coverage/lcov-report/dist/test-utils/order/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/order/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/product.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/utm-source.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/entities.js.html +204 -0
- package/coverage/lcov-report/dist/test-utils/order-more/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/order-more/models/actual-product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/color.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/customer.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/gender.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/inventory-level.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-event.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/physical-address.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant-image.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/product.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/refund.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/shipment-actual-product-variant.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/shipment.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/size.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/utm-medium.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/utm-source.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/entities.js.html +114 -0
- package/coverage/lcov-report/dist/test-utils/six/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/six/models/customer.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/order.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/parcel-line-item.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/parcel.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/entities.js.html +132 -0
- package/coverage/lcov-report/dist/test-utils/thirteen/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/thirteen/models/audience.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/brand.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/category.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/member.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/passion.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/product.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation-audience.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/three/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/three/results.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/entities.js.html +87 -0
- package/coverage/lcov-report/dist/test-utils/twelve/index.html +6 -6
- package/coverage/lcov-report/dist/test-utils/twelve/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/models/member.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/models/prompt.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/orm.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/two/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/two/results.js.html +1 -1
- package/coverage/lcov-report/index.html +47 -47
- package/coverage/lcov-report/src/core.ts.html +1593 -0
- package/coverage/lcov-report/src/drivers/index.html +97 -0
- package/coverage/lcov-report/src/drivers/pgp.ts.html +516 -0
- package/coverage/lcov-report/src/factory.ts.html +436 -250
- package/coverage/lcov-report/src/index.html +20 -33
- package/coverage/lcov-report/src/index.ts.html +23 -5
- package/coverage/lcov-report/src/orm.ts.html +954 -0
- package/coverage/lcov-report/test-utils/blog/entities.ts.html +102 -0
- package/coverage/lcov-report/test-utils/blog/index.html +6 -6
- package/coverage/lcov-report/test-utils/blog/models/article.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/article_tag.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/person.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/tag.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/entities.ts.html +105 -0
- package/coverage/lcov-report/test-utils/five/index.html +2 -2
- package/coverage/lcov-report/test-utils/five/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/parcel-event.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/parcel-line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/parcel.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/nine/entities.ts.html +75 -0
- package/coverage/lcov-report/test-utils/nine/index.html +2 -2
- package/coverage/lcov-report/test-utils/nine/models/feature-switch.ts.html +1 -1
- package/coverage/lcov-report/test-utils/nine/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/nine/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/entities.ts.html +108 -0
- package/coverage/lcov-report/test-utils/order/index.html +2 -2
- package/coverage/lcov-report/test-utils/order/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/product.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/utm-source.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/entities.ts.html +198 -0
- package/coverage/lcov-report/test-utils/order-more/index.html +2 -2
- package/coverage/lcov-report/test-utils/order-more/models/actual-product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/color.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/customer.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/gender.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/inventory-level.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/parcel-event.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/parcel-line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/parcel.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/physical-address.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/product-variant-image.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/product.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/refund.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/shipment-actual-product-variant.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/shipment.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/size.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/utm-medium.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/utm-source.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/entities.ts.html +105 -0
- package/coverage/lcov-report/test-utils/six/index.html +2 -2
- package/coverage/lcov-report/test-utils/six/models/customer.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/order.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/parcel-line-item.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/parcel.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/entities.ts.html +123 -0
- package/coverage/lcov-report/test-utils/thirteen/index.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/models/audience.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/brand.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/category.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/member.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/passion.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/product.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/recommendation-audience.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/recommendation.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/three/index.html +1 -1
- package/coverage/lcov-report/test-utils/three/results.js.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/entities.ts.html +78 -0
- package/coverage/lcov-report/test-utils/twelve/index.html +2 -2
- package/coverage/lcov-report/test-utils/twelve/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/models/member.ts.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/models/prompt.ts.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/orm.ts.html +1 -1
- package/coverage/lcov-report/test-utils/two/index.html +1 -1
- package/coverage/lcov-report/test-utils/two/results.js.html +1 -1
- package/coverage/lcov.info +726 -1143
- package/dist/example/factories/orm.d.ts +1 -47
- package/dist/example/models/employer.d.ts +1 -1
- package/dist/example/models/job.d.ts +1 -1
- package/dist/example/models/person.d.ts +1 -1
- package/dist/src/core.d.ts +66 -0
- package/dist/src/{factory.js → core.js} +51 -245
- package/dist/src/{factory.spec.d.ts → core.spec.d.ts} +0 -0
- package/dist/src/{factory.spec.js → core.spec.js} +56 -43
- package/dist/src/driver-integrations/index.d.ts +13 -0
- package/dist/src/driver-integrations/index.js +2 -0
- package/dist/src/driver-integrations/pgp.d.ts +2 -0
- package/dist/src/driver-integrations/pgp.js +57 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +5 -3
- package/dist/src/orm.d.ts +20 -0
- package/dist/src/orm.js +190 -0
- package/dist/test-utils/blog/entities.d.ts +1 -0
- package/dist/test-utils/blog/{orm.js → entities.js} +7 -6
- package/dist/test-utils/blog/{orm.ts → entities.ts} +6 -6
- package/dist/test-utils/blog/models/article.d.ts +1 -1
- package/dist/test-utils/blog/models/article_tag.d.ts +1 -1
- package/dist/test-utils/blog/models/person.d.ts +1 -1
- package/dist/test-utils/blog/models/tag.d.ts +1 -1
- package/dist/test-utils/five/entities.d.ts +6 -0
- package/dist/test-utils/five/{orm.js → entities.js} +8 -12
- package/dist/test-utils/five/{orm.ts → entities.ts} +7 -12
- package/dist/test-utils/five/models/line-item.d.ts +1 -1
- package/dist/test-utils/five/models/order.d.ts +1 -1
- package/dist/test-utils/five/models/parcel-event.d.ts +1 -1
- package/dist/test-utils/five/models/parcel-line-item.d.ts +1 -1
- package/dist/test-utils/five/models/parcel.d.ts +1 -1
- package/dist/test-utils/nine/entities.d.ts +6 -0
- package/dist/test-utils/nine/entities.js +5 -0
- package/dist/test-utils/nine/entities.ts +2 -0
- package/dist/test-utils/nine/models/feature-switch.d.ts +1 -1
- package/dist/test-utils/order/entities.d.ts +26 -0
- package/dist/test-utils/order/{orm.js → entities.js} +8 -12
- package/{test-utils/order/orm.ts → dist/test-utils/order/entities.ts} +7 -12
- package/dist/test-utils/order/models/line-item.d.ts +1 -1
- package/dist/test-utils/order/models/order.d.ts +1 -1
- package/dist/test-utils/order/models/product-variant.d.ts +1 -1
- package/dist/test-utils/order/models/product.d.ts +1 -1
- package/dist/test-utils/order/models/utm-source.d.ts +1 -1
- package/dist/test-utils/order-more/entities.d.ts +6 -0
- package/dist/test-utils/order-more/{orm.js → entities.js} +23 -27
- package/dist/test-utils/order-more/{orm.ts → entities.ts} +22 -27
- package/dist/test-utils/order-more/models/actual-product-variant.d.ts +1 -1
- package/dist/test-utils/order-more/models/color.d.ts +1 -1
- package/dist/test-utils/order-more/models/customer.d.ts +1 -1
- package/dist/test-utils/order-more/models/gender.d.ts +1 -1
- package/dist/test-utils/order-more/models/inventory-level.d.ts +1 -1
- package/dist/test-utils/order-more/models/line-item.d.ts +1 -1
- package/dist/test-utils/order-more/models/order.d.ts +1 -1
- package/dist/test-utils/order-more/models/parcel-event.d.ts +1 -1
- package/dist/test-utils/order-more/models/parcel-line-item.d.ts +1 -1
- package/dist/test-utils/order-more/models/parcel.d.ts +1 -1
- package/dist/test-utils/order-more/models/physical-address.d.ts +1 -1
- package/dist/test-utils/order-more/models/product-variant-image.d.ts +1 -1
- package/dist/test-utils/order-more/models/product-variant.d.ts +1 -1
- package/dist/test-utils/order-more/models/product.d.ts +1 -1
- package/dist/test-utils/order-more/models/refund.d.ts +1 -1
- package/dist/test-utils/order-more/models/shipment-actual-product-variant.d.ts +1 -1
- package/dist/test-utils/order-more/models/shipment.d.ts +1 -1
- package/dist/test-utils/order-more/models/size.d.ts +1 -1
- package/dist/test-utils/order-more/models/utm-medium.d.ts +1 -1
- package/dist/test-utils/order-more/models/utm-source.d.ts +1 -1
- package/dist/test-utils/six/entities.d.ts +6 -0
- package/dist/test-utils/six/{orm.js → entities.js} +8 -12
- package/{test-utils/six/orm.ts → dist/test-utils/six/entities.ts} +7 -12
- package/dist/test-utils/six/models/customer.d.ts +1 -1
- package/dist/test-utils/six/models/line-item.d.ts +1 -1
- package/dist/test-utils/six/models/order.d.ts +1 -1
- package/dist/test-utils/six/models/parcel-line-item.d.ts +1 -1
- package/dist/test-utils/six/models/parcel.d.ts +1 -1
- package/dist/test-utils/thirteen/entities.d.ts +6 -0
- package/dist/test-utils/thirteen/{orm.js → entities.js} +11 -15
- package/dist/test-utils/thirteen/{orm.ts → entities.ts} +10 -15
- package/dist/test-utils/thirteen/models/audience.d.ts +1 -1
- package/dist/test-utils/thirteen/models/brand.d.ts +1 -1
- package/dist/test-utils/thirteen/models/category.d.ts +1 -1
- package/dist/test-utils/thirteen/models/member.d.ts +1 -1
- package/dist/test-utils/thirteen/models/passion.d.ts +1 -1
- package/dist/test-utils/thirteen/models/product.d.ts +1 -1
- package/dist/test-utils/thirteen/models/recommendation-audience.d.ts +1 -1
- package/dist/test-utils/thirteen/models/recommendation.d.ts +1 -1
- package/dist/test-utils/twelve/entities.d.ts +6 -0
- package/dist/test-utils/twelve/entities.js +6 -0
- package/dist/test-utils/twelve/entities.ts +3 -0
- package/dist/test-utils/twelve/models/member.d.ts +1 -1
- package/dist/test-utils/twelve/models/prompt.d.ts +1 -1
- package/package.json +4 -3
- package/src/{factory.spec.ts → core.spec.ts} +55 -41
- package/src/{factory.ts → core.ts} +102 -338
- package/src/driver-integrations/index.ts +56 -0
- package/src/driver-integrations/pgp.ts +92 -0
- package/src/index.ts +5 -3
- package/src/orm.ts +291 -0
- package/test-utils/blog/{orm.ts → entities.ts} +6 -6
- package/test-utils/five/{orm.ts → entities.ts} +7 -12
- package/test-utils/nine/entities.ts +2 -0
- package/{dist/test-utils/order/orm.ts → test-utils/order/entities.ts} +7 -12
- package/test-utils/order-more/{orm.ts → entities.ts} +22 -27
- package/{dist/test-utils/six/orm.ts → test-utils/six/entities.ts} +7 -12
- package/test-utils/thirteen/{orm.ts → entities.ts} +10 -15
- package/test-utils/twelve/entities.ts +3 -0
- package/dist/src/factory.d.ts +0 -100
- package/dist/test-utils/blog/orm.d.ts +0 -2
- package/dist/test-utils/five/orm.d.ts +0 -48
- package/dist/test-utils/nine/orm.d.ts +0 -48
- package/dist/test-utils/nine/orm.js +0 -9
- package/dist/test-utils/nine/orm.ts +0 -7
- package/dist/test-utils/order/orm.d.ts +0 -48
- package/dist/test-utils/order-more/orm.d.ts +0 -48
- package/dist/test-utils/six/orm.d.ts +0 -48
- package/dist/test-utils/thirteen/orm.d.ts +0 -48
- package/dist/test-utils/twelve/orm.d.ts +0 -48
- package/dist/test-utils/twelve/orm.js +0 -10
- package/dist/test-utils/twelve/orm.ts +0 -8
- package/test-utils/nine/orm.ts +0 -7
- package/test-utils/twelve/orm.ts +0 -8
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
3
|
+
/* eslint-disable max-len */
|
|
4
|
+
const core_1 = require("./core");
|
|
5
|
+
const entities_1 = require("../test-utils/order/entities");
|
|
6
|
+
const entities_2 = require("../test-utils/blog/entities");
|
|
7
|
+
const entities_3 = require("../test-utils/order-more/entities");
|
|
8
|
+
const entities_4 = require("../test-utils/nine/entities");
|
|
9
|
+
const entities_5 = require("../test-utils/five/entities");
|
|
10
|
+
const entities_6 = require("../test-utils/six/entities");
|
|
11
|
+
const entities_7 = require("../test-utils/twelve/entities");
|
|
12
|
+
const entities_8 = require("../test-utils/thirteen/entities");
|
|
14
13
|
const article_1 = require("../test-utils/blog/models/article");
|
|
15
14
|
const two = require('../test-utils/two/results');
|
|
16
15
|
const three = require('../test-utils/three/results');
|
|
@@ -25,8 +24,9 @@ const ten = require('../test-utils/ten/results.json');
|
|
|
25
24
|
const eleven = require('../test-utils/eleven/results.json');
|
|
26
25
|
const twelve = require('../test-utils/twelve/results.json');
|
|
27
26
|
const thirteen = require('../test-utils/thirteen/results.json');
|
|
28
|
-
test('
|
|
29
|
-
const
|
|
27
|
+
test('createOneFromDatabase where multiple rows reduce to one nested object (with all one-to-one or one-to-many tables)', () => {
|
|
28
|
+
const core = (0, core_1.createCore)({ entities: entities_1.entities });
|
|
29
|
+
const order = core.createOneFromDatabase(one);
|
|
30
30
|
expect(Array.isArray(order)).toBe(false);
|
|
31
31
|
expect(order === null || order === void 0 ? void 0 : order.id).toEqual(3866);
|
|
32
32
|
expect(order === null || order === void 0 ? void 0 : order.utmSource.id).toEqual(6);
|
|
@@ -50,8 +50,9 @@ test('Bo#parseFromDatabase where multiple rows reduce to one nested object (with
|
|
|
50
50
|
expect(order.lineItems.models[5].productVariant.id).toEqual(308);
|
|
51
51
|
expect(order.lineItems.models[5].productVariant.product.id).toEqual(3);
|
|
52
52
|
});
|
|
53
|
-
test('
|
|
54
|
-
const
|
|
53
|
+
test('createOneFromDatabase where multiple rows reduce to one nested object (with many-to-many tables)', () => {
|
|
54
|
+
const core = (0, core_1.createCore)({ entities: entities_2.entities });
|
|
55
|
+
const article = core.createOneFromDatabase(two);
|
|
55
56
|
expect(Array.isArray(article)).toBe(false);
|
|
56
57
|
expect(article.id).toEqual(14);
|
|
57
58
|
expect(article.person.id).toEqual(8);
|
|
@@ -77,8 +78,9 @@ test('Bo#parseFromDatabase where multiple rows reduce to one nested object (with
|
|
|
77
78
|
expect(article.articleTags.models[9].id).toEqual(45);
|
|
78
79
|
expect(article.articleTags.models[9].tag.id).toEqual(16);
|
|
79
80
|
});
|
|
80
|
-
test('
|
|
81
|
-
const
|
|
81
|
+
test('createFromDatabase where multiple rows reduce to many rows with nested objects (with many-to-many tables)', () => {
|
|
82
|
+
const core = (0, core_1.createCore)({ entities: entities_2.entities });
|
|
83
|
+
const articles = core.createFromDatabase(three);
|
|
82
84
|
expect(Array.isArray(articles.models)).toBe(true);
|
|
83
85
|
expect(articles instanceof article_1.Articles).toBe(true);
|
|
84
86
|
expect(articles.models.length).toEqual(2);
|
|
@@ -124,8 +126,9 @@ test('Bo#parseFromDatabase where multiple rows reduce to many rows with nested o
|
|
|
124
126
|
// productVariantImages append to it, instead of each productVariantImage
|
|
125
127
|
// living on its own productVariant (which would keep overwriting itself
|
|
126
128
|
// on the actualProductVariant node).
|
|
127
|
-
test('
|
|
128
|
-
const
|
|
129
|
+
test('createFromDatabase where node is already seen', () => {
|
|
130
|
+
const core = (0, core_1.createCore)({ entities: entities_3.entities });
|
|
131
|
+
const inventoryLevels = core.createFromDatabase(four);
|
|
129
132
|
expect(inventoryLevels).toBeDefined();
|
|
130
133
|
const first = inventoryLevels === null || inventoryLevels === void 0 ? void 0 : inventoryLevels.models[0];
|
|
131
134
|
expect(first === null || first === void 0 ? void 0 : first.id).toEqual(15);
|
|
@@ -185,8 +188,9 @@ test('Bo#parseFromDatabase where node is already seen', () => {
|
|
|
185
188
|
// the two relevant line items of the one relevant order. This test should
|
|
186
189
|
// be doing that, but since code coverage all-around isn't great and I already
|
|
187
190
|
// had this fuller json dump from production, I just used it all - YOLO.
|
|
188
|
-
test('
|
|
189
|
-
const
|
|
191
|
+
test('createFromDatabase where a deeply nested models property was misbehaving', () => {
|
|
192
|
+
const core = (0, core_1.createCore)({ entities: entities_5.entities });
|
|
193
|
+
const orders = core.createFromDatabase(five);
|
|
190
194
|
// The assertion that failed when the bug was present
|
|
191
195
|
expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(2);
|
|
192
196
|
// Lots of other assertions that are unrelated and shouldn't be here except
|
|
@@ -227,8 +231,9 @@ test('Bo#parseFromDatabase where a deeply nested models property was misbehaving
|
|
|
227
231
|
// [MISSING ORDER]
|
|
228
232
|
// Issue occcurs in nestClump
|
|
229
233
|
// Problem only surfaced when custom was included
|
|
230
|
-
test('
|
|
231
|
-
const
|
|
234
|
+
test('createOneFromDatabase where a deeply nested models property was misbehaving', () => {
|
|
235
|
+
const core = (0, core_1.createCore)({ entities: entities_6.entities });
|
|
236
|
+
const parcel = core.createOneFromDatabase(six);
|
|
232
237
|
// The assertion that failed when the bug was present
|
|
233
238
|
expect(parcel.parcelLineItems.models[1].lineItem.order).toBeDefined();
|
|
234
239
|
// Lots of other assertions that are unrelated and shouldn't be here except
|
|
@@ -260,8 +265,9 @@ test('Bo#parseOneFromDatabase where a deeply nested models property was misbehav
|
|
|
260
265
|
// ProductVariant(2)
|
|
261
266
|
// Color
|
|
262
267
|
// Issue occcurs in nestClump
|
|
263
|
-
test('
|
|
264
|
-
const
|
|
268
|
+
test('createOneFromDatabase where a deeply nested models property was attaching to wrong parent', () => {
|
|
269
|
+
const core = (0, core_1.createCore)({ entities: entities_3.entities });
|
|
270
|
+
const inventoryLevel = core.createOneFromDatabase(seven);
|
|
265
271
|
// The assertion that failed when the bug was present
|
|
266
272
|
expect(inventoryLevel.actualProductVariant.productVariants.models[1]).toBeDefined();
|
|
267
273
|
// Lots of other assertions that are unrelated and shouldn't be here except
|
|
@@ -298,8 +304,9 @@ test('Bo#parseOneFromDatabase where a deeply nested models property was attachin
|
|
|
298
304
|
// ProductVariant(2)
|
|
299
305
|
// Product
|
|
300
306
|
// Issue occcurs in nestClump
|
|
301
|
-
test('
|
|
302
|
-
const
|
|
307
|
+
test('createFromDatabase where a deeply nested models property was attaching to wrong parent 2', () => {
|
|
308
|
+
const core = (0, core_1.createCore)({ entities: entities_3.entities });
|
|
309
|
+
const shipments = core.createFromDatabase(eight);
|
|
303
310
|
// The assertion that failed when the bug was present
|
|
304
311
|
expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants).toBeDefined();
|
|
305
312
|
// IN ADDITION TO ABOVE ASSERTION and helpful test description of what is
|
|
@@ -354,11 +361,12 @@ test('Bo#parseOneFromDatabase where a deeply nested models property was attachin
|
|
|
354
361
|
});
|
|
355
362
|
// Issue occcurs in nestClump
|
|
356
363
|
// Problem is with only top level nodes
|
|
357
|
-
test('
|
|
364
|
+
test('createFromDatabase with just top level nodes', () => {
|
|
365
|
+
const core = (0, core_1.createCore)({ entities: entities_4.entities });
|
|
358
366
|
let featureSwitches;
|
|
359
367
|
try {
|
|
360
368
|
// This failed when the bug was present
|
|
361
|
-
featureSwitches =
|
|
369
|
+
featureSwitches = core.createFromDatabase(nine);
|
|
362
370
|
}
|
|
363
371
|
catch (e) {
|
|
364
372
|
expect(e).not.toBeDefined();
|
|
@@ -374,11 +382,12 @@ test('Bo#parseFromDatabase with just top level nodes', () => {
|
|
|
374
382
|
// Problem is when oldest parent is an empty join record and is not included
|
|
375
383
|
// which results in the oldest parent search returning -1 and parent heirarchy
|
|
376
384
|
// is thus messed up.
|
|
377
|
-
test('
|
|
385
|
+
test('createFromDatabase 10', () => {
|
|
386
|
+
const core = (0, core_1.createCore)({ entities: entities_3.entities });
|
|
378
387
|
let orders;
|
|
379
388
|
try {
|
|
380
389
|
// This failed when the bug was present
|
|
381
|
-
orders =
|
|
390
|
+
orders = core.createFromDatabase(ten);
|
|
382
391
|
}
|
|
383
392
|
catch (e) {
|
|
384
393
|
expect(e).not.toBeDefined();
|
|
@@ -495,11 +504,12 @@ test('Bo#parseFromDatabase 10', () => {
|
|
|
495
504
|
});
|
|
496
505
|
// Issue occcurs in nestClump
|
|
497
506
|
// Problem from early returning not logging bo so parent hierarcy was missing it
|
|
498
|
-
test('
|
|
507
|
+
test('createFromDatabase 11', () => {
|
|
508
|
+
const core = (0, core_1.createCore)({ entities: entities_3.entities });
|
|
499
509
|
let orders;
|
|
500
510
|
try {
|
|
501
511
|
// This failed when the bug was present
|
|
502
|
-
orders =
|
|
512
|
+
orders = core.createFromDatabase(eleven);
|
|
503
513
|
}
|
|
504
514
|
catch (e) {
|
|
505
515
|
expect(e).not.toBeDefined();
|
|
@@ -508,11 +518,12 @@ test('Bo#parseFromDatabase 11', () => {
|
|
|
508
518
|
});
|
|
509
519
|
// Issue occcurs in nestClump
|
|
510
520
|
// Problem when a table references another model twice (two columns)
|
|
511
|
-
test('
|
|
521
|
+
test('createFromDatabase 12', () => {
|
|
522
|
+
const core = (0, core_1.createCore)({ entities: entities_7.entities });
|
|
512
523
|
let prompt;
|
|
513
524
|
try {
|
|
514
525
|
// This failed when the bug was present
|
|
515
|
-
prompt =
|
|
526
|
+
prompt = core.createFromDatabase(twelve);
|
|
516
527
|
}
|
|
517
528
|
catch (e) {
|
|
518
529
|
expect(e).not.toBeDefined();
|
|
@@ -535,8 +546,9 @@ test('Bo#parseFromDatabase 12', () => {
|
|
|
535
546
|
// Recommendations[4]
|
|
536
547
|
// Brand
|
|
537
548
|
// Passion
|
|
538
|
-
test('
|
|
539
|
-
const
|
|
549
|
+
test('createFromDatabase 13', () => {
|
|
550
|
+
const core = (0, core_1.createCore)({ entities: entities_8.entities });
|
|
551
|
+
const members = core.createFromDatabase(thirteen);
|
|
540
552
|
const member = members === null || members === void 0 ? void 0 : members.models[0];
|
|
541
553
|
expect(member === null || member === void 0 ? void 0 : member.recommendations.models.length).toEqual(4);
|
|
542
554
|
expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].brand.id).toEqual(2);
|
|
@@ -557,10 +569,11 @@ test('Bo#parseFromDatabase 13', () => {
|
|
|
557
569
|
expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].recommendationAudiences.models[0].audience.id).toEqual(1);
|
|
558
570
|
});
|
|
559
571
|
test('orm.tables', () => {
|
|
560
|
-
|
|
561
|
-
expect(
|
|
562
|
-
expect(
|
|
563
|
-
expect(
|
|
564
|
-
expect(
|
|
565
|
-
expect(
|
|
572
|
+
const core = (0, core_1.createCore)({ entities: entities_1.entities });
|
|
573
|
+
expect(Object.keys(core.tables).length).toEqual(5);
|
|
574
|
+
expect(core.tables.utmSource.columns).toEqual('"utm_source".id as "utm_source#id", "utm_source".value as "utm_source#value", "utm_source".label as "utm_source#label", "utm_source".internal as "utm_source#internal"');
|
|
575
|
+
expect(core.tables.order.columns).toEqual('"order".id as "order#id", "order".email as "order#email", "order".browser_ip as "order#browser_ip", "order".browser_user_agent as "order#browser_user_agent", "order".kujo_imported_date as "order#kujo_imported_date", "order".created_date as "order#created_date", "order".cancel_reason as "order#cancel_reason", "order".cancelled_date as "order#cancelled_date", "order".closed_date as "order#closed_date", "order".processed_date as "order#processed_date", "order".updated_date as "order#updated_date", "order".note as "order#note", "order".subtotal_price as "order#subtotal_price", "order".taxes_included as "order#taxes_included", "order".total_discounts as "order#total_discounts", "order".total_price as "order#total_price", "order".total_tax as "order#total_tax", "order".total_weight as "order#total_weight", "order".order_status_url as "order#order_status_url", "order".utm_source_id as "order#utm_source_id", "order".utm_medium_id as "order#utm_medium_id", "order".utm_campaign as "order#utm_campaign", "order".utm_content as "order#utm_content", "order".utm_term as "order#utm_term"');
|
|
576
|
+
expect(core.tables.lineItem.columns).toEqual('"line_item".id as "line_item#id", "line_item".product_variant_id as "line_item#product_variant_id", "line_item".order_id as "line_item#order_id", "line_item".fulfillment_status_id as "line_item#fulfillment_status_id", "line_item".fulfillable_quantity as "line_item#fulfillable_quantity", "line_item".fulfillment_service as "line_item#fulfillment_service", "line_item".grams as "line_item#grams", "line_item".price as "line_item#price", "line_item".quantity as "line_item#quantity", "line_item".requires_shipping as "line_item#requires_shipping", "line_item".taxable as "line_item#taxable", "line_item".total_discount as "line_item#total_discount"');
|
|
577
|
+
expect(core.tables.productVariant.columns).toEqual('"product_variant".id as "product_variant#id", "product_variant".product_id as "product_variant#product_id", "product_variant".actual_product_variant_id as "product_variant#actual_product_variant_id", "product_variant".color_id as "product_variant#color_id", "product_variant".gender_id as "product_variant#gender_id", "product_variant".size_id as "product_variant#size_id", "product_variant".barcode as "product_variant#barcode", "product_variant".price as "product_variant#price", "product_variant".compare_at_price as "product_variant#compare_at_price", "product_variant".created_date as "product_variant#created_date", "product_variant".updated_date as "product_variant#updated_date", "product_variant".grams as "product_variant#grams", "product_variant".requires_shipping as "product_variant#requires_shipping"');
|
|
578
|
+
expect(core.tables.product.columns).toEqual('"product".id as "product#id", "product".vendor_id as "product#vendor_id", "product".value as "product#value", "product".label as "product#label", "product".product_type as "product#product_type", "product".created_date as "product#created_date", "product".updated_date as "product#updated_date", "product".published_date as "product#published_date", "product".category as "product#category"');
|
|
566
579
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ICore, IModel, ICollection } from '../core';
|
|
2
|
+
export interface ICreateForDriverOptions {
|
|
3
|
+
core: ICore;
|
|
4
|
+
db: any;
|
|
5
|
+
logError?: (err: Error) => never;
|
|
6
|
+
}
|
|
7
|
+
export interface ICoreIntegratedDriver extends ICore {
|
|
8
|
+
one: <T extends IModel>(query: string, values?: object, errorHandler?: (err: Error) => never) => T;
|
|
9
|
+
oneOrNone: <T extends IModel>(query: string, values?: object, errorHandler?: (err: Error) => never) => T | void;
|
|
10
|
+
many: <T extends ICollection<IModel>>(query: string, values?: object, errorHandler?: (err: Error) => never) => T;
|
|
11
|
+
any: <T extends ICollection<IModel>>(query: string, values?: object, errorHandler?: (err: Error) => never) => T | void;
|
|
12
|
+
none: (query: string, values?: object, errorHandler?: (err: Error) => never) => void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createForPGP = void 0;
|
|
4
|
+
const createForPGP = ({ core, db, logError }) => {
|
|
5
|
+
const defaultErrorHandler = (err) => {
|
|
6
|
+
if (!(err.name === 'QueryResultError')) {
|
|
7
|
+
if (logError) {
|
|
8
|
+
logError(err);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
throw err;
|
|
12
|
+
};
|
|
13
|
+
/* ------------------------------------------------------------------------*/
|
|
14
|
+
/* Query functions --------------------------------------------------------*/
|
|
15
|
+
/* ------------------------------------------------------------------------*/
|
|
16
|
+
const one = (query, values, errorHandler = defaultErrorHandler) => {
|
|
17
|
+
return db
|
|
18
|
+
.many(query, values)
|
|
19
|
+
.then((rows) => core.createOneFromDatabase(rows))
|
|
20
|
+
.catch(errorHandler);
|
|
21
|
+
};
|
|
22
|
+
const oneOrNone = (query, values, errorHandler = defaultErrorHandler) => {
|
|
23
|
+
return db
|
|
24
|
+
.any(query, values)
|
|
25
|
+
.then((rows) => core.createOneOrNoneFromDatabase(rows))
|
|
26
|
+
.catch(errorHandler);
|
|
27
|
+
};
|
|
28
|
+
const many = (query, values, errorHandler = defaultErrorHandler) => {
|
|
29
|
+
return db
|
|
30
|
+
.any(query, values)
|
|
31
|
+
.then((rows) => core.createManyFromDatabase(rows))
|
|
32
|
+
.catch(errorHandler);
|
|
33
|
+
};
|
|
34
|
+
const any = (query, values, errorHandler = defaultErrorHandler) => {
|
|
35
|
+
return db
|
|
36
|
+
.result(query, values)
|
|
37
|
+
.then((result) => core.createAnyFromDatabase(result.rows, result.fields[0].name.split('#')[0]))
|
|
38
|
+
.catch(errorHandler);
|
|
39
|
+
};
|
|
40
|
+
const none = (query, values, errorHandler = defaultErrorHandler) => {
|
|
41
|
+
return db
|
|
42
|
+
.none(query, values)
|
|
43
|
+
.then(() => null)
|
|
44
|
+
.catch(errorHandler);
|
|
45
|
+
};
|
|
46
|
+
return Object.assign({}, core, {
|
|
47
|
+
// Query Functions
|
|
48
|
+
one,
|
|
49
|
+
oneOrNone,
|
|
50
|
+
many,
|
|
51
|
+
any,
|
|
52
|
+
none,
|
|
53
|
+
// provide direct access to db
|
|
54
|
+
db
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
exports.createForPGP = createForPGP;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createCore, ICreateCoreOptions, ICore, IModel, IModelClass, ICollection, IColumns } from './core';
|
|
2
|
+
export { create, ICreateOptions, IPureORM } from './orm';
|
package/dist/src/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.create = exports.createCore = void 0;
|
|
4
|
+
var core_1 = require("./core");
|
|
5
|
+
Object.defineProperty(exports, "createCore", { enumerable: true, get: function () { return core_1.createCore; } });
|
|
6
|
+
var orm_1 = require("./orm");
|
|
7
|
+
Object.defineProperty(exports, "create", { enumerable: true, get: function () { return orm_1.create; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IModel, ICollection, IEntities } from './core';
|
|
2
|
+
import { ICoreIntegratedDriver } from './driver-integrations/index';
|
|
3
|
+
export interface ICreateOptions {
|
|
4
|
+
entities: IEntities<IModel>;
|
|
5
|
+
db: any;
|
|
6
|
+
logError?: (err: Error) => never;
|
|
7
|
+
}
|
|
8
|
+
export interface IPureORM extends ICoreIntegratedDriver {
|
|
9
|
+
getMatching: <T extends IModel>(model: T) => T;
|
|
10
|
+
getOneOrNoneMatching: <T extends IModel>(model: T) => T | void;
|
|
11
|
+
getAnyMatching: <T extends ICollection<IModel>>(model: IModel) => T | void;
|
|
12
|
+
getAllMatching: <T extends ICollection<IModel>>(model: IModel) => T;
|
|
13
|
+
create: <T extends IModel>(model: T) => T;
|
|
14
|
+
update: <T extends IModel>(model: T, options: {
|
|
15
|
+
on: string;
|
|
16
|
+
}) => T;
|
|
17
|
+
delete: <T extends IModel>(model: T) => void;
|
|
18
|
+
deleteMatching: <T extends IModel>(model: T) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare const create: ({ entities: externalEntities, db, logError }: ICreateOptions) => IPureORM;
|
package/dist/src/orm.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const core_1 = require("./core");
|
|
5
|
+
const pgp_1 = require("./driver-integrations/pgp");
|
|
6
|
+
const create = ({ entities: externalEntities, db, logError }) => {
|
|
7
|
+
const core = (0, core_1.createCore)({ entities: externalEntities });
|
|
8
|
+
let orm;
|
|
9
|
+
if (db.$config.pgp) {
|
|
10
|
+
orm = (0, pgp_1.createForPGP)({ core, db, logError });
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
throw new Error(`You're database driver is not yet supported. You can make a PR to add it, or use the \`createCore\` export which doesn't try to abstract over the database driver, and instead you pass the results of the database driver queries to it.`);
|
|
14
|
+
}
|
|
15
|
+
/* ------------------------------------------------------------------------*/
|
|
16
|
+
/* Helper Utilities for CRUD functions ------------------------------------*/
|
|
17
|
+
/* ------------------------------------------------------------------------*/
|
|
18
|
+
const getSqlInsertParts = (model) => {
|
|
19
|
+
const columns = orm
|
|
20
|
+
.getEntityByModel(model)
|
|
21
|
+
.columnNames.filter((column, index) => model[orm.getEntityByModel(model).propertyNames[index]] !== void 0)
|
|
22
|
+
.map((col) => `"${col}"`)
|
|
23
|
+
.join(', ');
|
|
24
|
+
const values = orm
|
|
25
|
+
.getEntityByModel(model)
|
|
26
|
+
.propertyNames.map((property) => model[property])
|
|
27
|
+
.filter((value) => value !== void 0);
|
|
28
|
+
const valuesVar = values.map((value, index) => `$${index + 1}`);
|
|
29
|
+
return { columns, values, valuesVar };
|
|
30
|
+
};
|
|
31
|
+
const getSqlUpdateParts = (model, on = 'id') => {
|
|
32
|
+
const clauseArray = orm
|
|
33
|
+
.getEntityByModel(model)
|
|
34
|
+
.columnNames.filter((sqlColumn, index) => model[orm.getEntityByModel(model).propertyNames[index]] !== void 0)
|
|
35
|
+
.map((sqlColumn, index) => `"${sqlColumn}" = $${index + 1}`);
|
|
36
|
+
const clause = clauseArray.join(', ');
|
|
37
|
+
const idVar = `$${clauseArray.length + 1}`;
|
|
38
|
+
const _values = orm
|
|
39
|
+
.getEntityByModel(model)
|
|
40
|
+
.propertyNames.map((property) => model[property])
|
|
41
|
+
.filter((value) => value !== void 0);
|
|
42
|
+
const values = [..._values, model[on]];
|
|
43
|
+
return { clause, idVar, values };
|
|
44
|
+
};
|
|
45
|
+
const getMatchingParts = (model) => {
|
|
46
|
+
const whereClause = orm
|
|
47
|
+
.getEntityByModel(model)
|
|
48
|
+
.propertyNames.map((property, index) => model[property] != null
|
|
49
|
+
? `"${orm.getEntityByModel(model).tableName}"."${orm.getEntityByModel(model).columnNames[index]}"`
|
|
50
|
+
: null)
|
|
51
|
+
.filter((x) => x != null)
|
|
52
|
+
.map((x, i) => `${x} = $${i + 1}`)
|
|
53
|
+
.join(' AND ');
|
|
54
|
+
const values = orm
|
|
55
|
+
.getEntityByModel(model)
|
|
56
|
+
.propertyNames.map((property) => model[property] != null
|
|
57
|
+
? model[property]
|
|
58
|
+
: null)
|
|
59
|
+
.filter((x) => x != null);
|
|
60
|
+
return { whereClause, values };
|
|
61
|
+
};
|
|
62
|
+
// This one returns an object, which allows it to be more versatile.
|
|
63
|
+
// To-do: make this one even better and use it instead of the one above.
|
|
64
|
+
const getMatchingPartsObject = (model) => {
|
|
65
|
+
const whereClause = orm
|
|
66
|
+
.getEntityByModel(model)
|
|
67
|
+
.propertyNames.map((property, index) => model[property] != null
|
|
68
|
+
? `"${orm.getEntityByModel(model).tableName}"."${orm.getEntityByModel(model).columnNames[index]}"`
|
|
69
|
+
: null)
|
|
70
|
+
.filter((x) => x != null)
|
|
71
|
+
.map((x, i) => `${x} = $(${i + 1})`)
|
|
72
|
+
.join(' AND ');
|
|
73
|
+
const values = orm
|
|
74
|
+
.getEntityByModel(model)
|
|
75
|
+
.propertyNames.map((property) => model[property] != null
|
|
76
|
+
? model[property]
|
|
77
|
+
: null)
|
|
78
|
+
.filter((x) => x != null)
|
|
79
|
+
.reduce((accum, val, index) => Object.assign({}, accum, { [index + 1]: val }), {});
|
|
80
|
+
return { whereClause, values };
|
|
81
|
+
};
|
|
82
|
+
const getNewWith = (model, sqlColumns, values) => {
|
|
83
|
+
const Constructor = model.constructor;
|
|
84
|
+
const modelKeys = sqlColumns.map((key) => orm.getEntityByModel(model).propertyNames[orm.getEntityByModel(model).columnNames.indexOf(key)]);
|
|
85
|
+
const modelData = modelKeys.reduce((data, key, index) => {
|
|
86
|
+
data[key] = values[index];
|
|
87
|
+
return data;
|
|
88
|
+
}, {});
|
|
89
|
+
return new Constructor(modelData);
|
|
90
|
+
};
|
|
91
|
+
const getValueBySqlColumn = (model, sqlColumn) => {
|
|
92
|
+
return model[orm.getEntityByModel(model).propertyNames[orm.getEntityByModel(model).columnNames.indexOf(sqlColumn)]];
|
|
93
|
+
};
|
|
94
|
+
/* ------------------------------------------------------------------------*/
|
|
95
|
+
/* Built-in basic CRUD functions ------------------------------------------*/
|
|
96
|
+
/* ------------------------------------------------------------------------*/
|
|
97
|
+
// Standard create
|
|
98
|
+
const create = (model) => {
|
|
99
|
+
const { columns, values, valuesVar } = getSqlInsertParts(model);
|
|
100
|
+
const query = `
|
|
101
|
+
INSERT INTO "${orm.getEntityByModel(model).tableName}" ( ${columns} )
|
|
102
|
+
VALUES ( ${valuesVar} )
|
|
103
|
+
RETURNING ${orm.getEntityByModel(model).selectColumnsClause};
|
|
104
|
+
`;
|
|
105
|
+
return orm.one(query, values);
|
|
106
|
+
};
|
|
107
|
+
// Standard update
|
|
108
|
+
const update = (model, { on = 'id' } = {}) => {
|
|
109
|
+
const { clause, idVar, values } = getSqlUpdateParts(model, on);
|
|
110
|
+
const query = `
|
|
111
|
+
UPDATE "${orm.getEntityByModel(model).tableName}"
|
|
112
|
+
SET ${clause}
|
|
113
|
+
WHERE "${orm.getEntityByModel(model).tableName}".${on} = ${idVar}
|
|
114
|
+
RETURNING ${orm.getEntityByModel(model).selectColumnsClause};
|
|
115
|
+
`;
|
|
116
|
+
return orm.one(query, values);
|
|
117
|
+
};
|
|
118
|
+
// Standard delete
|
|
119
|
+
const _delete = (model) => {
|
|
120
|
+
const id = model.id;
|
|
121
|
+
const query = `
|
|
122
|
+
DELETE FROM "${orm.getEntityByModel(model).tableName}"
|
|
123
|
+
WHERE "${orm.getEntityByModel(model).tableName}".id = $(id)
|
|
124
|
+
`;
|
|
125
|
+
return orm.none(query, { id });
|
|
126
|
+
};
|
|
127
|
+
const deleteMatching = (model) => {
|
|
128
|
+
const { whereClause, values } = getMatchingParts(model);
|
|
129
|
+
const query = `
|
|
130
|
+
DELETE FROM "${orm.getEntityByModel(model).tableName}"
|
|
131
|
+
WHERE ${whereClause};
|
|
132
|
+
`;
|
|
133
|
+
return orm.none(query, values);
|
|
134
|
+
};
|
|
135
|
+
const getMatching = (model) => {
|
|
136
|
+
const { whereClause, values } = getMatchingParts(model);
|
|
137
|
+
const query = `
|
|
138
|
+
SELECT ${orm.getEntityByModel(model).selectColumnsClause}
|
|
139
|
+
FROM "${orm.getEntityByModel(model).tableName}"
|
|
140
|
+
WHERE ${whereClause};
|
|
141
|
+
`;
|
|
142
|
+
return orm.one(query, values);
|
|
143
|
+
};
|
|
144
|
+
const getOneOrNoneMatching = (model) => {
|
|
145
|
+
const { whereClause, values } = getMatchingParts(model);
|
|
146
|
+
const query = `
|
|
147
|
+
SELECT ${orm.getEntityByModel(model).selectColumnsClause}
|
|
148
|
+
FROM "${orm.getEntityByModel(model).tableName}"
|
|
149
|
+
WHERE ${whereClause};
|
|
150
|
+
`;
|
|
151
|
+
return orm.oneOrNone(query, values);
|
|
152
|
+
};
|
|
153
|
+
const getAnyMatching = (model) => {
|
|
154
|
+
const { whereClause, values } = getMatchingParts(model);
|
|
155
|
+
const query = `
|
|
156
|
+
SELECT ${orm.getEntityByModel(model).selectColumnsClause}
|
|
157
|
+
FROM "${orm.getEntityByModel(model).tableName}"
|
|
158
|
+
WHERE ${whereClause};
|
|
159
|
+
`;
|
|
160
|
+
return orm.any(query, values);
|
|
161
|
+
};
|
|
162
|
+
const getAllMatching = (model) => {
|
|
163
|
+
const { whereClause, values } = getMatchingParts(model);
|
|
164
|
+
const query = `
|
|
165
|
+
SELECT ${orm.getEntityByModel(model).selectColumnsClause}
|
|
166
|
+
FROM "${orm.getEntityByModel(model).tableName}"
|
|
167
|
+
WHERE ${whereClause};
|
|
168
|
+
`;
|
|
169
|
+
return orm.many(query, values);
|
|
170
|
+
};
|
|
171
|
+
return Object.assign({}, orm, {
|
|
172
|
+
// Built-in basic CRUD functions
|
|
173
|
+
create,
|
|
174
|
+
update,
|
|
175
|
+
delete: _delete,
|
|
176
|
+
deleteMatching,
|
|
177
|
+
getMatching,
|
|
178
|
+
getOneOrNoneMatching,
|
|
179
|
+
getAnyMatching,
|
|
180
|
+
getAllMatching,
|
|
181
|
+
// Helper Utility functions
|
|
182
|
+
getSqlInsertParts,
|
|
183
|
+
getSqlUpdateParts,
|
|
184
|
+
getMatchingParts,
|
|
185
|
+
getMatchingPartsObject,
|
|
186
|
+
getNewWith,
|
|
187
|
+
getValueBySqlColumn
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
exports.create = create;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const entities: any[];
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.entities = void 0;
|
|
4
4
|
const { articleEntity } = require('./models/article');
|
|
5
5
|
const { personEntity } = require('./models/person');
|
|
6
6
|
const { articleTagEntity } = require('./models/article_tag');
|
|
7
7
|
const { tagEntity } = require('./models/tag');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
exports.entities = [
|
|
9
|
+
articleEntity,
|
|
10
|
+
personEntity,
|
|
11
|
+
articleTagEntity,
|
|
12
|
+
tagEntity
|
|
13
|
+
];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const { create } = require('../../src/index');
|
|
2
1
|
const { articleEntity } = require('./models/article');
|
|
3
2
|
const { personEntity } = require('./models/person');
|
|
4
3
|
const { articleTagEntity } = require('./models/article_tag');
|
|
5
4
|
const { tagEntity } = require('./models/tag');
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export const entities = [
|
|
7
|
+
articleEntity,
|
|
8
|
+
personEntity,
|
|
9
|
+
articleTagEntity,
|
|
10
|
+
tagEntity
|
|
11
|
+
];
|
|
@@ -24,7 +24,7 @@ export declare class Articles implements ICollection<Article> {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const articleEntity: {
|
|
26
26
|
tableName: string;
|
|
27
|
-
columns: import("../../../src/
|
|
27
|
+
columns: import("../../../src/core").IColumn[];
|
|
28
28
|
Model: typeof Article;
|
|
29
29
|
Collection: typeof Articles;
|
|
30
30
|
};
|
|
@@ -17,7 +17,7 @@ export declare class ArticleTags implements ICollection<ArticleTag> {
|
|
|
17
17
|
}
|
|
18
18
|
export declare const articleTagEntity: {
|
|
19
19
|
tableName: string;
|
|
20
|
-
columns: import("../../../src/
|
|
20
|
+
columns: import("../../../src/core").IColumn[];
|
|
21
21
|
Model: typeof ArticleTag;
|
|
22
22
|
Collection: typeof ArticleTags;
|
|
23
23
|
};
|
|
@@ -36,7 +36,7 @@ export declare class Persons implements ICollection<Person> {
|
|
|
36
36
|
}
|
|
37
37
|
export declare const personEntity: {
|
|
38
38
|
tableName: string;
|
|
39
|
-
columns: import("../../../src/
|
|
39
|
+
columns: import("../../../src/core").IColumn[];
|
|
40
40
|
Model: typeof Person;
|
|
41
41
|
Collection: typeof Persons;
|
|
42
42
|
};
|
|
@@ -13,7 +13,7 @@ export declare class Tags implements ICollection<Tag> {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const tagEntity: {
|
|
15
15
|
tableName: string;
|
|
16
|
-
columns: import("../../../src/
|
|
16
|
+
columns: import("../../../src/core").IColumn[];
|
|
17
17
|
Model: typeof Tag;
|
|
18
18
|
Collection: typeof Tags;
|
|
19
19
|
};
|