db

package
v0.0.0-...-019cbbf Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBTYPE     = "DATABASE"
	CONNSTRING = "DBCONNSTRING"
)

Variables

View Source
var (
	ErrFieldNotAPointer = fmt.Errorf("Field needs to be a pointer")
	ErrFieldNotInStruct = fmt.Errorf("Field pointer needs to be defined in the struct")
)
View Source
var (
	ErrWrongSchemaType = fmt.Errorf("Schema can only be created from a pointer to a struct!")
	ErrFieldNotInit    = fmt.Errorf("Field is not initialized in the schema")
)
View Source
var (
	ErrCantAddress = fmt.Errorf("Can't get address of passed variable")
	ErrNotPointer  = fmt.Errorf("Pass object is not a pointer")
	ErrNotStruct   = fmt.Errorf("Object is not a struct")
)
View Source
var (
	ErrCantGetName = fmt.Errorf("Can't name for the field")
)
View Source
var (

	//error to load env
	ErrEnvLoad = fmt.Errorf("Error loading .env file. Check if the .env file exists!")
)

Functions

func CharField

func CharField(fieldPtr *string, maxLen int) *field

func DefSchema

func DefSchema[T any](userStruct T, fields ...Field) (schema[T], error)

func EmailField

func EmailField(fieldPtr *string) *field

func Get

func Get[T any](obj T, id int) (T, error)

func IntField

func IntField(fieldPtr *int) *field

func MustDefSchema

func MustDefSchema[T any](userStruct T, fields ...Field) schema[T]

func MustRegister

func MustRegister(schemas ...Schema)

func RegisterModels

func RegisterModels(schemas ...Schema) error

func Save

func Save[T any](obj T) error

func TextField

func TextField(fieldPtr *string) *field

func Where

func Where[T stndValue](t *T) *condition[T]

Types

type Condition

type Condition interface {
	ToSQL() string
	Error() error
	Name(obj any) (string, error)
	SetName(string)
}

type ErrDb

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

func (ErrDb) Error

func (e ErrDb) Error() string

type ErrTable

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

func (ErrTable) Error

func (e ErrTable) Error() string

type Field

type Field interface {
	Name() string
	//Type() reflect.Type
	ToSQL() string
}

type FieldValidator

type FieldValidator func() error

type Query

type Query[T any] struct {
	// contains filtered or unexported fields
}

func Filter

func Filter[T any](structPtr T, conditions ...Condition) *Query[T]

func (*Query[T]) All

func (q *Query[T]) All() ([]T, error)

type Schema

type Schema interface {
	Schema() Table
}

type Table

type Table interface {
	ToSQL() string
	TableName() string
}

Jump to

Keyboard shortcuts

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