mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
feat: support push notification clients
This commit is contained in:
192
ent/client.go
192
ent/client.go
@@ -16,6 +16,7 @@ import (
|
||||
"polaris/ent/history"
|
||||
"polaris/ent/indexers"
|
||||
"polaris/ent/media"
|
||||
"polaris/ent/notificationclient"
|
||||
"polaris/ent/settings"
|
||||
"polaris/ent/storage"
|
||||
|
||||
@@ -40,6 +41,8 @@ type Client struct {
|
||||
Indexers *IndexersClient
|
||||
// Media is the client for interacting with the Media builders.
|
||||
Media *MediaClient
|
||||
// NotificationClient is the client for interacting with the NotificationClient builders.
|
||||
NotificationClient *NotificationClientClient
|
||||
// Settings is the client for interacting with the Settings builders.
|
||||
Settings *SettingsClient
|
||||
// Storage is the client for interacting with the Storage builders.
|
||||
@@ -60,6 +63,7 @@ func (c *Client) init() {
|
||||
c.History = NewHistoryClient(c.config)
|
||||
c.Indexers = NewIndexersClient(c.config)
|
||||
c.Media = NewMediaClient(c.config)
|
||||
c.NotificationClient = NewNotificationClientClient(c.config)
|
||||
c.Settings = NewSettingsClient(c.config)
|
||||
c.Storage = NewStorageClient(c.config)
|
||||
}
|
||||
@@ -152,15 +156,16 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
cfg := c.config
|
||||
cfg.driver = tx
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
Indexers: NewIndexersClient(cfg),
|
||||
Media: NewMediaClient(cfg),
|
||||
Settings: NewSettingsClient(cfg),
|
||||
Storage: NewStorageClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
Indexers: NewIndexersClient(cfg),
|
||||
Media: NewMediaClient(cfg),
|
||||
NotificationClient: NewNotificationClientClient(cfg),
|
||||
Settings: NewSettingsClient(cfg),
|
||||
Storage: NewStorageClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -178,15 +183,16 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
cfg := c.config
|
||||
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
Indexers: NewIndexersClient(cfg),
|
||||
Media: NewMediaClient(cfg),
|
||||
Settings: NewSettingsClient(cfg),
|
||||
Storage: NewStorageClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
Indexers: NewIndexersClient(cfg),
|
||||
Media: NewMediaClient(cfg),
|
||||
NotificationClient: NewNotificationClientClient(cfg),
|
||||
Settings: NewSettingsClient(cfg),
|
||||
Storage: NewStorageClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -216,8 +222,8 @@ func (c *Client) Close() error {
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media, c.Settings,
|
||||
c.Storage,
|
||||
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -227,8 +233,8 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media, c.Settings,
|
||||
c.Storage,
|
||||
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -247,6 +253,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
return c.Indexers.mutate(ctx, m)
|
||||
case *MediaMutation:
|
||||
return c.Media.mutate(ctx, m)
|
||||
case *NotificationClientMutation:
|
||||
return c.NotificationClient.mutate(ctx, m)
|
||||
case *SettingsMutation:
|
||||
return c.Settings.mutate(ctx, m)
|
||||
case *StorageMutation:
|
||||
@@ -953,6 +961,139 @@ func (c *MediaClient) mutate(ctx context.Context, m *MediaMutation) (Value, erro
|
||||
}
|
||||
}
|
||||
|
||||
// NotificationClientClient is a client for the NotificationClient schema.
|
||||
type NotificationClientClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewNotificationClientClient returns a client for the NotificationClient from the given config.
|
||||
func NewNotificationClientClient(c config) *NotificationClientClient {
|
||||
return &NotificationClientClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `notificationclient.Hooks(f(g(h())))`.
|
||||
func (c *NotificationClientClient) Use(hooks ...Hook) {
|
||||
c.hooks.NotificationClient = append(c.hooks.NotificationClient, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `notificationclient.Intercept(f(g(h())))`.
|
||||
func (c *NotificationClientClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.NotificationClient = append(c.inters.NotificationClient, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a NotificationClient entity.
|
||||
func (c *NotificationClientClient) Create() *NotificationClientCreate {
|
||||
mutation := newNotificationClientMutation(c.config, OpCreate)
|
||||
return &NotificationClientCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of NotificationClient entities.
|
||||
func (c *NotificationClientClient) CreateBulk(builders ...*NotificationClientCreate) *NotificationClientCreateBulk {
|
||||
return &NotificationClientCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *NotificationClientClient) MapCreateBulk(slice any, setFunc func(*NotificationClientCreate, int)) *NotificationClientCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &NotificationClientCreateBulk{err: fmt.Errorf("calling to NotificationClientClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*NotificationClientCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &NotificationClientCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for NotificationClient.
|
||||
func (c *NotificationClientClient) Update() *NotificationClientUpdate {
|
||||
mutation := newNotificationClientMutation(c.config, OpUpdate)
|
||||
return &NotificationClientUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *NotificationClientClient) UpdateOne(nc *NotificationClient) *NotificationClientUpdateOne {
|
||||
mutation := newNotificationClientMutation(c.config, OpUpdateOne, withNotificationClient(nc))
|
||||
return &NotificationClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *NotificationClientClient) UpdateOneID(id int) *NotificationClientUpdateOne {
|
||||
mutation := newNotificationClientMutation(c.config, OpUpdateOne, withNotificationClientID(id))
|
||||
return &NotificationClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for NotificationClient.
|
||||
func (c *NotificationClientClient) Delete() *NotificationClientDelete {
|
||||
mutation := newNotificationClientMutation(c.config, OpDelete)
|
||||
return &NotificationClientDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *NotificationClientClient) DeleteOne(nc *NotificationClient) *NotificationClientDeleteOne {
|
||||
return c.DeleteOneID(nc.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *NotificationClientClient) DeleteOneID(id int) *NotificationClientDeleteOne {
|
||||
builder := c.Delete().Where(notificationclient.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &NotificationClientDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for NotificationClient.
|
||||
func (c *NotificationClientClient) Query() *NotificationClientQuery {
|
||||
return &NotificationClientQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeNotificationClient},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a NotificationClient entity by its id.
|
||||
func (c *NotificationClientClient) Get(ctx context.Context, id int) (*NotificationClient, error) {
|
||||
return c.Query().Where(notificationclient.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *NotificationClientClient) GetX(ctx context.Context, id int) *NotificationClient {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *NotificationClientClient) Hooks() []Hook {
|
||||
return c.hooks.NotificationClient
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *NotificationClientClient) Interceptors() []Interceptor {
|
||||
return c.inters.NotificationClient
|
||||
}
|
||||
|
||||
func (c *NotificationClientClient) mutate(ctx context.Context, m *NotificationClientMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&NotificationClientCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&NotificationClientUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&NotificationClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&NotificationClientDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown NotificationClient mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SettingsClient is a client for the Settings schema.
|
||||
type SettingsClient struct {
|
||||
config
|
||||
@@ -1222,10 +1363,11 @@ func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value,
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
DownloadClients, Episode, History, Indexers, Media, Settings, Storage []ent.Hook
|
||||
DownloadClients, Episode, History, Indexers, Media, NotificationClient,
|
||||
Settings, Storage []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
DownloadClients, Episode, History, Indexers, Media, Settings,
|
||||
Storage []ent.Interceptor
|
||||
DownloadClients, Episode, History, Indexers, Media, NotificationClient,
|
||||
Settings, Storage []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
16
ent/ent.go
16
ent/ent.go
@@ -11,6 +11,7 @@ import (
|
||||
"polaris/ent/history"
|
||||
"polaris/ent/indexers"
|
||||
"polaris/ent/media"
|
||||
"polaris/ent/notificationclient"
|
||||
"polaris/ent/settings"
|
||||
"polaris/ent/storage"
|
||||
"reflect"
|
||||
@@ -79,13 +80,14 @@ var (
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
downloadclients.Table: downloadclients.ValidColumn,
|
||||
episode.Table: episode.ValidColumn,
|
||||
history.Table: history.ValidColumn,
|
||||
indexers.Table: indexers.ValidColumn,
|
||||
media.Table: media.ValidColumn,
|
||||
settings.Table: settings.ValidColumn,
|
||||
storage.Table: storage.ValidColumn,
|
||||
downloadclients.Table: downloadclients.ValidColumn,
|
||||
episode.Table: episode.ValidColumn,
|
||||
history.Table: history.ValidColumn,
|
||||
indexers.Table: indexers.ValidColumn,
|
||||
media.Table: media.ValidColumn,
|
||||
notificationclient.Table: notificationclient.ValidColumn,
|
||||
settings.Table: settings.ValidColumn,
|
||||
storage.Table: storage.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(table, column)
|
||||
|
||||
@@ -68,6 +68,18 @@ func (f MediaFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MediaMutation", m)
|
||||
}
|
||||
|
||||
// The NotificationClientFunc type is an adapter to allow the use of ordinary
|
||||
// function as NotificationClient mutator.
|
||||
type NotificationClientFunc func(context.Context, *ent.NotificationClientMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f NotificationClientFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.NotificationClientMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.NotificationClientMutation", m)
|
||||
}
|
||||
|
||||
// The SettingsFunc type is an adapter to allow the use of ordinary
|
||||
// function as Settings mutator.
|
||||
type SettingsFunc func(context.Context, *ent.SettingsMutation) (ent.Value, error)
|
||||
|
||||
@@ -110,6 +110,20 @@ var (
|
||||
Columns: MediaColumns,
|
||||
PrimaryKey: []*schema.Column{MediaColumns[0]},
|
||||
}
|
||||
// NotificationClientsColumns holds the columns for the "notification_clients" table.
|
||||
NotificationClientsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "service", Type: field.TypeString},
|
||||
{Name: "settings", Type: field.TypeString},
|
||||
{Name: "enabled", Type: field.TypeBool, Default: true},
|
||||
}
|
||||
// NotificationClientsTable holds the schema information for the "notification_clients" table.
|
||||
NotificationClientsTable = &schema.Table{
|
||||
Name: "notification_clients",
|
||||
Columns: NotificationClientsColumns,
|
||||
PrimaryKey: []*schema.Column{NotificationClientsColumns[0]},
|
||||
}
|
||||
// SettingsColumns holds the columns for the "settings" table.
|
||||
SettingsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@@ -144,6 +158,7 @@ var (
|
||||
HistoriesTable,
|
||||
IndexersTable,
|
||||
MediaTable,
|
||||
NotificationClientsTable,
|
||||
SettingsTable,
|
||||
StoragesTable,
|
||||
}
|
||||
|
||||
504
ent/mutation.go
504
ent/mutation.go
@@ -11,6 +11,7 @@ import (
|
||||
"polaris/ent/history"
|
||||
"polaris/ent/indexers"
|
||||
"polaris/ent/media"
|
||||
"polaris/ent/notificationclient"
|
||||
"polaris/ent/predicate"
|
||||
"polaris/ent/settings"
|
||||
"polaris/ent/storage"
|
||||
@@ -30,13 +31,14 @@ const (
|
||||
OpUpdateOne = ent.OpUpdateOne
|
||||
|
||||
// Node types.
|
||||
TypeDownloadClients = "DownloadClients"
|
||||
TypeEpisode = "Episode"
|
||||
TypeHistory = "History"
|
||||
TypeIndexers = "Indexers"
|
||||
TypeMedia = "Media"
|
||||
TypeSettings = "Settings"
|
||||
TypeStorage = "Storage"
|
||||
TypeDownloadClients = "DownloadClients"
|
||||
TypeEpisode = "Episode"
|
||||
TypeHistory = "History"
|
||||
TypeIndexers = "Indexers"
|
||||
TypeMedia = "Media"
|
||||
TypeNotificationClient = "NotificationClient"
|
||||
TypeSettings = "Settings"
|
||||
TypeStorage = "Storage"
|
||||
)
|
||||
|
||||
// DownloadClientsMutation represents an operation that mutates the DownloadClients nodes in the graph.
|
||||
@@ -4342,6 +4344,494 @@ func (m *MediaMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Media edge %s", name)
|
||||
}
|
||||
|
||||
// NotificationClientMutation represents an operation that mutates the NotificationClient nodes in the graph.
|
||||
type NotificationClientMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
name *string
|
||||
service *string
|
||||
settings *string
|
||||
enabled *bool
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*NotificationClient, error)
|
||||
predicates []predicate.NotificationClient
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*NotificationClientMutation)(nil)
|
||||
|
||||
// notificationclientOption allows management of the mutation configuration using functional options.
|
||||
type notificationclientOption func(*NotificationClientMutation)
|
||||
|
||||
// newNotificationClientMutation creates new mutation for the NotificationClient entity.
|
||||
func newNotificationClientMutation(c config, op Op, opts ...notificationclientOption) *NotificationClientMutation {
|
||||
m := &NotificationClientMutation{
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeNotificationClient,
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// withNotificationClientID sets the ID field of the mutation.
|
||||
func withNotificationClientID(id int) notificationclientOption {
|
||||
return func(m *NotificationClientMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *NotificationClient
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*NotificationClient, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().NotificationClient.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withNotificationClient sets the old NotificationClient of the mutation.
|
||||
func withNotificationClient(node *NotificationClient) notificationclientOption {
|
||||
return func(m *NotificationClientMutation) {
|
||||
m.oldValue = func(context.Context) (*NotificationClient, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m NotificationClientMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m NotificationClientMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *NotificationClientMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *NotificationClientMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().NotificationClient.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *NotificationClientMutation) SetName(s string) {
|
||||
m.name = &s
|
||||
}
|
||||
|
||||
// Name returns the value of the "name" field in the mutation.
|
||||
func (m *NotificationClientMutation) Name() (r string, exists bool) {
|
||||
v := m.name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldName returns the old "name" field's value of the NotificationClient entity.
|
||||
// If the NotificationClient object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NotificationClientMutation) OldName(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldName requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
||||
}
|
||||
return oldValue.Name, nil
|
||||
}
|
||||
|
||||
// ResetName resets all changes to the "name" field.
|
||||
func (m *NotificationClientMutation) ResetName() {
|
||||
m.name = nil
|
||||
}
|
||||
|
||||
// SetService sets the "service" field.
|
||||
func (m *NotificationClientMutation) SetService(s string) {
|
||||
m.service = &s
|
||||
}
|
||||
|
||||
// Service returns the value of the "service" field in the mutation.
|
||||
func (m *NotificationClientMutation) Service() (r string, exists bool) {
|
||||
v := m.service
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldService returns the old "service" field's value of the NotificationClient entity.
|
||||
// If the NotificationClient object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NotificationClientMutation) OldService(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldService is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldService requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldService: %w", err)
|
||||
}
|
||||
return oldValue.Service, nil
|
||||
}
|
||||
|
||||
// ResetService resets all changes to the "service" field.
|
||||
func (m *NotificationClientMutation) ResetService() {
|
||||
m.service = nil
|
||||
}
|
||||
|
||||
// SetSettings sets the "settings" field.
|
||||
func (m *NotificationClientMutation) SetSettings(s string) {
|
||||
m.settings = &s
|
||||
}
|
||||
|
||||
// Settings returns the value of the "settings" field in the mutation.
|
||||
func (m *NotificationClientMutation) Settings() (r string, exists bool) {
|
||||
v := m.settings
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldSettings returns the old "settings" field's value of the NotificationClient entity.
|
||||
// If the NotificationClient object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NotificationClientMutation) OldSettings(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldSettings is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldSettings requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldSettings: %w", err)
|
||||
}
|
||||
return oldValue.Settings, nil
|
||||
}
|
||||
|
||||
// ResetSettings resets all changes to the "settings" field.
|
||||
func (m *NotificationClientMutation) ResetSettings() {
|
||||
m.settings = nil
|
||||
}
|
||||
|
||||
// SetEnabled sets the "enabled" field.
|
||||
func (m *NotificationClientMutation) SetEnabled(b bool) {
|
||||
m.enabled = &b
|
||||
}
|
||||
|
||||
// Enabled returns the value of the "enabled" field in the mutation.
|
||||
func (m *NotificationClientMutation) Enabled() (r bool, exists bool) {
|
||||
v := m.enabled
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldEnabled returns the old "enabled" field's value of the NotificationClient entity.
|
||||
// If the NotificationClient object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NotificationClientMutation) OldEnabled(ctx context.Context) (v bool, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldEnabled is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldEnabled requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldEnabled: %w", err)
|
||||
}
|
||||
return oldValue.Enabled, nil
|
||||
}
|
||||
|
||||
// ResetEnabled resets all changes to the "enabled" field.
|
||||
func (m *NotificationClientMutation) ResetEnabled() {
|
||||
m.enabled = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotificationClientMutation builder.
|
||||
func (m *NotificationClientMutation) Where(ps ...predicate.NotificationClient) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the NotificationClientMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *NotificationClientMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.NotificationClient, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *NotificationClientMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *NotificationClientMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (NotificationClient).
|
||||
func (m *NotificationClientMutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *NotificationClientMutation) Fields() []string {
|
||||
fields := make([]string, 0, 4)
|
||||
if m.name != nil {
|
||||
fields = append(fields, notificationclient.FieldName)
|
||||
}
|
||||
if m.service != nil {
|
||||
fields = append(fields, notificationclient.FieldService)
|
||||
}
|
||||
if m.settings != nil {
|
||||
fields = append(fields, notificationclient.FieldSettings)
|
||||
}
|
||||
if m.enabled != nil {
|
||||
fields = append(fields, notificationclient.FieldEnabled)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *NotificationClientMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case notificationclient.FieldName:
|
||||
return m.Name()
|
||||
case notificationclient.FieldService:
|
||||
return m.Service()
|
||||
case notificationclient.FieldSettings:
|
||||
return m.Settings()
|
||||
case notificationclient.FieldEnabled:
|
||||
return m.Enabled()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *NotificationClientMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case notificationclient.FieldName:
|
||||
return m.OldName(ctx)
|
||||
case notificationclient.FieldService:
|
||||
return m.OldService(ctx)
|
||||
case notificationclient.FieldSettings:
|
||||
return m.OldSettings(ctx)
|
||||
case notificationclient.FieldEnabled:
|
||||
return m.OldEnabled(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown NotificationClient field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *NotificationClientMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case notificationclient.FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetName(v)
|
||||
return nil
|
||||
case notificationclient.FieldService:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetService(v)
|
||||
return nil
|
||||
case notificationclient.FieldSettings:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetSettings(v)
|
||||
return nil
|
||||
case notificationclient.FieldEnabled:
|
||||
v, ok := value.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetEnabled(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown NotificationClient field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *NotificationClientMutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *NotificationClientMutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *NotificationClientMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown NotificationClient numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *NotificationClientMutation) ClearedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *NotificationClientMutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *NotificationClientMutation) ClearField(name string) error {
|
||||
return fmt.Errorf("unknown NotificationClient nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *NotificationClientMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case notificationclient.FieldName:
|
||||
m.ResetName()
|
||||
return nil
|
||||
case notificationclient.FieldService:
|
||||
m.ResetService()
|
||||
return nil
|
||||
case notificationclient.FieldSettings:
|
||||
m.ResetSettings()
|
||||
return nil
|
||||
case notificationclient.FieldEnabled:
|
||||
m.ResetEnabled()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown NotificationClient field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *NotificationClientMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *NotificationClientMutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *NotificationClientMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *NotificationClientMutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *NotificationClientMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *NotificationClientMutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *NotificationClientMutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown NotificationClient unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *NotificationClientMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown NotificationClient edge %s", name)
|
||||
}
|
||||
|
||||
// SettingsMutation represents an operation that mutates the Settings nodes in the graph.
|
||||
type SettingsMutation struct {
|
||||
config
|
||||
|
||||
138
ent/notificationclient.go
Normal file
138
ent/notificationclient.go
Normal file
@@ -0,0 +1,138 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/ent/notificationclient"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// NotificationClient is the model entity for the NotificationClient schema.
|
||||
type NotificationClient struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Service holds the value of the "service" field.
|
||||
Service string `json:"service,omitempty"`
|
||||
// Settings holds the value of the "settings" field.
|
||||
Settings string `json:"settings,omitempty"`
|
||||
// Enabled holds the value of the "enabled" field.
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*NotificationClient) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case notificationclient.FieldEnabled:
|
||||
values[i] = new(sql.NullBool)
|
||||
case notificationclient.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case notificationclient.FieldName, notificationclient.FieldService, notificationclient.FieldSettings:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the NotificationClient fields.
|
||||
func (nc *NotificationClient) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case notificationclient.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
nc.ID = int(value.Int64)
|
||||
case notificationclient.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
nc.Name = value.String
|
||||
}
|
||||
case notificationclient.FieldService:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field service", values[i])
|
||||
} else if value.Valid {
|
||||
nc.Service = value.String
|
||||
}
|
||||
case notificationclient.FieldSettings:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field settings", values[i])
|
||||
} else if value.Valid {
|
||||
nc.Settings = value.String
|
||||
}
|
||||
case notificationclient.FieldEnabled:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field enabled", values[i])
|
||||
} else if value.Valid {
|
||||
nc.Enabled = value.Bool
|
||||
}
|
||||
default:
|
||||
nc.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the NotificationClient.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (nc *NotificationClient) Value(name string) (ent.Value, error) {
|
||||
return nc.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this NotificationClient.
|
||||
// Note that you need to call NotificationClient.Unwrap() before calling this method if this NotificationClient
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (nc *NotificationClient) Update() *NotificationClientUpdateOne {
|
||||
return NewNotificationClientClient(nc.config).UpdateOne(nc)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the NotificationClient entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (nc *NotificationClient) Unwrap() *NotificationClient {
|
||||
_tx, ok := nc.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: NotificationClient is not a transactional entity")
|
||||
}
|
||||
nc.config.driver = _tx.drv
|
||||
return nc
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (nc *NotificationClient) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("NotificationClient(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", nc.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(nc.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("service=")
|
||||
builder.WriteString(nc.Service)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("settings=")
|
||||
builder.WriteString(nc.Settings)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("enabled=")
|
||||
builder.WriteString(fmt.Sprintf("%v", nc.Enabled))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// NotificationClients is a parsable slice of NotificationClient.
|
||||
type NotificationClients []*NotificationClient
|
||||
76
ent/notificationclient/notificationclient.go
Normal file
76
ent/notificationclient/notificationclient.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package notificationclient
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the notificationclient type in the database.
|
||||
Label = "notification_client"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldService holds the string denoting the service field in the database.
|
||||
FieldService = "service"
|
||||
// FieldSettings holds the string denoting the settings field in the database.
|
||||
FieldSettings = "settings"
|
||||
// FieldEnabled holds the string denoting the enabled field in the database.
|
||||
FieldEnabled = "enabled"
|
||||
// Table holds the table name of the notificationclient in the database.
|
||||
Table = "notification_clients"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for notificationclient fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldService,
|
||||
FieldSettings,
|
||||
FieldEnabled,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultEnabled holds the default value on creation for the "enabled" field.
|
||||
DefaultEnabled bool
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the NotificationClient queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByService orders the results by the service field.
|
||||
func ByService(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldService, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySettings orders the results by the settings field.
|
||||
func BySettings(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSettings, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByEnabled orders the results by the enabled field.
|
||||
func ByEnabled(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldEnabled, opts...).ToFunc()
|
||||
}
|
||||
294
ent/notificationclient/where.go
Normal file
294
ent/notificationclient/where.go
Normal file
@@ -0,0 +1,294 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package notificationclient
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Service applies equality check predicate on the "service" field. It's identical to ServiceEQ.
|
||||
func Service(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldService, v))
|
||||
}
|
||||
|
||||
// Settings applies equality check predicate on the "settings" field. It's identical to SettingsEQ.
|
||||
func Settings(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldSettings, v))
|
||||
}
|
||||
|
||||
// Enabled applies equality check predicate on the "enabled" field. It's identical to EnabledEQ.
|
||||
func Enabled(v bool) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldEnabled, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// ServiceEQ applies the EQ predicate on the "service" field.
|
||||
func ServiceEQ(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceNEQ applies the NEQ predicate on the "service" field.
|
||||
func ServiceNEQ(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNEQ(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceIn applies the In predicate on the "service" field.
|
||||
func ServiceIn(vs ...string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldIn(FieldService, vs...))
|
||||
}
|
||||
|
||||
// ServiceNotIn applies the NotIn predicate on the "service" field.
|
||||
func ServiceNotIn(vs ...string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNotIn(FieldService, vs...))
|
||||
}
|
||||
|
||||
// ServiceGT applies the GT predicate on the "service" field.
|
||||
func ServiceGT(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGT(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceGTE applies the GTE predicate on the "service" field.
|
||||
func ServiceGTE(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGTE(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceLT applies the LT predicate on the "service" field.
|
||||
func ServiceLT(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLT(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceLTE applies the LTE predicate on the "service" field.
|
||||
func ServiceLTE(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLTE(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceContains applies the Contains predicate on the "service" field.
|
||||
func ServiceContains(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldContains(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceHasPrefix applies the HasPrefix predicate on the "service" field.
|
||||
func ServiceHasPrefix(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldHasPrefix(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceHasSuffix applies the HasSuffix predicate on the "service" field.
|
||||
func ServiceHasSuffix(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldHasSuffix(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceEqualFold applies the EqualFold predicate on the "service" field.
|
||||
func ServiceEqualFold(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEqualFold(FieldService, v))
|
||||
}
|
||||
|
||||
// ServiceContainsFold applies the ContainsFold predicate on the "service" field.
|
||||
func ServiceContainsFold(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldContainsFold(FieldService, v))
|
||||
}
|
||||
|
||||
// SettingsEQ applies the EQ predicate on the "settings" field.
|
||||
func SettingsEQ(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsNEQ applies the NEQ predicate on the "settings" field.
|
||||
func SettingsNEQ(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNEQ(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsIn applies the In predicate on the "settings" field.
|
||||
func SettingsIn(vs ...string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldIn(FieldSettings, vs...))
|
||||
}
|
||||
|
||||
// SettingsNotIn applies the NotIn predicate on the "settings" field.
|
||||
func SettingsNotIn(vs ...string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNotIn(FieldSettings, vs...))
|
||||
}
|
||||
|
||||
// SettingsGT applies the GT predicate on the "settings" field.
|
||||
func SettingsGT(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGT(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsGTE applies the GTE predicate on the "settings" field.
|
||||
func SettingsGTE(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldGTE(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsLT applies the LT predicate on the "settings" field.
|
||||
func SettingsLT(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLT(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsLTE applies the LTE predicate on the "settings" field.
|
||||
func SettingsLTE(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldLTE(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsContains applies the Contains predicate on the "settings" field.
|
||||
func SettingsContains(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldContains(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsHasPrefix applies the HasPrefix predicate on the "settings" field.
|
||||
func SettingsHasPrefix(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldHasPrefix(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsHasSuffix applies the HasSuffix predicate on the "settings" field.
|
||||
func SettingsHasSuffix(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldHasSuffix(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsEqualFold applies the EqualFold predicate on the "settings" field.
|
||||
func SettingsEqualFold(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEqualFold(FieldSettings, v))
|
||||
}
|
||||
|
||||
// SettingsContainsFold applies the ContainsFold predicate on the "settings" field.
|
||||
func SettingsContainsFold(v string) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldContainsFold(FieldSettings, v))
|
||||
}
|
||||
|
||||
// EnabledEQ applies the EQ predicate on the "enabled" field.
|
||||
func EnabledEQ(v bool) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldEQ(FieldEnabled, v))
|
||||
}
|
||||
|
||||
// EnabledNEQ applies the NEQ predicate on the "enabled" field.
|
||||
func EnabledNEQ(v bool) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.FieldNEQ(FieldEnabled, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.NotificationClient) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.NotificationClient) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.NotificationClient) predicate.NotificationClient {
|
||||
return predicate.NotificationClient(sql.NotPredicates(p))
|
||||
}
|
||||
240
ent/notificationclient_create.go
Normal file
240
ent/notificationclient_create.go
Normal file
@@ -0,0 +1,240 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/notificationclient"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NotificationClientCreate is the builder for creating a NotificationClient entity.
|
||||
type NotificationClientCreate struct {
|
||||
config
|
||||
mutation *NotificationClientMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (ncc *NotificationClientCreate) SetName(s string) *NotificationClientCreate {
|
||||
ncc.mutation.SetName(s)
|
||||
return ncc
|
||||
}
|
||||
|
||||
// SetService sets the "service" field.
|
||||
func (ncc *NotificationClientCreate) SetService(s string) *NotificationClientCreate {
|
||||
ncc.mutation.SetService(s)
|
||||
return ncc
|
||||
}
|
||||
|
||||
// SetSettings sets the "settings" field.
|
||||
func (ncc *NotificationClientCreate) SetSettings(s string) *NotificationClientCreate {
|
||||
ncc.mutation.SetSettings(s)
|
||||
return ncc
|
||||
}
|
||||
|
||||
// SetEnabled sets the "enabled" field.
|
||||
func (ncc *NotificationClientCreate) SetEnabled(b bool) *NotificationClientCreate {
|
||||
ncc.mutation.SetEnabled(b)
|
||||
return ncc
|
||||
}
|
||||
|
||||
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
||||
func (ncc *NotificationClientCreate) SetNillableEnabled(b *bool) *NotificationClientCreate {
|
||||
if b != nil {
|
||||
ncc.SetEnabled(*b)
|
||||
}
|
||||
return ncc
|
||||
}
|
||||
|
||||
// Mutation returns the NotificationClientMutation object of the builder.
|
||||
func (ncc *NotificationClientCreate) Mutation() *NotificationClientMutation {
|
||||
return ncc.mutation
|
||||
}
|
||||
|
||||
// Save creates the NotificationClient in the database.
|
||||
func (ncc *NotificationClientCreate) Save(ctx context.Context) (*NotificationClient, error) {
|
||||
ncc.defaults()
|
||||
return withHooks(ctx, ncc.sqlSave, ncc.mutation, ncc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (ncc *NotificationClientCreate) SaveX(ctx context.Context) *NotificationClient {
|
||||
v, err := ncc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ncc *NotificationClientCreate) Exec(ctx context.Context) error {
|
||||
_, err := ncc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ncc *NotificationClientCreate) ExecX(ctx context.Context) {
|
||||
if err := ncc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (ncc *NotificationClientCreate) defaults() {
|
||||
if _, ok := ncc.mutation.Enabled(); !ok {
|
||||
v := notificationclient.DefaultEnabled
|
||||
ncc.mutation.SetEnabled(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ncc *NotificationClientCreate) check() error {
|
||||
if _, ok := ncc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "NotificationClient.name"`)}
|
||||
}
|
||||
if _, ok := ncc.mutation.Service(); !ok {
|
||||
return &ValidationError{Name: "service", err: errors.New(`ent: missing required field "NotificationClient.service"`)}
|
||||
}
|
||||
if _, ok := ncc.mutation.Settings(); !ok {
|
||||
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "NotificationClient.settings"`)}
|
||||
}
|
||||
if _, ok := ncc.mutation.Enabled(); !ok {
|
||||
return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "NotificationClient.enabled"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ncc *NotificationClientCreate) sqlSave(ctx context.Context) (*NotificationClient, error) {
|
||||
if err := ncc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := ncc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, ncc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
ncc.mutation.id = &_node.ID
|
||||
ncc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (ncc *NotificationClientCreate) createSpec() (*NotificationClient, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &NotificationClient{config: ncc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(notificationclient.Table, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := ncc.mutation.Name(); ok {
|
||||
_spec.SetField(notificationclient.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := ncc.mutation.Service(); ok {
|
||||
_spec.SetField(notificationclient.FieldService, field.TypeString, value)
|
||||
_node.Service = value
|
||||
}
|
||||
if value, ok := ncc.mutation.Settings(); ok {
|
||||
_spec.SetField(notificationclient.FieldSettings, field.TypeString, value)
|
||||
_node.Settings = value
|
||||
}
|
||||
if value, ok := ncc.mutation.Enabled(); ok {
|
||||
_spec.SetField(notificationclient.FieldEnabled, field.TypeBool, value)
|
||||
_node.Enabled = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// NotificationClientCreateBulk is the builder for creating many NotificationClient entities in bulk.
|
||||
type NotificationClientCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*NotificationClientCreate
|
||||
}
|
||||
|
||||
// Save creates the NotificationClient entities in the database.
|
||||
func (nccb *NotificationClientCreateBulk) Save(ctx context.Context) ([]*NotificationClient, error) {
|
||||
if nccb.err != nil {
|
||||
return nil, nccb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(nccb.builders))
|
||||
nodes := make([]*NotificationClient, len(nccb.builders))
|
||||
mutators := make([]Mutator, len(nccb.builders))
|
||||
for i := range nccb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := nccb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*NotificationClientMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, nccb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, nccb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, nccb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (nccb *NotificationClientCreateBulk) SaveX(ctx context.Context) []*NotificationClient {
|
||||
v, err := nccb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (nccb *NotificationClientCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := nccb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (nccb *NotificationClientCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := nccb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
ent/notificationclient_delete.go
Normal file
88
ent/notificationclient_delete.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"polaris/ent/notificationclient"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NotificationClientDelete is the builder for deleting a NotificationClient entity.
|
||||
type NotificationClientDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *NotificationClientMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotificationClientDelete builder.
|
||||
func (ncd *NotificationClientDelete) Where(ps ...predicate.NotificationClient) *NotificationClientDelete {
|
||||
ncd.mutation.Where(ps...)
|
||||
return ncd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ncd *NotificationClientDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, ncd.sqlExec, ncd.mutation, ncd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ncd *NotificationClientDelete) ExecX(ctx context.Context) int {
|
||||
n, err := ncd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (ncd *NotificationClientDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(notificationclient.Table, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
|
||||
if ps := ncd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ncd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ncd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// NotificationClientDeleteOne is the builder for deleting a single NotificationClient entity.
|
||||
type NotificationClientDeleteOne struct {
|
||||
ncd *NotificationClientDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotificationClientDelete builder.
|
||||
func (ncdo *NotificationClientDeleteOne) Where(ps ...predicate.NotificationClient) *NotificationClientDeleteOne {
|
||||
ncdo.ncd.mutation.Where(ps...)
|
||||
return ncdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ncdo *NotificationClientDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ncdo.ncd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{notificationclient.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ncdo *NotificationClientDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := ncdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
526
ent/notificationclient_query.go
Normal file
526
ent/notificationclient_query.go
Normal file
@@ -0,0 +1,526 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"polaris/ent/notificationclient"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NotificationClientQuery is the builder for querying NotificationClient entities.
|
||||
type NotificationClientQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []notificationclient.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.NotificationClient
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the NotificationClientQuery builder.
|
||||
func (ncq *NotificationClientQuery) Where(ps ...predicate.NotificationClient) *NotificationClientQuery {
|
||||
ncq.predicates = append(ncq.predicates, ps...)
|
||||
return ncq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (ncq *NotificationClientQuery) Limit(limit int) *NotificationClientQuery {
|
||||
ncq.ctx.Limit = &limit
|
||||
return ncq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (ncq *NotificationClientQuery) Offset(offset int) *NotificationClientQuery {
|
||||
ncq.ctx.Offset = &offset
|
||||
return ncq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (ncq *NotificationClientQuery) Unique(unique bool) *NotificationClientQuery {
|
||||
ncq.ctx.Unique = &unique
|
||||
return ncq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (ncq *NotificationClientQuery) Order(o ...notificationclient.OrderOption) *NotificationClientQuery {
|
||||
ncq.order = append(ncq.order, o...)
|
||||
return ncq
|
||||
}
|
||||
|
||||
// First returns the first NotificationClient entity from the query.
|
||||
// Returns a *NotFoundError when no NotificationClient was found.
|
||||
func (ncq *NotificationClientQuery) First(ctx context.Context) (*NotificationClient, error) {
|
||||
nodes, err := ncq.Limit(1).All(setContextOp(ctx, ncq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{notificationclient.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) FirstX(ctx context.Context) *NotificationClient {
|
||||
node, err := ncq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first NotificationClient ID from the query.
|
||||
// Returns a *NotFoundError when no NotificationClient ID was found.
|
||||
func (ncq *NotificationClientQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ncq.Limit(1).IDs(setContextOp(ctx, ncq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{notificationclient.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := ncq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single NotificationClient entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one NotificationClient entity is found.
|
||||
// Returns a *NotFoundError when no NotificationClient entities are found.
|
||||
func (ncq *NotificationClientQuery) Only(ctx context.Context) (*NotificationClient, error) {
|
||||
nodes, err := ncq.Limit(2).All(setContextOp(ctx, ncq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{notificationclient.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{notificationclient.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) OnlyX(ctx context.Context) *NotificationClient {
|
||||
node, err := ncq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only NotificationClient ID in the query.
|
||||
// Returns a *NotSingularError when more than one NotificationClient ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (ncq *NotificationClientQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ncq.Limit(2).IDs(setContextOp(ctx, ncq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{notificationclient.Label}
|
||||
default:
|
||||
err = &NotSingularError{notificationclient.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := ncq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of NotificationClients.
|
||||
func (ncq *NotificationClientQuery) All(ctx context.Context) ([]*NotificationClient, error) {
|
||||
ctx = setContextOp(ctx, ncq.ctx, "All")
|
||||
if err := ncq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*NotificationClient, *NotificationClientQuery]()
|
||||
return withInterceptors[[]*NotificationClient](ctx, ncq, qr, ncq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) AllX(ctx context.Context) []*NotificationClient {
|
||||
nodes, err := ncq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of NotificationClient IDs.
|
||||
func (ncq *NotificationClientQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if ncq.ctx.Unique == nil && ncq.path != nil {
|
||||
ncq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, ncq.ctx, "IDs")
|
||||
if err = ncq.Select(notificationclient.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := ncq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (ncq *NotificationClientQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, ncq.ctx, "Count")
|
||||
if err := ncq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, ncq, querierCount[*NotificationClientQuery](), ncq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) CountX(ctx context.Context) int {
|
||||
count, err := ncq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (ncq *NotificationClientQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, ncq.ctx, "Exist")
|
||||
switch _, err := ncq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (ncq *NotificationClientQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := ncq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the NotificationClientQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (ncq *NotificationClientQuery) Clone() *NotificationClientQuery {
|
||||
if ncq == nil {
|
||||
return nil
|
||||
}
|
||||
return &NotificationClientQuery{
|
||||
config: ncq.config,
|
||||
ctx: ncq.ctx.Clone(),
|
||||
order: append([]notificationclient.OrderOption{}, ncq.order...),
|
||||
inters: append([]Interceptor{}, ncq.inters...),
|
||||
predicates: append([]predicate.NotificationClient{}, ncq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: ncq.sql.Clone(),
|
||||
path: ncq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.NotificationClient.Query().
|
||||
// GroupBy(notificationclient.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (ncq *NotificationClientQuery) GroupBy(field string, fields ...string) *NotificationClientGroupBy {
|
||||
ncq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &NotificationClientGroupBy{build: ncq}
|
||||
grbuild.flds = &ncq.ctx.Fields
|
||||
grbuild.label = notificationclient.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.NotificationClient.Query().
|
||||
// Select(notificationclient.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (ncq *NotificationClientQuery) Select(fields ...string) *NotificationClientSelect {
|
||||
ncq.ctx.Fields = append(ncq.ctx.Fields, fields...)
|
||||
sbuild := &NotificationClientSelect{NotificationClientQuery: ncq}
|
||||
sbuild.label = notificationclient.Label
|
||||
sbuild.flds, sbuild.scan = &ncq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a NotificationClientSelect configured with the given aggregations.
|
||||
func (ncq *NotificationClientQuery) Aggregate(fns ...AggregateFunc) *NotificationClientSelect {
|
||||
return ncq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (ncq *NotificationClientQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range ncq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, ncq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range ncq.ctx.Fields {
|
||||
if !notificationclient.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if ncq.path != nil {
|
||||
prev, err := ncq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ncq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ncq *NotificationClientQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*NotificationClient, error) {
|
||||
var (
|
||||
nodes = []*NotificationClient{}
|
||||
_spec = ncq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*NotificationClient).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &NotificationClient{config: ncq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, ncq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (ncq *NotificationClientQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := ncq.querySpec()
|
||||
_spec.Node.Columns = ncq.ctx.Fields
|
||||
if len(ncq.ctx.Fields) > 0 {
|
||||
_spec.Unique = ncq.ctx.Unique != nil && *ncq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, ncq.driver, _spec)
|
||||
}
|
||||
|
||||
func (ncq *NotificationClientQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(notificationclient.Table, notificationclient.Columns, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
|
||||
_spec.From = ncq.sql
|
||||
if unique := ncq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if ncq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := ncq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, notificationclient.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != notificationclient.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := ncq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := ncq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := ncq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := ncq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (ncq *NotificationClientQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(ncq.driver.Dialect())
|
||||
t1 := builder.Table(notificationclient.Table)
|
||||
columns := ncq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = notificationclient.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if ncq.sql != nil {
|
||||
selector = ncq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if ncq.ctx.Unique != nil && *ncq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range ncq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range ncq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := ncq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := ncq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// NotificationClientGroupBy is the group-by builder for NotificationClient entities.
|
||||
type NotificationClientGroupBy struct {
|
||||
selector
|
||||
build *NotificationClientQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ncgb *NotificationClientGroupBy) Aggregate(fns ...AggregateFunc) *NotificationClientGroupBy {
|
||||
ncgb.fns = append(ncgb.fns, fns...)
|
||||
return ncgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ncgb *NotificationClientGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ncgb.build.ctx, "GroupBy")
|
||||
if err := ncgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*NotificationClientQuery, *NotificationClientGroupBy](ctx, ncgb.build, ncgb, ncgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (ncgb *NotificationClientGroupBy) sqlScan(ctx context.Context, root *NotificationClientQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(ncgb.fns))
|
||||
for _, fn := range ncgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*ncgb.flds)+len(ncgb.fns))
|
||||
for _, f := range *ncgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*ncgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ncgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// NotificationClientSelect is the builder for selecting fields of NotificationClient entities.
|
||||
type NotificationClientSelect struct {
|
||||
*NotificationClientQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ncs *NotificationClientSelect) Aggregate(fns ...AggregateFunc) *NotificationClientSelect {
|
||||
ncs.fns = append(ncs.fns, fns...)
|
||||
return ncs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ncs *NotificationClientSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ncs.ctx, "Select")
|
||||
if err := ncs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*NotificationClientQuery, *NotificationClientSelect](ctx, ncs.NotificationClientQuery, ncs, ncs.inters, v)
|
||||
}
|
||||
|
||||
func (ncs *NotificationClientSelect) sqlScan(ctx context.Context, root *NotificationClientQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ncs.fns))
|
||||
for _, fn := range ncs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ncs.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ncs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
311
ent/notificationclient_update.go
Normal file
311
ent/notificationclient_update.go
Normal file
@@ -0,0 +1,311 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/notificationclient"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NotificationClientUpdate is the builder for updating NotificationClient entities.
|
||||
type NotificationClientUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *NotificationClientMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotificationClientUpdate builder.
|
||||
func (ncu *NotificationClientUpdate) Where(ps ...predicate.NotificationClient) *NotificationClientUpdate {
|
||||
ncu.mutation.Where(ps...)
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (ncu *NotificationClientUpdate) SetName(s string) *NotificationClientUpdate {
|
||||
ncu.mutation.SetName(s)
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (ncu *NotificationClientUpdate) SetNillableName(s *string) *NotificationClientUpdate {
|
||||
if s != nil {
|
||||
ncu.SetName(*s)
|
||||
}
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetService sets the "service" field.
|
||||
func (ncu *NotificationClientUpdate) SetService(s string) *NotificationClientUpdate {
|
||||
ncu.mutation.SetService(s)
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetNillableService sets the "service" field if the given value is not nil.
|
||||
func (ncu *NotificationClientUpdate) SetNillableService(s *string) *NotificationClientUpdate {
|
||||
if s != nil {
|
||||
ncu.SetService(*s)
|
||||
}
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetSettings sets the "settings" field.
|
||||
func (ncu *NotificationClientUpdate) SetSettings(s string) *NotificationClientUpdate {
|
||||
ncu.mutation.SetSettings(s)
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
||||
func (ncu *NotificationClientUpdate) SetNillableSettings(s *string) *NotificationClientUpdate {
|
||||
if s != nil {
|
||||
ncu.SetSettings(*s)
|
||||
}
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetEnabled sets the "enabled" field.
|
||||
func (ncu *NotificationClientUpdate) SetEnabled(b bool) *NotificationClientUpdate {
|
||||
ncu.mutation.SetEnabled(b)
|
||||
return ncu
|
||||
}
|
||||
|
||||
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
||||
func (ncu *NotificationClientUpdate) SetNillableEnabled(b *bool) *NotificationClientUpdate {
|
||||
if b != nil {
|
||||
ncu.SetEnabled(*b)
|
||||
}
|
||||
return ncu
|
||||
}
|
||||
|
||||
// Mutation returns the NotificationClientMutation object of the builder.
|
||||
func (ncu *NotificationClientUpdate) Mutation() *NotificationClientMutation {
|
||||
return ncu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (ncu *NotificationClientUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, ncu.sqlSave, ncu.mutation, ncu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ncu *NotificationClientUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := ncu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ncu *NotificationClientUpdate) Exec(ctx context.Context) error {
|
||||
_, err := ncu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ncu *NotificationClientUpdate) ExecX(ctx context.Context) {
|
||||
if err := ncu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ncu *NotificationClientUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(notificationclient.Table, notificationclient.Columns, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
|
||||
if ps := ncu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := ncu.mutation.Name(); ok {
|
||||
_spec.SetField(notificationclient.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ncu.mutation.Service(); ok {
|
||||
_spec.SetField(notificationclient.FieldService, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ncu.mutation.Settings(); ok {
|
||||
_spec.SetField(notificationclient.FieldSettings, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ncu.mutation.Enabled(); ok {
|
||||
_spec.SetField(notificationclient.FieldEnabled, field.TypeBool, value)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, ncu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{notificationclient.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
ncu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// NotificationClientUpdateOne is the builder for updating a single NotificationClient entity.
|
||||
type NotificationClientUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *NotificationClientMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (ncuo *NotificationClientUpdateOne) SetName(s string) *NotificationClientUpdateOne {
|
||||
ncuo.mutation.SetName(s)
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (ncuo *NotificationClientUpdateOne) SetNillableName(s *string) *NotificationClientUpdateOne {
|
||||
if s != nil {
|
||||
ncuo.SetName(*s)
|
||||
}
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// SetService sets the "service" field.
|
||||
func (ncuo *NotificationClientUpdateOne) SetService(s string) *NotificationClientUpdateOne {
|
||||
ncuo.mutation.SetService(s)
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// SetNillableService sets the "service" field if the given value is not nil.
|
||||
func (ncuo *NotificationClientUpdateOne) SetNillableService(s *string) *NotificationClientUpdateOne {
|
||||
if s != nil {
|
||||
ncuo.SetService(*s)
|
||||
}
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// SetSettings sets the "settings" field.
|
||||
func (ncuo *NotificationClientUpdateOne) SetSettings(s string) *NotificationClientUpdateOne {
|
||||
ncuo.mutation.SetSettings(s)
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// SetNillableSettings sets the "settings" field if the given value is not nil.
|
||||
func (ncuo *NotificationClientUpdateOne) SetNillableSettings(s *string) *NotificationClientUpdateOne {
|
||||
if s != nil {
|
||||
ncuo.SetSettings(*s)
|
||||
}
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// SetEnabled sets the "enabled" field.
|
||||
func (ncuo *NotificationClientUpdateOne) SetEnabled(b bool) *NotificationClientUpdateOne {
|
||||
ncuo.mutation.SetEnabled(b)
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
||||
func (ncuo *NotificationClientUpdateOne) SetNillableEnabled(b *bool) *NotificationClientUpdateOne {
|
||||
if b != nil {
|
||||
ncuo.SetEnabled(*b)
|
||||
}
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// Mutation returns the NotificationClientMutation object of the builder.
|
||||
func (ncuo *NotificationClientUpdateOne) Mutation() *NotificationClientMutation {
|
||||
return ncuo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotificationClientUpdate builder.
|
||||
func (ncuo *NotificationClientUpdateOne) Where(ps ...predicate.NotificationClient) *NotificationClientUpdateOne {
|
||||
ncuo.mutation.Where(ps...)
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (ncuo *NotificationClientUpdateOne) Select(field string, fields ...string) *NotificationClientUpdateOne {
|
||||
ncuo.fields = append([]string{field}, fields...)
|
||||
return ncuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated NotificationClient entity.
|
||||
func (ncuo *NotificationClientUpdateOne) Save(ctx context.Context) (*NotificationClient, error) {
|
||||
return withHooks(ctx, ncuo.sqlSave, ncuo.mutation, ncuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ncuo *NotificationClientUpdateOne) SaveX(ctx context.Context) *NotificationClient {
|
||||
node, err := ncuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (ncuo *NotificationClientUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := ncuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ncuo *NotificationClientUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := ncuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ncuo *NotificationClientUpdateOne) sqlSave(ctx context.Context) (_node *NotificationClient, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(notificationclient.Table, notificationclient.Columns, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
|
||||
id, ok := ncuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "NotificationClient.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := ncuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, notificationclient.FieldID)
|
||||
for _, f := range fields {
|
||||
if !notificationclient.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != notificationclient.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := ncuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := ncuo.mutation.Name(); ok {
|
||||
_spec.SetField(notificationclient.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ncuo.mutation.Service(); ok {
|
||||
_spec.SetField(notificationclient.FieldService, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ncuo.mutation.Settings(); ok {
|
||||
_spec.SetField(notificationclient.FieldSettings, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ncuo.mutation.Enabled(); ok {
|
||||
_spec.SetField(notificationclient.FieldEnabled, field.TypeBool, value)
|
||||
}
|
||||
_node = &NotificationClient{config: ncuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, ncuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{notificationclient.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
ncuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -21,6 +21,9 @@ type Indexers func(*sql.Selector)
|
||||
// Media is the predicate function for media builders.
|
||||
type Media func(*sql.Selector)
|
||||
|
||||
// NotificationClient is the predicate function for notificationclient builders.
|
||||
type NotificationClient func(*sql.Selector)
|
||||
|
||||
// Settings is the predicate function for settings builders.
|
||||
type Settings func(*sql.Selector)
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"polaris/ent/history"
|
||||
"polaris/ent/indexers"
|
||||
"polaris/ent/media"
|
||||
"polaris/ent/notificationclient"
|
||||
"polaris/ent/schema"
|
||||
"polaris/ent/storage"
|
||||
"time"
|
||||
@@ -74,6 +75,12 @@ func init() {
|
||||
mediaDescDownloadHistoryEpisodes := mediaFields[12].Descriptor()
|
||||
// media.DefaultDownloadHistoryEpisodes holds the default value on creation for the download_history_episodes field.
|
||||
media.DefaultDownloadHistoryEpisodes = mediaDescDownloadHistoryEpisodes.Default.(bool)
|
||||
notificationclientFields := schema.NotificationClient{}.Fields()
|
||||
_ = notificationclientFields
|
||||
// notificationclientDescEnabled is the schema descriptor for enabled field.
|
||||
notificationclientDescEnabled := notificationclientFields[3].Descriptor()
|
||||
// notificationclient.DefaultEnabled holds the default value on creation for the enabled field.
|
||||
notificationclient.DefaultEnabled = notificationclientDescEnabled.Default.(bool)
|
||||
storageFields := schema.Storage{}.Fields()
|
||||
_ = storageFields
|
||||
// storageDescDeleted is the schema descriptor for deleted field.
|
||||
|
||||
26
ent/schema/notificationclient.go
Normal file
26
ent/schema/notificationclient.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NotificationClient holds the schema definition for the NotificationClient entity.
|
||||
type NotificationClient struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the NotificationClient.
|
||||
func (NotificationClient) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
field.String("service"),
|
||||
field.String("settings"),
|
||||
field.Bool("enabled").Default(true),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the NotificationClient.
|
||||
func (NotificationClient) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -22,6 +22,8 @@ type Tx struct {
|
||||
Indexers *IndexersClient
|
||||
// Media is the client for interacting with the Media builders.
|
||||
Media *MediaClient
|
||||
// NotificationClient is the client for interacting with the NotificationClient builders.
|
||||
NotificationClient *NotificationClientClient
|
||||
// Settings is the client for interacting with the Settings builders.
|
||||
Settings *SettingsClient
|
||||
// Storage is the client for interacting with the Storage builders.
|
||||
@@ -162,6 +164,7 @@ func (tx *Tx) init() {
|
||||
tx.History = NewHistoryClient(tx.config)
|
||||
tx.Indexers = NewIndexersClient(tx.config)
|
||||
tx.Media = NewMediaClient(tx.config)
|
||||
tx.NotificationClient = NewNotificationClientClient(tx.config)
|
||||
tx.Settings = NewSettingsClient(tx.config)
|
||||
tx.Storage = NewStorageClient(tx.config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user