github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/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 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/migrate" 11 12 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/comment" 13 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/file" 14 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/page" 15 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/permission" 16 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/post" 17 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/role" 18 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/setting" 19 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/topic" 20 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/user" 21 22 "entgo.io/ent/dialect" 23 "entgo.io/ent/dialect/sql" 24 "entgo.io/ent/dialect/sql/sqlgraph" 25 ) 26 27 // Client is the client that holds all ent builders. 28 type Client struct { 29 config 30 // Schema is the client for creating, migrating and dropping schema. 31 Schema *migrate.Schema 32 // Comment is the client for interacting with the Comment builders. 33 Comment *CommentClient 34 // File is the client for interacting with the File builders. 35 File *FileClient 36 // Page is the client for interacting with the Page builders. 37 Page *PageClient 38 // Permission is the client for interacting with the Permission builders. 39 Permission *PermissionClient 40 // Post is the client for interacting with the Post builders. 41 Post *PostClient 42 // Role is the client for interacting with the Role builders. 43 Role *RoleClient 44 // Setting is the client for interacting with the Setting builders. 45 Setting *SettingClient 46 // Topic is the client for interacting with the Topic builders. 47 Topic *TopicClient 48 // User is the client for interacting with the User builders. 49 User *UserClient 50 } 51 52 // NewClient creates a new client configured with the given options. 53 func NewClient(opts ...Option) *Client { 54 cfg := config{log: log.Println, hooks: &hooks{}} 55 cfg.options(opts...) 56 client := &Client{config: cfg} 57 client.init() 58 return client 59 } 60 61 func (c *Client) init() { 62 c.Schema = migrate.NewSchema(c.driver) 63 c.Comment = NewCommentClient(c.config) 64 c.File = NewFileClient(c.config) 65 c.Page = NewPageClient(c.config) 66 c.Permission = NewPermissionClient(c.config) 67 c.Post = NewPostClient(c.config) 68 c.Role = NewRoleClient(c.config) 69 c.Setting = NewSettingClient(c.config) 70 c.Topic = NewTopicClient(c.config) 71 c.User = NewUserClient(c.config) 72 } 73 74 // Open opens a database/sql.DB specified by the driver name and 75 // the data source name, and returns a new client attached to it. 76 // Optional parameters can be added for configuring the client. 77 func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { 78 switch driverName { 79 case dialect.MySQL, dialect.Postgres, dialect.SQLite: 80 drv, err := sql.Open(driverName, dataSourceName) 81 if err != nil { 82 return nil, err 83 } 84 return NewClient(append(options, Driver(drv))...), nil 85 default: 86 return nil, fmt.Errorf("unsupported driver: %q", driverName) 87 } 88 } 89 90 // Tx returns a new transactional client. The provided context 91 // is used until the transaction is committed or rolled back. 92 func (c *Client) Tx(ctx context.Context) (*Tx, error) { 93 if _, ok := c.driver.(*txDriver); ok { 94 return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") 95 } 96 tx, err := newTx(ctx, c.driver) 97 if err != nil { 98 return nil, fmt.Errorf("ent: starting a transaction: %w", err) 99 } 100 cfg := c.config 101 cfg.driver = tx 102 return &Tx{ 103 ctx: ctx, 104 config: cfg, 105 Comment: NewCommentClient(cfg), 106 File: NewFileClient(cfg), 107 Page: NewPageClient(cfg), 108 Permission: NewPermissionClient(cfg), 109 Post: NewPostClient(cfg), 110 Role: NewRoleClient(cfg), 111 Setting: NewSettingClient(cfg), 112 Topic: NewTopicClient(cfg), 113 User: NewUserClient(cfg), 114 }, nil 115 } 116 117 // BeginTx returns a transactional client with specified options. 118 func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { 119 if _, ok := c.driver.(*txDriver); ok { 120 return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") 121 } 122 tx, err := c.driver.(interface { 123 BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) 124 }).BeginTx(ctx, opts) 125 if err != nil { 126 return nil, fmt.Errorf("ent: starting a transaction: %w", err) 127 } 128 cfg := c.config 129 cfg.driver = &txDriver{tx: tx, drv: c.driver} 130 return &Tx{ 131 ctx: ctx, 132 config: cfg, 133 Comment: NewCommentClient(cfg), 134 File: NewFileClient(cfg), 135 Page: NewPageClient(cfg), 136 Permission: NewPermissionClient(cfg), 137 Post: NewPostClient(cfg), 138 Role: NewRoleClient(cfg), 139 Setting: NewSettingClient(cfg), 140 Topic: NewTopicClient(cfg), 141 User: NewUserClient(cfg), 142 }, nil 143 } 144 145 // Debug returns a new debug-client. It's used to get verbose logging on specific operations. 146 // 147 // client.Debug(). 148 // Comment. 149 // Query(). 150 // Count(ctx) 151 // 152 func (c *Client) Debug() *Client { 153 if c.debug { 154 return c 155 } 156 cfg := c.config 157 cfg.driver = dialect.Debug(c.driver, c.log) 158 client := &Client{config: cfg} 159 client.init() 160 return client 161 } 162 163 // Close closes the database connection and prevents new queries from starting. 164 func (c *Client) Close() error { 165 return c.driver.Close() 166 } 167 168 // Use adds the mutation hooks to all the entity clients. 169 // In order to add hooks to a specific client, call: `client.Node.Use(...)`. 170 func (c *Client) Use(hooks ...Hook) { 171 c.Comment.Use(hooks...) 172 c.File.Use(hooks...) 173 c.Page.Use(hooks...) 174 c.Permission.Use(hooks...) 175 c.Post.Use(hooks...) 176 c.Role.Use(hooks...) 177 c.Setting.Use(hooks...) 178 c.Topic.Use(hooks...) 179 c.User.Use(hooks...) 180 } 181 182 // CommentClient is a client for the Comment schema. 183 type CommentClient struct { 184 config 185 } 186 187 // NewCommentClient returns a client for the Comment from the given config. 188 func NewCommentClient(c config) *CommentClient { 189 return &CommentClient{config: c} 190 } 191 192 // Use adds a list of mutation hooks to the hooks stack. 193 // A call to `Use(f, g, h)` equals to `comment.Hooks(f(g(h())))`. 194 func (c *CommentClient) Use(hooks ...Hook) { 195 c.hooks.Comment = append(c.hooks.Comment, hooks...) 196 } 197 198 // Create returns a create builder for Comment. 199 func (c *CommentClient) Create() *CommentCreate { 200 mutation := newCommentMutation(c.config, OpCreate) 201 return &CommentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 202 } 203 204 // CreateBulk returns a builder for creating a bulk of Comment entities. 205 func (c *CommentClient) CreateBulk(builders ...*CommentCreate) *CommentCreateBulk { 206 return &CommentCreateBulk{config: c.config, builders: builders} 207 } 208 209 // Update returns an update builder for Comment. 210 func (c *CommentClient) Update() *CommentUpdate { 211 mutation := newCommentMutation(c.config, OpUpdate) 212 return &CommentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 213 } 214 215 // UpdateOne returns an update builder for the given entity. 216 func (c *CommentClient) UpdateOne(co *Comment) *CommentUpdateOne { 217 mutation := newCommentMutation(c.config, OpUpdateOne, withComment(co)) 218 return &CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 219 } 220 221 // UpdateOneID returns an update builder for the given id. 222 func (c *CommentClient) UpdateOneID(id int) *CommentUpdateOne { 223 mutation := newCommentMutation(c.config, OpUpdateOne, withCommentID(id)) 224 return &CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 225 } 226 227 // Delete returns a delete builder for Comment. 228 func (c *CommentClient) Delete() *CommentDelete { 229 mutation := newCommentMutation(c.config, OpDelete) 230 return &CommentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 231 } 232 233 // DeleteOne returns a delete builder for the given entity. 234 func (c *CommentClient) DeleteOne(co *Comment) *CommentDeleteOne { 235 return c.DeleteOneID(co.ID) 236 } 237 238 // DeleteOneID returns a delete builder for the given id. 239 func (c *CommentClient) DeleteOneID(id int) *CommentDeleteOne { 240 builder := c.Delete().Where(comment.ID(id)) 241 builder.mutation.id = &id 242 builder.mutation.op = OpDeleteOne 243 return &CommentDeleteOne{builder} 244 } 245 246 // Query returns a query builder for Comment. 247 func (c *CommentClient) Query() *CommentQuery { 248 return &CommentQuery{ 249 config: c.config, 250 } 251 } 252 253 // Get returns a Comment entity by its id. 254 func (c *CommentClient) Get(ctx context.Context, id int) (*Comment, error) { 255 return c.Query().Where(comment.ID(id)).Only(ctx) 256 } 257 258 // GetX is like Get, but panics if an error occurs. 259 func (c *CommentClient) GetX(ctx context.Context, id int) *Comment { 260 obj, err := c.Get(ctx, id) 261 if err != nil { 262 panic(err) 263 } 264 return obj 265 } 266 267 // QueryPost queries the post edge of a Comment. 268 func (c *CommentClient) QueryPost(co *Comment) *PostQuery { 269 query := &PostQuery{config: c.config} 270 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 271 id := co.ID 272 step := sqlgraph.NewStep( 273 sqlgraph.From(comment.Table, comment.FieldID, id), 274 sqlgraph.To(post.Table, post.FieldID), 275 sqlgraph.Edge(sqlgraph.M2O, true, comment.PostTable, comment.PostColumn), 276 ) 277 fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) 278 return fromV, nil 279 } 280 return query 281 } 282 283 // QueryUser queries the user edge of a Comment. 284 func (c *CommentClient) QueryUser(co *Comment) *UserQuery { 285 query := &UserQuery{config: c.config} 286 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 287 id := co.ID 288 step := sqlgraph.NewStep( 289 sqlgraph.From(comment.Table, comment.FieldID, id), 290 sqlgraph.To(user.Table, user.FieldID), 291 sqlgraph.Edge(sqlgraph.M2O, true, comment.UserTable, comment.UserColumn), 292 ) 293 fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) 294 return fromV, nil 295 } 296 return query 297 } 298 299 // QueryChildren queries the children edge of a Comment. 300 func (c *CommentClient) QueryChildren(co *Comment) *CommentQuery { 301 query := &CommentQuery{config: c.config} 302 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 303 id := co.ID 304 step := sqlgraph.NewStep( 305 sqlgraph.From(comment.Table, comment.FieldID, id), 306 sqlgraph.To(comment.Table, comment.FieldID), 307 sqlgraph.Edge(sqlgraph.O2M, false, comment.ChildrenTable, comment.ChildrenColumn), 308 ) 309 fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) 310 return fromV, nil 311 } 312 return query 313 } 314 315 // QueryParent queries the parent edge of a Comment. 316 func (c *CommentClient) QueryParent(co *Comment) *CommentQuery { 317 query := &CommentQuery{config: c.config} 318 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 319 id := co.ID 320 step := sqlgraph.NewStep( 321 sqlgraph.From(comment.Table, comment.FieldID, id), 322 sqlgraph.To(comment.Table, comment.FieldID), 323 sqlgraph.Edge(sqlgraph.M2O, true, comment.ParentTable, comment.ParentColumn), 324 ) 325 fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) 326 return fromV, nil 327 } 328 return query 329 } 330 331 // Hooks returns the client hooks. 332 func (c *CommentClient) Hooks() []Hook { 333 return c.hooks.Comment 334 } 335 336 // FileClient is a client for the File schema. 337 type FileClient struct { 338 config 339 } 340 341 // NewFileClient returns a client for the File from the given config. 342 func NewFileClient(c config) *FileClient { 343 return &FileClient{config: c} 344 } 345 346 // Use adds a list of mutation hooks to the hooks stack. 347 // A call to `Use(f, g, h)` equals to `file.Hooks(f(g(h())))`. 348 func (c *FileClient) Use(hooks ...Hook) { 349 c.hooks.File = append(c.hooks.File, hooks...) 350 } 351 352 // Create returns a create builder for File. 353 func (c *FileClient) Create() *FileCreate { 354 mutation := newFileMutation(c.config, OpCreate) 355 return &FileCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 356 } 357 358 // CreateBulk returns a builder for creating a bulk of File entities. 359 func (c *FileClient) CreateBulk(builders ...*FileCreate) *FileCreateBulk { 360 return &FileCreateBulk{config: c.config, builders: builders} 361 } 362 363 // Update returns an update builder for File. 364 func (c *FileClient) Update() *FileUpdate { 365 mutation := newFileMutation(c.config, OpUpdate) 366 return &FileUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 367 } 368 369 // UpdateOne returns an update builder for the given entity. 370 func (c *FileClient) UpdateOne(f *File) *FileUpdateOne { 371 mutation := newFileMutation(c.config, OpUpdateOne, withFile(f)) 372 return &FileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 373 } 374 375 // UpdateOneID returns an update builder for the given id. 376 func (c *FileClient) UpdateOneID(id int) *FileUpdateOne { 377 mutation := newFileMutation(c.config, OpUpdateOne, withFileID(id)) 378 return &FileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 379 } 380 381 // Delete returns a delete builder for File. 382 func (c *FileClient) Delete() *FileDelete { 383 mutation := newFileMutation(c.config, OpDelete) 384 return &FileDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 385 } 386 387 // DeleteOne returns a delete builder for the given entity. 388 func (c *FileClient) DeleteOne(f *File) *FileDeleteOne { 389 return c.DeleteOneID(f.ID) 390 } 391 392 // DeleteOneID returns a delete builder for the given id. 393 func (c *FileClient) DeleteOneID(id int) *FileDeleteOne { 394 builder := c.Delete().Where(file.ID(id)) 395 builder.mutation.id = &id 396 builder.mutation.op = OpDeleteOne 397 return &FileDeleteOne{builder} 398 } 399 400 // Query returns a query builder for File. 401 func (c *FileClient) Query() *FileQuery { 402 return &FileQuery{ 403 config: c.config, 404 } 405 } 406 407 // Get returns a File entity by its id. 408 func (c *FileClient) Get(ctx context.Context, id int) (*File, error) { 409 return c.Query().Where(file.ID(id)).Only(ctx) 410 } 411 412 // GetX is like Get, but panics if an error occurs. 413 func (c *FileClient) GetX(ctx context.Context, id int) *File { 414 obj, err := c.Get(ctx, id) 415 if err != nil { 416 panic(err) 417 } 418 return obj 419 } 420 421 // QueryUser queries the user edge of a File. 422 func (c *FileClient) QueryUser(f *File) *UserQuery { 423 query := &UserQuery{config: c.config} 424 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 425 id := f.ID 426 step := sqlgraph.NewStep( 427 sqlgraph.From(file.Table, file.FieldID, id), 428 sqlgraph.To(user.Table, user.FieldID), 429 sqlgraph.Edge(sqlgraph.M2O, true, file.UserTable, file.UserColumn), 430 ) 431 fromV = sqlgraph.Neighbors(f.driver.Dialect(), step) 432 return fromV, nil 433 } 434 return query 435 } 436 437 // QueryPosts queries the posts edge of a File. 438 func (c *FileClient) QueryPosts(f *File) *PostQuery { 439 query := &PostQuery{config: c.config} 440 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 441 id := f.ID 442 step := sqlgraph.NewStep( 443 sqlgraph.From(file.Table, file.FieldID, id), 444 sqlgraph.To(post.Table, post.FieldID), 445 sqlgraph.Edge(sqlgraph.O2M, false, file.PostsTable, file.PostsColumn), 446 ) 447 fromV = sqlgraph.Neighbors(f.driver.Dialect(), step) 448 return fromV, nil 449 } 450 return query 451 } 452 453 // QueryPages queries the pages edge of a File. 454 func (c *FileClient) QueryPages(f *File) *PageQuery { 455 query := &PageQuery{config: c.config} 456 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 457 id := f.ID 458 step := sqlgraph.NewStep( 459 sqlgraph.From(file.Table, file.FieldID, id), 460 sqlgraph.To(page.Table, page.FieldID), 461 sqlgraph.Edge(sqlgraph.O2M, false, file.PagesTable, file.PagesColumn), 462 ) 463 fromV = sqlgraph.Neighbors(f.driver.Dialect(), step) 464 return fromV, nil 465 } 466 return query 467 } 468 469 // QueryUserAvatars queries the user_avatars edge of a File. 470 func (c *FileClient) QueryUserAvatars(f *File) *UserQuery { 471 query := &UserQuery{config: c.config} 472 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 473 id := f.ID 474 step := sqlgraph.NewStep( 475 sqlgraph.From(file.Table, file.FieldID, id), 476 sqlgraph.To(user.Table, user.FieldID), 477 sqlgraph.Edge(sqlgraph.O2M, false, file.UserAvatarsTable, file.UserAvatarsColumn), 478 ) 479 fromV = sqlgraph.Neighbors(f.driver.Dialect(), step) 480 return fromV, nil 481 } 482 return query 483 } 484 485 // Hooks returns the client hooks. 486 func (c *FileClient) Hooks() []Hook { 487 return c.hooks.File 488 } 489 490 // PageClient is a client for the Page schema. 491 type PageClient struct { 492 config 493 } 494 495 // NewPageClient returns a client for the Page from the given config. 496 func NewPageClient(c config) *PageClient { 497 return &PageClient{config: c} 498 } 499 500 // Use adds a list of mutation hooks to the hooks stack. 501 // A call to `Use(f, g, h)` equals to `page.Hooks(f(g(h())))`. 502 func (c *PageClient) Use(hooks ...Hook) { 503 c.hooks.Page = append(c.hooks.Page, hooks...) 504 } 505 506 // Create returns a create builder for Page. 507 func (c *PageClient) Create() *PageCreate { 508 mutation := newPageMutation(c.config, OpCreate) 509 return &PageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 510 } 511 512 // CreateBulk returns a builder for creating a bulk of Page entities. 513 func (c *PageClient) CreateBulk(builders ...*PageCreate) *PageCreateBulk { 514 return &PageCreateBulk{config: c.config, builders: builders} 515 } 516 517 // Update returns an update builder for Page. 518 func (c *PageClient) Update() *PageUpdate { 519 mutation := newPageMutation(c.config, OpUpdate) 520 return &PageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 521 } 522 523 // UpdateOne returns an update builder for the given entity. 524 func (c *PageClient) UpdateOne(pa *Page) *PageUpdateOne { 525 mutation := newPageMutation(c.config, OpUpdateOne, withPage(pa)) 526 return &PageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 527 } 528 529 // UpdateOneID returns an update builder for the given id. 530 func (c *PageClient) UpdateOneID(id int) *PageUpdateOne { 531 mutation := newPageMutation(c.config, OpUpdateOne, withPageID(id)) 532 return &PageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 533 } 534 535 // Delete returns a delete builder for Page. 536 func (c *PageClient) Delete() *PageDelete { 537 mutation := newPageMutation(c.config, OpDelete) 538 return &PageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 539 } 540 541 // DeleteOne returns a delete builder for the given entity. 542 func (c *PageClient) DeleteOne(pa *Page) *PageDeleteOne { 543 return c.DeleteOneID(pa.ID) 544 } 545 546 // DeleteOneID returns a delete builder for the given id. 547 func (c *PageClient) DeleteOneID(id int) *PageDeleteOne { 548 builder := c.Delete().Where(page.ID(id)) 549 builder.mutation.id = &id 550 builder.mutation.op = OpDeleteOne 551 return &PageDeleteOne{builder} 552 } 553 554 // Query returns a query builder for Page. 555 func (c *PageClient) Query() *PageQuery { 556 return &PageQuery{ 557 config: c.config, 558 } 559 } 560 561 // Get returns a Page entity by its id. 562 func (c *PageClient) Get(ctx context.Context, id int) (*Page, error) { 563 return c.Query().Where(page.ID(id)).Only(ctx) 564 } 565 566 // GetX is like Get, but panics if an error occurs. 567 func (c *PageClient) GetX(ctx context.Context, id int) *Page { 568 obj, err := c.Get(ctx, id) 569 if err != nil { 570 panic(err) 571 } 572 return obj 573 } 574 575 // QueryFeaturedImage queries the featured_image edge of a Page. 576 func (c *PageClient) QueryFeaturedImage(pa *Page) *FileQuery { 577 query := &FileQuery{config: c.config} 578 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 579 id := pa.ID 580 step := sqlgraph.NewStep( 581 sqlgraph.From(page.Table, page.FieldID, id), 582 sqlgraph.To(file.Table, file.FieldID), 583 sqlgraph.Edge(sqlgraph.M2O, true, page.FeaturedImageTable, page.FeaturedImageColumn), 584 ) 585 fromV = sqlgraph.Neighbors(pa.driver.Dialect(), step) 586 return fromV, nil 587 } 588 return query 589 } 590 591 // Hooks returns the client hooks. 592 func (c *PageClient) Hooks() []Hook { 593 return c.hooks.Page 594 } 595 596 // PermissionClient is a client for the Permission schema. 597 type PermissionClient struct { 598 config 599 } 600 601 // NewPermissionClient returns a client for the Permission from the given config. 602 func NewPermissionClient(c config) *PermissionClient { 603 return &PermissionClient{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 `permission.Hooks(f(g(h())))`. 608 func (c *PermissionClient) Use(hooks ...Hook) { 609 c.hooks.Permission = append(c.hooks.Permission, hooks...) 610 } 611 612 // Create returns a create builder for Permission. 613 func (c *PermissionClient) Create() *PermissionCreate { 614 mutation := newPermissionMutation(c.config, OpCreate) 615 return &PermissionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 616 } 617 618 // CreateBulk returns a builder for creating a bulk of Permission entities. 619 func (c *PermissionClient) CreateBulk(builders ...*PermissionCreate) *PermissionCreateBulk { 620 return &PermissionCreateBulk{config: c.config, builders: builders} 621 } 622 623 // Update returns an update builder for Permission. 624 func (c *PermissionClient) Update() *PermissionUpdate { 625 mutation := newPermissionMutation(c.config, OpUpdate) 626 return &PermissionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 627 } 628 629 // UpdateOne returns an update builder for the given entity. 630 func (c *PermissionClient) UpdateOne(pe *Permission) *PermissionUpdateOne { 631 mutation := newPermissionMutation(c.config, OpUpdateOne, withPermission(pe)) 632 return &PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 633 } 634 635 // UpdateOneID returns an update builder for the given id. 636 func (c *PermissionClient) UpdateOneID(id int) *PermissionUpdateOne { 637 mutation := newPermissionMutation(c.config, OpUpdateOne, withPermissionID(id)) 638 return &PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 639 } 640 641 // Delete returns a delete builder for Permission. 642 func (c *PermissionClient) Delete() *PermissionDelete { 643 mutation := newPermissionMutation(c.config, OpDelete) 644 return &PermissionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 645 } 646 647 // DeleteOne returns a delete builder for the given entity. 648 func (c *PermissionClient) DeleteOne(pe *Permission) *PermissionDeleteOne { 649 return c.DeleteOneID(pe.ID) 650 } 651 652 // DeleteOneID returns a delete builder for the given id. 653 func (c *PermissionClient) DeleteOneID(id int) *PermissionDeleteOne { 654 builder := c.Delete().Where(permission.ID(id)) 655 builder.mutation.id = &id 656 builder.mutation.op = OpDeleteOne 657 return &PermissionDeleteOne{builder} 658 } 659 660 // Query returns a query builder for Permission. 661 func (c *PermissionClient) Query() *PermissionQuery { 662 return &PermissionQuery{ 663 config: c.config, 664 } 665 } 666 667 // Get returns a Permission entity by its id. 668 func (c *PermissionClient) Get(ctx context.Context, id int) (*Permission, error) { 669 return c.Query().Where(permission.ID(id)).Only(ctx) 670 } 671 672 // GetX is like Get, but panics if an error occurs. 673 func (c *PermissionClient) GetX(ctx context.Context, id int) *Permission { 674 obj, err := c.Get(ctx, id) 675 if err != nil { 676 panic(err) 677 } 678 return obj 679 } 680 681 // QueryRole queries the role edge of a Permission. 682 func (c *PermissionClient) QueryRole(pe *Permission) *RoleQuery { 683 query := &RoleQuery{config: c.config} 684 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 685 id := pe.ID 686 step := sqlgraph.NewStep( 687 sqlgraph.From(permission.Table, permission.FieldID, id), 688 sqlgraph.To(role.Table, role.FieldID), 689 sqlgraph.Edge(sqlgraph.M2O, true, permission.RoleTable, permission.RoleColumn), 690 ) 691 fromV = sqlgraph.Neighbors(pe.driver.Dialect(), step) 692 return fromV, nil 693 } 694 return query 695 } 696 697 // Hooks returns the client hooks. 698 func (c *PermissionClient) Hooks() []Hook { 699 return c.hooks.Permission 700 } 701 702 // PostClient is a client for the Post schema. 703 type PostClient struct { 704 config 705 } 706 707 // NewPostClient returns a client for the Post from the given config. 708 func NewPostClient(c config) *PostClient { 709 return &PostClient{config: c} 710 } 711 712 // Use adds a list of mutation hooks to the hooks stack. 713 // A call to `Use(f, g, h)` equals to `post.Hooks(f(g(h())))`. 714 func (c *PostClient) Use(hooks ...Hook) { 715 c.hooks.Post = append(c.hooks.Post, hooks...) 716 } 717 718 // Create returns a create builder for Post. 719 func (c *PostClient) Create() *PostCreate { 720 mutation := newPostMutation(c.config, OpCreate) 721 return &PostCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 722 } 723 724 // CreateBulk returns a builder for creating a bulk of Post entities. 725 func (c *PostClient) CreateBulk(builders ...*PostCreate) *PostCreateBulk { 726 return &PostCreateBulk{config: c.config, builders: builders} 727 } 728 729 // Update returns an update builder for Post. 730 func (c *PostClient) Update() *PostUpdate { 731 mutation := newPostMutation(c.config, OpUpdate) 732 return &PostUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 733 } 734 735 // UpdateOne returns an update builder for the given entity. 736 func (c *PostClient) UpdateOne(po *Post) *PostUpdateOne { 737 mutation := newPostMutation(c.config, OpUpdateOne, withPost(po)) 738 return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 739 } 740 741 // UpdateOneID returns an update builder for the given id. 742 func (c *PostClient) UpdateOneID(id int) *PostUpdateOne { 743 mutation := newPostMutation(c.config, OpUpdateOne, withPostID(id)) 744 return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 745 } 746 747 // Delete returns a delete builder for Post. 748 func (c *PostClient) Delete() *PostDelete { 749 mutation := newPostMutation(c.config, OpDelete) 750 return &PostDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 751 } 752 753 // DeleteOne returns a delete builder for the given entity. 754 func (c *PostClient) DeleteOne(po *Post) *PostDeleteOne { 755 return c.DeleteOneID(po.ID) 756 } 757 758 // DeleteOneID returns a delete builder for the given id. 759 func (c *PostClient) DeleteOneID(id int) *PostDeleteOne { 760 builder := c.Delete().Where(post.ID(id)) 761 builder.mutation.id = &id 762 builder.mutation.op = OpDeleteOne 763 return &PostDeleteOne{builder} 764 } 765 766 // Query returns a query builder for Post. 767 func (c *PostClient) Query() *PostQuery { 768 return &PostQuery{ 769 config: c.config, 770 } 771 } 772 773 // Get returns a Post entity by its id. 774 func (c *PostClient) Get(ctx context.Context, id int) (*Post, error) { 775 return c.Query().Where(post.ID(id)).Only(ctx) 776 } 777 778 // GetX is like Get, but panics if an error occurs. 779 func (c *PostClient) GetX(ctx context.Context, id int) *Post { 780 obj, err := c.Get(ctx, id) 781 if err != nil { 782 panic(err) 783 } 784 return obj 785 } 786 787 // QueryUser queries the user edge of a Post. 788 func (c *PostClient) QueryUser(po *Post) *UserQuery { 789 query := &UserQuery{config: c.config} 790 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 791 id := po.ID 792 step := sqlgraph.NewStep( 793 sqlgraph.From(post.Table, post.FieldID, id), 794 sqlgraph.To(user.Table, user.FieldID), 795 sqlgraph.Edge(sqlgraph.M2O, true, post.UserTable, post.UserColumn), 796 ) 797 fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) 798 return fromV, nil 799 } 800 return query 801 } 802 803 // QueryTopics queries the topics edge of a Post. 804 func (c *PostClient) QueryTopics(po *Post) *TopicQuery { 805 query := &TopicQuery{config: c.config} 806 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 807 id := po.ID 808 step := sqlgraph.NewStep( 809 sqlgraph.From(post.Table, post.FieldID, id), 810 sqlgraph.To(topic.Table, topic.FieldID), 811 sqlgraph.Edge(sqlgraph.M2M, true, post.TopicsTable, post.TopicsPrimaryKey...), 812 ) 813 fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) 814 return fromV, nil 815 } 816 return query 817 } 818 819 // QueryFeaturedImage queries the featured_image edge of a Post. 820 func (c *PostClient) QueryFeaturedImage(po *Post) *FileQuery { 821 query := &FileQuery{config: c.config} 822 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 823 id := po.ID 824 step := sqlgraph.NewStep( 825 sqlgraph.From(post.Table, post.FieldID, id), 826 sqlgraph.To(file.Table, file.FieldID), 827 sqlgraph.Edge(sqlgraph.M2O, true, post.FeaturedImageTable, post.FeaturedImageColumn), 828 ) 829 fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) 830 return fromV, nil 831 } 832 return query 833 } 834 835 // QueryComments queries the comments edge of a Post. 836 func (c *PostClient) QueryComments(po *Post) *CommentQuery { 837 query := &CommentQuery{config: c.config} 838 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 839 id := po.ID 840 step := sqlgraph.NewStep( 841 sqlgraph.From(post.Table, post.FieldID, id), 842 sqlgraph.To(comment.Table, comment.FieldID), 843 sqlgraph.Edge(sqlgraph.O2M, false, post.CommentsTable, post.CommentsColumn), 844 ) 845 fromV = sqlgraph.Neighbors(po.driver.Dialect(), step) 846 return fromV, nil 847 } 848 return query 849 } 850 851 // Hooks returns the client hooks. 852 func (c *PostClient) Hooks() []Hook { 853 return c.hooks.Post 854 } 855 856 // RoleClient is a client for the Role schema. 857 type RoleClient struct { 858 config 859 } 860 861 // NewRoleClient returns a client for the Role from the given config. 862 func NewRoleClient(c config) *RoleClient { 863 return &RoleClient{config: c} 864 } 865 866 // Use adds a list of mutation hooks to the hooks stack. 867 // A call to `Use(f, g, h)` equals to `role.Hooks(f(g(h())))`. 868 func (c *RoleClient) Use(hooks ...Hook) { 869 c.hooks.Role = append(c.hooks.Role, hooks...) 870 } 871 872 // Create returns a create builder for Role. 873 func (c *RoleClient) Create() *RoleCreate { 874 mutation := newRoleMutation(c.config, OpCreate) 875 return &RoleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 876 } 877 878 // CreateBulk returns a builder for creating a bulk of Role entities. 879 func (c *RoleClient) CreateBulk(builders ...*RoleCreate) *RoleCreateBulk { 880 return &RoleCreateBulk{config: c.config, builders: builders} 881 } 882 883 // Update returns an update builder for Role. 884 func (c *RoleClient) Update() *RoleUpdate { 885 mutation := newRoleMutation(c.config, OpUpdate) 886 return &RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 887 } 888 889 // UpdateOne returns an update builder for the given entity. 890 func (c *RoleClient) UpdateOne(r *Role) *RoleUpdateOne { 891 mutation := newRoleMutation(c.config, OpUpdateOne, withRole(r)) 892 return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 893 } 894 895 // UpdateOneID returns an update builder for the given id. 896 func (c *RoleClient) UpdateOneID(id int) *RoleUpdateOne { 897 mutation := newRoleMutation(c.config, OpUpdateOne, withRoleID(id)) 898 return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 899 } 900 901 // Delete returns a delete builder for Role. 902 func (c *RoleClient) Delete() *RoleDelete { 903 mutation := newRoleMutation(c.config, OpDelete) 904 return &RoleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 905 } 906 907 // DeleteOne returns a delete builder for the given entity. 908 func (c *RoleClient) DeleteOne(r *Role) *RoleDeleteOne { 909 return c.DeleteOneID(r.ID) 910 } 911 912 // DeleteOneID returns a delete builder for the given id. 913 func (c *RoleClient) DeleteOneID(id int) *RoleDeleteOne { 914 builder := c.Delete().Where(role.ID(id)) 915 builder.mutation.id = &id 916 builder.mutation.op = OpDeleteOne 917 return &RoleDeleteOne{builder} 918 } 919 920 // Query returns a query builder for Role. 921 func (c *RoleClient) Query() *RoleQuery { 922 return &RoleQuery{ 923 config: c.config, 924 } 925 } 926 927 // Get returns a Role entity by its id. 928 func (c *RoleClient) Get(ctx context.Context, id int) (*Role, error) { 929 return c.Query().Where(role.ID(id)).Only(ctx) 930 } 931 932 // GetX is like Get, but panics if an error occurs. 933 func (c *RoleClient) GetX(ctx context.Context, id int) *Role { 934 obj, err := c.Get(ctx, id) 935 if err != nil { 936 panic(err) 937 } 938 return obj 939 } 940 941 // QueryPermissions queries the permissions edge of a Role. 942 func (c *RoleClient) QueryPermissions(r *Role) *PermissionQuery { 943 query := &PermissionQuery{config: c.config} 944 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 945 id := r.ID 946 step := sqlgraph.NewStep( 947 sqlgraph.From(role.Table, role.FieldID, id), 948 sqlgraph.To(permission.Table, permission.FieldID), 949 sqlgraph.Edge(sqlgraph.O2M, false, role.PermissionsTable, role.PermissionsColumn), 950 ) 951 fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) 952 return fromV, nil 953 } 954 return query 955 } 956 957 // QueryUsers queries the users edge of a Role. 958 func (c *RoleClient) QueryUsers(r *Role) *UserQuery { 959 query := &UserQuery{config: c.config} 960 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 961 id := r.ID 962 step := sqlgraph.NewStep( 963 sqlgraph.From(role.Table, role.FieldID, id), 964 sqlgraph.To(user.Table, user.FieldID), 965 sqlgraph.Edge(sqlgraph.M2M, false, role.UsersTable, role.UsersPrimaryKey...), 966 ) 967 fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) 968 return fromV, nil 969 } 970 return query 971 } 972 973 // Hooks returns the client hooks. 974 func (c *RoleClient) Hooks() []Hook { 975 return c.hooks.Role 976 } 977 978 // SettingClient is a client for the Setting schema. 979 type SettingClient struct { 980 config 981 } 982 983 // NewSettingClient returns a client for the Setting from the given config. 984 func NewSettingClient(c config) *SettingClient { 985 return &SettingClient{config: c} 986 } 987 988 // Use adds a list of mutation hooks to the hooks stack. 989 // A call to `Use(f, g, h)` equals to `setting.Hooks(f(g(h())))`. 990 func (c *SettingClient) Use(hooks ...Hook) { 991 c.hooks.Setting = append(c.hooks.Setting, hooks...) 992 } 993 994 // Create returns a create builder for Setting. 995 func (c *SettingClient) Create() *SettingCreate { 996 mutation := newSettingMutation(c.config, OpCreate) 997 return &SettingCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 998 } 999 1000 // CreateBulk returns a builder for creating a bulk of Setting entities. 1001 func (c *SettingClient) CreateBulk(builders ...*SettingCreate) *SettingCreateBulk { 1002 return &SettingCreateBulk{config: c.config, builders: builders} 1003 } 1004 1005 // Update returns an update builder for Setting. 1006 func (c *SettingClient) Update() *SettingUpdate { 1007 mutation := newSettingMutation(c.config, OpUpdate) 1008 return &SettingUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1009 } 1010 1011 // UpdateOne returns an update builder for the given entity. 1012 func (c *SettingClient) UpdateOne(s *Setting) *SettingUpdateOne { 1013 mutation := newSettingMutation(c.config, OpUpdateOne, withSetting(s)) 1014 return &SettingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1015 } 1016 1017 // UpdateOneID returns an update builder for the given id. 1018 func (c *SettingClient) UpdateOneID(id int) *SettingUpdateOne { 1019 mutation := newSettingMutation(c.config, OpUpdateOne, withSettingID(id)) 1020 return &SettingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1021 } 1022 1023 // Delete returns a delete builder for Setting. 1024 func (c *SettingClient) Delete() *SettingDelete { 1025 mutation := newSettingMutation(c.config, OpDelete) 1026 return &SettingDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 1027 } 1028 1029 // DeleteOne returns a delete builder for the given entity. 1030 func (c *SettingClient) DeleteOne(s *Setting) *SettingDeleteOne { 1031 return c.DeleteOneID(s.ID) 1032 } 1033 1034 // DeleteOneID returns a delete builder for the given id. 1035 func (c *SettingClient) DeleteOneID(id int) *SettingDeleteOne { 1036 builder := c.Delete().Where(setting.ID(id)) 1037 builder.mutation.id = &id 1038 builder.mutation.op = OpDeleteOne 1039 return &SettingDeleteOne{builder} 1040 } 1041 1042 // Query returns a query builder for Setting. 1043 func (c *SettingClient) Query() *SettingQuery { 1044 return &SettingQuery{ 1045 config: c.config, 1046 } 1047 } 1048 1049 // Get returns a Setting entity by its id. 1050 func (c *SettingClient) Get(ctx context.Context, id int) (*Setting, error) { 1051 return c.Query().Where(setting.ID(id)).Only(ctx) 1052 } 1053 1054 // GetX is like Get, but panics if an error occurs. 1055 func (c *SettingClient) GetX(ctx context.Context, id int) *Setting { 1056 obj, err := c.Get(ctx, id) 1057 if err != nil { 1058 panic(err) 1059 } 1060 return obj 1061 } 1062 1063 // Hooks returns the client hooks. 1064 func (c *SettingClient) Hooks() []Hook { 1065 return c.hooks.Setting 1066 } 1067 1068 // TopicClient is a client for the Topic schema. 1069 type TopicClient struct { 1070 config 1071 } 1072 1073 // NewTopicClient returns a client for the Topic from the given config. 1074 func NewTopicClient(c config) *TopicClient { 1075 return &TopicClient{config: c} 1076 } 1077 1078 // Use adds a list of mutation hooks to the hooks stack. 1079 // A call to `Use(f, g, h)` equals to `topic.Hooks(f(g(h())))`. 1080 func (c *TopicClient) Use(hooks ...Hook) { 1081 c.hooks.Topic = append(c.hooks.Topic, hooks...) 1082 } 1083 1084 // Create returns a create builder for Topic. 1085 func (c *TopicClient) Create() *TopicCreate { 1086 mutation := newTopicMutation(c.config, OpCreate) 1087 return &TopicCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1088 } 1089 1090 // CreateBulk returns a builder for creating a bulk of Topic entities. 1091 func (c *TopicClient) CreateBulk(builders ...*TopicCreate) *TopicCreateBulk { 1092 return &TopicCreateBulk{config: c.config, builders: builders} 1093 } 1094 1095 // Update returns an update builder for Topic. 1096 func (c *TopicClient) Update() *TopicUpdate { 1097 mutation := newTopicMutation(c.config, OpUpdate) 1098 return &TopicUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1099 } 1100 1101 // UpdateOne returns an update builder for the given entity. 1102 func (c *TopicClient) UpdateOne(t *Topic) *TopicUpdateOne { 1103 mutation := newTopicMutation(c.config, OpUpdateOne, withTopic(t)) 1104 return &TopicUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1105 } 1106 1107 // UpdateOneID returns an update builder for the given id. 1108 func (c *TopicClient) UpdateOneID(id int) *TopicUpdateOne { 1109 mutation := newTopicMutation(c.config, OpUpdateOne, withTopicID(id)) 1110 return &TopicUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1111 } 1112 1113 // Delete returns a delete builder for Topic. 1114 func (c *TopicClient) Delete() *TopicDelete { 1115 mutation := newTopicMutation(c.config, OpDelete) 1116 return &TopicDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 1117 } 1118 1119 // DeleteOne returns a delete builder for the given entity. 1120 func (c *TopicClient) DeleteOne(t *Topic) *TopicDeleteOne { 1121 return c.DeleteOneID(t.ID) 1122 } 1123 1124 // DeleteOneID returns a delete builder for the given id. 1125 func (c *TopicClient) DeleteOneID(id int) *TopicDeleteOne { 1126 builder := c.Delete().Where(topic.ID(id)) 1127 builder.mutation.id = &id 1128 builder.mutation.op = OpDeleteOne 1129 return &TopicDeleteOne{builder} 1130 } 1131 1132 // Query returns a query builder for Topic. 1133 func (c *TopicClient) Query() *TopicQuery { 1134 return &TopicQuery{ 1135 config: c.config, 1136 } 1137 } 1138 1139 // Get returns a Topic entity by its id. 1140 func (c *TopicClient) Get(ctx context.Context, id int) (*Topic, error) { 1141 return c.Query().Where(topic.ID(id)).Only(ctx) 1142 } 1143 1144 // GetX is like Get, but panics if an error occurs. 1145 func (c *TopicClient) GetX(ctx context.Context, id int) *Topic { 1146 obj, err := c.Get(ctx, id) 1147 if err != nil { 1148 panic(err) 1149 } 1150 return obj 1151 } 1152 1153 // QueryPosts queries the posts edge of a Topic. 1154 func (c *TopicClient) QueryPosts(t *Topic) *PostQuery { 1155 query := &PostQuery{config: c.config} 1156 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1157 id := t.ID 1158 step := sqlgraph.NewStep( 1159 sqlgraph.From(topic.Table, topic.FieldID, id), 1160 sqlgraph.To(post.Table, post.FieldID), 1161 sqlgraph.Edge(sqlgraph.M2M, false, topic.PostsTable, topic.PostsPrimaryKey...), 1162 ) 1163 fromV = sqlgraph.Neighbors(t.driver.Dialect(), step) 1164 return fromV, nil 1165 } 1166 return query 1167 } 1168 1169 // QueryChildren queries the children edge of a Topic. 1170 func (c *TopicClient) QueryChildren(t *Topic) *TopicQuery { 1171 query := &TopicQuery{config: c.config} 1172 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1173 id := t.ID 1174 step := sqlgraph.NewStep( 1175 sqlgraph.From(topic.Table, topic.FieldID, id), 1176 sqlgraph.To(topic.Table, topic.FieldID), 1177 sqlgraph.Edge(sqlgraph.O2M, false, topic.ChildrenTable, topic.ChildrenColumn), 1178 ) 1179 fromV = sqlgraph.Neighbors(t.driver.Dialect(), step) 1180 return fromV, nil 1181 } 1182 return query 1183 } 1184 1185 // QueryParent queries the parent edge of a Topic. 1186 func (c *TopicClient) QueryParent(t *Topic) *TopicQuery { 1187 query := &TopicQuery{config: c.config} 1188 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1189 id := t.ID 1190 step := sqlgraph.NewStep( 1191 sqlgraph.From(topic.Table, topic.FieldID, id), 1192 sqlgraph.To(topic.Table, topic.FieldID), 1193 sqlgraph.Edge(sqlgraph.M2O, true, topic.ParentTable, topic.ParentColumn), 1194 ) 1195 fromV = sqlgraph.Neighbors(t.driver.Dialect(), step) 1196 return fromV, nil 1197 } 1198 return query 1199 } 1200 1201 // Hooks returns the client hooks. 1202 func (c *TopicClient) Hooks() []Hook { 1203 return c.hooks.Topic 1204 } 1205 1206 // UserClient is a client for the User schema. 1207 type UserClient struct { 1208 config 1209 } 1210 1211 // NewUserClient returns a client for the User from the given config. 1212 func NewUserClient(c config) *UserClient { 1213 return &UserClient{config: c} 1214 } 1215 1216 // Use adds a list of mutation hooks to the hooks stack. 1217 // A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`. 1218 func (c *UserClient) Use(hooks ...Hook) { 1219 c.hooks.User = append(c.hooks.User, hooks...) 1220 } 1221 1222 // Create returns a create builder for User. 1223 func (c *UserClient) Create() *UserCreate { 1224 mutation := newUserMutation(c.config, OpCreate) 1225 return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1226 } 1227 1228 // CreateBulk returns a builder for creating a bulk of User entities. 1229 func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { 1230 return &UserCreateBulk{config: c.config, builders: builders} 1231 } 1232 1233 // Update returns an update builder for User. 1234 func (c *UserClient) Update() *UserUpdate { 1235 mutation := newUserMutation(c.config, OpUpdate) 1236 return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} 1237 } 1238 1239 // UpdateOne returns an update builder for the given entity. 1240 func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { 1241 mutation := newUserMutation(c.config, OpUpdateOne, withUser(u)) 1242 return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1243 } 1244 1245 // UpdateOneID returns an update builder for the given id. 1246 func (c *UserClient) UpdateOneID(id int) *UserUpdateOne { 1247 mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id)) 1248 return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} 1249 } 1250 1251 // Delete returns a delete builder for User. 1252 func (c *UserClient) Delete() *UserDelete { 1253 mutation := newUserMutation(c.config, OpDelete) 1254 return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} 1255 } 1256 1257 // DeleteOne returns a delete builder for the given entity. 1258 func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { 1259 return c.DeleteOneID(u.ID) 1260 } 1261 1262 // DeleteOneID returns a delete builder for the given id. 1263 func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { 1264 builder := c.Delete().Where(user.ID(id)) 1265 builder.mutation.id = &id 1266 builder.mutation.op = OpDeleteOne 1267 return &UserDeleteOne{builder} 1268 } 1269 1270 // Query returns a query builder for User. 1271 func (c *UserClient) Query() *UserQuery { 1272 return &UserQuery{ 1273 config: c.config, 1274 } 1275 } 1276 1277 // Get returns a User entity by its id. 1278 func (c *UserClient) Get(ctx context.Context, id int) (*User, error) { 1279 return c.Query().Where(user.ID(id)).Only(ctx) 1280 } 1281 1282 // GetX is like Get, but panics if an error occurs. 1283 func (c *UserClient) GetX(ctx context.Context, id int) *User { 1284 obj, err := c.Get(ctx, id) 1285 if err != nil { 1286 panic(err) 1287 } 1288 return obj 1289 } 1290 1291 // QueryPosts queries the posts edge of a User. 1292 func (c *UserClient) QueryPosts(u *User) *PostQuery { 1293 query := &PostQuery{config: c.config} 1294 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1295 id := u.ID 1296 step := sqlgraph.NewStep( 1297 sqlgraph.From(user.Table, user.FieldID, id), 1298 sqlgraph.To(post.Table, post.FieldID), 1299 sqlgraph.Edge(sqlgraph.O2M, false, user.PostsTable, user.PostsColumn), 1300 ) 1301 fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) 1302 return fromV, nil 1303 } 1304 return query 1305 } 1306 1307 // QueryFiles queries the files edge of a User. 1308 func (c *UserClient) QueryFiles(u *User) *FileQuery { 1309 query := &FileQuery{config: c.config} 1310 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1311 id := u.ID 1312 step := sqlgraph.NewStep( 1313 sqlgraph.From(user.Table, user.FieldID, id), 1314 sqlgraph.To(file.Table, file.FieldID), 1315 sqlgraph.Edge(sqlgraph.O2M, false, user.FilesTable, user.FilesColumn), 1316 ) 1317 fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) 1318 return fromV, nil 1319 } 1320 return query 1321 } 1322 1323 // QueryComments queries the comments edge of a User. 1324 func (c *UserClient) QueryComments(u *User) *CommentQuery { 1325 query := &CommentQuery{config: c.config} 1326 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1327 id := u.ID 1328 step := sqlgraph.NewStep( 1329 sqlgraph.From(user.Table, user.FieldID, id), 1330 sqlgraph.To(comment.Table, comment.FieldID), 1331 sqlgraph.Edge(sqlgraph.O2M, false, user.CommentsTable, user.CommentsColumn), 1332 ) 1333 fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) 1334 return fromV, nil 1335 } 1336 return query 1337 } 1338 1339 // QueryRoles queries the roles edge of a User. 1340 func (c *UserClient) QueryRoles(u *User) *RoleQuery { 1341 query := &RoleQuery{config: c.config} 1342 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1343 id := u.ID 1344 step := sqlgraph.NewStep( 1345 sqlgraph.From(user.Table, user.FieldID, id), 1346 sqlgraph.To(role.Table, role.FieldID), 1347 sqlgraph.Edge(sqlgraph.M2M, true, user.RolesTable, user.RolesPrimaryKey...), 1348 ) 1349 fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) 1350 return fromV, nil 1351 } 1352 return query 1353 } 1354 1355 // QueryAvatarImage queries the avatar_image edge of a User. 1356 func (c *UserClient) QueryAvatarImage(u *User) *FileQuery { 1357 query := &FileQuery{config: c.config} 1358 query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { 1359 id := u.ID 1360 step := sqlgraph.NewStep( 1361 sqlgraph.From(user.Table, user.FieldID, id), 1362 sqlgraph.To(file.Table, file.FieldID), 1363 sqlgraph.Edge(sqlgraph.M2O, true, user.AvatarImageTable, user.AvatarImageColumn), 1364 ) 1365 fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) 1366 return fromV, nil 1367 } 1368 return query 1369 } 1370 1371 // Hooks returns the client hooks. 1372 func (c *UserClient) Hooks() []Hook { 1373 return c.hooks.User 1374 }