Skip to content

Commit e940ce9

Browse files
Merge branch 'main' into 374-improve-project-directory-structure
2 parents 0b12a4a + 845bca8 commit e940ce9

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

CodeGenerator/Generators/QueriesGen.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,22 @@ private MemberDeclarationSyntax AddMethodDeclaration(Query query)
183183
var argInterface = ClassMember.Args.Name(query.Name);
184184
var returnInterface = ClassMember.Row.Name(query.Name);
185185

186-
return query.Cmd switch
186+
try
187187
{
188-
":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query),
189-
":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query),
190-
":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query),
191-
":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query),
192-
":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query),
193-
":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query),
194-
_ => throw new NotSupportedException($"{query.Cmd} is not supported")
195-
};
188+
return query.Cmd switch
189+
{
190+
":exec" => ((IExec)dbDriver).ExecDeclare(queryTextConstant, argInterface, query),
191+
":one" => ((IOne)dbDriver).OneDeclare(queryTextConstant, argInterface, returnInterface, query),
192+
":many" => ((IMany)dbDriver).ManyDeclare(queryTextConstant, argInterface, returnInterface, query),
193+
":execrows" => ((IExecRows)dbDriver).ExecRowsDeclare(queryTextConstant, argInterface, query),
194+
":execlastid" => ((IExecLastId)dbDriver).ExecLastIdDeclare(queryTextConstant, argInterface, query),
195+
":copyfrom" => ((ICopyFrom)dbDriver).CopyFromDeclare(queryTextConstant, argInterface, query),
196+
_ => throw new NotSupportedException($"{query.Cmd} is not supported")
197+
};
198+
}
199+
catch (Exception e)
200+
{
201+
throw new SystemException($"Failed to add method declaration for query: {query.Name}", e);
202+
}
196203
}
197204
}

Drivers/DbDriver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@ this method uses a few heuristics to assess the data type of the id column
280280
public string GetIdColumnType(Query query)
281281
{
282282
var tableColumns = Tables[query.InsertIntoTable.Schema][query.InsertIntoTable.Name].Columns;
283-
var idColumn = tableColumns.First(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase));
283+
var idColumn = tableColumns.FirstOrDefault(c => c.Name.Equals("id", StringComparison.OrdinalIgnoreCase));
284284
if (idColumn is not null)
285285
return GetCsharpType(idColumn, query);
286286

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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ version: "2"
1212
plugins:
1313
- name: csharp
1414
wasm:
15-
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/v0.22.1/sqlc-gen-csharp.wasm
16-
sha256: 0b07a86555e7adf9aed7f5e4eeb5f89762e182420574edf81cf98173e0d80121
15+
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/v0.22.2/sqlc-gen-csharp.wasm
16+
sha256: 40af6dbb1447fb42f9e12d094a79e5adbfcb3669470cf7055896a179ee2e7427
1717
sql:
1818
# For PostgresSQL
1919
- schema: schema.sql

docs/02_Quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version: "2"
44
plugins:
55
- name: csharp
66
wasm:
7-
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/v0.22.1/sqlc-gen-csharp.wasm
8-
sha256: 0b07a86555e7adf9aed7f5e4eeb5f89762e182420574edf81cf98173e0d80121
7+
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/v0.22.2/sqlc-gen-csharp.wasm
8+
sha256: 40af6dbb1447fb42f9e12d094a79e5adbfcb3669470cf7055896a179ee2e7427
99
sql:
1010
# For PostgresSQL
1111
- schema: schema.sql

0 commit comments

Comments
 (0)