From dbd51ccb9b2d32c106bc2d8e0ebf4d6ab3a4c3f2 Mon Sep 17 00:00:00 2001 From: Levichev Dmitry Date: Sun, 12 Jul 2020 21:26:14 +0300 Subject: [PATCH] Moved some CRUD operations from IdentifiableMongoDbPersistence to MongoDbPersistence --- changelog.md | 6 + component.json | 2 +- go.mod | 19 +- go.sum | 103 +++++-- persistence/IdentifiableMongoDbPersistence.go | 202 +------------- persistence/MongoDbPersistence.go | 253 ++++++++++++++++++ 6 files changed, 353 insertions(+), 232 deletions(-) create mode 100644 changelog.md diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..c35c867 --- /dev/null +++ b/changelog.md @@ -0,0 +1,6 @@ +# MongoDB components for Pip.Services in Golang Changelog + +## 1.0.2 (2020-07-12) + +### Features +* Moved some CRUD operations from IdentifiableMongoDbPersistence to MongoDbPersistence \ No newline at end of file diff --git a/component.json b/component.json index db9637d..020386d 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name": "pip-services3-mongodb-go", "registry": "pip-services", - "version": "3.0.0", + "version": "1.0.2", "build": null } diff --git a/go.mod b/go.mod index fd8d58f..e9c9ea6 100644 --- a/go.mod +++ b/go.mod @@ -3,20 +3,15 @@ module github.com/pip-services3-go/pip-services3-mongodb-go go 1.13 require ( - github.com/DataDog/zstd v1.4.4 // indirect - github.com/go-stack/stack v1.8.0 // indirect - github.com/golang/snappy v0.0.1 // indirect github.com/google/go-cmp v0.3.1 // indirect - github.com/pip-services3-go/pip-services3-commons-go v1.0.0 - github.com/pip-services3-go/pip-services3-components-go v1.0.0 - github.com/pip-services3-go/pip-services3-data-go v1.0.1 + github.com/klauspost/compress v1.10.10 // indirect + github.com/pip-services3-go/pip-services3-commons-go v1.0.1 + github.com/pip-services3-go/pip-services3-components-go v1.0.2 + github.com/pip-services3-go/pip-services3-data-go v1.0.4 github.com/pkg/errors v0.9.1 // indirect github.com/stretchr/testify v1.4.0 - github.com/tidwall/pretty v1.0.0 // indirect - github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect github.com/xdg/stringprep v1.0.0 // indirect - go.mongodb.org/mongo-driver v1.2.1 - golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d // indirect - golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect - golang.org/x/text v0.3.2 // indirect + go.mongodb.org/mongo-driver v1.3.5 + golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect + golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 // indirect ) diff --git a/go.sum b/go.sum index e2f14d9..b655779 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,4 @@ -github.com/DataDog/zstd v1.4.4 h1:+IawcoXhCBylN7ccwdwf8LOH2jKq7NavGpEPanrlTzE= -github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -7,12 +6,47 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o= github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/klauspost/compress v1.9.5 h1:U+CaK85mrNNb4k8BNOfgJtJ/gr6kswUCFj6miSzVC6M= +github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.10.10 h1:a/y8CglcM7gLGYmlbP/stPE5sR3hbhFRUjCBfd/0B3I= +github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= @@ -20,27 +54,40 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pip-services3-go/pip-services3-commons-go v0.0.0-20190804203000-6456cc90b324/go.mod h1:bcPnEp+IIvYa4zP4Qb6E6VYM9ByV7qcSSrq6yL2GQlo= -github.com/pip-services3-go/pip-services3-commons-go v0.0.0-20191120184752-e90ca65ad1c9 h1:cXsSF2JEivf5eyV2w3WSvRR9+yuOnQNOXjYnqV/C6ew= -github.com/pip-services3-go/pip-services3-commons-go v0.0.0-20191120184752-e90ca65ad1c9/go.mod h1:zuPMQBL05n7s1oEaEdMvJZy6bWnUhbV6LH9wq60+0VE= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= github.com/pip-services3-go/pip-services3-commons-go v1.0.0 h1:hAX42NwjY6k9KGDfsVyeL+8lfNZAzcpJ5+bgAP5PPsc= github.com/pip-services3-go/pip-services3-commons-go v1.0.0/go.mod h1:a2fIaCl4TUShJhgMMHmO+7773pf+Nkyrq1JDmJVYjd0= -github.com/pip-services3-go/pip-services3-components-go v0.0.0-20191121193353-fd649422216e h1:j/rWy+ZKGMi+kWKWv0uAgWMAPku7fw3Nu4LaElljvwA= -github.com/pip-services3-go/pip-services3-components-go v0.0.0-20191121193353-fd649422216e/go.mod h1:HXw/ZY1ptv0WEICtazRu6ZeWjtmn90maApMBGfzRj8I= +github.com/pip-services3-go/pip-services3-commons-go v1.0.1 h1:Dm2QMettphyXPVcwhVKBN78qwq3ZLlGJ5JPd81hO520= +github.com/pip-services3-go/pip-services3-commons-go v1.0.1/go.mod h1:a2fIaCl4TUShJhgMMHmO+7773pf+Nkyrq1JDmJVYjd0= github.com/pip-services3-go/pip-services3-components-go v1.0.0 h1:v2aJdHYohzNg50jcCrWDmprYRvXwhMaKnDXhNo3WkgM= github.com/pip-services3-go/pip-services3-components-go v1.0.0/go.mod h1:Me/KFWw/xeMML89twlGdFKqnvprgt2qyi8xAV1+XKGs= -github.com/pip-services3-go/pip-services3-data-go v1.0.0 h1:hyk/bMtzxVlZuhSUYMIj9kEW+CXJ28gYpsq9Q+rK6lk= -github.com/pip-services3-go/pip-services3-data-go v1.0.0/go.mod h1:DExl49aIGpYj7P78WAdfL6PuKZ3GbQ5OTeVwD19n2lY= -github.com/pip-services3-go/pip-services3-data-go v1.0.1 h1:p9egUgg6CJ/viDH+QQ+WrgHOY8ROPspt3pRkUd7mROU= -github.com/pip-services3-go/pip-services3-data-go v1.0.1/go.mod h1:GlF516tSRHiEpQP5370Ttzl7eUEvH5B53xRS6/3r0cQ= +github.com/pip-services3-go/pip-services3-components-go v1.0.2 h1:46jDnLU9f4H+vIUKyTGY5MqZiTK7gKYjF6xU3iXZcWI= +github.com/pip-services3-go/pip-services3-components-go v1.0.2/go.mod h1:Me/KFWw/xeMML89twlGdFKqnvprgt2qyi8xAV1+XKGs= +github.com/pip-services3-go/pip-services3-data-go v1.0.4 h1:7WNt9uRTxDw+Z5ne9L0IKqBxAMqsMLbgRDYayOJsDAs= +github.com/pip-services3-go/pip-services3-data-go v1.0.4/go.mod h1:GlF516tSRHiEpQP5370Ttzl7eUEvH5B53xRS6/3r0cQ= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -48,27 +95,45 @@ github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk= github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= +github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0= github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= -go.mongodb.org/mongo-driver v1.2.1 h1:ANAlYXXM5XmOdW/Nc38jOr+wS5nlk7YihT24U1imiWM= -go.mongodb.org/mongo-driver v1.2.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= +go.mongodb.org/mongo-driver v1.3.5 h1:S0ZOruh4YGHjD7JoN7mIsTrNjnQbOjrmgrx6l6pZN7I= +go.mongodb.org/mongo-driver v1.3.5/go.mod h1:Ual6Gkco7ZGQw8wE1t4tLnvBsf6yVSM60qW6TgOeJ5c= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d h1:9FCpayM9Egr1baVnV1SX0H87m+XB0B8S0hAMi99X/3U= -golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg= +golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= diff --git a/persistence/IdentifiableMongoDbPersistence.go b/persistence/IdentifiableMongoDbPersistence.go index c69bf31..c214b53 100644 --- a/persistence/IdentifiableMongoDbPersistence.go +++ b/persistence/IdentifiableMongoDbPersistence.go @@ -1,9 +1,7 @@ package persistence import ( - "math/rand" "reflect" - "time" cconf "github.com/pip-services3-go/pip-services3-commons-go/config" cdata "github.com/pip-services3-go/pip-services3-commons-go/data" @@ -121,11 +119,11 @@ Example: persistence.deleteById("123", "1") ... - */ + type IdentifiableMongoDbPersistence struct { MongoDbPersistence - maxPageSize int32 + } // NewIdentifiableMongoDbPersistence is creates a new instance of the persistence component. @@ -156,124 +154,6 @@ func (c *IdentifiableMongoDbPersistence) Configure(config *cconf.ConfigParams) { c.maxPageSize = (int32)(config.GetAsIntegerWithDefault("options.max_page_size", (int)(c.maxPageSize))) } -// GetPageByFilter is gets a page of data items retrieved by a given filter and sorted according to sort parameters. -// This method shall be called by a func (c *IdentifiableMongoDbPersistence) GetPageByFilter method from child type that -// receives FilterParams and converts them into a filter function. -// Parameters: -// - correlationId string -// (optional) transaction id to Trace execution through call chain. -// - filter interface{} -// (optional) a filter JSON object -// - paging *cdata.PagingParams -// (optional) paging parameters -// - sort interface{} -// (optional) sorting BSON object -// - select interface{} -// (optional) projection BSON object -// Returns page cdata.DataPage, err error -// a data page or error, if they are occured -func (c *IdentifiableMongoDbPersistence) GetPageByFilter(correlationId string, filter interface{}, paging *cdata.PagingParams, - sort interface{}, sel interface{}) (page cdata.DataPage, err error) { - // Adjust max item count based on configuration - if paging == nil { - paging = cdata.NewEmptyPagingParams() - } - skip := paging.GetSkip(-1) - take := paging.GetTake((int64)(c.maxPageSize)) - pagingEnabled := paging.Total - // Configure options - var options mngoptions.FindOptions - if skip >= 0 { - options.Skip = &skip - } - options.Limit = &take - if sort != nil { - options.Sort = sort - } - if sel != nil { - options.Projection = sel - } - cursor, ferr := c.Collection.Find(c.Connection.Ctx, filter, &options) - items := make([]interface{}, 0, 1) - if ferr != nil { - var total int64 = 0 - page = *cdata.NewDataPage(&total, items) - return page, ferr - } - for cursor.Next(c.Connection.Ctx) { - docPointer := c.GetProtoPtr() - curErr := cursor.Decode(docPointer.Interface()) - if curErr != nil { - continue - } - // item := docPointer.Elem().Interface() - // c.ConvertToPublic(&item) - item := c.GetConvResult(docPointer, c.Prototype) - items = append(items, item) - } - if items != nil { - c.Logger.Trace(correlationId, "Retrieved %d from %s", len(items), c.CollectionName) - } - if pagingEnabled { - docCount, _ := c.Collection.CountDocuments(c.Connection.Ctx, filter) - page = *cdata.NewDataPage(&docCount, items) - } else { - var total int64 = 0 - page = *cdata.NewDataPage(&total, items) - } - return page, nil -} - -// GetListByFilter is gets a list of data items retrieved by a given filter and sorted according to sort parameters. -// This method shall be called by a func (c *IdentifiableMongoDbPersistence) GetListByFilter method from child type that -// receives FilterParams and converts them into a filter function. -// Parameters: -// - correlationId string -// (optional) transaction id to Trace execution through call chain. -// - filter interface{} -// (optional) a filter BSON object -// - sort interface{} -// (optional) sorting BSON object -// - select interface{} -// (optional) projection BSON object -// Returns items []interface{}, err error -// data list and error, if they are ocurred -func (c *IdentifiableMongoDbPersistence) GetListByFilter(correlationId string, filter interface{}, sort interface{}, sel interface{}) (items []interface{}, err error) { - - // Configure options - var options mngoptions.FindOptions - - if sort != nil { - options.Sort = sort - } - if sel != nil { - options.Projection = sel - } - - cursor, ferr := c.Collection.Find(c.Connection.Ctx, filter, &options) - if ferr != nil { - return nil, ferr - } - - for cursor.Next(c.Connection.Ctx) { - docPointer := c.GetProtoPtr() - curErr := cursor.Decode(docPointer.Interface()) - if curErr != nil { - continue - } - - // item := docPointer.Elem().Interface() - // c.ConvertToPublic(&item) - item := c.GetConvResult(docPointer, c.Prototype) - - items = append(items, item) - } - - if items != nil { - c.Logger.Trace(correlationId, "Retrieved %d from %s", len(items), c.CollectionName) - } - return items, nil -} // GetListByIds is gets a list of data items retrieved by given unique ids. // Parameters: @@ -314,47 +194,6 @@ func (c *IdentifiableMongoDbPersistence) GetOneById(correlationId string, id int return item, nil } -// GetOneRandom is gets a random item from items that match to a given filter. -// This method shall be called by a func (c *IdentifiableMongoDbPersistence) getOneRandom method from child class that -// receives FilterParams and converts them into a filter function. -// Parameters: -// - correlationId string -// (optional) transaction id to Trace execution through call chain. -// - filter interface{} -// (optional) a filter BSON object -// Returns: item interface{}, err error -// random item and error, if theq are occured -func (c *IdentifiableMongoDbPersistence) GetOneRandom(correlationId string, filter interface{}) (item interface{}, err error) { - - docCount, cntErr := c.Collection.CountDocuments(c.Connection.Ctx, filter) - if cntErr != nil { - return nil, cntErr - } - var options mngoptions.FindOptions - rand.Seed(time.Now().UnixNano()) - var itemNum int64 = rand.Int63n(docCount) - var itemLim int64 = 1 - - if itemNum < 0 { - itemNum = 0 - } - options.Skip = &itemNum - options.Limit = &itemLim - cursor, fndErr := c.Collection.Find(c.Connection.Ctx, filter, &options) - if fndErr != nil { - return nil, fndErr - } - docPointer := c.GetProtoPtr() - err = cursor.Decode(docPointer.Interface()) - if err != nil { - return nil, err - } - // item = docPointer.Elem().Interface() - // c.ConvertToPublic(&item) - item = c.GetConvResult(docPointer, c.Prototype) - return item, nil -} - // Create was creates a data item. // Parameters: // - correlation_id string @@ -541,25 +380,6 @@ func (c *IdentifiableMongoDbPersistence) DeleteById(correlationId string, id int return item, nil } -// DeleteByFilter is deletes data items that match to a given filter. -// This method shall be called by a func (c *IdentifiableMongoDbPersistence) deleteByFilter method from child class that -// receives FilterParams and converts them into a filter function. -// Parameters: -// - correlationId string -// (optional) transaction id to Trace execution through call chain. -// - filter interface{} -// (optional) a filter BSON object. -// Return error -// error or nil for success. -func (c *IdentifiableMongoDbPersistence) DeleteByFilter(correlationId string, filter interface{}) error { - delRes, delErr := c.Collection.DeleteMany(c.Connection.Ctx, filter) - var count = delRes.DeletedCount - if delErr != nil { - return delErr - } - c.Logger.Trace(correlationId, "Deleted %d items from %s", count, c.Collection) - return nil -} // DeleteByIds is deletes multiple data items by their unique ids. // - correlationId string @@ -575,24 +395,6 @@ func (c *IdentifiableMongoDbPersistence) DeleteByIds(correlationId string, ids [ return c.DeleteByFilter(correlationId, filter) } -// service function for return pointer on new prototype object for unmarshaling -func (c *IdentifiableMongoDbPersistence) GetProtoPtr() reflect.Value { - proto := c.Prototype - if proto.Kind() == reflect.Ptr { - proto = proto.Elem() - } - return reflect.New(proto) -} - -func (c *IdentifiableMongoDbPersistence) GetConvResult(docPointer reflect.Value, proto reflect.Type) interface{} { - item := docPointer.Elem().Interface() - c.ConvertToPublic(&item) - if proto.Kind() == reflect.Ptr { - return docPointer.Interface() - } - return item -} - // GetCountByFilter is gets a count of data items retrieved by a given filter. // This method shall be called by a func (c *IdentifiableMongoDbPersistence) GetCountByFilter method from child type that // receives FilterParams and converts them into a filter function. diff --git a/persistence/MongoDbPersistence.go b/persistence/MongoDbPersistence.go index 20266eb..8c56aa7 100644 --- a/persistence/MongoDbPersistence.go +++ b/persistence/MongoDbPersistence.go @@ -1,13 +1,18 @@ package persistence import ( + "math/rand" "reflect" + "time" cconf "github.com/pip-services3-go/pip-services3-commons-go/config" + cdata "github.com/pip-services3-go/pip-services3-commons-go/data" cerror "github.com/pip-services3-go/pip-services3-commons-go/errors" crefer "github.com/pip-services3-go/pip-services3-commons-go/refer" clog "github.com/pip-services3-go/pip-services3-components-go/log" + cmpersist "github.com/pip-services3-go/pip-services3-data-go/persistence" mongodrv "go.mongodb.org/mongo-driver/mongo" + mngoptions "go.mongodb.org/mongo-driver/mongo/options" mongoopt "go.mongodb.org/mongo-driver/mongo/options" ) @@ -130,7 +135,19 @@ Configuration parameters: ... } fmt.Println(item) // Result: { name: "ABC" } + ("123", "ABC") + if getErr != nil { + ... + } + fmt.Println(item) // Result: { name: "ABC" } + + ("123", "ABC") + if getErr != nil { + ... + } + fmt.Println(item) // Result: { name: "ABC" } */ + type MongoDbPersistence struct { defaultConfig cconf.ConfigParams @@ -140,6 +157,7 @@ type MongoDbPersistence struct { localConnection bool indexes []mongodrv.IndexModel Prototype reflect.Type + maxPageSize int32 // The dependency resolver. DependencyResolver crefer.DependencyResolver @@ -415,3 +433,238 @@ func (c *MongoDbPersistence) Clear(correlationId string) error { } return nil } + +// GetPageByFilter is gets a page of data items retrieved by a given filter and sorted according to sort parameters. +// This method shall be called by a func (c *IdentifiableMongoDbPersistence) GetPageByFilter method from child type that +// receives FilterParams and converts them into a filter function. +// Parameters: +// - correlationId string +// (optional) transaction id to Trace execution through call chain. +// - filter interface{} +// (optional) a filter JSON object +// - paging *cdata.PagingParams +// (optional) paging parameters +// - sort interface{} +// (optional) sorting BSON object +// - select interface{} +// (optional) projection BSON object +// Returns page cdata.DataPage, err error +// a data page or error, if they are occured +func (c *MongoDbPersistence) GetPageByFilter(correlationId string, filter interface{}, paging *cdata.PagingParams, + sort interface{}, sel interface{}) (page cdata.DataPage, err error) { + // Adjust max item count based on configuration + if paging == nil { + paging = cdata.NewEmptyPagingParams() + } + skip := paging.GetSkip(-1) + take := paging.GetTake((int64)(c.maxPageSize)) + pagingEnabled := paging.Total + // Configure options + var options mngoptions.FindOptions + if skip >= 0 { + options.Skip = &skip + } + options.Limit = &take + if sort != nil { + options.Sort = sort + } + if sel != nil { + options.Projection = sel + } + cursor, ferr := c.Collection.Find(c.Connection.Ctx, filter, &options) + items := make([]interface{}, 0, 1) + if ferr != nil { + var total int64 = 0 + page = *cdata.NewDataPage(&total, items) + return page, ferr + } + for cursor.Next(c.Connection.Ctx) { + docPointer := c.GetProtoPtr() + curErr := cursor.Decode(docPointer.Interface()) + if curErr != nil { + continue + } + // item := docPointer.Elem().Interface() + // c.ConvertToPublic(&item) + item := c.GetConvResult(docPointer, c.Prototype) + items = append(items, item) + } + if items != nil { + c.Logger.Trace(correlationId, "Retrieved %d from %s", len(items), c.CollectionName) + } + if pagingEnabled { + docCount, _ := c.Collection.CountDocuments(c.Connection.Ctx, filter) + page = *cdata.NewDataPage(&docCount, items) + } else { + var total int64 = 0 + page = *cdata.NewDataPage(&total, items) + } + return page, nil +} + +// GetListByFilter is gets a list of data items retrieved by a given filter and sorted according to sort parameters. +// This method shall be called by a func (c *IdentifiableMongoDbPersistence) GetListByFilter method from child type that +// receives FilterParams and converts them into a filter function. +// Parameters: +// - correlationId string +// (optional) transaction id to Trace execution through call chain. +// - filter interface{} +// (optional) a filter BSON object +// - sort interface{} +// (optional) sorting BSON object +// - select interface{} +// (optional) projection BSON object +// Returns items []interface{}, err error +// data list and error, if they are ocurred +func (c *MongoDbPersistence) GetListByFilter(correlationId string, filter interface{}, sort interface{}, sel interface{}) (items []interface{}, err error) { + + // Configure options + var options mngoptions.FindOptions + + if sort != nil { + options.Sort = sort + } + if sel != nil { + options.Projection = sel + } + + cursor, ferr := c.Collection.Find(c.Connection.Ctx, filter, &options) + if ferr != nil { + return nil, ferr + } + + for cursor.Next(c.Connection.Ctx) { + docPointer := c.GetProtoPtr() + curErr := cursor.Decode(docPointer.Interface()) + if curErr != nil { + continue + } + + // item := docPointer.Elem().Interface() + // c.ConvertToPublic(&item) + item := c.GetConvResult(docPointer, c.Prototype) + + items = append(items, item) + } + + if items != nil { + c.Logger.Trace(correlationId, "Retrieved %d from %s", len(items), c.CollectionName) + } + return items, nil +} + +// GetOneRandom is gets a random item from items that match to a given filter. +// This method shall be called by a func (c *IdentifiableMongoDbPersistence) getOneRandom method from child class that +// receives FilterParams and converts them into a filter function. +// Parameters: +// - correlationId string +// (optional) transaction id to Trace execution through call chain. +// - filter interface{} +// (optional) a filter BSON object +// Returns: item interface{}, err error +// random item and error, if theq are occured +func (c *MongoDbPersistence) GetOneRandom(correlationId string, filter interface{}) (item interface{}, err error) { + + docCount, cntErr := c.Collection.CountDocuments(c.Connection.Ctx, filter) + if cntErr != nil { + return nil, cntErr + } + var options mngoptions.FindOptions + rand.Seed(time.Now().UnixNano()) + var itemNum int64 = rand.Int63n(docCount) + var itemLim int64 = 1 + + if itemNum < 0 { + itemNum = 0 + } + options.Skip = &itemNum + options.Limit = &itemLim + cursor, fndErr := c.Collection.Find(c.Connection.Ctx, filter, &options) + if fndErr != nil { + return nil, fndErr + } + docPointer := c.GetProtoPtr() + err = cursor.Decode(docPointer.Interface()) + if err != nil { + return nil, err + } + // item = docPointer.Elem().Interface() + // c.ConvertToPublic(&item) + item = c.GetConvResult(docPointer, c.Prototype) + return item, nil +} + + +// Create was creates a data item. +// Parameters: +// - correlation_id string +// (optional) transaction id to Trace execution through call chain. +// - item interface{} +// an item to be created. +// Returns result interface{}, err error +// created item and error, if they are occured +func (c *MongoDbPersistence) Create(correlationId string, item interface{}) (result interface{}, err error) { + if item == nil { + return nil, nil + } + var newItem interface{} + newItem = cmpersist.CloneObject(item) + // Assign unique id if not exist + c.ConvertFromPublic(&newItem) + insRes, insErr := c.Collection.InsertOne(c.Connection.Ctx, newItem) + c.ConvertToPublic(&newItem) + if insErr != nil { + return nil, insErr + } + c.Logger.Trace(correlationId, "Created in %s with id = %s", c.Collection, insRes.InsertedID) + + if c.Prototype.Kind() == reflect.Ptr { + newPtr := reflect.New(c.Prototype.Elem()) + newPtr.Elem().Set(reflect.ValueOf(newItem)) + return newPtr.Interface(), nil + } + return newItem, nil +} + +// DeleteByFilter is deletes data items that match to a given filter. +// This method shall be called by a func (c *IdentifiableMongoDbPersistence) deleteByFilter method from child class that +// receives FilterParams and converts them into a filter function. +// Parameters: +// - correlationId string +// (optional) transaction id to Trace execution through call chain. +// - filter interface{} +// (optional) a filter BSON object. +// Return error +// error or nil for success. +func (c *MongoDbPersistence) DeleteByFilter(correlationId string, filter interface{}) error { + delRes, delErr := c.Collection.DeleteMany(c.Connection.Ctx, filter) + var count = delRes.DeletedCount + if delErr != nil { + return delErr + } + c.Logger.Trace(correlationId, "Deleted %d items from %s", count, c.Collection) + return nil +} + + + + + + +// service function for return pointer on new prototype object for unmarshaling +func (c *MongoDbPersistence) GetProtoPtr() reflect.Value { + proto := c.Prototype + if proto.Kind() == reflect.Ptr { + proto = proto.Elem() + } + return reflect.New(proto) +} + +func (c *MongoDbPersistence) GetConvResult(docPointer reflect.Value, proto reflect.Type) interface{} { + item := docPointer.Elem().Interface() + c.ConvertToPublic(&item) + if proto.Kind() == reflect.Ptr { + return docPointer.Interface() + } + return item +} \ No newline at end of file