-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mongodb): add findRaw, aggregateRaw and runCommandRaw (#1410)
Co-authored-by: Luca Steeb <[email protected]>
- Loading branch information
1 parent
bbe8959
commit 6b25039
Showing
11 changed files
with
246 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"os" | ||
"slices" | ||
"testing" | ||
"fmt" | ||
|
||
// no-op import for go modules | ||
_ "github.com/joho/godotenv" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{{- /*gotype:github.com/steebchen/prisma-client-go/generator.Root*/ -}} | ||
|
||
{{ range $model := $.DMMF.Datamodel.Models }} | ||
{{ $name := $model.Name.GoLowerCase }} | ||
{{ $ns := (print $name "Actions") }} | ||
{{ $result := (print $name "AggregateRaw") }} | ||
|
||
type {{ $result }} struct { | ||
query builder.Query | ||
} | ||
|
||
func (r {{ $result }}) getQuery() builder.Query { | ||
return r.query | ||
} | ||
|
||
func (r {{ $result }}) ExtractQuery() builder.Query { | ||
return r.query | ||
} | ||
|
||
func (r {{ $result }}) with() {} | ||
func (r {{ $result }}) {{ $model.Name.GoLowerCase }}Model() {} | ||
func (r {{ $result }}) {{ $model.Name.GoLowerCase }}Relation() {} | ||
|
||
func (r {{ $ns }}) FindRaw(filter interface{}, options ...interface{}) {{ $result }} { | ||
var v {{ $result }} | ||
v.query = builder.NewQuery() | ||
v.query.Engine = r.client | ||
v.query.Method = "findRaw" | ||
v.query.Operation = "query" | ||
v.query.Model = "{{ $model.Name.String }}" | ||
|
||
v.query.Inputs = append(v.query.Inputs, builder.Input{ | ||
Name: "filter", | ||
Value: fmt.Sprintf("%v", filter), | ||
}) | ||
|
||
if len(options) > 0 { | ||
v.query.Inputs = append(v.query.Inputs, builder.Input{ | ||
Name: "options", | ||
Value: fmt.Sprintf("%v", options[0]), | ||
}) | ||
} | ||
return v | ||
} | ||
|
||
func (r {{ $ns }}) AggregateRaw(pipeline []interface{}, options ...interface{}) {{ $result }} { | ||
var v {{ $result }} | ||
v.query = builder.NewQuery() | ||
v.query.Engine = r.client | ||
v.query.Method = "aggregateRaw" | ||
v.query.Operation = "query" | ||
v.query.Model = "{{ $model.Name.String }}" | ||
|
||
parsedPip := []interface{}{} | ||
for _, p := range pipeline { | ||
parsedPip = append(parsedPip, fmt.Sprintf("%v", p)) | ||
} | ||
|
||
v.query.Inputs = append(v.query.Inputs, builder.Input{ | ||
Name: "pipeline", | ||
Value: parsedPip, | ||
}) | ||
|
||
if len(options) > 0 { | ||
v.query.Inputs = append(v.query.Inputs, builder.Input{ | ||
Name: "options", | ||
Value: fmt.Sprintf("%v", options[0]), | ||
}) | ||
} | ||
return v | ||
} | ||
|
||
func (r {{ $result }}) Exec(ctx context.Context) ([]{{ $model.Name.GoCase }}Model, error) { | ||
var v []{{ $model.Name.GoCase }}Model | ||
if err := r.query.Exec(ctx, &v); err != nil { | ||
return nil, err | ||
} | ||
return v, nil | ||
} | ||
|
||
func (r {{ $result }}) ExecInner(ctx context.Context) ([]Inner{{ $model.Name.GoCase }}, error) { | ||
var v []Inner{{ $model.Name.GoCase }} | ||
if err := r.query.Exec(ctx, &v); err != nil { | ||
return nil, err | ||
} | ||
return v, nil | ||
} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package raw | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/steebchen/prisma-client-go/runtime/builder" | ||
) | ||
|
||
func (r Raw) RunCommandRaw(cmd interface{}) RunCommandExec { | ||
return RunCommandExec{ | ||
query: doCommandRaw(r.Engine, "runCommandRaw", fmt.Sprintf("%v", cmd)), | ||
} | ||
} | ||
|
||
type RunCommandExec struct { | ||
query builder.Query | ||
} | ||
|
||
func (r RunCommandExec) ExtractQuery() builder.Query { | ||
return r.query | ||
} | ||
|
||
func (r RunCommandExec) Tx() TxQueryResult { | ||
v := NewTxQueryResult() | ||
v.query = r.query | ||
v.query.TxResult = make(chan []byte, 1) | ||
return v | ||
} | ||
|
||
func (r RunCommandExec) Exec(ctx context.Context, into interface{}) error { | ||
if err := r.query.Exec(ctx, &into); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |