bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/client.go (about) 1 // Code generated by entc, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "context" 7 "fmt" 8 "log" 9 10 "bitbucket.org/Aishee/synsec/pkg/database/ent/migrate" 11 12 "bitbucket.org/Aishee/synsec/pkg/database/ent/alert" 13 "bitbucket.org/Aishee/synsec/pkg/database/ent/bouncer" 14 "bitbucket.org/Aishee/synsec/pkg/database/ent/decision" 15 "bitbucket.org/Aishee/synsec/pkg/database/ent/event" 16 "bitbucket.org/Aishee/synsec/pkg/database/ent/machine" 17 "bitbucket.org/Aishee/synsec/pkg/database/ent/meta" 18 19 "entgo.io/ent/dialect" 20 "entgo.io/ent/dialect/sql" 21 "entgo.io/ent/dialect/sql/sqlgraph" 22 ) 23 24 // Client is the client that holds all ent builders. 25 type Client struct { 26 config 27 // Schema is the client for creating, migrating and dropping schema. 28 Schema *migrate.Schema 29 // Alert is the client for interacting with the Alert builders. 30 Alert *AlertClient 31 // Bouncer is the client for interacting with the Bouncer builders. 32 Bouncer *BouncerClient 33 // Decision is the client for interacting with the Decision builders. 34 Decision *DecisionClient 35 // Event is the client for interacting with the Event builders. 36 Event *EventClient 37 // Machine is the client for interacting with the Machine builders. 38 Machine *MachineClient 39 // Meta is the client for interacting with the Meta builders. 40 Meta *MetaClient 41 } 42 43 // NewClient creates a new client configured with the given options. 44 func NewClient(opts ...Option) *Client { 45 cfg := config{log: log.Println, hooks: &hooks{}} 46 cfg.options(opts...) 47 client := &Client{config: cfg} 48 client.init() 49 return client 50 } 51 52 func (c *Client) init() { 53 c.Schema = migrate.NewSchema(c.driver) 54 c.Alert = NewAlertClient(c.config) 55 c.Bouncer = NewBouncerClient(c.config) 56 c.Decision = NewDecisionClient(c.config) 57 c.Event = NewEventClient(c.config) 58 c.Machine = NewMachineClient(c.config) 59 c.Meta = NewMetaClient(c.config) 60 } 61 62 // Open opens a database/sql.DB specified by the driver name and 63 // the data source name, and returns a new client attached to it. 64 // Optional parameters can be added for configuring the client. 65 func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { 66 switch driverName { 67 case dialect.MySQL, dialect.Postgres, dialect.SQLite: 68 drv, err := sql.Open(driverName, dataSourceName) 69 if err != nil { 70 return nil, err 71 } 72 return NewClient(append(options, Driver(drv))...), nil 73 default: 74 return nil, fmt.Errorf("unsupported driver: %q", driverName) 75 } 76 } 77 78 // Tx returns a new transactional client. The provided context 79 // is used until the transaction is committed or rolled back. 80 func (c *Client) Tx(ctx context.Context) (*Tx, error) { 81 if _, ok := c.driver.(*txDriver); ok { 82 return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") 83 } 84 tx, err := newTx(ctx, c.driver) 85 if err != nil { 86 return nil, fmt.Errorf("ent: starting a transaction: %w", err) 87 } 88 cfg := c.config 89 cfg.driver = tx 90 return &Tx{ 91 ctx: ctx, 92 config: cfg, 93 Alert: NewAlertClient(cfg), 94 Bouncer: NewBouncerClient(cfg), 95 Decision: NewDecisionClient(cfg), 96 Event: NewEventClient(cfg), 97 Machine: NewMachineClient(cfg), 98 Meta: NewMetaClient(cfg), 99 }, nil 100 } 101 102 // BeginTx returns a transactional client with specified options. 103 func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { 104 if _, ok := c.driver.(*txDriver); ok { 105 return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") 106 } 107 tx, err := c.driver.(interface { 108 BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) 109 }).BeginTx(ctx, opts) 110 if err != nil { 111 return nil, fmt.Errorf("ent: starting a transaction: %w", err) 112 } 113 cfg := c.config 114 cfg.driver = &txDriver{tx: tx, drv: c.driver} 115 return &Tx{ 116 config: cfg, 117 Alert: NewAlertClient(cfg), 118 Bouncer: NewBouncerClient(cfg), 119 Decision: NewDecisionClient(cfg), 120 Event: NewEventClient(cfg), 121 Machine: NewMachineClient(cfg), 122 Meta: NewMetaClient(cfg), 123 }, nil 124 } 125 126 // Debug returns a new debug-client. It's used to get verbose logging on specific operations. 127 // 128 // client.Debug(). 129 // Alert. 130 // Query(). 131 // Count(ctx) 132 // 133 func (c *Client) Debug() *Client { 134 if c.debug { 135 return c 136 } 137 cfg := c.config 138 cfg.driver = dialect.Debug(c.driver, c.log) 139 client := &Client{config: cfg} 140 client.init() 141 return client 142 } 143 144 // Close closes the database connection and prevents new queries from starting. 145 func (c *Client) Close() error { 146 return c.driver.Close() 147 } 148 149 // Use adds the mutation hooks to all the entity clients. 150 // In order to add hooks to a specific client, call: `client.Node.Use(...)`. 151 func (c *Client) Use(hooks ...Hook) { 152 c.Alert.Use(hooks...) 153 c.Bouncer.Use(hooks...) 154 c.Decision.Use(hooks...) 155 c.Event.Use(hooks...) 156 c.Machine.Use(hooks...) 157 c.Meta.Use(hooks...) 158 } 159 160 // AlertClient is a client for the Alert schema. 161 type AlertClient struct { 162 config 163 } 164 165 // NewAlertClient returns a client for the Alert from the given config. 166 func NewAlertClient(c config) *AlertClient { 167 return &AlertClient{config: c} 168 } 169 170 // Use adds a list of mutation hooks to the hooks stack. 171 // A call to `Use(f, g, h)` equals to `alert.Hooks(f(g(h())))`. 172 func (c *AlertClient) Use(hooks ...Hook) { 173 c.hooks.Alert = append(c.hooks.Alert, hooks...) 174 } 175 176 // Create returns a create builder for Alert. 177 func (c *AlertClient) Create() *AlertCreate { 178 mutation := newAlertMutation(c.config, OpCreate) 179 return &AlertCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 180 } 181 182 // CreateBulk returns a builder for creating a bulk of Alert entities. 183 func (c *AlertClient) CreateBulk(builders ...*AlertCreate) *AlertCreateBulk { 184 return &AlertCreateBulk{config: c.config, builders: builders} 185 } 186 187 // Update returns an update builder for Alert. 188 func (c *AlertClient) Update() *AlertUpdate { 189 mutation := newAlertMutation(c.config, OpUpdate) 190 return &AlertUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 191 } 192 193 // UpdateOne returns an update builder for the given entity. 194 func (c *AlertClient) UpdateOne(a *Alert) *AlertUpdateOne { 195 mutation := newAlertMutation(c.config, OpUpdateOne, withAlert(a)) 196 return &AlertUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 197 } 198 199 // UpdateOneID returns an update builder for the given id. 200 func (c *AlertClient) UpdateOneID(id int) *AlertUpdateOne { 201 mutation := newAlertMutation(c.config, OpUpdateOne, withAlertID(id)) 202 return &AlertUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 203 } 204 205 // Delete returns a delete builder for Alert. 206 func (c *AlertClient) Delete() *AlertDelete { 207 mutation := newAlertMutation(c.config, OpDelete) 208 return &AlertDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 209 } 210 211 // DeleteOne returns a delete builder for the given entity. 212 func (c *AlertClient) DeleteOne(a *Alert) *AlertDeleteOne { 213 return c.DeleteOneID(a.ID) 214 } 215 216 // DeleteOneID returns a delete builder for the given id. 217 func (c *AlertClient) DeleteOneID(id int) *AlertDeleteOne { 218 builder := c.Delete().Where(alert.ID(id)) 219 builder.mutation.id = &id 220 builder.mutation.op = OpDeleteOne 221 return &AlertDeleteOne{builder} 222 } 223 224 // Query returns a query builder for Alert. 225 func (c *AlertClient) Query() *AlertQuery { 226 return &AlertQuery{config: c.config} 227 } 228 229 // Get returns a Alert entity by its id. 230 func (c *AlertClient) Get(ctx context.Context, id int) (*Alert, error) { 231 return c.Query().Where(alert.ID(id)).Only(ctx) 232 } 233 234 // GetX is like Get, but panics if an error occurs. 235 func (c *AlertClient) GetX(ctx context.Context, id int) *Alert { 236 obj, err := c.Get(ctx, id) 237 if err != nil { 238 panic(err) 239 } 240 return obj 241 } 242 243 // QueryOwner queries the owner edge of a Alert. 244 func (c *AlertClient) QueryOwner(a *Alert) *MachineQuery { 245 query := &MachineQuery{config: c.config} 246 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 247 id := a.ID 248 step := sqlgraph.NewStep( 249 sqlgraph.From(alert.Table, alert.FieldID, id), 250 sqlgraph.To(machine.Table, machine.FieldID), 251 sqlgraph.Edge(sqlgraph.M2O, true, alert.OwnerTable, alert.OwnerColumn), 252 ) 253 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 254 return fromV, nil 255 } 256 return query 257 } 258 259 // QueryDecisions queries the decisions edge of a Alert. 260 func (c *AlertClient) QueryDecisions(a *Alert) *DecisionQuery { 261 query := &DecisionQuery{config: c.config} 262 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 263 id := a.ID 264 step := sqlgraph.NewStep( 265 sqlgraph.From(alert.Table, alert.FieldID, id), 266 sqlgraph.To(decision.Table, decision.FieldID), 267 sqlgraph.Edge(sqlgraph.O2M, false, alert.DecisionsTable, alert.DecisionsColumn), 268 ) 269 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 270 return fromV, nil 271 } 272 return query 273 } 274 275 // QueryEvents queries the events edge of a Alert. 276 func (c *AlertClient) QueryEvents(a *Alert) *EventQuery { 277 query := &EventQuery{config: c.config} 278 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 279 id := a.ID 280 step := sqlgraph.NewStep( 281 sqlgraph.From(alert.Table, alert.FieldID, id), 282 sqlgraph.To(event.Table, event.FieldID), 283 sqlgraph.Edge(sqlgraph.O2M, false, alert.EventsTable, alert.EventsColumn), 284 ) 285 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 286 return fromV, nil 287 } 288 return query 289 } 290 291 // QueryMetas queries the metas edge of a Alert. 292 func (c *AlertClient) QueryMetas(a *Alert) *MetaQuery { 293 query := &MetaQuery{config: c.config} 294 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 295 id := a.ID 296 step := sqlgraph.NewStep( 297 sqlgraph.From(alert.Table, alert.FieldID, id), 298 sqlgraph.To(meta.Table, meta.FieldID), 299 sqlgraph.Edge(sqlgraph.O2M, false, alert.MetasTable, alert.MetasColumn), 300 ) 301 fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) 302 return fromV, nil 303 } 304 return query 305 } 306 307 // Hooks returns the client hooks. 308 func (c *AlertClient) Hooks() []Hook { 309 return c.hooks.Alert 310 } 311 312 // BouncerClient is a client for the Bouncer schema. 313 type BouncerClient struct { 314 config 315 } 316 317 // NewBouncerClient returns a client for the Bouncer from the given config. 318 func NewBouncerClient(c config) *BouncerClient { 319 return &BouncerClient{config: c} 320 } 321 322 // Use adds a list of mutation hooks to the hooks stack. 323 // A call to `Use(f, g, h)` equals to `bouncer.Hooks(f(g(h())))`. 324 func (c *BouncerClient) Use(hooks ...Hook) { 325 c.hooks.Bouncer = append(c.hooks.Bouncer, hooks...) 326 } 327 328 // Create returns a create builder for Bouncer. 329 func (c *BouncerClient) Create() *BouncerCreate { 330 mutation := newBouncerMutation(c.config, OpCreate) 331 return &BouncerCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 332 } 333 334 // CreateBulk returns a builder for creating a bulk of Bouncer entities. 335 func (c *BouncerClient) CreateBulk(builders ...*BouncerCreate) *BouncerCreateBulk { 336 return &BouncerCreateBulk{config: c.config, builders: builders} 337 } 338 339 // Update returns an update builder for Bouncer. 340 func (c *BouncerClient) Update() *BouncerUpdate { 341 mutation := newBouncerMutation(c.config, OpUpdate) 342 return &BouncerUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 343 } 344 345 // UpdateOne returns an update builder for the given entity. 346 func (c *BouncerClient) UpdateOne(b *Bouncer) *BouncerUpdateOne { 347 mutation := newBouncerMutation(c.config, OpUpdateOne, withBouncer(b)) 348 return &BouncerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 349 } 350 351 // UpdateOneID returns an update builder for the given id. 352 func (c *BouncerClient) UpdateOneID(id int) *BouncerUpdateOne { 353 mutation := newBouncerMutation(c.config, OpUpdateOne, withBouncerID(id)) 354 return &BouncerUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 355 } 356 357 // Delete returns a delete builder for Bouncer. 358 func (c *BouncerClient) Delete() *BouncerDelete { 359 mutation := newBouncerMutation(c.config, OpDelete) 360 return &BouncerDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 361 } 362 363 // DeleteOne returns a delete builder for the given entity. 364 func (c *BouncerClient) DeleteOne(b *Bouncer) *BouncerDeleteOne { 365 return c.DeleteOneID(b.ID) 366 } 367 368 // DeleteOneID returns a delete builder for the given id. 369 func (c *BouncerClient) DeleteOneID(id int) *BouncerDeleteOne { 370 builder := c.Delete().Where(bouncer.ID(id)) 371 builder.mutation.id = &id 372 builder.mutation.op = OpDeleteOne 373 return &BouncerDeleteOne{builder} 374 } 375 376 // Query returns a query builder for Bouncer. 377 func (c *BouncerClient) Query() *BouncerQuery { 378 return &BouncerQuery{config: c.config} 379 } 380 381 // Get returns a Bouncer entity by its id. 382 func (c *BouncerClient) Get(ctx context.Context, id int) (*Bouncer, error) { 383 return c.Query().Where(bouncer.ID(id)).Only(ctx) 384 } 385 386 // GetX is like Get, but panics if an error occurs. 387 func (c *BouncerClient) GetX(ctx context.Context, id int) *Bouncer { 388 obj, err := c.Get(ctx, id) 389 if err != nil { 390 panic(err) 391 } 392 return obj 393 } 394 395 // Hooks returns the client hooks. 396 func (c *BouncerClient) Hooks() []Hook { 397 return c.hooks.Bouncer 398 } 399 400 // DecisionClient is a client for the Decision schema. 401 type DecisionClient struct { 402 config 403 } 404 405 // NewDecisionClient returns a client for the Decision from the given config. 406 func NewDecisionClient(c config) *DecisionClient { 407 return &DecisionClient{config: c} 408 } 409 410 // Use adds a list of mutation hooks to the hooks stack. 411 // A call to `Use(f, g, h)` equals to `decision.Hooks(f(g(h())))`. 412 func (c *DecisionClient) Use(hooks ...Hook) { 413 c.hooks.Decision = append(c.hooks.Decision, hooks...) 414 } 415 416 // Create returns a create builder for Decision. 417 func (c *DecisionClient) Create() *DecisionCreate { 418 mutation := newDecisionMutation(c.config, OpCreate) 419 return &DecisionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 420 } 421 422 // CreateBulk returns a builder for creating a bulk of Decision entities. 423 func (c *DecisionClient) CreateBulk(builders ...*DecisionCreate) *DecisionCreateBulk { 424 return &DecisionCreateBulk{config: c.config, builders: builders} 425 } 426 427 // Update returns an update builder for Decision. 428 func (c *DecisionClient) Update() *DecisionUpdate { 429 mutation := newDecisionMutation(c.config, OpUpdate) 430 return &DecisionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 431 } 432 433 // UpdateOne returns an update builder for the given entity. 434 func (c *DecisionClient) UpdateOne(d *Decision) *DecisionUpdateOne { 435 mutation := newDecisionMutation(c.config, OpUpdateOne, withDecision(d)) 436 return &DecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 437 } 438 439 // UpdateOneID returns an update builder for the given id. 440 func (c *DecisionClient) UpdateOneID(id int) *DecisionUpdateOne { 441 mutation := newDecisionMutation(c.config, OpUpdateOne, withDecisionID(id)) 442 return &DecisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 443 } 444 445 // Delete returns a delete builder for Decision. 446 func (c *DecisionClient) Delete() *DecisionDelete { 447 mutation := newDecisionMutation(c.config, OpDelete) 448 return &DecisionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 449 } 450 451 // DeleteOne returns a delete builder for the given entity. 452 func (c *DecisionClient) DeleteOne(d *Decision) *DecisionDeleteOne { 453 return c.DeleteOneID(d.ID) 454 } 455 456 // DeleteOneID returns a delete builder for the given id. 457 func (c *DecisionClient) DeleteOneID(id int) *DecisionDeleteOne { 458 builder := c.Delete().Where(decision.ID(id)) 459 builder.mutation.id = &id 460 builder.mutation.op = OpDeleteOne 461 return &DecisionDeleteOne{builder} 462 } 463 464 // Query returns a query builder for Decision. 465 func (c *DecisionClient) Query() *DecisionQuery { 466 return &DecisionQuery{config: c.config} 467 } 468 469 // Get returns a Decision entity by its id. 470 func (c *DecisionClient) Get(ctx context.Context, id int) (*Decision, error) { 471 return c.Query().Where(decision.ID(id)).Only(ctx) 472 } 473 474 // GetX is like Get, but panics if an error occurs. 475 func (c *DecisionClient) GetX(ctx context.Context, id int) *Decision { 476 obj, err := c.Get(ctx, id) 477 if err != nil { 478 panic(err) 479 } 480 return obj 481 } 482 483 // QueryOwner queries the owner edge of a Decision. 484 func (c *DecisionClient) QueryOwner(d *Decision) *AlertQuery { 485 query := &AlertQuery{config: c.config} 486 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 487 id := d.ID 488 step := sqlgraph.NewStep( 489 sqlgraph.From(decision.Table, decision.FieldID, id), 490 sqlgraph.To(alert.Table, alert.FieldID), 491 sqlgraph.Edge(sqlgraph.M2O, true, decision.OwnerTable, decision.OwnerColumn), 492 ) 493 fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) 494 return fromV, nil 495 } 496 return query 497 } 498 499 // Hooks returns the client hooks. 500 func (c *DecisionClient) Hooks() []Hook { 501 return c.hooks.Decision 502 } 503 504 // EventClient is a client for the Event schema. 505 type EventClient struct { 506 config 507 } 508 509 // NewEventClient returns a client for the Event from the given config. 510 func NewEventClient(c config) *EventClient { 511 return &EventClient{config: c} 512 } 513 514 // Use adds a list of mutation hooks to the hooks stack. 515 // A call to `Use(f, g, h)` equals to `event.Hooks(f(g(h())))`. 516 func (c *EventClient) Use(hooks ...Hook) { 517 c.hooks.Event = append(c.hooks.Event, hooks...) 518 } 519 520 // Create returns a create builder for Event. 521 func (c *EventClient) Create() *EventCreate { 522 mutation := newEventMutation(c.config, OpCreate) 523 return &EventCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 524 } 525 526 // CreateBulk returns a builder for creating a bulk of Event entities. 527 func (c *EventClient) CreateBulk(builders ...*EventCreate) *EventCreateBulk { 528 return &EventCreateBulk{config: c.config, builders: builders} 529 } 530 531 // Update returns an update builder for Event. 532 func (c *EventClient) Update() *EventUpdate { 533 mutation := newEventMutation(c.config, OpUpdate) 534 return &EventUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 535 } 536 537 // UpdateOne returns an update builder for the given entity. 538 func (c *EventClient) UpdateOne(e *Event) *EventUpdateOne { 539 mutation := newEventMutation(c.config, OpUpdateOne, withEvent(e)) 540 return &EventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 541 } 542 543 // UpdateOneID returns an update builder for the given id. 544 func (c *EventClient) UpdateOneID(id int) *EventUpdateOne { 545 mutation := newEventMutation(c.config, OpUpdateOne, withEventID(id)) 546 return &EventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 547 } 548 549 // Delete returns a delete builder for Event. 550 func (c *EventClient) Delete() *EventDelete { 551 mutation := newEventMutation(c.config, OpDelete) 552 return &EventDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 553 } 554 555 // DeleteOne returns a delete builder for the given entity. 556 func (c *EventClient) DeleteOne(e *Event) *EventDeleteOne { 557 return c.DeleteOneID(e.ID) 558 } 559 560 // DeleteOneID returns a delete builder for the given id. 561 func (c *EventClient) DeleteOneID(id int) *EventDeleteOne { 562 builder := c.Delete().Where(event.ID(id)) 563 builder.mutation.id = &id 564 builder.mutation.op = OpDeleteOne 565 return &EventDeleteOne{builder} 566 } 567 568 // Query returns a query builder for Event. 569 func (c *EventClient) Query() *EventQuery { 570 return &EventQuery{config: c.config} 571 } 572 573 // Get returns a Event entity by its id. 574 func (c *EventClient) Get(ctx context.Context, id int) (*Event, error) { 575 return c.Query().Where(event.ID(id)).Only(ctx) 576 } 577 578 // GetX is like Get, but panics if an error occurs. 579 func (c *EventClient) GetX(ctx context.Context, id int) *Event { 580 obj, err := c.Get(ctx, id) 581 if err != nil { 582 panic(err) 583 } 584 return obj 585 } 586 587 // QueryOwner queries the owner edge of a Event. 588 func (c *EventClient) QueryOwner(e *Event) *AlertQuery { 589 query := &AlertQuery{config: c.config} 590 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 591 id := e.ID 592 step := sqlgraph.NewStep( 593 sqlgraph.From(event.Table, event.FieldID, id), 594 sqlgraph.To(alert.Table, alert.FieldID), 595 sqlgraph.Edge(sqlgraph.M2O, true, event.OwnerTable, event.OwnerColumn), 596 ) 597 fromV = sqlgraph.Neighbors(e.driver.Dialect(), step) 598 return fromV, nil 599 } 600 return query 601 } 602 603 // Hooks returns the client hooks. 604 func (c *EventClient) Hooks() []Hook { 605 return c.hooks.Event 606 } 607 608 // MachineClient is a client for the Machine schema. 609 type MachineClient struct { 610 config 611 } 612 613 // NewMachineClient returns a client for the Machine from the given config. 614 func NewMachineClient(c config) *MachineClient { 615 return &MachineClient{config: c} 616 } 617 618 // Use adds a list of mutation hooks to the hooks stack. 619 // A call to `Use(f, g, h)` equals to `machine.Hooks(f(g(h())))`. 620 func (c *MachineClient) Use(hooks ...Hook) { 621 c.hooks.Machine = append(c.hooks.Machine, hooks...) 622 } 623 624 // Create returns a create builder for Machine. 625 func (c *MachineClient) Create() *MachineCreate { 626 mutation := newMachineMutation(c.config, OpCreate) 627 return &MachineCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 628 } 629 630 // CreateBulk returns a builder for creating a bulk of Machine entities. 631 func (c *MachineClient) CreateBulk(builders ...*MachineCreate) *MachineCreateBulk { 632 return &MachineCreateBulk{config: c.config, builders: builders} 633 } 634 635 // Update returns an update builder for Machine. 636 func (c *MachineClient) Update() *MachineUpdate { 637 mutation := newMachineMutation(c.config, OpUpdate) 638 return &MachineUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 639 } 640 641 // UpdateOne returns an update builder for the given entity. 642 func (c *MachineClient) UpdateOne(m *Machine) *MachineUpdateOne { 643 mutation := newMachineMutation(c.config, OpUpdateOne, withMachine(m)) 644 return &MachineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 645 } 646 647 // UpdateOneID returns an update builder for the given id. 648 func (c *MachineClient) UpdateOneID(id int) *MachineUpdateOne { 649 mutation := newMachineMutation(c.config, OpUpdateOne, withMachineID(id)) 650 return &MachineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 651 } 652 653 // Delete returns a delete builder for Machine. 654 func (c *MachineClient) Delete() *MachineDelete { 655 mutation := newMachineMutation(c.config, OpDelete) 656 return &MachineDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 657 } 658 659 // DeleteOne returns a delete builder for the given entity. 660 func (c *MachineClient) DeleteOne(m *Machine) *MachineDeleteOne { 661 return c.DeleteOneID(m.ID) 662 } 663 664 // DeleteOneID returns a delete builder for the given id. 665 func (c *MachineClient) DeleteOneID(id int) *MachineDeleteOne { 666 builder := c.Delete().Where(machine.ID(id)) 667 builder.mutation.id = &id 668 builder.mutation.op = OpDeleteOne 669 return &MachineDeleteOne{builder} 670 } 671 672 // Query returns a query builder for Machine. 673 func (c *MachineClient) Query() *MachineQuery { 674 return &MachineQuery{config: c.config} 675 } 676 677 // Get returns a Machine entity by its id. 678 func (c *MachineClient) Get(ctx context.Context, id int) (*Machine, error) { 679 return c.Query().Where(machine.ID(id)).Only(ctx) 680 } 681 682 // GetX is like Get, but panics if an error occurs. 683 func (c *MachineClient) GetX(ctx context.Context, id int) *Machine { 684 obj, err := c.Get(ctx, id) 685 if err != nil { 686 panic(err) 687 } 688 return obj 689 } 690 691 // QueryAlerts queries the alerts edge of a Machine. 692 func (c *MachineClient) QueryAlerts(m *Machine) *AlertQuery { 693 query := &AlertQuery{config: c.config} 694 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 695 id := m.ID 696 step := sqlgraph.NewStep( 697 sqlgraph.From(machine.Table, machine.FieldID, id), 698 sqlgraph.To(alert.Table, alert.FieldID), 699 sqlgraph.Edge(sqlgraph.O2M, false, machine.AlertsTable, machine.AlertsColumn), 700 ) 701 fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) 702 return fromV, nil 703 } 704 return query 705 } 706 707 // Hooks returns the client hooks. 708 func (c *MachineClient) Hooks() []Hook { 709 return c.hooks.Machine 710 } 711 712 // MetaClient is a client for the Meta schema. 713 type MetaClient struct { 714 config 715 } 716 717 // NewMetaClient returns a client for the Meta from the given config. 718 func NewMetaClient(c config) *MetaClient { 719 return &MetaClient{config: c} 720 } 721 722 // Use adds a list of mutation hooks to the hooks stack. 723 // A call to `Use(f, g, h)` equals to `meta.Hooks(f(g(h())))`. 724 func (c *MetaClient) Use(hooks ...Hook) { 725 c.hooks.Meta = append(c.hooks.Meta, hooks...) 726 } 727 728 // Create returns a create builder for Meta. 729 func (c *MetaClient) Create() *MetaCreate { 730 mutation := newMetaMutation(c.config, OpCreate) 731 return &MetaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 732 } 733 734 // CreateBulk returns a builder for creating a bulk of Meta entities. 735 func (c *MetaClient) CreateBulk(builders ...*MetaCreate) *MetaCreateBulk { 736 return &MetaCreateBulk{config: c.config, builders: builders} 737 } 738 739 // Update returns an update builder for Meta. 740 func (c *MetaClient) Update() *MetaUpdate { 741 mutation := newMetaMutation(c.config, OpUpdate) 742 return &MetaUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 743 } 744 745 // UpdateOne returns an update builder for the given entity. 746 func (c *MetaClient) UpdateOne(m *Meta) *MetaUpdateOne { 747 mutation := newMetaMutation(c.config, OpUpdateOne, withMeta(m)) 748 return &MetaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 749 } 750 751 // UpdateOneID returns an update builder for the given id. 752 func (c *MetaClient) UpdateOneID(id int) *MetaUpdateOne { 753 mutation := newMetaMutation(c.config, OpUpdateOne, withMetaID(id)) 754 return &MetaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 755 } 756 757 // Delete returns a delete builder for Meta. 758 func (c *MetaClient) Delete() *MetaDelete { 759 mutation := newMetaMutation(c.config, OpDelete) 760 return &MetaDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 761 } 762 763 // DeleteOne returns a delete builder for the given entity. 764 func (c *MetaClient) DeleteOne(m *Meta) *MetaDeleteOne { 765 return c.DeleteOneID(m.ID) 766 } 767 768 // DeleteOneID returns a delete builder for the given id. 769 func (c *MetaClient) DeleteOneID(id int) *MetaDeleteOne { 770 builder := c.Delete().Where(meta.ID(id)) 771 builder.mutation.id = &id 772 builder.mutation.op = OpDeleteOne 773 return &MetaDeleteOne{builder} 774 } 775 776 // Query returns a query builder for Meta. 777 func (c *MetaClient) Query() *MetaQuery { 778 return &MetaQuery{config: c.config} 779 } 780 781 // Get returns a Meta entity by its id. 782 func (c *MetaClient) Get(ctx context.Context, id int) (*Meta, error) { 783 return c.Query().Where(meta.ID(id)).Only(ctx) 784 } 785 786 // GetX is like Get, but panics if an error occurs. 787 func (c *MetaClient) GetX(ctx context.Context, id int) *Meta { 788 obj, err := c.Get(ctx, id) 789 if err != nil { 790 panic(err) 791 } 792 return obj 793 } 794 795 // QueryOwner queries the owner edge of a Meta. 796 func (c *MetaClient) QueryOwner(m *Meta) *AlertQuery { 797 query := &AlertQuery{config: c.config} 798 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 799 id := m.ID 800 step := sqlgraph.NewStep( 801 sqlgraph.From(meta.Table, meta.FieldID, id), 802 sqlgraph.To(alert.Table, alert.FieldID), 803 sqlgraph.Edge(sqlgraph.M2O, true, meta.OwnerTable, meta.OwnerColumn), 804 ) 805 fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) 806 return fromV, nil 807 } 808 return query 809 } 810 811 // Hooks returns the client hooks. 812 func (c *MetaClient) Hooks() []Hook { 813 return c.hooks.Meta 814 }