Skip to content
aodin edited this page May 31, 2016 · 1 revision

Sol supports deeply nested struct types as both a source of parameters and a destination for queries. Consider the following complex struct:

type Serial struct {
	ID int64 `db:"id,omitempty"`
}

type metadata struct{ Attrs map[string]string }

type customScanner struct{ info []byte }

func (cs customScanner) Scan(src interface{}) error { return nil }

type Nested struct {
	Level2 struct {
		Level3 struct {
			Value bool
		}
	}
}

type embedded struct {
	Serial
	Name      string
	Timestamp struct {
		CreatedAt time.Time `db:",omitempty"`
		UpdatedAt *time.Time
		isActive  bool
	}
	manager  *struct{}
	Custom   customScanner
	Metadata metadata `db:"-"`
	Deep     Nested
}

Sol will detect the following fields via DeepFields:

  1. id - index of [0, 0]
  2. Name - index of [1]
  3. CreatedAt - index of [2, 0]
  4. UpdatedAt - index of [2, 1]
  5. Custom - index of [4]
  6. Value - index of [6, 0, 0, 0]

Sol will ignore unexported (lowercase) fields or those marked with the tag db:"-". Sol will stop descent on any time.Time types and any types that implement the sql.Scanner interface (e.g. Custom in the above example).

Clone this wiki locally