arraysource

package
v0.43.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertSliceToRows added in v0.39.0

func ConvertSliceToRows(data any) ([]map[string]any, error)

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

func New(rows []map[string]any) *Model

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

func NewArraySourceFrom[T any](items []T) *Model

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

func NewWithSchema(rows []map[string]any, schema map[string]string) *Model

NewWithSchema creates an ArraySource with an explicit column schema. Rows are shallow-copied (snapshot at call time).

func (*Model) Rows

func (m *Model) Rows() ([]map[string]any, error)

func (*Model) Schema

func (m *Model) Schema() map[string]string

func (*Model) Table

func (m *Model) Table(name string) *Model

Table sets a custom table name. Must be called before passing to Model(). Not safe to call concurrently with a query using this source.

func (*Model) TableName

func (m *Model) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL