Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
399 changes: 210 additions & 189 deletions internal/analysis/analysis.pb.go

Large diffs are not rendered by default.

117 changes: 68 additions & 49 deletions internal/cmd/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,20 @@ func pluginCatalog(c *catalog.Catalog) *plugin.Catalog {
for _, typ := range s.Types {
switch typ := typ.(type) {
case *catalog.Enum:
enums = append(enums, &plugin.Enum{
Name: typ.Name,
Comment: typ.Comment,
Vals: typ.Vals,
})
enums = append(
enums, &plugin.Enum{
Name: typ.Name,
Comment: typ.Comment,
Vals: typ.Vals,
},
)
case *catalog.CompositeType:
cts = append(cts, &plugin.CompositeType{
Name: typ.Name,
Comment: typ.Comment,
})
cts = append(
cts, &plugin.CompositeType{
Name: typ.Name,
Comment: typ.Comment,
},
)
}
}
var tables []*plugin.Table
Expand All @@ -87,43 +91,49 @@ func pluginCatalog(c *catalog.Catalog) *plugin.Catalog {
if c.Length != nil {
l = *c.Length
}
columns = append(columns, &plugin.Column{
Name: c.Name,
Type: &plugin.Identifier{
Catalog: c.Type.Catalog,
Schema: c.Type.Schema,
Name: c.Type.Name,
columns = append(
columns, &plugin.Column{
Name: c.Name,
Type: &plugin.Identifier{
Catalog: c.Type.Catalog,
Schema: c.Type.Schema,
Name: c.Type.Name,
},
Comment: c.Comment,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: int32(c.ArrayDims),
Length: int32(l),
Table: &plugin.Identifier{
Catalog: t.Rel.Catalog,
Schema: t.Rel.Schema,
Name: t.Rel.Name,
},
},
Comment: c.Comment,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: int32(c.ArrayDims),
Length: int32(l),
Table: &plugin.Identifier{
)
}
tables = append(
tables, &plugin.Table{
Rel: &plugin.Identifier{
Catalog: t.Rel.Catalog,
Schema: t.Rel.Schema,
Name: t.Rel.Name,
},
})
}
tables = append(tables, &plugin.Table{
Rel: &plugin.Identifier{
Catalog: t.Rel.Catalog,
Schema: t.Rel.Schema,
Name: t.Rel.Name,
Columns: columns,
Comment: t.Comment,
},
Columns: columns,
Comment: t.Comment,
})
)
}
schemas = append(schemas, &plugin.Schema{
Comment: s.Comment,
Name: s.Name,
Tables: tables,
Enums: enums,
CompositeTypes: cts,
})
schemas = append(
schemas, &plugin.Schema{
Comment: s.Comment,
Name: s.Name,
Tables: tables,
Enums: enums,
CompositeTypes: cts,
},
)
}
return &plugin.Catalog{
Name: c.Name,
Expand Down Expand Up @@ -152,16 +162,18 @@ func pluginQueries(r *compiler.Result) []*plugin.Query {
Name: q.InsertIntoTable.Name,
}
}
out = append(out, &plugin.Query{
Name: q.Metadata.Name,
Cmd: q.Metadata.Cmd,
Text: q.SQL,
Comments: q.Metadata.Comments,
Columns: columns,
Params: params,
Filename: q.Metadata.Filename,
InsertIntoTable: iit,
})
out = append(
out, &plugin.Query{
Name: q.Metadata.Name,
Cmd: q.Metadata.Cmd,
Text: q.SQL,
Comments: q.Metadata.Comments,
Columns: columns,
Params: params,
Filename: q.Metadata.Filename,
InsertIntoTable: iit,
},
)
}
return out
}
Expand All @@ -184,6 +196,13 @@ func pluginQueryColumn(c *compiler.Column) *plugin.Column {
IsFuncCall: c.IsFuncCall,
IsSqlcSlice: c.IsSqlcSlice,
}
if c.SqlcSortOpts != nil {
out.SqlcSortOpts = &plugin.SqlcSortOpts{
IsOrder: c.SqlcSortOpts.IsOrder,
DefaultField: c.SqlcSortOpts.DefaultField,
DefaultOrder: c.SqlcSortOpts.DefaultOrder,
}
}

if c.Type != nil {
out.Type = &plugin.Identifier{
Expand Down
20 changes: 17 additions & 3 deletions internal/codegen/golang/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ func (gf Field) HasSqlcSlice() bool {
return gf.Column.IsSqlcSlice
}

func (gf Field) HasSqlcSort() bool {
return gf.Column.SqlcSortOpts != nil
}

func (gf Field) NotNull() bool {
return gf.Column.NotNull
}

func (gf Field) SqlcSortOpts() *plugin.SqlcSortOpts {
return gf.Column.SqlcSortOpts
}

func TagsToString(tags map[string]string) string {
if len(tags) == 0 {
return ""
Expand Down Expand Up @@ -81,9 +93,11 @@ var camelPattern = regexp.MustCompile("[^A-Z][A-Z]+")

func toSnakeCase(s string) string {
if !strings.ContainsRune(s, '_') {
s = camelPattern.ReplaceAllStringFunc(s, func(x string) string {
return x[:1] + "_" + x[1:]
})
s = camelPattern.ReplaceAllStringFunc(
s, func(x string) string {
return x[:1] + "_" + x[1:]
},
)
}
return strings.ToLower(s)
}
Expand Down
Loading
Loading