-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexecutor.go
More file actions
46 lines (42 loc) · 1.52 KB
/
executor.go
File metadata and controls
46 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package executor
import (
"context"
"fmt"
"github.com/bytebase/gomongo/internal/translator"
"go.mongodb.org/mongo-driver/v2/mongo"
)
// Result represents query execution results.
type Result struct {
Rows []string
RowCount int
Statement string
}
// Execute executes a parsed operation against MongoDB.
func Execute(ctx context.Context, client *mongo.Client, database string, op *translator.Operation, statement string, maxRows *int64) (*Result, error) {
switch op.OpType {
case translator.OpFind:
return executeFind(ctx, client, database, op, maxRows)
case translator.OpFindOne:
return executeFindOne(ctx, client, database, op)
case translator.OpAggregate:
return executeAggregate(ctx, client, database, op)
case translator.OpShowDatabases:
return executeShowDatabases(ctx, client)
case translator.OpShowCollections:
return executeShowCollections(ctx, client, database)
case translator.OpGetCollectionNames:
return executeGetCollectionNames(ctx, client, database)
case translator.OpGetCollectionInfos:
return executeGetCollectionInfos(ctx, client, database, op)
case translator.OpGetIndexes:
return executeGetIndexes(ctx, client, database, op)
case translator.OpCountDocuments:
return executeCountDocuments(ctx, client, database, op, maxRows)
case translator.OpEstimatedDocumentCount:
return executeEstimatedDocumentCount(ctx, client, database, op)
case translator.OpDistinct:
return executeDistinct(ctx, client, database, op)
default:
return nil, fmt.Errorf("unsupported operation: %s", statement)
}
}