diff --git a/doc/TODO.txt b/doc/TODO.txt index 1e42d24..0b32a9e 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -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 - 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: join-tables diff --git a/doc/links.txt b/doc/links.txt index 2aaef8b..200f480 100644 --- a/doc/links.txt +++ b/doc/links.txt @@ -1 +1,3 @@ https://astexplorer.net/ +https://github.com/dave/dst +https://disaev.me/p/writing-useful-go-analysis-linter/ diff --git a/pkg/codegen/modelgenerate/generate_model.go b/pkg/codegen/modelgenerate/generate_model.go index 2c71942..88e7e2e 100644 --- a/pkg/codegen/modelgenerate/generate_model.go +++ b/pkg/codegen/modelgenerate/generate_model.go @@ -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{ - Doc: &ast.CommentGroup{List: []*ast.Comment{ - {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."}, - }}, + Doc: &ast.CommentGroup{List: docLines}, Recv: dbRecv, Name: ast.NewIdent("Save" + tbl.GoTypeName), Type: &ast.FuncType{