Skip to content

Commit

Permalink
patched side relation index generation
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Jun 24, 2024
1 parent b11ffab commit 9fc7f4e
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.7.0.1
v0.8.6
2 changes: 1 addition & 1 deletion cmd/command/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (s *Service) ensureDefaultImportInit(ctx context.Context, pkgLocation strin
}

func (s *Service) ensureChecksum(ctx context.Context, pkgLocation string, replacer rdata.Map) error {
checksumDest := url.Join(pkgLocation, "checksum/init.go")
checksumDest := url.Join(pkgLocation, "dependency/checksum/init.go")
if ok, _ := s.fs.Exists(ctx, checksumDest); ok {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/command/tmpl/pkg/bootstrap/bootstrap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bootstrap

import (
"github.com/viant/xdatly/types/core"
"${impModule}/checksum"
"${impModule}/dependency/checksum"
"reflect"
)

Expand Down
5 changes: 3 additions & 2 deletions cmd/datly/datly.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/google/gops/agent"
"github.com/viant/datly"
"github.com/viant/datly/cmd"
"github.com/viant/datly/cmd/env"
"log"
Expand All @@ -11,8 +12,8 @@ import (
"time"
)

var Version string
var (
Version = "development"
BuildTimeInS string
)

Expand Down Expand Up @@ -40,7 +41,7 @@ func main() {
log.Fatal(err)
}
}()
err := cmd.RunApp(Version, os.Args[1:])
err := cmd.RunApp(datly.Version, os.Args[1:])
if err != nil {
fmt.Printf("ERROR: %v\n", err)
log.Fatal(err)
Expand Down
4 changes: 3 additions & 1 deletion cmd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ type (
var mysqlDev string

func (o *Options) BuildOption() *options.Options {
var result = &options.Options{}
var result = &options.Options{
Version: o.Version,
}
prep := o.Prepare

if prep.PrepareRule != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/options/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (g *Generate) customType(result string, methodFragment string) string {
}
pkg := g.Package()
if g.ModulePrefix != "" {
if strings.HasSuffix(g.ModulePrefix, pkg) {
if strings.Contains(g.ModulePrefix, pkg) {
pkg = g.ModulePrefix
} else {
pkg = url.Join(g.ModulePrefix, pkg)
Expand Down
2 changes: 1 addition & 1 deletion cmd/options/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *Rule) GoCodeLocation() string {
return module
}
if r.ModulePrefix != "" {
if strings.HasSuffix(r.ModulePrefix, r.Package()) {
if strings.Contains(r.ModulePrefix, r.Package()) {
return url.Join(module, r.ModulePrefix)
}
return url.Join(module, r.ModulePrefix, r.Package())
Expand Down
11 changes: 10 additions & 1 deletion internal/codegen/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (n *IndexGenerator) lookupParam(name string) (*inference.Parameter, error)

func (n *IndexGenerator) pathInType(segments []string, receiverType reflect.Type) (reflect.StructField, error) {
var structField reflect.StructField

for i := 0; i < len(segments); i++ {
elem := n.deref(receiverType)
if elem.Kind() != reflect.Struct {
Expand All @@ -146,6 +147,7 @@ func (n *IndexGenerator) pathInType(segments []string, receiverType reflect.Type

field, ok := elem.FieldByName(segments[i])
if !ok {

return reflect.StructField{}, n.fieldNotFoundError(segments[i], receiverType)
}

Expand Down Expand Up @@ -228,7 +230,14 @@ func (n *IndexGenerator) findVariableType(expression *ast.Ident) (reflect.Type,
return nil, nil
}

inType, err := n.pathInType(split[1:], rType.Elem())
rawType := rType
if rawType.Kind() == reflect.Slice {
rawType = rawType.Elem()
}
if rawType.Kind() == reflect.Ptr {
rawType = rawType.Elem()
}
inType, err := n.pathInType(split[1:], rawType)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/inference/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (s *Spec) EnsureRelationType() {
continue
}
rel := s.Relations[i]

rel.EnsureRelationType()
if rel.Type != nil {
field.Schema = state.NewSchema(reflect.StructOf(rel.Type.Fields()))
}
Expand Down
3 changes: 3 additions & 0 deletions internal/inference/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func WithStructTag() ReflectOption {
}

func (f *Field) StructField(opts ...ReflectOption) reflect.StructField {

ret := reflect.StructField{
Name: f.Name,
Type: f.Field.Schema.Type(),
Expand Down Expand Up @@ -191,12 +192,14 @@ func (t *Type) Fields(opts ...ReflectOption) []reflect.StructField {
continue
}
unique[field.Name] = true

fields = append(fields, field.StructField(opts...))
}
for _, field := range t.RelationFields {
if unique[field.Name] {
continue
}

unique[field.Name] = true
fields = append(fields, field.StructField(opts...))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/plugin/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
codecPkg = "github.com/viant/xdatly/codec"

dependencyDirectory = "dependency"
checksumDirectory = "checksum"
checksumDirectory = "dependency/checksum"
pluginDirectory = "plugin"
)

Expand Down
4 changes: 4 additions & 0 deletions repository/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func (c *Component) generatorImports(modulePath string) []string {
if index != -1 {
checksumModule = modulePath[:index] + "/pkg/checksum"
}
checksumParent, _ := path.Split(checksumModule)
if !strings.HasSuffix(checksumParent, "dependency") {
checksumModule = path.Join(checksumParent, "dependency", "checksum")
}

return []string{"embed",
"github.com/viant/datly",
Expand Down
4 changes: 4 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datly

import (
"context"
_ "embed"
"fmt"
"github.com/viant/datly/gateway"
"github.com/viant/datly/repository"
Expand All @@ -28,6 +29,9 @@ import (
"time"
)

//go:embed Version
var Version string

type (
Service struct {
repository *repository.Service
Expand Down

0 comments on commit 9fc7f4e

Please sign in to comment.