Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertSliceToRows ¶ added in v0.39.0
ConvertSliceToRows converts a slice of maps, structs, or pointer-to-structs to []map[string]any using reflection. If data is nil, or represents an empty slice, it returns nil, nil. If any element of the slice is not a struct, pointer-to-struct, or map[string]any, it returns an error.
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
func New ¶
New creates an ArraySource from []map[string]any rows. Table name is auto-generated. Rows are shallow-copied (snapshot at call time). Panics if rows is nil or empty — use NewWithSchema for empty datasets.
func NewArraySourceFrom ¶
NewArraySourceFrom creates an array-backed data source from a slice of structs or []map[string]any, with zero setup: no custom struct, no table name, no schema. This is the primary, day-to-day entry point for the array driver — the third constructor in the NewArraySource family.
statuses := []Status{{ID: 1, Name: "Pending"}, {ID: 2, Name: "Active"}}
database.Query().Model(neat.NewArraySourceFrom(statuses)).Get(&out)
For struct slices, field names are resolved to column names using the same tag convention as the ORM (db > neat > gorm > snake_case). Embedded structs are flattened. Association fields (slices, struct pointers) are skipped. Nullable pointer fields (*string, *int) are dereferenced; nil pointers become nil (NULL in SQLite). time.Time fields are included as-is.
For []map[string]any, rows are shallow-copied (snapshot at call time).
Panics if T is not a struct, pointer-to-struct, or map[string]any — this is a programmer error, not a runtime condition. Panics if the slice is empty — use NewWithSchema for empty datasets.
func NewWithSchema ¶
NewWithSchema creates an ArraySource with an explicit column schema. Rows are shallow-copied (snapshot at call time).