WIP: initial commit

This commit is contained in:
jdl
2026-06-25 13:14:06 +02:00
parent 8f3fac98a9
commit 9f4c86f39f
19 changed files with 1036 additions and 1 deletions

40
template.go Normal file
View File

@@ -0,0 +1,40 @@
package sqlgen
import (
_ "embed"
"os"
"os/exec"
"path/filepath"
"text/template"
)
//go:embed gen.go.tmpl
var fileTemplate string
func render(driver, schemaPath, outputPath string) (err error) {
outputPath, err = filepath.Abs(outputPath)
if err != nil {
return err
}
sch, err := parsePath(driver, schemaPath)
if err != nil {
return err
}
tmpl := template.Must(template.New("").Parse(fileTemplate))
fOut, err := os.Create(outputPath)
if err != nil {
return err
}
defer fOut.Close()
err = tmpl.Execute(fOut, struct {
PackageName string
Schema *schema
}{filepath.Base(filepath.Dir(outputPath)), sch})
if err != nil {
return err
}
return exec.Command("gofmt", "-w", outputPath).Run()
}