QueryConn queries a SQL statement in a given connection.
(ctx context.Context, _ *sql.Conn, statement string, queryContext db.QueryContext)
| 177 | |
| 178 | // QueryConn queries a SQL statement in a given connection. |
| 179 | func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, queryContext db.QueryContext) ([]*v1pb.QueryResult, error) { |
| 180 | if queryContext.Explain { |
| 181 | return nil, errors.New("MongoDB does not support EXPLAIN") |
| 182 | } |
| 183 | |
| 184 | statement = strings.Trim(statement, " \t\n\r\f;") |
| 185 | startTime := time.Now() |
| 186 | |
| 187 | gmClient := gomongo.NewClient(d.client) |
| 188 | var gmOpts []gomongo.ExecuteOption |
| 189 | if queryContext.Limit > 0 { |
| 190 | gmOpts = append(gmOpts, gomongo.WithMaxRows(int64(queryContext.Limit))) |
| 191 | } |
| 192 | result, err := gmClient.Execute(ctx, d.databaseName, statement, gmOpts...) |
| 193 | if err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | return d.convertGomongoResult(result, statement, startTime), nil |
| 197 | } |
| 198 | |
| 199 | func (*Driver) convertGomongoResult(res *gomongo.Result, statement string, startTime time.Time) []*v1pb.QueryResult { |
| 200 | rows := []*v1pb.QueryRow{} |
nothing calls this directly
no test coverage detected