-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.go
37 lines (32 loc) · 1.31 KB
/
generate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Package sqlcgeneratecrud provides a set of utilities for generating CRUD SQL statements such as INSERT, SELECT, UPDATE and DELETE.
//
// Source code and other details for the project are available at GitHub:
//
// https://github.com/Paulo-Lopes-Estevao/sqlc-generate-crud
package sqlcgeneratecrud
import "github.com/Paulo-Lopes-Estevao/sqlc-generate-crud/internal/codegen"
// GenerateConfig represents the configuration options for generating CRUD SQL statements.
type GenerateConfig struct {
TagFormat string // The tag format to use for struct field tags (default: "json").
PathTarget int // The target path for the generated SQL files (default: 0).
}
// Generate generates CRUD SQL statements for the given data using the specified options.
// It returns an error if any error occurs during the generation process.
func Generate(data interface{}, option *GenerateConfig) error {
err := codegen.GenerateCrudSql(data, option.pathTarget(), option.tag())
if err != nil {
return err
}
return nil
}
// tag returns the tag format to use. If not specified, it defaults to "json".
func (g *GenerateConfig) tag() string {
if g.TagFormat == "" {
g.TagFormat = "json"
}
return g.TagFormat
}
// pathTarget returns the target path for the generated SQL files.
func (g *GenerateConfig) pathTarget() int {
return g.PathTarget
}