441 lines
13 KiB
Go
441 lines
13 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"home-vue-go/internal/ent/siteconfig"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// SiteConfigCreate is the builder for creating a SiteConfig entity.
|
|
type SiteConfigCreate struct {
|
|
config
|
|
mutation *SiteConfigMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetSiteName sets the "site_name" field.
|
|
func (_c *SiteConfigCreate) SetSiteName(v string) *SiteConfigCreate {
|
|
_c.mutation.SetSiteName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetSiteURL sets the "site_url" field.
|
|
func (_c *SiteConfigCreate) SetSiteURL(v string) *SiteConfigCreate {
|
|
_c.mutation.SetSiteURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetSiteIcon sets the "site_icon" field.
|
|
func (_c *SiteConfigCreate) SetSiteIcon(v string) *SiteConfigCreate {
|
|
_c.mutation.SetSiteIcon(v)
|
|
return _c
|
|
}
|
|
|
|
// SetSiteDescription sets the "site_description" field.
|
|
func (_c *SiteConfigCreate) SetSiteDescription(v string) *SiteConfigCreate {
|
|
_c.mutation.SetSiteDescription(v)
|
|
return _c
|
|
}
|
|
|
|
// SetSiteKeywords sets the "site_keywords" field.
|
|
func (_c *SiteConfigCreate) SetSiteKeywords(v string) *SiteConfigCreate {
|
|
_c.mutation.SetSiteKeywords(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUserName sets the "user_name" field.
|
|
func (_c *SiteConfigCreate) SetUserName(v string) *SiteConfigCreate {
|
|
_c.mutation.SetUserName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetProfileImageURL sets the "profile_image_url" field.
|
|
func (_c *SiteConfigCreate) SetProfileImageURL(v string) *SiteConfigCreate {
|
|
_c.mutation.SetProfileImageURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableProfileImageURL sets the "profile_image_url" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableProfileImageURL(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetProfileImageURL(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetIcpNumber sets the "icp_number" field.
|
|
func (_c *SiteConfigCreate) SetIcpNumber(v string) *SiteConfigCreate {
|
|
_c.mutation.SetIcpNumber(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableIcpNumber sets the "icp_number" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableIcpNumber(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetIcpNumber(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetPoliceNumber sets the "police_number" field.
|
|
func (_c *SiteConfigCreate) SetPoliceNumber(v string) *SiteConfigCreate {
|
|
_c.mutation.SetPoliceNumber(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillablePoliceNumber sets the "police_number" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillablePoliceNumber(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetPoliceNumber(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetPageTitle sets the "page_title" field.
|
|
func (_c *SiteConfigCreate) SetPageTitle(v string) *SiteConfigCreate {
|
|
_c.mutation.SetPageTitle(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillablePageTitle sets the "page_title" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillablePageTitle(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetPageTitle(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetFavicon sets the "favicon" field.
|
|
func (_c *SiteConfigCreate) SetFavicon(v string) *SiteConfigCreate {
|
|
_c.mutation.SetFavicon(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableFavicon sets the "favicon" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableFavicon(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetFavicon(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUmamiScript sets the "umami_script" field.
|
|
func (_c *SiteConfigCreate) SetUmamiScript(v string) *SiteConfigCreate {
|
|
_c.mutation.SetUmamiScript(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUmamiScript sets the "umami_script" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableUmamiScript(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetUmamiScript(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUmamiWebsiteID sets the "umami_website_id" field.
|
|
func (_c *SiteConfigCreate) SetUmamiWebsiteID(v string) *SiteConfigCreate {
|
|
_c.mutation.SetUmamiWebsiteID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUmamiWebsiteID sets the "umami_website_id" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableUmamiWebsiteID(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetUmamiWebsiteID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetIconLibrary sets the "icon_library" field.
|
|
func (_c *SiteConfigCreate) SetIconLibrary(v string) *SiteConfigCreate {
|
|
_c.mutation.SetIconLibrary(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableIconLibrary sets the "icon_library" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableIconLibrary(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetIconLibrary(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetFontLibrary sets the "font_library" field.
|
|
func (_c *SiteConfigCreate) SetFontLibrary(v string) *SiteConfigCreate {
|
|
_c.mutation.SetFontLibrary(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableFontLibrary sets the "font_library" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableFontLibrary(v *string) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetFontLibrary(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *SiteConfigCreate) SetID(v int) *SiteConfigCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableID sets the "id" field if the given value is not nil.
|
|
func (_c *SiteConfigCreate) SetNillableID(v *int) *SiteConfigCreate {
|
|
if v != nil {
|
|
_c.SetID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the SiteConfigMutation object of the builder.
|
|
func (_c *SiteConfigCreate) Mutation() *SiteConfigMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the SiteConfig in the database.
|
|
func (_c *SiteConfigCreate) Save(ctx context.Context) (*SiteConfig, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *SiteConfigCreate) SaveX(ctx context.Context) *SiteConfig {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SiteConfigCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SiteConfigCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *SiteConfigCreate) defaults() {
|
|
if _, ok := _c.mutation.ID(); !ok {
|
|
v := siteconfig.DefaultID
|
|
_c.mutation.SetID(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *SiteConfigCreate) check() error {
|
|
if _, ok := _c.mutation.SiteName(); !ok {
|
|
return &ValidationError{Name: "site_name", err: errors.New(`ent: missing required field "SiteConfig.site_name"`)}
|
|
}
|
|
if _, ok := _c.mutation.SiteURL(); !ok {
|
|
return &ValidationError{Name: "site_url", err: errors.New(`ent: missing required field "SiteConfig.site_url"`)}
|
|
}
|
|
if _, ok := _c.mutation.SiteIcon(); !ok {
|
|
return &ValidationError{Name: "site_icon", err: errors.New(`ent: missing required field "SiteConfig.site_icon"`)}
|
|
}
|
|
if _, ok := _c.mutation.SiteDescription(); !ok {
|
|
return &ValidationError{Name: "site_description", err: errors.New(`ent: missing required field "SiteConfig.site_description"`)}
|
|
}
|
|
if _, ok := _c.mutation.SiteKeywords(); !ok {
|
|
return &ValidationError{Name: "site_keywords", err: errors.New(`ent: missing required field "SiteConfig.site_keywords"`)}
|
|
}
|
|
if _, ok := _c.mutation.UserName(); !ok {
|
|
return &ValidationError{Name: "user_name", err: errors.New(`ent: missing required field "SiteConfig.user_name"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *SiteConfigCreate) sqlSave(ctx context.Context) (*SiteConfig, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != _node.ID {
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *SiteConfigCreate) createSpec() (*SiteConfig, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &SiteConfig{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(siteconfig.Table, sqlgraph.NewFieldSpec(siteconfig.FieldID, field.TypeInt))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.SiteName(); ok {
|
|
_spec.SetField(siteconfig.FieldSiteName, field.TypeString, value)
|
|
_node.SiteName = value
|
|
}
|
|
if value, ok := _c.mutation.SiteURL(); ok {
|
|
_spec.SetField(siteconfig.FieldSiteURL, field.TypeString, value)
|
|
_node.SiteURL = value
|
|
}
|
|
if value, ok := _c.mutation.SiteIcon(); ok {
|
|
_spec.SetField(siteconfig.FieldSiteIcon, field.TypeString, value)
|
|
_node.SiteIcon = value
|
|
}
|
|
if value, ok := _c.mutation.SiteDescription(); ok {
|
|
_spec.SetField(siteconfig.FieldSiteDescription, field.TypeString, value)
|
|
_node.SiteDescription = value
|
|
}
|
|
if value, ok := _c.mutation.SiteKeywords(); ok {
|
|
_spec.SetField(siteconfig.FieldSiteKeywords, field.TypeString, value)
|
|
_node.SiteKeywords = value
|
|
}
|
|
if value, ok := _c.mutation.UserName(); ok {
|
|
_spec.SetField(siteconfig.FieldUserName, field.TypeString, value)
|
|
_node.UserName = value
|
|
}
|
|
if value, ok := _c.mutation.ProfileImageURL(); ok {
|
|
_spec.SetField(siteconfig.FieldProfileImageURL, field.TypeString, value)
|
|
_node.ProfileImageURL = value
|
|
}
|
|
if value, ok := _c.mutation.IcpNumber(); ok {
|
|
_spec.SetField(siteconfig.FieldIcpNumber, field.TypeString, value)
|
|
_node.IcpNumber = value
|
|
}
|
|
if value, ok := _c.mutation.PoliceNumber(); ok {
|
|
_spec.SetField(siteconfig.FieldPoliceNumber, field.TypeString, value)
|
|
_node.PoliceNumber = value
|
|
}
|
|
if value, ok := _c.mutation.PageTitle(); ok {
|
|
_spec.SetField(siteconfig.FieldPageTitle, field.TypeString, value)
|
|
_node.PageTitle = value
|
|
}
|
|
if value, ok := _c.mutation.Favicon(); ok {
|
|
_spec.SetField(siteconfig.FieldFavicon, field.TypeString, value)
|
|
_node.Favicon = value
|
|
}
|
|
if value, ok := _c.mutation.UmamiScript(); ok {
|
|
_spec.SetField(siteconfig.FieldUmamiScript, field.TypeString, value)
|
|
_node.UmamiScript = value
|
|
}
|
|
if value, ok := _c.mutation.UmamiWebsiteID(); ok {
|
|
_spec.SetField(siteconfig.FieldUmamiWebsiteID, field.TypeString, value)
|
|
_node.UmamiWebsiteID = value
|
|
}
|
|
if value, ok := _c.mutation.IconLibrary(); ok {
|
|
_spec.SetField(siteconfig.FieldIconLibrary, field.TypeString, value)
|
|
_node.IconLibrary = value
|
|
}
|
|
if value, ok := _c.mutation.FontLibrary(); ok {
|
|
_spec.SetField(siteconfig.FieldFontLibrary, field.TypeString, value)
|
|
_node.FontLibrary = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// SiteConfigCreateBulk is the builder for creating many SiteConfig entities in bulk.
|
|
type SiteConfigCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*SiteConfigCreate
|
|
}
|
|
|
|
// Save creates the SiteConfig entities in the database.
|
|
func (_c *SiteConfigCreateBulk) Save(ctx context.Context) ([]*SiteConfig, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*SiteConfig, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SiteConfigMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(id)
|
|
}
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *SiteConfigCreateBulk) SaveX(ctx context.Context) []*SiteConfig {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SiteConfigCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SiteConfigCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|