( ctx context.Context, driver db.Driver, conn *sql.Conn, statement string, queryContext db.QueryContext, )
| 925 | } |
| 926 | |
| 927 | func executeWithTimeout( |
| 928 | ctx context.Context, |
| 929 | driver db.Driver, |
| 930 | conn *sql.Conn, |
| 931 | statement string, |
| 932 | queryContext db.QueryContext, |
| 933 | ) ([]*v1pb.QueryResult, time.Duration, error) { |
| 934 | queryCtx := ctx |
| 935 | var timeout time.Duration |
| 936 | // For access control feature, we will use the timeout from request and query data policy. |
| 937 | // Otherwise, no timeout will be applied. |
| 938 | if queryContext.Timeout != nil { |
| 939 | timeout = queryContext.Timeout.AsDuration() |
| 940 | slog.Debug("create query context with timeout", slog.Duration("timeout", timeout)) |
| 941 | newCtx, cancelCtx := context.WithTimeout(ctx, timeout) |
| 942 | defer cancelCtx() |
| 943 | queryCtx = newCtx |
| 944 | } |
| 945 | |
| 946 | start := time.Now() |
| 947 | result, err := driver.QueryConn(queryCtx, conn, statement, queryContext) |
| 948 | select { |
| 949 | case <-queryCtx.Done(): |
| 950 | // canceled or timed out |
| 951 | return nil, time.Since(start), errors.Errorf("timeout reached: %v", timeout) |
| 952 | default: |
| 953 | // So the select will not block |
| 954 | } |
| 955 | sanitizeResults(result) |
| 956 | return result, time.Since(start), err |
| 957 | } |
| 958 | |
| 959 | // Export exports the SQL query result. |
| 960 | func (s *SQLService) Export(ctx context.Context, req *connect.Request[v1pb.ExportRequest]) (*connect.Response[v1pb.ExportResponse], error) { |
no test coverage detected