Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions CodeGenerator/Generators/QueriesGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,22 @@ private MemberDeclarationSyntax AddMethodDeclaration(Query query)
var argInterface = ClassMember.Args.Name(query.Name);
var returnInterface = ClassMember.Row.Name(query.Name);

return query.Cmd switch
try
{
":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query),
":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query),
":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query),
":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query),
":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query),
":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query),
_ => throw new NotSupportedException($"{query.Cmd} is not supported")
};
return query.Cmd switch
{
":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query),
":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query),
":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query),
":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query),
":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query),
":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query),
_ => throw new NotSupportedException($"{query.Cmd} is not supported")
};
}
catch (Exception e)
{
throw new SystemException($"Failed to add method declaration for query: {query.Name}", e);
}
}
}
4 changes: 2 additions & 2 deletions Drivers/DbDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ this method uses a few heuristics to assess the data type of the id column
public string GetIdColumnType(Query query)
{
var tableColumns = Tables[query.InsertIntoTable.Schema][query.InsertIntoTable.Name].Columns;
var idColumn = tableColumns.First(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase));
var idColumn = tableColumns.FirstOrDefault(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase));
if (idColumn is not null)
return GetCsharpType(idColumn, query);

idColumn = tableColumns.First(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase));
idColumn = tableColumns.FirstOrDefault(c => c.Name.Contains("id", StringComparison.CurrentCultureIgnoreCase));
return GetCsharpType(idColumn ?? tableColumns[0], query);
}

Expand Down
Loading