github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/client.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 "log" 10 "reflect" 11 12 "github.com/crowdsecurity/crowdsec/pkg/database/ent/migrate" 13 14 "entgo.io/ent" 15 "entgo.io/ent/dialect" 16 "entgo.io/ent/dialect/sql" 17 "entgo.io/ent/dialect/sql/sqlgraph" 18 "github.com/crowdsecurity/crowdsec/pkg/database/ent/alert" 19 "github.com/crowdsecurity/crowdsec/pkg/database/ent/bouncer" 20 "github.com/crowdsecurity/crowdsec/pkg/database/ent/configitem" 21 "github.com/crowdsecurity/crowdsec/pkg/database/ent/decision" 22 "github.com/crowdsecurity/crowdsec/pkg/database/ent/event" 23 "github.com/crowdsecurity/crowdsec/pkg/database/ent/lock" 24 "github.com/crowdsecurity/crowdsec/pkg/database/ent/machine" 25 "github.com/crowdsecurity/crowdsec/pkg/database/ent/meta" 26 ) 27 28 // Client is the client that holds all ent builders. 29 type Client struct { 30 config 31 // Schema is the client for creating, migrating and dropping schema. 32 Schema *migrate.Schema 33 // Alert is the client for interacting with the Alert builders. 34 Alert *AlertClient 35 // Bouncer is the client for interacting with the Bouncer builders. 36 Bouncer *BouncerClient 37 // ConfigItem is the client for interacting with the ConfigItem builders. 38 ConfigItem *ConfigItemClient 39 // Decision is the client for interacting with the Decision builders. 40 Decision *DecisionClient 41 // Event is the client for interacting with the Event builders. 42 Event *EventClient 43 // Lock is the client for interacting with the Lock builders. 44 Lock *LockClient 45 // Machine is the client for interacting with the Machine builders. 46 Machine *MachineClient 47 // Meta is the client for interacting with the Meta builders. 48 Meta *MetaClient 49 } 50 51 // NewClient creates a new client configured with the given options. 52 func NewClient(opts ...Option) *Client { 53 client := &Client{config: newConfig(opts...)} 54 client.init() 55 return client 56 } 57 58 func (c *Client) init() { 59 c.Schema = migrate.NewSchema(c.driver) 60 c.Alert = NewAlertClient(c.config) 61 c.Bouncer = NewBouncerClient(c.config) 62 c.ConfigItem = NewConfigItemClient(c.config) 63 c.Decision = NewDecisionClient(c.config) 64 c.Event = NewEventClient(c.config) 65 c.Lock = NewLockClient(c.config) 66 c.Machine = NewMachineClient(c.config) 67 c.Meta = NewMetaClient(c.config) 68 } 69 70 type ( 71 // config is the configuration for the client and its builder. 72 config struct { 73 // driver used for executing database requests. 74 driver dialect.Driver 75 // debug enable a debug logging. 76 debug bool 77 // log used for logging on debug mode. 78 log func(...any) 79 // hooks to execute on mutations. 80 hooks *hooks 81 // interceptors to execute on queries. 82 inters *inters 83 } 84 // Option function to configure the client. 85 Option func(*config) 86 ) 87 88 // newConfig creates a new config for the client. 89 func newConfig(opts ...Option) config { 90 cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} 91 cfg.options(opts...) 92 return cfg 93 } 94 95 // options applies the options on the config object. 96 func (c *config) options(opts ...Option) { 97 for _, opt := range opts { 98 opt(c) 99 } 100 if c.debug { 101 c.driver = dialect.Debug(c.driver, c.log) 102 } 103 } 104 105 // Debug enables debug logging on the ent.Driver. 106 func Debug() Option { 107 return func(c *config) { 108 c.debug = true 109 } 110 } 111 112 // Log sets the logging function for debug mode. 113 func Log(fn func(...any)) Option { 114 return func(c *config) { 115 c.log = fn 116 } 117 } 118 119 // Driver configures the client driver. 120 func Driver(driver dialect.Driver) Option { 121 return func(c *config) { 122 c.driver = driver 123 } 124 } 125 126 // Open opens a database/sql.DB specified by the driver name and 127 // the data source name, and returns a new client attached to it. 128 // Optional parameters can be added for configuring the client. 129 func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { 130 switch driverName { 131 case dialect.MySQL, dialect.Postgres, dialect.SQLite: 132 drv, err := sql.Open(driverName, dataSourceName) 133 if err != nil { 134 return nil, err 135 } 136 return NewClient(append(options, Driver(drv))...), nil 137 default: 138 return nil, fmt.Errorf("unsupported driver: %q", driverName) 139 } 140 } 141 142 // ErrTxStarted is returned when trying to start a new transaction from a transactional client. 143 var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") 144 145 // Tx returns a new transactional client. The provided context 146 // is used until the transaction is committed or rolled back. 147 func (c *Client) Tx(ctx context.Context) (*Tx, error) { 148 if _, ok := c.driver.(*txDriver); ok { 149 return nil, ErrTxStarted 150 } 151 tx, err := newTx(ctx, c.driver) 152 if err != nil { 153 return nil, fmt.Errorf("ent: starting a transaction: %w", err) 154 } 155 cfg := c.config 156 cfg.driver = tx 157 return &Tx{ 158 ctx: ctx, 159 config: cfg, 160 Alert: NewAlertClient(cfg), 161 Bouncer: NewBouncerClient(cfg), 162 ConfigItem: NewConfigItemClient(cfg), 163 Decision: NewDecisionClient(cfg), 164 Event: NewEventClient(cfg), 165 Lock: NewLockClient(cfg), 166 Machine: NewMachineClient(cfg), 167 Meta: NewMetaClient(cfg), 168 }, nil 169 } 170 171 // BeginTx returns a transactional client with specified options. 172 func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { 173 if _, ok := c.driver.(*txDriver); ok { 174 return nil, errors.New("ent: cannot start a transaction within a transaction") 175 } 176 tx, err := c.driver.(interface { 177 BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) 178 }).BeginTx(ctx, opts) 179 if err != nil { 180 return nil, fmt.Errorf("ent: starting a transaction: %w", err) 181 } 182 cfg := c.config 183 cfg.driver = &txDriver{tx: tx, drv: c.driver} 184 return &Tx{ 185 ctx: ctx, 186 config: cfg, 187 Alert: NewAlertClient(cfg), 188 Bouncer: NewBouncerClient(cfg), 189 ConfigItem: NewConfigItemClient(cfg), 190 Decision: NewDecisionClient(cfg), 191 Event: NewEventClient(cfg), 192 Lock: NewLockClient(cfg), 193 Machine: NewMachineClient(cfg), 194 Meta: NewMetaClient(cfg), 195 }, nil 196 } 197 198 // Debug returns a new debug-client. It's used to get verbose logging on specific operations. 199 // 200 // client.Debug(). 201 // Alert. 202 // Query(). 203 // Count(ctx) 204 func (c *Client) Debug() *Client { 205 if c.debug { 206 return c 207 } 208 cfg := c.config 209 cfg.driver = dialect.Debug(c.driver, c.log) 210 client := &Client{config: cfg} 211 client.init() 212 return client 213 } 214 215 // Close closes the database connection and prevents new queries from starting. 216 func (c *Client) Close() error { 217 return c.driver.Close() 218 } 219 220 // Use adds the mutation hooks to all the entity clients. 221 // In order to add hooks to a specific client, call: `client.Node.Use(...)`. 222 func (c *Client) Use(hooks ...Hook) { 223 for _, n := range []interface{ Use(...Hook) }{ 224 c.Alert, c.Bouncer, c.ConfigItem, c.Decision, c.Event, c.Lock, c.Machine, 225 c.Meta, 226 } { 227 n.Use(hooks...) 228 } 229 } 230 231 // Intercept adds the query interceptors to all the entity clients. 232 // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. 233 func (c *Client) Intercept(interceptors ...Interceptor) { 234 for _, n := range []interface{ Intercept(...Interceptor) }{ 235 c.Alert, c.Bouncer, c.ConfigItem, c.Decision, c.Event, c.Lock, c.Machine, 236 c.Meta, 237 } { 238 n.Intercept(interceptors...) 239 } 240 } 241 242 // Mutate implements the ent.Mutator interface. 243 func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { 244 switch m := m.(type) { 245 case *AlertMutation: 246 return c.Alert.mutate(ctx, m) 247 case *BouncerMutation: 248 return c.Bouncer.mutate(ctx, m) 249 case *ConfigItemMutation: 250 return c.ConfigItem.mutate(ctx, m) 251 case *DecisionMutation: 252 return c.Decision.mutate(ctx, m) 253 case *EventMutation: 254 return c.Event.mutate(ctx, m) 255 case *LockMutation: 256 return c.Lock.mutate(ctx, m) 257 case *MachineMutation: 258 return c.Machine.mutate(ctx, m) 259 case *MetaMutation: 260 return c.Meta.mutate(ctx, m) 261 default: 262 return nil, fmt.Errorf("ent: unknown mutation type %T", m) 263 } 264 } 265 266 // AlertClient is a client for the Alert schema. 267 type AlertClient struct { 268 config 269 } 270 271 // NewAlertClient returns a client for the Alert from the given config. 272 func NewAlertClient(c config) *AlertClient { 273 return &AlertClient{config: c} 274 } 275 276 // Use adds a list of mutation hooks to the hooks stack. 277 // A call to `Use(f, g, h)` equals to `alert.Hooks(f(g(h())))`. 278 func (c *AlertClient) Use(hooks ...Hook) { 279 c.hooks.Alert = append(c.hooks.Alert, hooks...) 280 } 281 282 // Intercept adds a list of query interceptors to the interceptors stack. 283 // A call to `Intercept(f, g, h)` equals to `alert.Intercept(f(g(h())))`. 284 func (c *AlertClient) Intercept(interceptors ...Interceptor) { 285 c.inters.Alert = append(c.inters.Alert, interceptors...) 286 } 287 288 // Create returns a builder for creating a Alert entity. 289 func (c *AlertClient) Create() *AlertCreate { 290 mutation := newAlertMutation(c.config, OpCreate) 291 return &AlertCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 292 } 293 294 // CreateBulk returns a builder for creating a bulk of Alert entities. 295 func (c *AlertClient) CreateBulk(builders ...*AlertCreate) *AlertCreateBulk { 296 return &AlertCreateBulk{config: c.config, builders: builders} 297 } 298 299 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 300 // a builder and applies setFunc on it. 301 func (c *AlertClient) MapCreateBulk(slice any, setFunc func(*AlertCreate, int)) *AlertCreateBulk { 302 rv := reflect.ValueOf(slice) 303 if rv.Kind() != reflect.Slice { 304 return &AlertCreateBulk{err: fmt.Errorf("calling to AlertClient.MapCreateBulk with wrong type %T, need slice", slice)} 305 } 306 builders := make([]*AlertCreate, rv.Len()) 307 for i := 0; i < rv.Len(); i++ { 308 builders[i] = c.Create() 309 setFunc(builders[i], i) 310 } 311 return &AlertCreateBulk{config: c.config, builders: builders} 312 } 313 314 // Update returns an update builder for Alert. 315 func (c *AlertClient) Update() *AlertUpdate { 316 mutation := newAlertMutation(c.config, OpUpdate) 317 return &AlertUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 318 } 319 320 // UpdateOne returns an update builder for the given entity. 321 func (c *AlertClient) UpdateOne(a *Alert) *AlertUpdateOne { 322 mutation := newAlertMutation(c.config, OpUpdateOne, withAlert(a)) 323 return &AlertUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 324 } 325 326 // UpdateOneID returns an update builder for the given id. 327 func (c *AlertClient) UpdateOneID(id int) *AlertUpdateOne { 328 mutation := newAlertMutation(c.config, OpUpdateOne, withAlertID(id)) 329 return &AlertUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 330 } 331 332 // Delete returns a delete builder for Alert. 333 func (c *AlertClient) Delete() *AlertDelete { 334 mutation := newAlertMutation(c.config, OpDelete) 335 return &AlertDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 336 } 337 338 // DeleteOne returns a builder for deleting the given entity. 339 func (c *AlertClient) DeleteOne(a *Alert) *AlertDeleteOne { 340 return c.DeleteOneID(a.ID) 341 } 342 343 // DeleteOneID returns a builder for deleting the given entity by its id. 344 func (c *AlertClient) DeleteOneID(id int) *AlertDeleteOne { 345 builder := c.Delete().Where(alert.ID(id)) 346 builder.mutation.id = &id 347 builder.mutation.op = OpDeleteOne 348 return &AlertDeleteOne{builder} 349 } 350 351 // Query returns a query builder for Alert. 352 func (c *AlertClient) Query() *AlertQuery { 353 return &AlertQuery{ 354 config: c.config, 355 ctx: &QueryContext{Type: TypeAlert}, 356 inters: c.Interceptors(), 357 } 358 } 359 360 // Get returns a Alert entity by its id. 361 func (c *AlertClient) Get(ctx context.Context, id int) (*Alert, error) { 362 return c.Query().Where(alert.ID(id)).Only(ctx) 363 } 364 365 // GetX is like Get, but panics if an error occurs. 366 func (c *AlertClient) GetX(ctx context.Context, id int) *Alert { 367 obj, err := c.Get(ctx, id) 368 if err != nil { 369 panic(err) 370 } 371 return obj 372 } 373 374 // QueryOwner queries the owner edge of a Alert. 375 func (c *AlertClient) QueryOwner(a *Alert) *MachineQuery { 376 query := (&MachineClient{config: c.config}).Query() 377 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 378 id := a.ID 379 step := sqlgraph.NewStep( 380 sqlgraph.From(alert.Table, alert.FieldID, id), 381 sqlgraph.To(machine.Table, machine.FieldID), 382 sqlgraph.Edge(sqlgraph.M2O, true, alert.OwnerTable, alert.OwnerColumn), 383 ) 384 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 385 return fromV, nil 386 } 387 return query 388 } 389 390 // QueryDecisions queries the decisions edge of a Alert. 391 func (c *AlertClient) QueryDecisions(a *Alert) *DecisionQuery { 392 query := (&DecisionClient{config: c.config}).Query() 393 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 394 id := a.ID 395 step := sqlgraph.NewStep( 396 sqlgraph.From(alert.Table, alert.FieldID, id), 397 sqlgraph.To(decision.Table, decision.FieldID), 398 sqlgraph.Edge(sqlgraph.O2M, false, alert.DecisionsTable, alert.DecisionsColumn), 399 ) 400 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 401 return fromV, nil 402 } 403 return query 404 } 405 406 // QueryEvents queries the events edge of a Alert. 407 func (c *AlertClient) QueryEvents(a *Alert) *EventQuery { 408 query := (&EventClient{config: c.config}).Query() 409 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 410 id := a.ID 411 step := sqlgraph.NewStep( 412 sqlgraph.From(alert.Table, alert.FieldID, id), 413 sqlgraph.To(event.Table, event.FieldID), 414 sqlgraph.Edge(sqlgraph.O2M, false, alert.EventsTable, alert.EventsColumn), 415 ) 416 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 417 return fromV, nil 418 } 419 return query 420 } 421 422 // QueryMetas queries the metas edge of a Alert. 423 func (c *AlertClient) QueryMetas(a *Alert) *MetaQuery { 424 query := (&MetaClient{config: c.config}).Query() 425 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 426 id := a.ID 427 step := sqlgraph.NewStep( 428 sqlgraph.From(alert.Table, alert.FieldID, id), 429 sqlgraph.To(meta.Table, meta.FieldID), 430 sqlgraph.Edge(sqlgraph.O2M, false, alert.MetasTable, alert.MetasColumn), 431 ) 432 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 433 return fromV, nil 434 } 435 return query 436 } 437 438 // Hooks returns the client hooks. 439 func (c *AlertClient) Hooks() []Hook { 440 return c.hooks.Alert 441 } 442 443 // Interceptors returns the client interceptors. 444 func (c *AlertClient) Interceptors() []Interceptor { 445 return c.inters.Alert 446 } 447 448 func (c *AlertClient) mutate(ctx context.Context, m *AlertMutation) (Value, error) { 449 switch m.Op() { 450 case OpCreate: 451 return (&AlertCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 452 case OpUpdate: 453 return (&AlertUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 454 case OpUpdateOne: 455 return (&AlertUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 456 case OpDelete, OpDeleteOne: 457 return (&AlertDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 458 default: 459 return nil, fmt.Errorf("ent: unknown Alert mutation op: %q", m.Op()) 460 } 461 } 462 463 // BouncerClient is a client for the Bouncer schema. 464 type BouncerClient struct { 465 config 466 } 467 468 // NewBouncerClient returns a client for the Bouncer from the given config. 469 func NewBouncerClient(c config) *BouncerClient { 470 return &BouncerClient{config: c} 471 } 472 473 // Use adds a list of mutation hooks to the hooks stack. 474 // A call to `Use(f, g, h)` equals to `bouncer.Hooks(f(g(h())))`. 475 func (c *BouncerClient) Use(hooks ...Hook) { 476 c.hooks.Bouncer = append(c.hooks.Bouncer, hooks...) 477 } 478 479 // Intercept adds a list of query interceptors to the interceptors stack. 480 // A call to `Intercept(f, g, h)` equals to `bouncer.Intercept(f(g(h())))`. 481 func (c *BouncerClient) Intercept(interceptors ...Interceptor) { 482 c.inters.Bouncer = append(c.inters.Bouncer, interceptors...) 483 } 484 485 // Create returns a builder for creating a Bouncer entity. 486 func (c *BouncerClient) Create() *BouncerCreate { 487 mutation := newBouncerMutation(c.config, OpCreate) 488 return &BouncerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 489 } 490 491 // CreateBulk returns a builder for creating a bulk of Bouncer entities. 492 func (c *BouncerClient) CreateBulk(builders ...*BouncerCreate) *BouncerCreateBulk { 493 return &BouncerCreateBulk{config: c.config, builders: builders} 494 } 495 496 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 497 // a builder and applies setFunc on it. 498 func (c *BouncerClient) MapCreateBulk(slice any, setFunc func(*BouncerCreate, int)) *BouncerCreateBulk { 499 rv := reflect.ValueOf(slice) 500 if rv.Kind() != reflect.Slice { 501 return &BouncerCreateBulk{err: fmt.Errorf("calling to BouncerClient.MapCreateBulk with wrong type %T, need slice", slice)} 502 } 503 builders := make([]*BouncerCreate, rv.Len()) 504 for i := 0; i < rv.Len(); i++ { 505 builders[i] = c.Create() 506 setFunc(builders[i], i) 507 } 508 return &BouncerCreateBulk{config: c.config, builders: builders} 509 } 510 511 // Update returns an update builder for Bouncer. 512 func (c *BouncerClient) Update() *BouncerUpdate { 513 mutation := newBouncerMutation(c.config, OpUpdate) 514 return &BouncerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 515 } 516 517 // UpdateOne returns an update builder for the given entity. 518 func (c *BouncerClient) UpdateOne(b *Bouncer) *BouncerUpdateOne { 519 mutation := newBouncerMutation(c.config, OpUpdateOne, withBouncer(b)) 520 return &BouncerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 521 } 522 523 // UpdateOneID returns an update builder for the given id. 524 func (c *BouncerClient) UpdateOneID(id int) *BouncerUpdateOne { 525 mutation := newBouncerMutation(c.config, OpUpdateOne, withBouncerID(id)) 526 return &BouncerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 527 } 528 529 // Delete returns a delete builder for Bouncer. 530 func (c *BouncerClient) Delete() *BouncerDelete { 531 mutation := newBouncerMutation(c.config, OpDelete) 532 return &BouncerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 533 } 534 535 // DeleteOne returns a builder for deleting the given entity. 536 func (c *BouncerClient) DeleteOne(b *Bouncer) *BouncerDeleteOne { 537 return c.DeleteOneID(b.ID) 538 } 539 540 // DeleteOneID returns a builder for deleting the given entity by its id. 541 func (c *BouncerClient) DeleteOneID(id int) *BouncerDeleteOne { 542 builder := c.Delete().Where(bouncer.ID(id)) 543 builder.mutation.id = &id 544 builder.mutation.op = OpDeleteOne 545 return &BouncerDeleteOne{builder} 546 } 547 548 // Query returns a query builder for Bouncer. 549 func (c *BouncerClient) Query() *BouncerQuery { 550 return &BouncerQuery{ 551 config: c.config, 552 ctx: &QueryContext{Type: TypeBouncer}, 553 inters: c.Interceptors(), 554 } 555 } 556 557 // Get returns a Bouncer entity by its id. 558 func (c *BouncerClient) Get(ctx context.Context, id int) (*Bouncer, error) { 559 return c.Query().Where(bouncer.ID(id)).Only(ctx) 560 } 561 562 // GetX is like Get, but panics if an error occurs. 563 func (c *BouncerClient) GetX(ctx context.Context, id int) *Bouncer { 564 obj, err := c.Get(ctx, id) 565 if err != nil { 566 panic(err) 567 } 568 return obj 569 } 570 571 // Hooks returns the client hooks. 572 func (c *BouncerClient) Hooks() []Hook { 573 return c.hooks.Bouncer 574 } 575 576 // Interceptors returns the client interceptors. 577 func (c *BouncerClient) Interceptors() []Interceptor { 578 return c.inters.Bouncer 579 } 580 581 func (c *BouncerClient) mutate(ctx context.Context, m *BouncerMutation) (Value, error) { 582 switch m.Op() { 583 case OpCreate: 584 return (&BouncerCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 585 case OpUpdate: 586 return (&BouncerUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 587 case OpUpdateOne: 588 return (&BouncerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 589 case OpDelete, OpDeleteOne: 590 return (&BouncerDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 591 default: 592 return nil, fmt.Errorf("ent: unknown Bouncer mutation op: %q", m.Op()) 593 } 594 } 595 596 // ConfigItemClient is a client for the ConfigItem schema. 597 type ConfigItemClient struct { 598 config 599 } 600 601 // NewConfigItemClient returns a client for the ConfigItem from the given config. 602 func NewConfigItemClient(c config) *ConfigItemClient { 603 return &ConfigItemClient{config: c} 604 } 605 606 // Use adds a list of mutation hooks to the hooks stack. 607 // A call to `Use(f, g, h)` equals to `configitem.Hooks(f(g(h())))`. 608 func (c *ConfigItemClient) Use(hooks ...Hook) { 609 c.hooks.ConfigItem = append(c.hooks.ConfigItem, hooks...) 610 } 611 612 // Intercept adds a list of query interceptors to the interceptors stack. 613 // A call to `Intercept(f, g, h)` equals to `configitem.Intercept(f(g(h())))`. 614 func (c *ConfigItemClient) Intercept(interceptors ...Interceptor) { 615 c.inters.ConfigItem = append(c.inters.ConfigItem, interceptors...) 616 } 617 618 // Create returns a builder for creating a ConfigItem entity. 619 func (c *ConfigItemClient) Create() *ConfigItemCreate { 620 mutation := newConfigItemMutation(c.config, OpCreate) 621 return &ConfigItemCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 622 } 623 624 // CreateBulk returns a builder for creating a bulk of ConfigItem entities. 625 func (c *ConfigItemClient) CreateBulk(builders ...*ConfigItemCreate) *ConfigItemCreateBulk { 626 return &ConfigItemCreateBulk{config: c.config, builders: builders} 627 } 628 629 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 630 // a builder and applies setFunc on it. 631 func (c *ConfigItemClient) MapCreateBulk(slice any, setFunc func(*ConfigItemCreate, int)) *ConfigItemCreateBulk { 632 rv := reflect.ValueOf(slice) 633 if rv.Kind() != reflect.Slice { 634 return &ConfigItemCreateBulk{err: fmt.Errorf("calling to ConfigItemClient.MapCreateBulk with wrong type %T, need slice", slice)} 635 } 636 builders := make([]*ConfigItemCreate, rv.Len()) 637 for i := 0; i < rv.Len(); i++ { 638 builders[i] = c.Create() 639 setFunc(builders[i], i) 640 } 641 return &ConfigItemCreateBulk{config: c.config, builders: builders} 642 } 643 644 // Update returns an update builder for ConfigItem. 645 func (c *ConfigItemClient) Update() *ConfigItemUpdate { 646 mutation := newConfigItemMutation(c.config, OpUpdate) 647 return &ConfigItemUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 648 } 649 650 // UpdateOne returns an update builder for the given entity. 651 func (c *ConfigItemClient) UpdateOne(ci *ConfigItem) *ConfigItemUpdateOne { 652 mutation := newConfigItemMutation(c.config, OpUpdateOne, withConfigItem(ci)) 653 return &ConfigItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 654 } 655 656 // UpdateOneID returns an update builder for the given id. 657 func (c *ConfigItemClient) UpdateOneID(id int) *ConfigItemUpdateOne { 658 mutation := newConfigItemMutation(c.config, OpUpdateOne, withConfigItemID(id)) 659 return &ConfigItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 660 } 661 662 // Delete returns a delete builder for ConfigItem. 663 func (c *ConfigItemClient) Delete() *ConfigItemDelete { 664 mutation := newConfigItemMutation(c.config, OpDelete) 665 return &ConfigItemDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 666 } 667 668 // DeleteOne returns a builder for deleting the given entity. 669 func (c *ConfigItemClient) DeleteOne(ci *ConfigItem) *ConfigItemDeleteOne { 670 return c.DeleteOneID(ci.ID) 671 } 672 673 // DeleteOneID returns a builder for deleting the given entity by its id. 674 func (c *ConfigItemClient) DeleteOneID(id int) *ConfigItemDeleteOne { 675 builder := c.Delete().Where(configitem.ID(id)) 676 builder.mutation.id = &id 677 builder.mutation.op = OpDeleteOne 678 return &ConfigItemDeleteOne{builder} 679 } 680 681 // Query returns a query builder for ConfigItem. 682 func (c *ConfigItemClient) Query() *ConfigItemQuery { 683 return &ConfigItemQuery{ 684 config: c.config, 685 ctx: &QueryContext{Type: TypeConfigItem}, 686 inters: c.Interceptors(), 687 } 688 } 689 690 // Get returns a ConfigItem entity by its id. 691 func (c *ConfigItemClient) Get(ctx context.Context, id int) (*ConfigItem, error) { 692 return c.Query().Where(configitem.ID(id)).Only(ctx) 693 } 694 695 // GetX is like Get, but panics if an error occurs. 696 func (c *ConfigItemClient) GetX(ctx context.Context, id int) *ConfigItem { 697 obj, err := c.Get(ctx, id) 698 if err != nil { 699 panic(err) 700 } 701 return obj 702 } 703 704 // Hooks returns the client hooks. 705 func (c *ConfigItemClient) Hooks() []Hook { 706 return c.hooks.ConfigItem 707 } 708 709 // Interceptors returns the client interceptors. 710 func (c *ConfigItemClient) Interceptors() []Interceptor { 711 return c.inters.ConfigItem 712 } 713 714 func (c *ConfigItemClient) mutate(ctx context.Context, m *ConfigItemMutation) (Value, error) { 715 switch m.Op() { 716 case OpCreate: 717 return (&ConfigItemCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 718 case OpUpdate: 719 return (&ConfigItemUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 720 case OpUpdateOne: 721 return (&ConfigItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 722 case OpDelete, OpDeleteOne: 723 return (&ConfigItemDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 724 default: 725 return nil, fmt.Errorf("ent: unknown ConfigItem mutation op: %q", m.Op()) 726 } 727 } 728 729 // DecisionClient is a client for the Decision schema. 730 type DecisionClient struct { 731 config 732 } 733 734 // NewDecisionClient returns a client for the Decision from the given config. 735 func NewDecisionClient(c config) *DecisionClient { 736 return &DecisionClient{config: c} 737 } 738 739 // Use adds a list of mutation hooks to the hooks stack. 740 // A call to `Use(f, g, h)` equals to `decision.Hooks(f(g(h())))`. 741 func (c *DecisionClient) Use(hooks ...Hook) { 742 c.hooks.Decision = append(c.hooks.Decision, hooks...) 743 } 744 745 // Intercept adds a list of query interceptors to the interceptors stack. 746 // A call to `Intercept(f, g, h)` equals to `decision.Intercept(f(g(h())))`. 747 func (c *DecisionClient) Intercept(interceptors ...Interceptor) { 748 c.inters.Decision = append(c.inters.Decision, interceptors...) 749 } 750 751 // Create returns a builder for creating a Decision entity. 752 func (c *DecisionClient) Create() *DecisionCreate { 753 mutation := newDecisionMutation(c.config, OpCreate) 754 return &DecisionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 755 } 756 757 // CreateBulk returns a builder for creating a bulk of Decision entities. 758 func (c *DecisionClient) CreateBulk(builders ...*DecisionCreate) *DecisionCreateBulk { 759 return &DecisionCreateBulk{config: c.config, builders: builders} 760 } 761 762 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 763 // a builder and applies setFunc on it. 764 func (c *DecisionClient) MapCreateBulk(slice any, setFunc func(*DecisionCreate, int)) *DecisionCreateBulk { 765 rv := reflect.ValueOf(slice) 766 if rv.Kind() != reflect.Slice { 767 return &DecisionCreateBulk{err: fmt.Errorf("calling to DecisionClient.MapCreateBulk with wrong type %T, need slice", slice)} 768 } 769 builders := make([]*DecisionCreate, rv.Len()) 770 for i := 0; i < rv.Len(); i++ { 771 builders[i] = c.Create() 772 setFunc(builders[i], i) 773 } 774 return &DecisionCreateBulk{config: c.config, builders: builders} 775 } 776 777 // Update returns an update builder for Decision. 778 func (c *DecisionClient) Update() *DecisionUpdate { 779 mutation := newDecisionMutation(c.config, OpUpdate) 780 return &DecisionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 781 } 782 783 // UpdateOne returns an update builder for the given entity. 784 func (c *DecisionClient) UpdateOne(d *Decision) *DecisionUpdateOne { 785 mutation := newDecisionMutation(c.config, OpUpdateOne, withDecision(d)) 786 return &DecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 787 } 788 789 // UpdateOneID returns an update builder for the given id. 790 func (c *DecisionClient) UpdateOneID(id int) *DecisionUpdateOne { 791 mutation := newDecisionMutation(c.config, OpUpdateOne, withDecisionID(id)) 792 return &DecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 793 } 794 795 // Delete returns a delete builder for Decision. 796 func (c *DecisionClient) Delete() *DecisionDelete { 797 mutation := newDecisionMutation(c.config, OpDelete) 798 return &DecisionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 799 } 800 801 // DeleteOne returns a builder for deleting the given entity. 802 func (c *DecisionClient) DeleteOne(d *Decision) *DecisionDeleteOne { 803 return c.DeleteOneID(d.ID) 804 } 805 806 // DeleteOneID returns a builder for deleting the given entity by its id. 807 func (c *DecisionClient) DeleteOneID(id int) *DecisionDeleteOne { 808 builder := c.Delete().Where(decision.ID(id)) 809 builder.mutation.id = &id 810 builder.mutation.op = OpDeleteOne 811 return &DecisionDeleteOne{builder} 812 } 813 814 // Query returns a query builder for Decision. 815 func (c *DecisionClient) Query() *DecisionQuery { 816 return &DecisionQuery{ 817 config: c.config, 818 ctx: &QueryContext{Type: TypeDecision}, 819 inters: c.Interceptors(), 820 } 821 } 822 823 // Get returns a Decision entity by its id. 824 func (c *DecisionClient) Get(ctx context.Context, id int) (*Decision, error) { 825 return c.Query().Where(decision.ID(id)).Only(ctx) 826 } 827 828 // GetX is like Get, but panics if an error occurs. 829 func (c *DecisionClient) GetX(ctx context.Context, id int) *Decision { 830 obj, err := c.Get(ctx, id) 831 if err != nil { 832 panic(err) 833 } 834 return obj 835 } 836 837 // QueryOwner queries the owner edge of a Decision. 838 func (c *DecisionClient) QueryOwner(d *Decision) *AlertQuery { 839 query := (&AlertClient{config: c.config}).Query() 840 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 841 id := d.ID 842 step := sqlgraph.NewStep( 843 sqlgraph.From(decision.Table, decision.FieldID, id), 844 sqlgraph.To(alert.Table, alert.FieldID), 845 sqlgraph.Edge(sqlgraph.M2O, true, decision.OwnerTable, decision.OwnerColumn), 846 ) 847 fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) 848 return fromV, nil 849 } 850 return query 851 } 852 853 // Hooks returns the client hooks. 854 func (c *DecisionClient) Hooks() []Hook { 855 return c.hooks.Decision 856 } 857 858 // Interceptors returns the client interceptors. 859 func (c *DecisionClient) Interceptors() []Interceptor { 860 return c.inters.Decision 861 } 862 863 func (c *DecisionClient) mutate(ctx context.Context, m *DecisionMutation) (Value, error) { 864 switch m.Op() { 865 case OpCreate: 866 return (&DecisionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 867 case OpUpdate: 868 return (&DecisionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 869 case OpUpdateOne: 870 return (&DecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 871 case OpDelete, OpDeleteOne: 872 return (&DecisionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 873 default: 874 return nil, fmt.Errorf("ent: unknown Decision mutation op: %q", m.Op()) 875 } 876 } 877 878 // EventClient is a client for the Event schema. 879 type EventClient struct { 880 config 881 } 882 883 // NewEventClient returns a client for the Event from the given config. 884 func NewEventClient(c config) *EventClient { 885 return &EventClient{config: c} 886 } 887 888 // Use adds a list of mutation hooks to the hooks stack. 889 // A call to `Use(f, g, h)` equals to `event.Hooks(f(g(h())))`. 890 func (c *EventClient) Use(hooks ...Hook) { 891 c.hooks.Event = append(c.hooks.Event, hooks...) 892 } 893 894 // Intercept adds a list of query interceptors to the interceptors stack. 895 // A call to `Intercept(f, g, h)` equals to `event.Intercept(f(g(h())))`. 896 func (c *EventClient) Intercept(interceptors ...Interceptor) { 897 c.inters.Event = append(c.inters.Event, interceptors...) 898 } 899 900 // Create returns a builder for creating a Event entity. 901 func (c *EventClient) Create() *EventCreate { 902 mutation := newEventMutation(c.config, OpCreate) 903 return &EventCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 904 } 905 906 // CreateBulk returns a builder for creating a bulk of Event entities. 907 func (c *EventClient) CreateBulk(builders ...*EventCreate) *EventCreateBulk { 908 return &EventCreateBulk{config: c.config, builders: builders} 909 } 910 911 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 912 // a builder and applies setFunc on it. 913 func (c *EventClient) MapCreateBulk(slice any, setFunc func(*EventCreate, int)) *EventCreateBulk { 914 rv := reflect.ValueOf(slice) 915 if rv.Kind() != reflect.Slice { 916 return &EventCreateBulk{err: fmt.Errorf("calling to EventClient.MapCreateBulk with wrong type %T, need slice", slice)} 917 } 918 builders := make([]*EventCreate, rv.Len()) 919 for i := 0; i < rv.Len(); i++ { 920 builders[i] = c.Create() 921 setFunc(builders[i], i) 922 } 923 return &EventCreateBulk{config: c.config, builders: builders} 924 } 925 926 // Update returns an update builder for Event. 927 func (c *EventClient) Update() *EventUpdate { 928 mutation := newEventMutation(c.config, OpUpdate) 929 return &EventUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 930 } 931 932 // UpdateOne returns an update builder for the given entity. 933 func (c *EventClient) UpdateOne(e *Event) *EventUpdateOne { 934 mutation := newEventMutation(c.config, OpUpdateOne, withEvent(e)) 935 return &EventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 936 } 937 938 // UpdateOneID returns an update builder for the given id. 939 func (c *EventClient) UpdateOneID(id int) *EventUpdateOne { 940 mutation := newEventMutation(c.config, OpUpdateOne, withEventID(id)) 941 return &EventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 942 } 943 944 // Delete returns a delete builder for Event. 945 func (c *EventClient) Delete() *EventDelete { 946 mutation := newEventMutation(c.config, OpDelete) 947 return &EventDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 948 } 949 950 // DeleteOne returns a builder for deleting the given entity. 951 func (c *EventClient) DeleteOne(e *Event) *EventDeleteOne { 952 return c.DeleteOneID(e.ID) 953 } 954 955 // DeleteOneID returns a builder for deleting the given entity by its id. 956 func (c *EventClient) DeleteOneID(id int) *EventDeleteOne { 957 builder := c.Delete().Where(event.ID(id)) 958 builder.mutation.id = &id 959 builder.mutation.op = OpDeleteOne 960 return &EventDeleteOne{builder} 961 } 962 963 // Query returns a query builder for Event. 964 func (c *EventClient) Query() *EventQuery { 965 return &EventQuery{ 966 config: c.config, 967 ctx: &QueryContext{Type: TypeEvent}, 968 inters: c.Interceptors(), 969 } 970 } 971 972 // Get returns a Event entity by its id. 973 func (c *EventClient) Get(ctx context.Context, id int) (*Event, error) { 974 return c.Query().Where(event.ID(id)).Only(ctx) 975 } 976 977 // GetX is like Get, but panics if an error occurs. 978 func (c *EventClient) GetX(ctx context.Context, id int) *Event { 979 obj, err := c.Get(ctx, id) 980 if err != nil { 981 panic(err) 982 } 983 return obj 984 } 985 986 // QueryOwner queries the owner edge of a Event. 987 func (c *EventClient) QueryOwner(e *Event) *AlertQuery { 988 query := (&AlertClient{config: c.config}).Query() 989 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 990 id := e.ID 991 step := sqlgraph.NewStep( 992 sqlgraph.From(event.Table, event.FieldID, id), 993 sqlgraph.To(alert.Table, alert.FieldID), 994 sqlgraph.Edge(sqlgraph.M2O, true, event.OwnerTable, event.OwnerColumn), 995 ) 996 fromV = sqlgraph.Neighbors(e.driver.Dialect(), step) 997 return fromV, nil 998 } 999 return query 1000 } 1001 1002 // Hooks returns the client hooks. 1003 func (c *EventClient) Hooks() []Hook { 1004 return c.hooks.Event 1005 } 1006 1007 // Interceptors returns the client interceptors. 1008 func (c *EventClient) Interceptors() []Interceptor { 1009 return c.inters.Event 1010 } 1011 1012 func (c *EventClient) mutate(ctx context.Context, m *EventMutation) (Value, error) { 1013 switch m.Op() { 1014 case OpCreate: 1015 return (&EventCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1016 case OpUpdate: 1017 return (&EventUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1018 case OpUpdateOne: 1019 return (&EventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1020 case OpDelete, OpDeleteOne: 1021 return (&EventDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 1022 default: 1023 return nil, fmt.Errorf("ent: unknown Event mutation op: %q", m.Op()) 1024 } 1025 } 1026 1027 // LockClient is a client for the Lock schema. 1028 type LockClient struct { 1029 config 1030 } 1031 1032 // NewLockClient returns a client for the Lock from the given config. 1033 func NewLockClient(c config) *LockClient { 1034 return &LockClient{config: c} 1035 } 1036 1037 // Use adds a list of mutation hooks to the hooks stack. 1038 // A call to `Use(f, g, h)` equals to `lock.Hooks(f(g(h())))`. 1039 func (c *LockClient) Use(hooks ...Hook) { 1040 c.hooks.Lock = append(c.hooks.Lock, hooks...) 1041 } 1042 1043 // Intercept adds a list of query interceptors to the interceptors stack. 1044 // A call to `Intercept(f, g, h)` equals to `lock.Intercept(f(g(h())))`. 1045 func (c *LockClient) Intercept(interceptors ...Interceptor) { 1046 c.inters.Lock = append(c.inters.Lock, interceptors...) 1047 } 1048 1049 // Create returns a builder for creating a Lock entity. 1050 func (c *LockClient) Create() *LockCreate { 1051 mutation := newLockMutation(c.config, OpCreate) 1052 return &LockCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1053 } 1054 1055 // CreateBulk returns a builder for creating a bulk of Lock entities. 1056 func (c *LockClient) CreateBulk(builders ...*LockCreate) *LockCreateBulk { 1057 return &LockCreateBulk{config: c.config, builders: builders} 1058 } 1059 1060 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 1061 // a builder and applies setFunc on it. 1062 func (c *LockClient) MapCreateBulk(slice any, setFunc func(*LockCreate, int)) *LockCreateBulk { 1063 rv := reflect.ValueOf(slice) 1064 if rv.Kind() != reflect.Slice { 1065 return &LockCreateBulk{err: fmt.Errorf("calling to LockClient.MapCreateBulk with wrong type %T, need slice", slice)} 1066 } 1067 builders := make([]*LockCreate, rv.Len()) 1068 for i := 0; i < rv.Len(); i++ { 1069 builders[i] = c.Create() 1070 setFunc(builders[i], i) 1071 } 1072 return &LockCreateBulk{config: c.config, builders: builders} 1073 } 1074 1075 // Update returns an update builder for Lock. 1076 func (c *LockClient) Update() *LockUpdate { 1077 mutation := newLockMutation(c.config, OpUpdate) 1078 return &LockUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1079 } 1080 1081 // UpdateOne returns an update builder for the given entity. 1082 func (c *LockClient) UpdateOne(l *Lock) *LockUpdateOne { 1083 mutation := newLockMutation(c.config, OpUpdateOne, withLock(l)) 1084 return &LockUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1085 } 1086 1087 // UpdateOneID returns an update builder for the given id. 1088 func (c *LockClient) UpdateOneID(id int) *LockUpdateOne { 1089 mutation := newLockMutation(c.config, OpUpdateOne, withLockID(id)) 1090 return &LockUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1091 } 1092 1093 // Delete returns a delete builder for Lock. 1094 func (c *LockClient) Delete() *LockDelete { 1095 mutation := newLockMutation(c.config, OpDelete) 1096 return &LockDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 1097 } 1098 1099 // DeleteOne returns a builder for deleting the given entity. 1100 func (c *LockClient) DeleteOne(l *Lock) *LockDeleteOne { 1101 return c.DeleteOneID(l.ID) 1102 } 1103 1104 // DeleteOneID returns a builder for deleting the given entity by its id. 1105 func (c *LockClient) DeleteOneID(id int) *LockDeleteOne { 1106 builder := c.Delete().Where(lock.ID(id)) 1107 builder.mutation.id = &id 1108 builder.mutation.op = OpDeleteOne 1109 return &LockDeleteOne{builder} 1110 } 1111 1112 // Query returns a query builder for Lock. 1113 func (c *LockClient) Query() *LockQuery { 1114 return &LockQuery{ 1115 config: c.config, 1116 ctx: &QueryContext{Type: TypeLock}, 1117 inters: c.Interceptors(), 1118 } 1119 } 1120 1121 // Get returns a Lock entity by its id. 1122 func (c *LockClient) Get(ctx context.Context, id int) (*Lock, error) { 1123 return c.Query().Where(lock.ID(id)).Only(ctx) 1124 } 1125 1126 // GetX is like Get, but panics if an error occurs. 1127 func (c *LockClient) GetX(ctx context.Context, id int) *Lock { 1128 obj, err := c.Get(ctx, id) 1129 if err != nil { 1130 panic(err) 1131 } 1132 return obj 1133 } 1134 1135 // Hooks returns the client hooks. 1136 func (c *LockClient) Hooks() []Hook { 1137 return c.hooks.Lock 1138 } 1139 1140 // Interceptors returns the client interceptors. 1141 func (c *LockClient) Interceptors() []Interceptor { 1142 return c.inters.Lock 1143 } 1144 1145 func (c *LockClient) mutate(ctx context.Context, m *LockMutation) (Value, error) { 1146 switch m.Op() { 1147 case OpCreate: 1148 return (&LockCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1149 case OpUpdate: 1150 return (&LockUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1151 case OpUpdateOne: 1152 return (&LockUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1153 case OpDelete, OpDeleteOne: 1154 return (&LockDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 1155 default: 1156 return nil, fmt.Errorf("ent: unknown Lock mutation op: %q", m.Op()) 1157 } 1158 } 1159 1160 // MachineClient is a client for the Machine schema. 1161 type MachineClient struct { 1162 config 1163 } 1164 1165 // NewMachineClient returns a client for the Machine from the given config. 1166 func NewMachineClient(c config) *MachineClient { 1167 return &MachineClient{config: c} 1168 } 1169 1170 // Use adds a list of mutation hooks to the hooks stack. 1171 // A call to `Use(f, g, h)` equals to `machine.Hooks(f(g(h())))`. 1172 func (c *MachineClient) Use(hooks ...Hook) { 1173 c.hooks.Machine = append(c.hooks.Machine, hooks...) 1174 } 1175 1176 // Intercept adds a list of query interceptors to the interceptors stack. 1177 // A call to `Intercept(f, g, h)` equals to `machine.Intercept(f(g(h())))`. 1178 func (c *MachineClient) Intercept(interceptors ...Interceptor) { 1179 c.inters.Machine = append(c.inters.Machine, interceptors...) 1180 } 1181 1182 // Create returns a builder for creating a Machine entity. 1183 func (c *MachineClient) Create() *MachineCreate { 1184 mutation := newMachineMutation(c.config, OpCreate) 1185 return &MachineCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1186 } 1187 1188 // CreateBulk returns a builder for creating a bulk of Machine entities. 1189 func (c *MachineClient) CreateBulk(builders ...*MachineCreate) *MachineCreateBulk { 1190 return &MachineCreateBulk{config: c.config, builders: builders} 1191 } 1192 1193 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 1194 // a builder and applies setFunc on it. 1195 func (c *MachineClient) MapCreateBulk(slice any, setFunc func(*MachineCreate, int)) *MachineCreateBulk { 1196 rv := reflect.ValueOf(slice) 1197 if rv.Kind() != reflect.Slice { 1198 return &MachineCreateBulk{err: fmt.Errorf("calling to MachineClient.MapCreateBulk with wrong type %T, need slice", slice)} 1199 } 1200 builders := make([]*MachineCreate, rv.Len()) 1201 for i := 0; i < rv.Len(); i++ { 1202 builders[i] = c.Create() 1203 setFunc(builders[i], i) 1204 } 1205 return &MachineCreateBulk{config: c.config, builders: builders} 1206 } 1207 1208 // Update returns an update builder for Machine. 1209 func (c *MachineClient) Update() *MachineUpdate { 1210 mutation := newMachineMutation(c.config, OpUpdate) 1211 return &MachineUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1212 } 1213 1214 // UpdateOne returns an update builder for the given entity. 1215 func (c *MachineClient) UpdateOne(m *Machine) *MachineUpdateOne { 1216 mutation := newMachineMutation(c.config, OpUpdateOne, withMachine(m)) 1217 return &MachineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1218 } 1219 1220 // UpdateOneID returns an update builder for the given id. 1221 func (c *MachineClient) UpdateOneID(id int) *MachineUpdateOne { 1222 mutation := newMachineMutation(c.config, OpUpdateOne, withMachineID(id)) 1223 return &MachineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1224 } 1225 1226 // Delete returns a delete builder for Machine. 1227 func (c *MachineClient) Delete() *MachineDelete { 1228 mutation := newMachineMutation(c.config, OpDelete) 1229 return &MachineDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 1230 } 1231 1232 // DeleteOne returns a builder for deleting the given entity. 1233 func (c *MachineClient) DeleteOne(m *Machine) *MachineDeleteOne { 1234 return c.DeleteOneID(m.ID) 1235 } 1236 1237 // DeleteOneID returns a builder for deleting the given entity by its id. 1238 func (c *MachineClient) DeleteOneID(id int) *MachineDeleteOne { 1239 builder := c.Delete().Where(machine.ID(id)) 1240 builder.mutation.id = &id 1241 builder.mutation.op = OpDeleteOne 1242 return &MachineDeleteOne{builder} 1243 } 1244 1245 // Query returns a query builder for Machine. 1246 func (c *MachineClient) Query() *MachineQuery { 1247 return &MachineQuery{ 1248 config: c.config, 1249 ctx: &QueryContext{Type: TypeMachine}, 1250 inters: c.Interceptors(), 1251 } 1252 } 1253 1254 // Get returns a Machine entity by its id. 1255 func (c *MachineClient) Get(ctx context.Context, id int) (*Machine, error) { 1256 return c.Query().Where(machine.ID(id)).Only(ctx) 1257 } 1258 1259 // GetX is like Get, but panics if an error occurs. 1260 func (c *MachineClient) GetX(ctx context.Context, id int) *Machine { 1261 obj, err := c.Get(ctx, id) 1262 if err != nil { 1263 panic(err) 1264 } 1265 return obj 1266 } 1267 1268 // QueryAlerts queries the alerts edge of a Machine. 1269 func (c *MachineClient) QueryAlerts(m *Machine) *AlertQuery { 1270 query := (&AlertClient{config: c.config}).Query() 1271 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 1272 id := m.ID 1273 step := sqlgraph.NewStep( 1274 sqlgraph.From(machine.Table, machine.FieldID, id), 1275 sqlgraph.To(alert.Table, alert.FieldID), 1276 sqlgraph.Edge(sqlgraph.O2M, false, machine.AlertsTable, machine.AlertsColumn), 1277 ) 1278 fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) 1279 return fromV, nil 1280 } 1281 return query 1282 } 1283 1284 // Hooks returns the client hooks. 1285 func (c *MachineClient) Hooks() []Hook { 1286 return c.hooks.Machine 1287 } 1288 1289 // Interceptors returns the client interceptors. 1290 func (c *MachineClient) Interceptors() []Interceptor { 1291 return c.inters.Machine 1292 } 1293 1294 func (c *MachineClient) mutate(ctx context.Context, m *MachineMutation) (Value, error) { 1295 switch m.Op() { 1296 case OpCreate: 1297 return (&MachineCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1298 case OpUpdate: 1299 return (&MachineUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1300 case OpUpdateOne: 1301 return (&MachineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1302 case OpDelete, OpDeleteOne: 1303 return (&MachineDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 1304 default: 1305 return nil, fmt.Errorf("ent: unknown Machine mutation op: %q", m.Op()) 1306 } 1307 } 1308 1309 // MetaClient is a client for the Meta schema. 1310 type MetaClient struct { 1311 config 1312 } 1313 1314 // NewMetaClient returns a client for the Meta from the given config. 1315 func NewMetaClient(c config) *MetaClient { 1316 return &MetaClient{config: c} 1317 } 1318 1319 // Use adds a list of mutation hooks to the hooks stack. 1320 // A call to `Use(f, g, h)` equals to `meta.Hooks(f(g(h())))`. 1321 func (c *MetaClient) Use(hooks ...Hook) { 1322 c.hooks.Meta = append(c.hooks.Meta, hooks...) 1323 } 1324 1325 // Intercept adds a list of query interceptors to the interceptors stack. 1326 // A call to `Intercept(f, g, h)` equals to `meta.Intercept(f(g(h())))`. 1327 func (c *MetaClient) Intercept(interceptors ...Interceptor) { 1328 c.inters.Meta = append(c.inters.Meta, interceptors...) 1329 } 1330 1331 // Create returns a builder for creating a Meta entity. 1332 func (c *MetaClient) Create() *MetaCreate { 1333 mutation := newMetaMutation(c.config, OpCreate) 1334 return &MetaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1335 } 1336 1337 // CreateBulk returns a builder for creating a bulk of Meta entities. 1338 func (c *MetaClient) CreateBulk(builders ...*MetaCreate) *MetaCreateBulk { 1339 return &MetaCreateBulk{config: c.config, builders: builders} 1340 } 1341 1342 // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates 1343 // a builder and applies setFunc on it. 1344 func (c *MetaClient) MapCreateBulk(slice any, setFunc func(*MetaCreate, int)) *MetaCreateBulk { 1345 rv := reflect.ValueOf(slice) 1346 if rv.Kind() != reflect.Slice { 1347 return &MetaCreateBulk{err: fmt.Errorf("calling to MetaClient.MapCreateBulk with wrong type %T, need slice", slice)} 1348 } 1349 builders := make([]*MetaCreate, rv.Len()) 1350 for i := 0; i < rv.Len(); i++ { 1351 builders[i] = c.Create() 1352 setFunc(builders[i], i) 1353 } 1354 return &MetaCreateBulk{config: c.config, builders: builders} 1355 } 1356 1357 // Update returns an update builder for Meta. 1358 func (c *MetaClient) Update() *MetaUpdate { 1359 mutation := newMetaMutation(c.config, OpUpdate) 1360 return &MetaUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1361 } 1362 1363 // UpdateOne returns an update builder for the given entity. 1364 func (c *MetaClient) UpdateOne(m *Meta) *MetaUpdateOne { 1365 mutation := newMetaMutation(c.config, OpUpdateOne, withMeta(m)) 1366 return &MetaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1367 } 1368 1369 // UpdateOneID returns an update builder for the given id. 1370 func (c *MetaClient) UpdateOneID(id int) *MetaUpdateOne { 1371 mutation := newMetaMutation(c.config, OpUpdateOne, withMetaID(id)) 1372 return &MetaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1373 } 1374 1375 // Delete returns a delete builder for Meta. 1376 func (c *MetaClient) Delete() *MetaDelete { 1377 mutation := newMetaMutation(c.config, OpDelete) 1378 return &MetaDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 1379 } 1380 1381 // DeleteOne returns a builder for deleting the given entity. 1382 func (c *MetaClient) DeleteOne(m *Meta) *MetaDeleteOne { 1383 return c.DeleteOneID(m.ID) 1384 } 1385 1386 // DeleteOneID returns a builder for deleting the given entity by its id. 1387 func (c *MetaClient) DeleteOneID(id int) *MetaDeleteOne { 1388 builder := c.Delete().Where(meta.ID(id)) 1389 builder.mutation.id = &id 1390 builder.mutation.op = OpDeleteOne 1391 return &MetaDeleteOne{builder} 1392 } 1393 1394 // Query returns a query builder for Meta. 1395 func (c *MetaClient) Query() *MetaQuery { 1396 return &MetaQuery{ 1397 config: c.config, 1398 ctx: &QueryContext{Type: TypeMeta}, 1399 inters: c.Interceptors(), 1400 } 1401 } 1402 1403 // Get returns a Meta entity by its id. 1404 func (c *MetaClient) Get(ctx context.Context, id int) (*Meta, error) { 1405 return c.Query().Where(meta.ID(id)).Only(ctx) 1406 } 1407 1408 // GetX is like Get, but panics if an error occurs. 1409 func (c *MetaClient) GetX(ctx context.Context, id int) *Meta { 1410 obj, err := c.Get(ctx, id) 1411 if err != nil { 1412 panic(err) 1413 } 1414 return obj 1415 } 1416 1417 // QueryOwner queries the owner edge of a Meta. 1418 func (c *MetaClient) QueryOwner(m *Meta) *AlertQuery { 1419 query := (&AlertClient{config: c.config}).Query() 1420 query.path = func(context.Context) (fromV *sql.Selector, _ error) { 1421 id := m.ID 1422 step := sqlgraph.NewStep( 1423 sqlgraph.From(meta.Table, meta.FieldID, id), 1424 sqlgraph.To(alert.Table, alert.FieldID), 1425 sqlgraph.Edge(sqlgraph.M2O, true, meta.OwnerTable, meta.OwnerColumn), 1426 ) 1427 fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) 1428 return fromV, nil 1429 } 1430 return query 1431 } 1432 1433 // Hooks returns the client hooks. 1434 func (c *MetaClient) Hooks() []Hook { 1435 return c.hooks.Meta 1436 } 1437 1438 // Interceptors returns the client interceptors. 1439 func (c *MetaClient) Interceptors() []Interceptor { 1440 return c.inters.Meta 1441 } 1442 1443 func (c *MetaClient) mutate(ctx context.Context, m *MetaMutation) (Value, error) { 1444 switch m.Op() { 1445 case OpCreate: 1446 return (&MetaCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1447 case OpUpdate: 1448 return (&MetaUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1449 case OpUpdateOne: 1450 return (&MetaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) 1451 case OpDelete, OpDeleteOne: 1452 return (&MetaDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) 1453 default: 1454 return nil, fmt.Errorf("ent: unknown Meta mutation op: %q", m.Op()) 1455 } 1456 } 1457 1458 // hooks and interceptors per client, for fast access. 1459 type ( 1460 hooks struct { 1461 Alert, Bouncer, ConfigItem, Decision, Event, Lock, Machine, Meta []ent.Hook 1462 } 1463 inters struct { 1464 Alert, Bouncer, ConfigItem, Decision, Event, Lock, Machine, 1465 Meta []ent.Interceptor 1466 } 1467 )