sdcrf

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

sdcrf

Simple Database Connected Resource Framework

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckName

func CheckName(name string) error

Types

type AttachedTableResource

type AttachedTableResource struct {
	*TableResource
	// contains filtered or unexported fields
}

func (*AttachedTableResource) Create added in v0.1.1

func (atr *AttachedTableResource) Create(data map[string]any) (map[string]any, error)

func (*AttachedTableResource) Delete added in v0.1.1

func (atr *AttachedTableResource) Delete(where map[string]any) ([]map[string]any, error)

func (*AttachedTableResource) FindMany

func (atr *AttachedTableResource) FindMany(opts FindManyOpts) ([]map[string]any, error)

func (*AttachedTableResource) FindUnique

func (atr *AttachedTableResource) FindUnique(opts FindUniqueOpts) (map[string]any, error)

returns (nil, nil), iff no resource has been found; returns (res, nil) on success and (nil, err) on error

func (*AttachedTableResource) Modify added in v0.1.1

func (atr *AttachedTableResource) Modify(where map[string]any, data map[string]any) ([]map[string]any, error)

type DBInstance

type DBInstance struct {
	// contains filtered or unexported fields
}

func OpenDB

func OpenDB(dsn string) (*DBInstance, error)

func (*DBInstance) Migrate

func (i *DBInstance) Migrate(direcory string) error

func (*DBInstance) QueryAsJson

func (i *DBInstance) QueryAsJson(q sqlbuilder.Builder) ([]map[string]any, error)

func (*DBInstance) QueryAsJsonRaw added in v0.1.1

func (i *DBInstance) QueryAsJsonRaw(query string, args ...any) ([]map[string]any, error)

func (*DBInstance) Transact

func (i *DBInstance) Transact(callback func(tx *sql.Tx) error) error

func (*DBInstance) Use

func (i *DBInstance) Use(callback func(conn *sql.Conn) error) error

type FindManyOpts

type FindManyOpts struct {
	Where   map[string]any
	Include []string
	Search  string
}

type FindUniqueOpts added in v0.1.1

type FindUniqueOpts struct {
	Where map[string]any
	// the references to include
	Include []string
}

type TableResource

type TableResource struct {
	// contains filtered or unexported fields
}

func NewTableResource

func NewTableResource(props TableResourceProps) (*TableResource, error)

func (*TableResource) Attach

func (tr *TableResource) Attach(db *DBInstance, ctx any) *AttachedTableResource

type TableResourceDynamicField

type TableResourceDynamicField struct {
	Type z.Validator
	Expr func(alias string, ctx any) string
}

type TableResourceProps

type TableResourceProps struct {
	Name             string
	TableName        string
	PrimaryKey       []string
	CreateOnlyFields []string
	ModifiableFields []string
	StaticFields     map[string]*TableResourceStaticField
	DynamicFields    map[string]*TableResourceDynamicField
	References       map[string]*TableResourceReference
	FindFilter       func(q *sqlbuilder.SelectBuilder, ctx any) error
	ModifyFilter     func(q *sqlbuilder.UpdateBuilder, ctx any) error
	DeleteFilter     func(q *sqlbuilder.UpdateBuilder, ctx any) error
}

type TableResourceReference

type TableResourceReference struct {
	Resource func() *TableResource

	Join func(lhs, rhs string) string

	JunctionTable string
	Junction      func(lhs, junc, rhs string) []string
}

type TableResourceStaticField

type TableResourceStaticField struct {
	Type   z.Validator
	Column string
}

Directories

Path Synopsis
z

Jump to

Keyboard shortcuts

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