< Summary

Information
Class: Elsa.Persistence.EFCore.Sqlite.Services.SqliteWorkflowReferenceQuery
Assembly: Elsa.Persistence.EFCore.Sqlite
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Sqlite/Services/SqliteWorkflowReferenceQuery.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 31
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
ExecuteAsync()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Sqlite/Services/SqliteWorkflowReferenceQuery.cs

#LineLine coverage
 1using Elsa.Persistence.EFCore.Modules.Management;
 2using Elsa.Workflows.Management;
 3using Elsa.Workflows.Management.Entities;
 4using Microsoft.EntityFrameworkCore;
 5
 6namespace Elsa.Persistence.EFCore.Sqlite.Services;
 7
 8/// <summary>
 9/// Provides an implementation of <see cref="IWorkflowReferenceQuery"/> for querying SQLite databases
 10/// to find all latest workflow definitions that reference a specific workflow definition.
 11/// </summary>
 012public class SqliteWorkflowReferenceQuery(IDbContextFactory<ManagementElsaDbContext> dbContextFactory) : IWorkflowRefere
 13{
 14    public async Task<IEnumerable<string>> ExecuteAsync(string workflowDefinitionId, CancellationToken cancellationToken
 15    {
 016        await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
 017        var tableName = dbContext.Model.FindEntityType(typeof(WorkflowDefinition))!.GetTableName();
 18
 019        var sql = $"""
 020                    SELECT DefinitionId, TenantId FROM {tableName} WHERE IsLatest = 1 AND EXISTS (
 021                    SELECT 1 FROM json_each(json_extract(StringData, '$.activities'))
 022                    WHERE json_extract(value, '$.workflowDefinitionId') = @p0
 023                    AND json_extract(value, '$.latestAvailablePublishedVersion') IS NOT NULL)
 024                   """;
 25
 026        return await dbContext.Set<WorkflowDefinition>()
 027            .FromSqlRaw(sql, workflowDefinitionId)
 028            .Select(x => x.DefinitionId)
 029            .ToListAsync(cancellationToken);
 030    }
 31}