schema

package
v1.0.0-beta.168 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AnnotationsValueScanner = field.ValueScannerFunc[notification.Annotations, *sql.NullString]{
	V: func(annotations notification.Annotations) (driver.Value, error) {
		b, err := json.Marshal(annotations)
		if err != nil {
			return nil, err
		}

		return string(b), nil
	},
	S: func(ns *sql.NullString) (notification.Annotations, error) {
		var annotations notification.Annotations
		if ns == nil || !ns.Valid {
			return annotations, nil
		}

		if err := json.Unmarshal([]byte(ns.String), &annotations); err != nil {
			return nil, err
		}

		return annotations, nil
	},
}
View Source
var ChannelConfigValueScanner = field.ValueScannerFunc[notification.ChannelConfig, *sql.NullString]{
	V: func(config notification.ChannelConfig) (driver.Value, error) {
		switch config.Type {
		case notification.ChannelTypeWebhook:
			serde := channelConfigSerde[notification.WebHookChannelConfig]{
				ChannelConfigMeta: notification.ChannelConfigMeta{
					Type: config.Type,
				},
				Data: config.WebHook,
			}
			return json.Marshal(serde)
		default:
			return nil, fmt.Errorf("unknown channel type: %s", config.Type)
		}
	},
	S: func(ns *sql.NullString) (notification.ChannelConfig, error) {
		var channelConfig notification.ChannelConfig
		if ns == nil || !ns.Valid {
			return channelConfig, nil
		}

		data := []byte(ns.String)

		var meta notification.ChannelConfigMeta
		if err := json.Unmarshal(data, &meta); err != nil {
			return channelConfig, err
		}

		switch meta.Type {
		case notification.ChannelTypeWebhook:
			serde := channelConfigSerde[notification.WebHookChannelConfig]{
				ChannelConfigMeta: notification.ChannelConfigMeta{
					Type: meta.Type,
				},
				Data: notification.WebHookChannelConfig{},
			}

			if err := json.Unmarshal(data, &serde); err != nil {
				return channelConfig, err
			}

			channelConfig = notification.ChannelConfig{
				ChannelConfigMeta: serde.ChannelConfigMeta,
				WebHook:           serde.Data,
			}

		default:
			return channelConfig, fmt.Errorf("unknown channel type: %s", meta.Type)
		}

		return channelConfig, nil
	},
}
View Source
var RuleConfigValueScanner = field.ValueScannerFunc[notification.RuleConfig, *sql.NullString]{
	V: func(config notification.RuleConfig) (driver.Value, error) {
		switch config.Type {
		case notification.RuleTypeBalanceThreshold:
			serde := ruleConfigSerde[notification.BalanceThresholdRuleConfig]{
				RuleConfigMeta: notification.RuleConfigMeta{
					Type: config.Type,
				},
				Data: config.BalanceThreshold,
			}
			return json.Marshal(serde)
		default:
			return nil, fmt.Errorf("unknown rule config type: %s", config.Type)
		}
	},
	S: func(ns *sql.NullString) (notification.RuleConfig, error) {
		var ruleConfig notification.RuleConfig
		if ns == nil || !ns.Valid {
			return ruleConfig, nil
		}

		data := []byte(ns.String)

		var meta notification.RuleConfigMeta
		if err := json.Unmarshal(data, &meta); err != nil {
			return ruleConfig, err
		}

		switch meta.Type {
		case notification.RuleTypeBalanceThreshold:
			serde := ruleConfigSerde[notification.BalanceThresholdRuleConfig]{
				RuleConfigMeta: notification.RuleConfigMeta{
					Type: meta.Type,
				},
				Data: notification.BalanceThresholdRuleConfig{},
			}

			if err := json.Unmarshal(data, &serde); err != nil {
				return ruleConfig, err
			}

			ruleConfig = notification.RuleConfig{
				RuleConfigMeta:   serde.RuleConfigMeta,
				BalanceThreshold: serde.Data,
			}

		default:
			return ruleConfig, fmt.Errorf("unknown rule type: %s", meta.Type)
		}

		return ruleConfig, nil
	},
}

Functions

This section is empty.

Types

type BalanceSnapshot

type BalanceSnapshot struct {
	ent.Schema
}

func (BalanceSnapshot) Edges

func (BalanceSnapshot) Edges() []ent.Edge

func (BalanceSnapshot) Fields

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

func (BalanceSnapshot) Indexes

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

func (BalanceSnapshot) Mixin

func (BalanceSnapshot) Mixin() []ent.Mixin

type Entitlement

type Entitlement struct {
	ent.Schema
}

func (Entitlement) Edges

func (Entitlement) Edges() []ent.Edge

func (Entitlement) Fields

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

func (Entitlement) Indexes

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

func (Entitlement) Mixin

func (Entitlement) Mixin() []ent.Mixin

type Feature

type Feature struct {
	ent.Schema
}

func (Feature) Edges

func (Feature) Edges() []ent.Edge

func (Feature) Fields

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

func (Feature) Indexes

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

func (Feature) Mixin

func (Feature) Mixin() []ent.Mixin

type Grant

type Grant struct {
	ent.Schema
}

func (Grant) Edges

func (Grant) Edges() []ent.Edge

func (Grant) Fields

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

func (Grant) Indexes

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

func (Grant) Mixin

func (Grant) Mixin() []ent.Mixin

type NotificationChannel

type NotificationChannel struct {
	ent.Schema
}

func (NotificationChannel) Edges

func (NotificationChannel) Edges() []ent.Edge

func (NotificationChannel) Fields

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

func (NotificationChannel) Indexes

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

func (NotificationChannel) Mixin

func (NotificationChannel) Mixin() []ent.Mixin

type NotificationEvent

type NotificationEvent struct {
	ent.Schema
}

func (NotificationEvent) Edges

func (NotificationEvent) Edges() []ent.Edge

func (NotificationEvent) Fields

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

func (NotificationEvent) Indexes

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

func (NotificationEvent) Mixin

func (NotificationEvent) Mixin() []ent.Mixin

type NotificationEventDeliveryStatus

type NotificationEventDeliveryStatus struct {
	ent.Schema
}

func (NotificationEventDeliveryStatus) Edges

func (NotificationEventDeliveryStatus) Fields

func (NotificationEventDeliveryStatus) Indexes

func (NotificationEventDeliveryStatus) Mixin

type NotificationRule

type NotificationRule struct {
	ent.Schema
}

func (NotificationRule) Edges

func (NotificationRule) Edges() []ent.Edge

func (NotificationRule) Fields

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

func (NotificationRule) Indexes

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

func (NotificationRule) Mixin

func (NotificationRule) Mixin() []ent.Mixin

type UsageReset

type UsageReset struct {
	ent.Schema
}

func (UsageReset) Edges

func (UsageReset) Edges() []ent.Edge

func (UsageReset) Fields

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

func (UsageReset) Indexes

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

func (UsageReset) Mixin

func (UsageReset) Mixin() []ent.Mixin

Jump to

Keyboard shortcuts

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