wip
This commit is contained in:
36
sqlgen/template.go
Normal file
36
sqlgen/template.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package sqlgen
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
//go:embed sqlite.go.tmpl
|
||||
var sqliteTemplate string
|
||||
|
||||
func render(templateStr, schemaPath, outputPath string) error {
|
||||
sch, err := parsePath(schemaPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpl := template.Must(template.New("").Parse(templateStr))
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user