-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUtils.cs
More file actions
28 lines (26 loc) · 1.35 KB
/
Utils.cs
File metadata and controls
28 lines (26 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// auto-generated by sqlc - do not edit
namespace SqliteLegacyExampleGen
{
using System;
using System.Linq;
using System.Text.RegularExpressions;
public static class Utils
{
public static string TransformQueryForSliceArgs(string originalSql, int sliceSize, string paramName)
{
var paramArgs = Enumerable.Range(0, sliceSize).Select(i => $"@{paramName}Arg{i}").ToList();
return originalSql.Replace($"/*SLICE:{paramName}*/@{paramName}", string.Join(",", paramArgs));
}
private static readonly Regex ValuesRegex = new Regex(@"VALUES\s*\((?<params>[^)]*)\)", RegexOptions.IgnoreCase);
public static string TransformQueryForSqliteBatch(string originalSql, int cntRecords)
{
var match = ValuesRegex.Match(originalSql);
if (!match.Success)
throw new ArgumentException("The query does not contain a valid VALUES clause.");
var valuesParams = match.Groups["params"].Value.Split(',').Select(p => p.Trim()).ToList();
var batchRows = Enumerable.Range(0, cntRecords).Select(i => "(" + string.Join(", ", valuesParams.Select(p => $"{p}{i}")) + ")");
var batchValuesClause = "VALUES " + string.Join(",\n", batchRows);
return ValuesRegex.Replace(originalSql, batchValuesClause);
}
}
}