MCPcopy Create free account
hub / github.com/temporalio/temporal / GenerateSelectQuery

Function GenerateSelectQuery

common/persistence/sql/sqlplugin/visibility.go:238–336  ·  view source on GitHub ↗

TODO (rodrigozhou): deprecate with standard visibility code. GenerateSelectQuery generates the SELECT query based on the fields of VisibilitySelectFilter for backward compatibility of any use case using old format (eg: unit test). It will be removed after all use cases change to use query converter.

(
	filter *VisibilitySelectFilter,
	convertToDbDateTime func(time.Time) time.Time,
)

Source from the content-addressed store, hash-verified

236// for backward compatibility of any use case using old format (eg: unit test).
237// It will be removed after all use cases change to use query converter.
238func GenerateSelectQuery(
239 filter *VisibilitySelectFilter,
240 convertToDbDateTime func(time.Time) time.Time,
241) error {
242 whereClauses := make([]string, 0, 10)
243 queryArgs := make([]any, 0, 10)
244
245 whereClauses = append(
246 whereClauses,
247 fmt.Sprintf("%s = ?", sadefs.GetSqlDbColName(sadefs.NamespaceID)),
248 )
249 queryArgs = append(queryArgs, filter.NamespaceID)
250
251 if filter.WorkflowID != nil {
252 whereClauses = append(
253 whereClauses,
254 fmt.Sprintf("%s = ?", sadefs.GetSqlDbColName(sadefs.WorkflowID)),
255 )
256 queryArgs = append(queryArgs, *filter.WorkflowID)
257 }
258
259 if filter.WorkflowTypeName != nil {
260 whereClauses = append(
261 whereClauses,
262 fmt.Sprintf("%s = ?", sadefs.GetSqlDbColName(sadefs.WorkflowType)),
263 )
264 queryArgs = append(queryArgs, *filter.WorkflowTypeName)
265 }
266
267 timeAttr := sadefs.StartTime
268 if filter.Status != int32(enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING) {
269 timeAttr = sadefs.CloseTime
270 }
271 if filter.Status == int32(enumspb.WORKFLOW_EXECUTION_STATUS_UNSPECIFIED) {
272 whereClauses = append(
273 whereClauses,
274 fmt.Sprintf("%s != ?", sadefs.GetSqlDbColName(sadefs.ExecutionStatus)),
275 )
276 queryArgs = append(queryArgs, int32(enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
277 } else {
278 whereClauses = append(
279 whereClauses,
280 fmt.Sprintf("%s = ?", sadefs.GetSqlDbColName(sadefs.ExecutionStatus)),
281 )
282 queryArgs = append(queryArgs, filter.Status)
283 }
284
285 switch {
286 case filter.RunID != nil && filter.MinTime == nil && filter.Status != 1:
287 whereClauses = append(
288 whereClauses,
289 fmt.Sprintf("%s = ?", sadefs.GetSqlDbColName(sadefs.RunID)),
290 )
291 queryArgs = append(
292 queryArgs,
293 *filter.RunID,
294 1, // page size arg
295 )

Callers 3

SelectFromVisibilityMethod · 0.92
SelectFromVisibilityMethod · 0.92
SelectFromVisibilityMethod · 0.92

Calls 2

GetSqlDbColNameFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected