Remove ignoring One from query (#34)
This commit is contained in:
parent
1e0ab5d701
commit
b00c2ac77a
7 changed files with 85 additions and 86 deletions
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
|
@ -10,12 +10,12 @@ jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: 1.18
|
|
||||||
|
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: 1.19
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v ./...
|
run: go build -v ./...
|
||||||
|
|
||||||
|
|
10
.github/workflows/lint.yml
vendored
10
.github/workflows/lint.yml
vendored
|
@ -10,13 +10,13 @@ jobs:
|
||||||
golangci-lint:
|
golangci-lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: 1.18
|
|
||||||
|
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: 1.19
|
||||||
|
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.50.0
|
version: v1.52.2
|
||||||
|
|
12
go.mod
12
go.mod
|
@ -1,11 +1,11 @@
|
||||||
module github.com/sunboyy/repogen
|
module github.com/sunboyy/repogen
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fatih/camelcase v1.0.0
|
github.com/fatih/camelcase v1.0.0
|
||||||
go.mongodb.org/mongo-driver v1.10.3
|
go.mongodb.org/mongo-driver v1.11.4
|
||||||
golang.org/x/tools v0.1.12
|
golang.org/x/tools v0.8.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -18,8 +18,8 @@ require (
|
||||||
github.com/xdg-go/stringprep v1.0.3 // indirect
|
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
golang.org/x/mod v0.10.0 // indirect
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
golang.org/x/sys v0.7.0 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
)
|
)
|
||||||
|
|
22
go.sum
22
go.sum
|
@ -9,8 +9,10 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||||
|
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.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
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/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||||
|
@ -31,28 +33,28 @@ github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCO
|
||||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||||
go.mongodb.org/mongo-driver v1.10.3 h1:XDQEvmh6z1EUsXuIkXE9TaVeqHw6SwS1uf93jFs0HBA=
|
go.mongodb.org/mongo-driver v1.11.4 h1:4ayjakA013OdpGyL2K3ZqylTac/rMjrJOMZ1EHizXas=
|
||||||
go.mongodb.org/mongo-driver v1.10.3/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8=
|
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
|
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|
|
@ -94,7 +94,7 @@ type UserModel struct {
|
||||||
Source: `package user
|
Source: `package user
|
||||||
|
|
||||||
type UserRepository interface {
|
type UserRepository interface {
|
||||||
FindOneByID(ctx context.Context, id primitive.ObjectID) (*UserModel, error)
|
FindByID(ctx context.Context, id primitive.ObjectID) (*UserModel, error)
|
||||||
FindAll(context.Context) ([]*UserModel, error)
|
FindAll(context.Context) ([]*UserModel, error)
|
||||||
FindByAgeBetween(ctx context.Context, fromAge, toAge int) ([]*UserModel, error)
|
FindByAgeBetween(ctx context.Context, fromAge, toAge int) ([]*UserModel, error)
|
||||||
InsertOne(ctx context.Context, user *UserModel) (interface{}, error)
|
InsertOne(ctx context.Context, user *UserModel) (interface{}, error)
|
||||||
|
@ -113,7 +113,7 @@ type UserRepository interface {
|
||||||
Name: "UserRepository",
|
Name: "UserRepository",
|
||||||
Methods: []code.Method{
|
Methods: []code.Method{
|
||||||
{
|
{
|
||||||
Name: "FindOneByID",
|
Name: "FindByID",
|
||||||
Params: []code.Param{
|
Params: []code.Param{
|
||||||
{Name: "ctx", Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
{Name: "ctx", Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
{Name: "id", Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
{Name: "id", Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
||||||
|
@ -251,7 +251,7 @@ type UserModel struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserRepository interface {
|
type UserRepository interface {
|
||||||
FindOneByID(ctx context.Context, id primitive.ObjectID) (*UserModel, error)
|
FindByID(ctx context.Context, id primitive.ObjectID) (*UserModel, error)
|
||||||
FindAll(ctx context.Context) ([]*UserModel, error)
|
FindAll(ctx context.Context) ([]*UserModel, error)
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
@ -289,7 +289,7 @@ type UserRepository interface {
|
||||||
Name: "UserRepository",
|
Name: "UserRepository",
|
||||||
Methods: []code.Method{
|
Methods: []code.Method{
|
||||||
{
|
{
|
||||||
Name: "FindOneByID",
|
Name: "FindByID",
|
||||||
Params: []code.Param{
|
Params: []code.Param{
|
||||||
{Name: "ctx", Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
{Name: "ctx", Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
{Name: "id", Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
{Name: "id", Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
||||||
|
|
|
@ -175,9 +175,9 @@ func TestParseInterfaceMethod_Insert(t *testing.T) {
|
||||||
func TestParseInterfaceMethod_Find(t *testing.T) {
|
func TestParseInterfaceMethod_Find(t *testing.T) {
|
||||||
testTable := []ParseInterfaceMethodTestCase{
|
testTable := []ParseInterfaceMethodTestCase{
|
||||||
{
|
{
|
||||||
Name: "FindOneByArg method",
|
Name: "FindByArg one-mode method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "FindOneByID",
|
Name: "FindByID",
|
||||||
Params: []code.Param{
|
Params: []code.Param{
|
||||||
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
{Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
{Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
||||||
|
@ -195,9 +195,29 @@ func TestParseInterfaceMethod_Find(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "FindOneByMultiWordArg method",
|
Name: "FindByArg many-mode method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "FindOneByPhoneNumber",
|
Name: "FindByCity",
|
||||||
|
Params: []code.Param{
|
||||||
|
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
|
{Type: code.TypeString},
|
||||||
|
},
|
||||||
|
Returns: []code.Type{
|
||||||
|
code.ArrayType{ContainedType: code.PointerType{ContainedType: code.SimpleType("UserModel")}},
|
||||||
|
code.TypeError,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ExpectedOperation: spec.FindOperation{
|
||||||
|
Mode: spec.QueryModeMany,
|
||||||
|
Query: spec.QuerySpec{Predicates: []spec.Predicate{
|
||||||
|
{FieldReference: spec.FieldReference{cityField}, Comparator: spec.ComparatorEqual, ParamIndex: 1},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "FindByMultiWordArg method",
|
||||||
|
Method: code.Method{
|
||||||
|
Name: "FindByPhoneNumber",
|
||||||
Params: []code.Param{
|
Params: []code.Param{
|
||||||
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
{Type: code.TypeString},
|
{Type: code.TypeString},
|
||||||
|
@ -218,26 +238,6 @@ func TestParseInterfaceMethod_Find(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "FindByArg method",
|
|
||||||
Method: code.Method{
|
|
||||||
Name: "FindByCity",
|
|
||||||
Params: []code.Param{
|
|
||||||
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
|
||||||
{Type: code.TypeString},
|
|
||||||
},
|
|
||||||
Returns: []code.Type{
|
|
||||||
code.ArrayType{ContainedType: code.PointerType{ContainedType: code.SimpleType("UserModel")}},
|
|
||||||
code.TypeError,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ExpectedOperation: spec.FindOperation{
|
|
||||||
Mode: spec.QueryModeMany,
|
|
||||||
Query: spec.QuerySpec{Predicates: []spec.Predicate{
|
|
||||||
{FieldReference: spec.FieldReference{cityField}, Comparator: spec.ComparatorEqual, ParamIndex: 1},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "FindByDeepArg method",
|
Name: "FindByDeepArg method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
|
@ -1044,9 +1044,9 @@ func TestParseInterfaceMethod_Update(t *testing.T) {
|
||||||
func TestParseInterfaceMethod_Delete(t *testing.T) {
|
func TestParseInterfaceMethod_Delete(t *testing.T) {
|
||||||
testTable := []ParseInterfaceMethodTestCase{
|
testTable := []ParseInterfaceMethodTestCase{
|
||||||
{
|
{
|
||||||
Name: "DeleteOneByArg method",
|
Name: "DeleteByArg one-mode method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "DeleteOneByID",
|
Name: "DeleteByID",
|
||||||
Params: []code.Param{
|
Params: []code.Param{
|
||||||
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
{Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
{Type: code.ExternalType{PackageAlias: "primitive", Name: "ObjectID"}},
|
||||||
|
@ -1064,9 +1064,29 @@ func TestParseInterfaceMethod_Delete(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "DeleteOneByMultiWordArg method",
|
Name: "DeleteByArg many-mode method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "DeleteOneByPhoneNumber",
|
Name: "DeleteByCity",
|
||||||
|
Params: []code.Param{
|
||||||
|
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
|
{Type: code.TypeString},
|
||||||
|
},
|
||||||
|
Returns: []code.Type{
|
||||||
|
code.TypeInt,
|
||||||
|
code.TypeError,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ExpectedOperation: spec.DeleteOperation{
|
||||||
|
Mode: spec.QueryModeMany,
|
||||||
|
Query: spec.QuerySpec{Predicates: []spec.Predicate{
|
||||||
|
{FieldReference: spec.FieldReference{cityField}, Comparator: spec.ComparatorEqual, ParamIndex: 1},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "DeleteByMultiWordArg method",
|
||||||
|
Method: code.Method{
|
||||||
|
Name: "DeleteByPhoneNumber",
|
||||||
Params: []code.Param{
|
Params: []code.Param{
|
||||||
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
||||||
{Type: code.TypeString},
|
{Type: code.TypeString},
|
||||||
|
@ -1087,26 +1107,6 @@ func TestParseInterfaceMethod_Delete(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "DeleteByArg method",
|
|
||||||
Method: code.Method{
|
|
||||||
Name: "DeleteByCity",
|
|
||||||
Params: []code.Param{
|
|
||||||
{Type: code.ExternalType{PackageAlias: "context", Name: "Context"}},
|
|
||||||
{Type: code.TypeString},
|
|
||||||
},
|
|
||||||
Returns: []code.Type{
|
|
||||||
code.TypeInt,
|
|
||||||
code.TypeError,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ExpectedOperation: spec.DeleteOperation{
|
|
||||||
Mode: spec.QueryModeMany,
|
|
||||||
Query: spec.QuerySpec{Predicates: []spec.Predicate{
|
|
||||||
{FieldReference: spec.FieldReference{cityField}, Comparator: spec.ComparatorEqual, ParamIndex: 1},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "DeleteAll method",
|
Name: "DeleteAll method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
|
@ -1572,7 +1572,7 @@ func TestParseInterfaceMethod_Find_Invalid(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "invalid number of returns",
|
Name: "invalid number of returns",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "FindOneByID",
|
Name: "FindByID",
|
||||||
Returns: []code.Type{
|
Returns: []code.Type{
|
||||||
code.SimpleType("UserModel"),
|
code.SimpleType("UserModel"),
|
||||||
code.TypeInt,
|
code.TypeInt,
|
||||||
|
@ -1584,7 +1584,7 @@ func TestParseInterfaceMethod_Find_Invalid(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "unsupported return types from find method",
|
Name: "unsupported return types from find method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "FindOneByID",
|
Name: "FindByID",
|
||||||
Returns: []code.Type{
|
Returns: []code.Type{
|
||||||
code.SimpleType("UserModel"),
|
code.SimpleType("UserModel"),
|
||||||
code.TypeError,
|
code.TypeError,
|
||||||
|
@ -1595,7 +1595,7 @@ func TestParseInterfaceMethod_Find_Invalid(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "error return not provided",
|
Name: "error return not provided",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "FindOneByID",
|
Name: "FindByID",
|
||||||
Returns: []code.Type{
|
Returns: []code.Type{
|
||||||
code.SimpleType("UserModel"),
|
code.SimpleType("UserModel"),
|
||||||
code.TypeInt,
|
code.TypeInt,
|
||||||
|
@ -2139,7 +2139,7 @@ func TestParseInterfaceMethod_Delete_Invalid(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "invalid number of returns",
|
Name: "invalid number of returns",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "DeleteOneByID",
|
Name: "DeleteByID",
|
||||||
Returns: []code.Type{
|
Returns: []code.Type{
|
||||||
code.SimpleType("UserModel"),
|
code.SimpleType("UserModel"),
|
||||||
code.TypeInt,
|
code.TypeInt,
|
||||||
|
@ -2151,7 +2151,7 @@ func TestParseInterfaceMethod_Delete_Invalid(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "unsupported return types from delete method",
|
Name: "unsupported return types from delete method",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "DeleteOneByID",
|
Name: "DeleteByID",
|
||||||
Returns: []code.Type{
|
Returns: []code.Type{
|
||||||
code.TypeFloat64,
|
code.TypeFloat64,
|
||||||
code.TypeError,
|
code.TypeError,
|
||||||
|
@ -2162,7 +2162,7 @@ func TestParseInterfaceMethod_Delete_Invalid(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "error return not provided",
|
Name: "error return not provided",
|
||||||
Method: code.Method{
|
Method: code.Method{
|
||||||
Name: "DeleteOneByID",
|
Name: "DeleteByID",
|
||||||
Returns: []code.Type{
|
Returns: []code.Type{
|
||||||
code.TypeInt,
|
code.TypeInt,
|
||||||
code.TypeBool,
|
code.TypeBool,
|
||||||
|
|
|
@ -96,9 +96,6 @@ func (p queryParser) parseQuery(rawTokens []string, paramIndex int) (QuerySpec,
|
||||||
return QuerySpec{}, nil
|
return QuerySpec{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if tokens[0] == "One" {
|
|
||||||
tokens = tokens[1:]
|
|
||||||
}
|
|
||||||
if tokens[0] == "By" {
|
if tokens[0] == "By" {
|
||||||
tokens = tokens[1:]
|
tokens = tokens[1:]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue