codegen: make generated godoc more relevant for without-rowid tables

This commit is contained in:
2026-02-14 18:33:41 -08:00
parent 4f3865deaa
commit ba89f0b818
3 changed files with 11 additions and 6 deletions

View File

@@ -22,8 +22,6 @@ TODO: codegen SaveXyz update path doesn't check foreign keys
- Insert path has FK error handling, but the update path wraps everything in Must - Insert path has FK error handling, but the update path wraps everything in Must
- An update that violates an FK constraint will panic instead of returning an error - An update that violates an FK constraint will panic instead of returning an error
TODO: codegen `without rowid` tables properly
TODO: generated test file inclues global test DB setup, which is wrong TODO: generated test file inclues global test DB setup, which is wrong
TODO: join-tables TODO: join-tables

View File

@@ -1 +1,3 @@
https://astexplorer.net/ https://astexplorer.net/
https://github.com/dave/dst
https://disaev.me/p/writing-useful-go-analysis-linter/

View File

@@ -515,11 +515,16 @@ func GenerateSaveItemFunc(tbl schema.Table) *ast.FuncDecl {
}(), }(),
} }
docLines := []*ast.Comment{
{Text: fmt.Sprintf("// Save%s creates or updates a %s in the database.", tbl.GoTypeName, tbl.GoTypeName)},
}
if tbl.IsWithoutRowid {
docLines = append(docLines, &ast.Comment{Text: "// If a row with the same key already exists, it will be updated; otherwise it will be created."})
} else {
docLines = append(docLines, &ast.Comment{Text: "// If the item doesn't exist (has no ID set), it will create it; otherwise it will do an update."})
}
funcDecl := &ast.FuncDecl{ funcDecl := &ast.FuncDecl{
Doc: &ast.CommentGroup{List: []*ast.Comment{ Doc: &ast.CommentGroup{List: docLines},
{Text: fmt.Sprintf("// Save%s creates or updates a %s in the database.", tbl.GoTypeName, tbl.GoTypeName)},
{Text: "// If the item doesn't exist (has no ID set), it will create it; otherwise it will do an update."},
}},
Recv: dbRecv, Recv: dbRecv,
Name: ast.NewIdent("Save" + tbl.GoTypeName), Name: ast.NewIdent("Save" + tbl.GoTypeName),
Type: &ast.FuncType{ Type: &ast.FuncType{