-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/Foundatio.Parsers.SqlQueries/Visitors/GenerateSqlVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Foundatio.Parsers.LuceneQueries.Nodes; | ||
using Foundatio.Parsers.LuceneQueries.Visitors; | ||
|
||
namespace Foundatio.Parsers.SqlQueries.Visitors; | ||
|
||
public class GenerateSqlVisitor : QueryNodeVisitorWithResultBase<string> | ||
{ | ||
private readonly StringBuilder _builder = new(); | ||
|
||
public override Task VisitAsync(GroupNode node, IQueryVisitorContext context) | ||
{ | ||
_builder.Append(node.ToString(context != null ? context.DefaultOperator : GroupOperator.Default)); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public override void Visit(TermNode node, IQueryVisitorContext context) | ||
{ | ||
_builder.Append(node); | ||
} | ||
|
||
public override void Visit(TermRangeNode node, IQueryVisitorContext context) | ||
{ | ||
_builder.Append(node); | ||
} | ||
|
||
public override void Visit(ExistsNode node, IQueryVisitorContext context) | ||
{ | ||
_builder.Append(node); | ||
} | ||
|
||
public override void Visit(MissingNode node, IQueryVisitorContext context) | ||
{ | ||
_builder.Append(node); | ||
} | ||
|
||
public override async Task<string> AcceptAsync(IQueryNode node, IQueryVisitorContext context) | ||
{ | ||
await node.AcceptAsync(this, context).ConfigureAwait(false); | ||
return _builder.ToString(); | ||
} | ||
|
||
public static Task<string> RunAsync(IQueryNode node, IQueryVisitorContext context = null) | ||
{ | ||
return new GenerateSqlVisitor().AcceptAsync(node, context); | ||
} | ||
|
||
public static string Run(IQueryNode node, IQueryVisitorContext context = null) | ||
{ | ||
return RunAsync(node, context).GetAwaiter().GetResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters