| |
|
|
| package addon |
|
|
| import ( |
| "fmt" |
| "time" |
|
|
| "entgo.io/ent/dialect/sql" |
| "entgo.io/ent/dialect/sql/sqlgraph" |
| "entgo.io/ent/schema/field" |
| "github.com/openmeterio/openmeter/openmeter/productcatalog" |
| "github.com/openmeterio/openmeter/pkg/models" |
| ) |
|
|
| const ( |
| |
| Label = "addon" |
| |
| FieldID = "id" |
| |
| FieldNamespace = "namespace" |
| |
| FieldMetadata = "metadata" |
| |
| FieldCreatedAt = "created_at" |
| |
| FieldUpdatedAt = "updated_at" |
| |
| FieldDeletedAt = "deleted_at" |
| |
| FieldName = "name" |
| |
| FieldDescription = "description" |
| |
| FieldKey = "key" |
| |
| FieldVersion = "version" |
| |
| FieldCurrency = "currency" |
| |
| FieldInstanceType = "instance_type" |
| |
| FieldEffectiveFrom = "effective_from" |
| |
| FieldEffectiveTo = "effective_to" |
| |
| FieldAnnotations = "annotations" |
| |
| EdgeRatecards = "ratecards" |
| |
| EdgePlans = "plans" |
| |
| EdgeSubscriptionAddons = "subscription_addons" |
| |
| Table = "addons" |
| |
| RatecardsTable = "addon_rate_cards" |
| |
| |
| RatecardsInverseTable = "addon_rate_cards" |
| |
| RatecardsColumn = "addon_id" |
| |
| PlansTable = "plan_addons" |
| |
| |
| PlansInverseTable = "plan_addons" |
| |
| PlansColumn = "addon_id" |
| |
| SubscriptionAddonsTable = "subscription_addons" |
| |
| |
| SubscriptionAddonsInverseTable = "subscription_addons" |
| |
| SubscriptionAddonsColumn = "addon_id" |
| ) |
|
|
| |
| var Columns = []string{ |
| FieldID, |
| FieldNamespace, |
| FieldMetadata, |
| FieldCreatedAt, |
| FieldUpdatedAt, |
| FieldDeletedAt, |
| FieldName, |
| FieldDescription, |
| FieldKey, |
| FieldVersion, |
| FieldCurrency, |
| FieldInstanceType, |
| FieldEffectiveFrom, |
| FieldEffectiveTo, |
| FieldAnnotations, |
| } |
|
|
| |
| func ValidColumn(column string) bool { |
| for i := range Columns { |
| if column == Columns[i] { |
| return true |
| } |
| } |
| return false |
| } |
|
|
| var ( |
| |
| NamespaceValidator func(string) error |
| |
| DefaultCreatedAt func() time.Time |
| |
| DefaultUpdatedAt func() time.Time |
| |
| UpdateDefaultUpdatedAt func() time.Time |
| |
| KeyValidator func(string) error |
| |
| VersionValidator func(int) error |
| |
| DefaultCurrency string |
| |
| CurrencyValidator func(string) error |
| |
| DefaultID func() string |
| |
| ValueScanner struct { |
| Annotations field.TypeValueScanner[models.Annotations] |
| } |
| ) |
|
|
| const DefaultInstanceType productcatalog.AddonInstanceType = "single" |
|
|
| |
| func InstanceTypeValidator(it productcatalog.AddonInstanceType) error { |
| switch it { |
| case "single", "multiple": |
| return nil |
| default: |
| return fmt.Errorf("addon: invalid enum value for instance_type field: %q", it) |
| } |
| } |
|
|
| |
| type OrderOption func(*sql.Selector) |
|
|
| |
| func ByID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldID, opts...).ToFunc() |
| } |
|
|
| |
| func ByNamespace(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldNamespace, opts...).ToFunc() |
| } |
|
|
| |
| func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() |
| } |
|
|
| |
| func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() |
| } |
|
|
| |
| func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() |
| } |
|
|
| |
| func ByName(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldName, opts...).ToFunc() |
| } |
|
|
| |
| func ByDescription(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldDescription, opts...).ToFunc() |
| } |
|
|
| |
| func ByKey(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldKey, opts...).ToFunc() |
| } |
|
|
| |
| func ByVersion(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldVersion, opts...).ToFunc() |
| } |
|
|
| |
| func ByCurrency(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldCurrency, opts...).ToFunc() |
| } |
|
|
| |
| func ByInstanceType(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldInstanceType, opts...).ToFunc() |
| } |
|
|
| |
| func ByEffectiveFrom(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldEffectiveFrom, opts...).ToFunc() |
| } |
|
|
| |
| func ByEffectiveTo(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldEffectiveTo, opts...).ToFunc() |
| } |
|
|
| |
| func ByAnnotations(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldAnnotations, opts...).ToFunc() |
| } |
|
|
| |
| func ByRatecardsCount(opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborsCount(s, newRatecardsStep(), opts...) |
| } |
| } |
|
|
| |
| func ByRatecards(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newRatecardsStep(), append([]sql.OrderTerm{term}, terms...)...) |
| } |
| } |
|
|
| |
| func ByPlansCount(opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborsCount(s, newPlansStep(), opts...) |
| } |
| } |
|
|
| |
| func ByPlans(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newPlansStep(), append([]sql.OrderTerm{term}, terms...)...) |
| } |
| } |
|
|
| |
| func BySubscriptionAddonsCount(opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborsCount(s, newSubscriptionAddonsStep(), opts...) |
| } |
| } |
|
|
| |
| func BySubscriptionAddons(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newSubscriptionAddonsStep(), append([]sql.OrderTerm{term}, terms...)...) |
| } |
| } |
| func newRatecardsStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(RatecardsInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.O2M, false, RatecardsTable, RatecardsColumn), |
| ) |
| } |
| func newPlansStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(PlansInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.O2M, false, PlansTable, PlansColumn), |
| ) |
| } |
| func newSubscriptionAddonsStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(SubscriptionAddonsInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.O2M, false, SubscriptionAddonsTable, SubscriptionAddonsColumn), |
| ) |
| } |
|
|