entutils

package
v1.0.0-beta.191 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOrdering

func GetOrdering(order sortx.Order) []sql.OrderTermOption

func JSONBIn

func JSONBIn(field string, key string, values []string) func(*sql.Selector)

JSONBIn returns a function that filters the given JSONB field by the given key and value Caveats: - PostgreSQL only - The field must be a JSONB field - The value must be a string (no support for other types, ->> converts all values to string) - This might not work if there's a join involved in the query, so add unit tests

func JSONBKeyExistsInObject

func JSONBKeyExistsInObject(field string, member string, expectedKey string) func(*sql.Selector)

JSONBKeyExistsInObject returns a function that filters the given JSONB field by mandating that a key exists in a specifc object.

Example: given the field value of

{"failed": false, "immutable": false, "availableActions": {"delete": {"resultingState": "deleted"}, "advance": {"resultingState": "draft.waiting_auto_approval"}}}

JSONBKeyExistsInObject("status_details_cache", "availableActions", "advance")

filters for such records that have the advance as an available action.

Resulting condition:

status_details_cache -> 'availableActions' ? 'advance'

func JSONStringValueScanner

func JSONStringValueScanner[T any]() field.ValueScannerFunc[T, *sql.NullString]

func TransactingRepo

func TransactingRepo[R, T any](
	ctx context.Context,
	repo interface {
		TxUser[T]
		TxCreator
	},
	cb func(ctx context.Context, rep T) (R, error),
) (R, error)

TransactingRepo is a helper that can be used inside repository methods. It uses any preexisting transaction in the context or starts and executes a new one.

func TransactingRepoWithNoValue

func TransactingRepoWithNoValue[T any](
	ctx context.Context,
	repo interface {
		TxUser[T]
		TxCreator
	},
	cb func(ctx context.Context, rep T) error,
) error

TransactingRepoWithNoValue is a helper that can be used inside repository methods.

Types

type CadencedMixin

type CadencedMixin struct {
	mixin.Schema
}

func (CadencedMixin) Fields

func (CadencedMixin) Fields() []ent.Field

type CustomerAddressMixin

type CustomerAddressMixin struct {
	ent.Schema
	FieldPrefix string
}

CustomerAddressMixin adds address fields to a customer, used by billing to snapshot addresses for invoices

func (CustomerAddressMixin) Fields

func (c CustomerAddressMixin) Fields() []ent.Field

type IDMixin

type IDMixin struct {
	mixin.Schema
}

IDMixin adds the ID field to the schema

func (IDMixin) Fields

func (IDMixin) Fields() []ent.Field

Fields of the IDMixin.

func (IDMixin) Indexes

func (IDMixin) Indexes() []ent.Index

type KeyMixin

type KeyMixin struct {
	mixin.Schema
}

KeyMixin adds the key field to the schema

func (KeyMixin) Fields

func (KeyMixin) Fields() []ent.Field

Fields of the KeyMixin.

type MetadataAnnotationsMixin

type MetadataAnnotationsMixin struct {
	mixin.Schema
}

MetadataAnnotationsMixin adds metadata to the schema

func (MetadataAnnotationsMixin) Fields

func (MetadataAnnotationsMixin) Fields() []ent.Field

Fields of the IDMixin.

type NamespaceMixin

type NamespaceMixin struct {
	mixin.Schema
}

NamespaceMixin can be used for namespaced entities

func (NamespaceMixin) Fields

func (NamespaceMixin) Fields() []ent.Field

Fields of the IDMixin.

func (NamespaceMixin) Indexes

func (NamespaceMixin) Indexes() []ent.Index

type RawEntConfig

type RawEntConfig struct {
	// driver used for executing database requests.
	Driver dialect.Driver
	// debug enable a debug logging.
	Debug bool
	// log used for logging on debug mode.
	Log func(...any)
}

type ResourceMixin

type ResourceMixin struct {
	mixin.Schema
}

ResourceMixin adds common fields

func (ResourceMixin) Fields

func (ResourceMixin) Fields() []ent.Field

func (ResourceMixin) Indexes

func (ResourceMixin) Indexes() []ent.Index

type TimeMixin

type TimeMixin struct {
	mixin.Schema
}

TimeMixin adds the created_at and updated_at fields to the schema

func (TimeMixin) Fields

func (TimeMixin) Fields() []ent.Field

Fields of the TimeMixin.

type Transactable

type Transactable interface {
	Commit() error
	Rollback() error
	SavePoint(name string) error
	RollbackTo(name string) error
	Release(name string) error
}

type TxCreator

type TxCreator = transaction.Creator

Able to start a new transaction

type TxDriver

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

func GetDriverFromContext

func GetDriverFromContext(ctx context.Context) (*TxDriver, error)

Only use for direct interacton with the Ent driver implementation

func NewTxDriver

func NewTxDriver(driver Transactable, cfg *RawEntConfig) *TxDriver

func (*TxDriver) Commit

func (t *TxDriver) Commit() error

Commit commits the (complete) transaction.

func (*TxDriver) GetConfig

func (t *TxDriver) GetConfig() *RawEntConfig

func (*TxDriver) Rollback

func (t *TxDriver) Rollback() error

Rollback rolls back the (complete) transaction.

func (*TxDriver) SavePoint

func (t *TxDriver) SavePoint() error

type TxHijacker

type TxHijacker interface {
	HijackTx(ctx context.Context, opts *sql.TxOptions) (context.Context, *RawEntConfig, Transactable, error)
}

type TxUser

type TxUser[T any] interface {
	// Creates a new instance of the adapter using the provided transaction.
	// Example:
	//
	// type dbAdapter struct {
	//     db *db.Client
	// }
	//
	// func (d *dbAdapter) WithTx(ctx context.Context, tx *entutils.TxDriver) SomeDB[db1.Example1] {
	//     // NewTxClientFromRawConfig gets generated when using expose.tpl
	//     txClient := db.NewTxClientFromRawConfig(ctx, *tx.GetConfig())
	//     res := &db1Adapter{db: txClient.Client()}
	//     return res
	// }
	WithTx(ctx context.Context, tx *TxDriver) T
}

Able to use an existing transaction

type ULID

type ULID struct {
	ulid.ULID
}

ULID implements a valuer (and Scanner) that can serialize string ULIDs into postgres instead of the binary representation, as postgres interprets those as UTF-8 strings

func Ptr

func Ptr(u *ulid.ULID) *ULID

func Wrap

func Wrap(u ulid.ULID) ULID

func (*ULID) ULIDPointer

func (v *ULID) ULIDPointer() *ulid.ULID

func (ULID) Value

func (v ULID) Value() (driver.Value, error)

type UniqueResourceMixin

type UniqueResourceMixin struct {
	mixin.Schema
}

UniqueResourceMixin adds common fields

func (UniqueResourceMixin) Fields

func (UniqueResourceMixin) Fields() []ent.Field

func (UniqueResourceMixin) Indexes

func (UniqueResourceMixin) Indexes() []ent.Index

Jump to

Keyboard shortcuts

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