package generator var autoGenWarningTemplate = ` // // Code generated by sqlbuilder DO NOT EDIT. // Generated at {{now}} // // WARNING: Changes to this file may cause incorrect behavior and will be lost // if the code is regenerated // // Licence under ... // ` var sqlBuilderTableTemplate = ` {{define "column-list" -}} {{- range $i, $c := . }} {{- if gt $i 0 }}, {{end}}{{camelize $c.Name}}Column {{- end}} {{- end}} {{define "nullable" -}} {{- if .IsNullable}}sqlbuilder.Nullable{{else}}sqlbuilder.NotNullable{{end}} {{- end}} package table import ( "github.com/sub0zero/go-sqlbuilder/sqlbuilder" ) type {{.GoStructName}} struct { sqlbuilder.Table //Columns {{- range .Columns}} {{camelize .Name}} *sqlbuilder.{{.SqlBuilderColumnType}} {{- end}} AllColumns sqlbuilder.ColumnList } var {{camelize .Name}} = new{{.GoStructName}}() func new{{.GoStructName}}() *{{.GoStructName}} { var ( {{- range .Columns}} {{camelize .Name}}Column = sqlbuilder.New{{.SqlBuilderColumnType}}("{{.Name}}", {{template "nullable" .}}) {{- end}} ) return &{{.GoStructName}}{ Table: *sqlbuilder.NewTable("{{.SchemaName}}", "{{.Name}}", {{template "column-list" .Columns}}), //Columns {{- range .Columns}} {{camelize .Name}}: {{camelize .Name}}Column, {{- end}} AllColumns: sqlbuilder.ColumnList{ {{template "column-list" .Columns}} }, } } func (a *{{.GoStructName}}) AS(alias string) *{{.GoStructName}} { aliasTable := new{{.GoStructName}}() aliasTable.Table.SetAlias(alias) return aliasTable } ` var dataModelTemplate = `package model {{ if .GetImports }} import ( {{- range .GetImports}} "{{.}}" {{- end}} ) {{end}} type {{camelize .Name}} struct { {{- range .Columns}} {{camelize .Name}} {{.GoModelType}} {{if $.IsUnique .Name}}` + "`sql:\"unique\"`" + ` {{end}} {{- end}} } ` var enumModelTemplate = `package model import "errors" type {{camelize $.Name}} string const ( {{- range $index, $element := .Values}} {{camelize $.Name}}_{{camelize $element}} {{camelize $.Name}} = "{{$element}}" {{- end}} ) func (e *{{camelize $.Name}}) Scan(value interface{}) error { if v, ok := value.(string); !ok { return errors.New("Invalid data for {{camelize $.Name}} enum") } else { switch string(v) { {{- range $index, $element := .Values}} case "{{$element}}": *e = {{camelize $.Name}}_{{camelize $element}} {{- end}} default: return errors.New("Inavlid data " + string(v) + "for {{camelize $.Name}} enum") } return nil } } func (e {{camelize $.Name}}) String() string { return string(e) } `