employee_create.go 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/employee"
  9. "wechat-api/ent/tutorial"
  10. "wechat-api/ent/workexperience"
  11. "entgo.io/ent/dialect/sql"
  12. "entgo.io/ent/dialect/sql/sqlgraph"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // EmployeeCreate is the builder for creating a Employee entity.
  16. type EmployeeCreate struct {
  17. config
  18. mutation *EmployeeMutation
  19. hooks []Hook
  20. conflict []sql.ConflictOption
  21. }
  22. // SetCreatedAt sets the "created_at" field.
  23. func (ec *EmployeeCreate) SetCreatedAt(t time.Time) *EmployeeCreate {
  24. ec.mutation.SetCreatedAt(t)
  25. return ec
  26. }
  27. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  28. func (ec *EmployeeCreate) SetNillableCreatedAt(t *time.Time) *EmployeeCreate {
  29. if t != nil {
  30. ec.SetCreatedAt(*t)
  31. }
  32. return ec
  33. }
  34. // SetUpdatedAt sets the "updated_at" field.
  35. func (ec *EmployeeCreate) SetUpdatedAt(t time.Time) *EmployeeCreate {
  36. ec.mutation.SetUpdatedAt(t)
  37. return ec
  38. }
  39. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  40. func (ec *EmployeeCreate) SetNillableUpdatedAt(t *time.Time) *EmployeeCreate {
  41. if t != nil {
  42. ec.SetUpdatedAt(*t)
  43. }
  44. return ec
  45. }
  46. // SetDeletedAt sets the "deleted_at" field.
  47. func (ec *EmployeeCreate) SetDeletedAt(t time.Time) *EmployeeCreate {
  48. ec.mutation.SetDeletedAt(t)
  49. return ec
  50. }
  51. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  52. func (ec *EmployeeCreate) SetNillableDeletedAt(t *time.Time) *EmployeeCreate {
  53. if t != nil {
  54. ec.SetDeletedAt(*t)
  55. }
  56. return ec
  57. }
  58. // SetTitle sets the "title" field.
  59. func (ec *EmployeeCreate) SetTitle(s string) *EmployeeCreate {
  60. ec.mutation.SetTitle(s)
  61. return ec
  62. }
  63. // SetAvatar sets the "avatar" field.
  64. func (ec *EmployeeCreate) SetAvatar(s string) *EmployeeCreate {
  65. ec.mutation.SetAvatar(s)
  66. return ec
  67. }
  68. // SetTags sets the "tags" field.
  69. func (ec *EmployeeCreate) SetTags(s string) *EmployeeCreate {
  70. ec.mutation.SetTags(s)
  71. return ec
  72. }
  73. // SetHireCount sets the "hire_count" field.
  74. func (ec *EmployeeCreate) SetHireCount(i int) *EmployeeCreate {
  75. ec.mutation.SetHireCount(i)
  76. return ec
  77. }
  78. // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
  79. func (ec *EmployeeCreate) SetNillableHireCount(i *int) *EmployeeCreate {
  80. if i != nil {
  81. ec.SetHireCount(*i)
  82. }
  83. return ec
  84. }
  85. // SetServiceCount sets the "service_count" field.
  86. func (ec *EmployeeCreate) SetServiceCount(i int) *EmployeeCreate {
  87. ec.mutation.SetServiceCount(i)
  88. return ec
  89. }
  90. // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
  91. func (ec *EmployeeCreate) SetNillableServiceCount(i *int) *EmployeeCreate {
  92. if i != nil {
  93. ec.SetServiceCount(*i)
  94. }
  95. return ec
  96. }
  97. // SetAchievementCount sets the "achievement_count" field.
  98. func (ec *EmployeeCreate) SetAchievementCount(i int) *EmployeeCreate {
  99. ec.mutation.SetAchievementCount(i)
  100. return ec
  101. }
  102. // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
  103. func (ec *EmployeeCreate) SetNillableAchievementCount(i *int) *EmployeeCreate {
  104. if i != nil {
  105. ec.SetAchievementCount(*i)
  106. }
  107. return ec
  108. }
  109. // SetIntro sets the "intro" field.
  110. func (ec *EmployeeCreate) SetIntro(s string) *EmployeeCreate {
  111. ec.mutation.SetIntro(s)
  112. return ec
  113. }
  114. // SetNillableIntro sets the "intro" field if the given value is not nil.
  115. func (ec *EmployeeCreate) SetNillableIntro(s *string) *EmployeeCreate {
  116. if s != nil {
  117. ec.SetIntro(*s)
  118. }
  119. return ec
  120. }
  121. // SetEstimate sets the "estimate" field.
  122. func (ec *EmployeeCreate) SetEstimate(s string) *EmployeeCreate {
  123. ec.mutation.SetEstimate(s)
  124. return ec
  125. }
  126. // SetNillableEstimate sets the "estimate" field if the given value is not nil.
  127. func (ec *EmployeeCreate) SetNillableEstimate(s *string) *EmployeeCreate {
  128. if s != nil {
  129. ec.SetEstimate(*s)
  130. }
  131. return ec
  132. }
  133. // SetSkill sets the "skill" field.
  134. func (ec *EmployeeCreate) SetSkill(s string) *EmployeeCreate {
  135. ec.mutation.SetSkill(s)
  136. return ec
  137. }
  138. // SetNillableSkill sets the "skill" field if the given value is not nil.
  139. func (ec *EmployeeCreate) SetNillableSkill(s *string) *EmployeeCreate {
  140. if s != nil {
  141. ec.SetSkill(*s)
  142. }
  143. return ec
  144. }
  145. // SetAbilityType sets the "ability_type" field.
  146. func (ec *EmployeeCreate) SetAbilityType(s string) *EmployeeCreate {
  147. ec.mutation.SetAbilityType(s)
  148. return ec
  149. }
  150. // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
  151. func (ec *EmployeeCreate) SetNillableAbilityType(s *string) *EmployeeCreate {
  152. if s != nil {
  153. ec.SetAbilityType(*s)
  154. }
  155. return ec
  156. }
  157. // SetScene sets the "scene" field.
  158. func (ec *EmployeeCreate) SetScene(s string) *EmployeeCreate {
  159. ec.mutation.SetScene(s)
  160. return ec
  161. }
  162. // SetNillableScene sets the "scene" field if the given value is not nil.
  163. func (ec *EmployeeCreate) SetNillableScene(s *string) *EmployeeCreate {
  164. if s != nil {
  165. ec.SetScene(*s)
  166. }
  167. return ec
  168. }
  169. // SetSwitchIn sets the "switch_in" field.
  170. func (ec *EmployeeCreate) SetSwitchIn(s string) *EmployeeCreate {
  171. ec.mutation.SetSwitchIn(s)
  172. return ec
  173. }
  174. // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
  175. func (ec *EmployeeCreate) SetNillableSwitchIn(s *string) *EmployeeCreate {
  176. if s != nil {
  177. ec.SetSwitchIn(*s)
  178. }
  179. return ec
  180. }
  181. // SetVideoURL sets the "video_url" field.
  182. func (ec *EmployeeCreate) SetVideoURL(s string) *EmployeeCreate {
  183. ec.mutation.SetVideoURL(s)
  184. return ec
  185. }
  186. // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
  187. func (ec *EmployeeCreate) SetNillableVideoURL(s *string) *EmployeeCreate {
  188. if s != nil {
  189. ec.SetVideoURL(*s)
  190. }
  191. return ec
  192. }
  193. // SetOrganizationID sets the "organization_id" field.
  194. func (ec *EmployeeCreate) SetOrganizationID(u uint64) *EmployeeCreate {
  195. ec.mutation.SetOrganizationID(u)
  196. return ec
  197. }
  198. // SetCategoryID sets the "category_id" field.
  199. func (ec *EmployeeCreate) SetCategoryID(u uint64) *EmployeeCreate {
  200. ec.mutation.SetCategoryID(u)
  201. return ec
  202. }
  203. // SetAPIBase sets the "api_base" field.
  204. func (ec *EmployeeCreate) SetAPIBase(s string) *EmployeeCreate {
  205. ec.mutation.SetAPIBase(s)
  206. return ec
  207. }
  208. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  209. func (ec *EmployeeCreate) SetNillableAPIBase(s *string) *EmployeeCreate {
  210. if s != nil {
  211. ec.SetAPIBase(*s)
  212. }
  213. return ec
  214. }
  215. // SetAPIKey sets the "api_key" field.
  216. func (ec *EmployeeCreate) SetAPIKey(s string) *EmployeeCreate {
  217. ec.mutation.SetAPIKey(s)
  218. return ec
  219. }
  220. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  221. func (ec *EmployeeCreate) SetNillableAPIKey(s *string) *EmployeeCreate {
  222. if s != nil {
  223. ec.SetAPIKey(*s)
  224. }
  225. return ec
  226. }
  227. // SetAiInfo sets the "ai_info" field.
  228. func (ec *EmployeeCreate) SetAiInfo(s string) *EmployeeCreate {
  229. ec.mutation.SetAiInfo(s)
  230. return ec
  231. }
  232. // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
  233. func (ec *EmployeeCreate) SetNillableAiInfo(s *string) *EmployeeCreate {
  234. if s != nil {
  235. ec.SetAiInfo(*s)
  236. }
  237. return ec
  238. }
  239. // SetIsVip sets the "is_vip" field.
  240. func (ec *EmployeeCreate) SetIsVip(i int) *EmployeeCreate {
  241. ec.mutation.SetIsVip(i)
  242. return ec
  243. }
  244. // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
  245. func (ec *EmployeeCreate) SetNillableIsVip(i *int) *EmployeeCreate {
  246. if i != nil {
  247. ec.SetIsVip(*i)
  248. }
  249. return ec
  250. }
  251. // SetID sets the "id" field.
  252. func (ec *EmployeeCreate) SetID(u uint64) *EmployeeCreate {
  253. ec.mutation.SetID(u)
  254. return ec
  255. }
  256. // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
  257. func (ec *EmployeeCreate) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeCreate {
  258. ec.mutation.AddEmWorkExperienceIDs(ids...)
  259. return ec
  260. }
  261. // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
  262. func (ec *EmployeeCreate) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeCreate {
  263. ids := make([]uint64, len(w))
  264. for i := range w {
  265. ids[i] = w[i].ID
  266. }
  267. return ec.AddEmWorkExperienceIDs(ids...)
  268. }
  269. // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
  270. func (ec *EmployeeCreate) AddEmTutorialIDs(ids ...uint64) *EmployeeCreate {
  271. ec.mutation.AddEmTutorialIDs(ids...)
  272. return ec
  273. }
  274. // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
  275. func (ec *EmployeeCreate) AddEmTutorial(t ...*Tutorial) *EmployeeCreate {
  276. ids := make([]uint64, len(t))
  277. for i := range t {
  278. ids[i] = t[i].ID
  279. }
  280. return ec.AddEmTutorialIDs(ids...)
  281. }
  282. // Mutation returns the EmployeeMutation object of the builder.
  283. func (ec *EmployeeCreate) Mutation() *EmployeeMutation {
  284. return ec.mutation
  285. }
  286. // Save creates the Employee in the database.
  287. func (ec *EmployeeCreate) Save(ctx context.Context) (*Employee, error) {
  288. if err := ec.defaults(); err != nil {
  289. return nil, err
  290. }
  291. return withHooks(ctx, ec.sqlSave, ec.mutation, ec.hooks)
  292. }
  293. // SaveX calls Save and panics if Save returns an error.
  294. func (ec *EmployeeCreate) SaveX(ctx context.Context) *Employee {
  295. v, err := ec.Save(ctx)
  296. if err != nil {
  297. panic(err)
  298. }
  299. return v
  300. }
  301. // Exec executes the query.
  302. func (ec *EmployeeCreate) Exec(ctx context.Context) error {
  303. _, err := ec.Save(ctx)
  304. return err
  305. }
  306. // ExecX is like Exec, but panics if an error occurs.
  307. func (ec *EmployeeCreate) ExecX(ctx context.Context) {
  308. if err := ec.Exec(ctx); err != nil {
  309. panic(err)
  310. }
  311. }
  312. // defaults sets the default values of the builder before save.
  313. func (ec *EmployeeCreate) defaults() error {
  314. if _, ok := ec.mutation.CreatedAt(); !ok {
  315. if employee.DefaultCreatedAt == nil {
  316. return fmt.Errorf("ent: uninitialized employee.DefaultCreatedAt (forgotten import ent/runtime?)")
  317. }
  318. v := employee.DefaultCreatedAt()
  319. ec.mutation.SetCreatedAt(v)
  320. }
  321. if _, ok := ec.mutation.UpdatedAt(); !ok {
  322. if employee.DefaultUpdatedAt == nil {
  323. return fmt.Errorf("ent: uninitialized employee.DefaultUpdatedAt (forgotten import ent/runtime?)")
  324. }
  325. v := employee.DefaultUpdatedAt()
  326. ec.mutation.SetUpdatedAt(v)
  327. }
  328. if _, ok := ec.mutation.HireCount(); !ok {
  329. v := employee.DefaultHireCount
  330. ec.mutation.SetHireCount(v)
  331. }
  332. if _, ok := ec.mutation.ServiceCount(); !ok {
  333. v := employee.DefaultServiceCount
  334. ec.mutation.SetServiceCount(v)
  335. }
  336. if _, ok := ec.mutation.AchievementCount(); !ok {
  337. v := employee.DefaultAchievementCount
  338. ec.mutation.SetAchievementCount(v)
  339. }
  340. if _, ok := ec.mutation.Intro(); !ok {
  341. v := employee.DefaultIntro
  342. ec.mutation.SetIntro(v)
  343. }
  344. if _, ok := ec.mutation.Estimate(); !ok {
  345. v := employee.DefaultEstimate
  346. ec.mutation.SetEstimate(v)
  347. }
  348. if _, ok := ec.mutation.Skill(); !ok {
  349. v := employee.DefaultSkill
  350. ec.mutation.SetSkill(v)
  351. }
  352. if _, ok := ec.mutation.AbilityType(); !ok {
  353. v := employee.DefaultAbilityType
  354. ec.mutation.SetAbilityType(v)
  355. }
  356. if _, ok := ec.mutation.Scene(); !ok {
  357. v := employee.DefaultScene
  358. ec.mutation.SetScene(v)
  359. }
  360. if _, ok := ec.mutation.SwitchIn(); !ok {
  361. v := employee.DefaultSwitchIn
  362. ec.mutation.SetSwitchIn(v)
  363. }
  364. if _, ok := ec.mutation.VideoURL(); !ok {
  365. v := employee.DefaultVideoURL
  366. ec.mutation.SetVideoURL(v)
  367. }
  368. if _, ok := ec.mutation.APIBase(); !ok {
  369. v := employee.DefaultAPIBase
  370. ec.mutation.SetAPIBase(v)
  371. }
  372. if _, ok := ec.mutation.APIKey(); !ok {
  373. v := employee.DefaultAPIKey
  374. ec.mutation.SetAPIKey(v)
  375. }
  376. if _, ok := ec.mutation.IsVip(); !ok {
  377. v := employee.DefaultIsVip
  378. ec.mutation.SetIsVip(v)
  379. }
  380. return nil
  381. }
  382. // check runs all checks and user-defined validators on the builder.
  383. func (ec *EmployeeCreate) check() error {
  384. if _, ok := ec.mutation.CreatedAt(); !ok {
  385. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Employee.created_at"`)}
  386. }
  387. if _, ok := ec.mutation.UpdatedAt(); !ok {
  388. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Employee.updated_at"`)}
  389. }
  390. if _, ok := ec.mutation.Title(); !ok {
  391. return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Employee.title"`)}
  392. }
  393. if v, ok := ec.mutation.Title(); ok {
  394. if err := employee.TitleValidator(v); err != nil {
  395. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
  396. }
  397. }
  398. if _, ok := ec.mutation.Avatar(); !ok {
  399. return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "Employee.avatar"`)}
  400. }
  401. if v, ok := ec.mutation.Avatar(); ok {
  402. if err := employee.AvatarValidator(v); err != nil {
  403. return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Employee.avatar": %w`, err)}
  404. }
  405. }
  406. if _, ok := ec.mutation.Tags(); !ok {
  407. return &ValidationError{Name: "tags", err: errors.New(`ent: missing required field "Employee.tags"`)}
  408. }
  409. if v, ok := ec.mutation.Tags(); ok {
  410. if err := employee.TagsValidator(v); err != nil {
  411. return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Employee.tags": %w`, err)}
  412. }
  413. }
  414. if _, ok := ec.mutation.HireCount(); !ok {
  415. return &ValidationError{Name: "hire_count", err: errors.New(`ent: missing required field "Employee.hire_count"`)}
  416. }
  417. if v, ok := ec.mutation.HireCount(); ok {
  418. if err := employee.HireCountValidator(v); err != nil {
  419. return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
  420. }
  421. }
  422. if _, ok := ec.mutation.ServiceCount(); !ok {
  423. return &ValidationError{Name: "service_count", err: errors.New(`ent: missing required field "Employee.service_count"`)}
  424. }
  425. if v, ok := ec.mutation.ServiceCount(); ok {
  426. if err := employee.ServiceCountValidator(v); err != nil {
  427. return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
  428. }
  429. }
  430. if _, ok := ec.mutation.AchievementCount(); !ok {
  431. return &ValidationError{Name: "achievement_count", err: errors.New(`ent: missing required field "Employee.achievement_count"`)}
  432. }
  433. if v, ok := ec.mutation.AchievementCount(); ok {
  434. if err := employee.AchievementCountValidator(v); err != nil {
  435. return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
  436. }
  437. }
  438. if _, ok := ec.mutation.Intro(); !ok {
  439. return &ValidationError{Name: "intro", err: errors.New(`ent: missing required field "Employee.intro"`)}
  440. }
  441. if v, ok := ec.mutation.Intro(); ok {
  442. if err := employee.IntroValidator(v); err != nil {
  443. return &ValidationError{Name: "intro", err: fmt.Errorf(`ent: validator failed for field "Employee.intro": %w`, err)}
  444. }
  445. }
  446. if _, ok := ec.mutation.Estimate(); !ok {
  447. return &ValidationError{Name: "estimate", err: errors.New(`ent: missing required field "Employee.estimate"`)}
  448. }
  449. if v, ok := ec.mutation.Estimate(); ok {
  450. if err := employee.EstimateValidator(v); err != nil {
  451. return &ValidationError{Name: "estimate", err: fmt.Errorf(`ent: validator failed for field "Employee.estimate": %w`, err)}
  452. }
  453. }
  454. if _, ok := ec.mutation.Skill(); !ok {
  455. return &ValidationError{Name: "skill", err: errors.New(`ent: missing required field "Employee.skill"`)}
  456. }
  457. if v, ok := ec.mutation.Skill(); ok {
  458. if err := employee.SkillValidator(v); err != nil {
  459. return &ValidationError{Name: "skill", err: fmt.Errorf(`ent: validator failed for field "Employee.skill": %w`, err)}
  460. }
  461. }
  462. if _, ok := ec.mutation.AbilityType(); !ok {
  463. return &ValidationError{Name: "ability_type", err: errors.New(`ent: missing required field "Employee.ability_type"`)}
  464. }
  465. if _, ok := ec.mutation.Scene(); !ok {
  466. return &ValidationError{Name: "scene", err: errors.New(`ent: missing required field "Employee.scene"`)}
  467. }
  468. if _, ok := ec.mutation.SwitchIn(); !ok {
  469. return &ValidationError{Name: "switch_in", err: errors.New(`ent: missing required field "Employee.switch_in"`)}
  470. }
  471. if _, ok := ec.mutation.VideoURL(); !ok {
  472. return &ValidationError{Name: "video_url", err: errors.New(`ent: missing required field "Employee.video_url"`)}
  473. }
  474. if v, ok := ec.mutation.VideoURL(); ok {
  475. if err := employee.VideoURLValidator(v); err != nil {
  476. return &ValidationError{Name: "video_url", err: fmt.Errorf(`ent: validator failed for field "Employee.video_url": %w`, err)}
  477. }
  478. }
  479. if _, ok := ec.mutation.OrganizationID(); !ok {
  480. return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Employee.organization_id"`)}
  481. }
  482. if v, ok := ec.mutation.OrganizationID(); ok {
  483. if err := employee.OrganizationIDValidator(v); err != nil {
  484. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
  485. }
  486. }
  487. if _, ok := ec.mutation.CategoryID(); !ok {
  488. return &ValidationError{Name: "category_id", err: errors.New(`ent: missing required field "Employee.category_id"`)}
  489. }
  490. if v, ok := ec.mutation.CategoryID(); ok {
  491. if err := employee.CategoryIDValidator(v); err != nil {
  492. return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
  493. }
  494. }
  495. if _, ok := ec.mutation.APIBase(); !ok {
  496. return &ValidationError{Name: "api_base", err: errors.New(`ent: missing required field "Employee.api_base"`)}
  497. }
  498. if _, ok := ec.mutation.APIKey(); !ok {
  499. return &ValidationError{Name: "api_key", err: errors.New(`ent: missing required field "Employee.api_key"`)}
  500. }
  501. if _, ok := ec.mutation.IsVip(); !ok {
  502. return &ValidationError{Name: "is_vip", err: errors.New(`ent: missing required field "Employee.is_vip"`)}
  503. }
  504. return nil
  505. }
  506. func (ec *EmployeeCreate) sqlSave(ctx context.Context) (*Employee, error) {
  507. if err := ec.check(); err != nil {
  508. return nil, err
  509. }
  510. _node, _spec := ec.createSpec()
  511. if err := sqlgraph.CreateNode(ctx, ec.driver, _spec); err != nil {
  512. if sqlgraph.IsConstraintError(err) {
  513. err = &ConstraintError{msg: err.Error(), wrap: err}
  514. }
  515. return nil, err
  516. }
  517. if _spec.ID.Value != _node.ID {
  518. id := _spec.ID.Value.(int64)
  519. _node.ID = uint64(id)
  520. }
  521. ec.mutation.id = &_node.ID
  522. ec.mutation.done = true
  523. return _node, nil
  524. }
  525. func (ec *EmployeeCreate) createSpec() (*Employee, *sqlgraph.CreateSpec) {
  526. var (
  527. _node = &Employee{config: ec.config}
  528. _spec = sqlgraph.NewCreateSpec(employee.Table, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
  529. )
  530. _spec.OnConflict = ec.conflict
  531. if id, ok := ec.mutation.ID(); ok {
  532. _node.ID = id
  533. _spec.ID.Value = id
  534. }
  535. if value, ok := ec.mutation.CreatedAt(); ok {
  536. _spec.SetField(employee.FieldCreatedAt, field.TypeTime, value)
  537. _node.CreatedAt = value
  538. }
  539. if value, ok := ec.mutation.UpdatedAt(); ok {
  540. _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
  541. _node.UpdatedAt = value
  542. }
  543. if value, ok := ec.mutation.DeletedAt(); ok {
  544. _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
  545. _node.DeletedAt = value
  546. }
  547. if value, ok := ec.mutation.Title(); ok {
  548. _spec.SetField(employee.FieldTitle, field.TypeString, value)
  549. _node.Title = value
  550. }
  551. if value, ok := ec.mutation.Avatar(); ok {
  552. _spec.SetField(employee.FieldAvatar, field.TypeString, value)
  553. _node.Avatar = value
  554. }
  555. if value, ok := ec.mutation.Tags(); ok {
  556. _spec.SetField(employee.FieldTags, field.TypeString, value)
  557. _node.Tags = value
  558. }
  559. if value, ok := ec.mutation.HireCount(); ok {
  560. _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
  561. _node.HireCount = value
  562. }
  563. if value, ok := ec.mutation.ServiceCount(); ok {
  564. _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
  565. _node.ServiceCount = value
  566. }
  567. if value, ok := ec.mutation.AchievementCount(); ok {
  568. _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
  569. _node.AchievementCount = value
  570. }
  571. if value, ok := ec.mutation.Intro(); ok {
  572. _spec.SetField(employee.FieldIntro, field.TypeString, value)
  573. _node.Intro = value
  574. }
  575. if value, ok := ec.mutation.Estimate(); ok {
  576. _spec.SetField(employee.FieldEstimate, field.TypeString, value)
  577. _node.Estimate = value
  578. }
  579. if value, ok := ec.mutation.Skill(); ok {
  580. _spec.SetField(employee.FieldSkill, field.TypeString, value)
  581. _node.Skill = value
  582. }
  583. if value, ok := ec.mutation.AbilityType(); ok {
  584. _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
  585. _node.AbilityType = value
  586. }
  587. if value, ok := ec.mutation.Scene(); ok {
  588. _spec.SetField(employee.FieldScene, field.TypeString, value)
  589. _node.Scene = value
  590. }
  591. if value, ok := ec.mutation.SwitchIn(); ok {
  592. _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
  593. _node.SwitchIn = value
  594. }
  595. if value, ok := ec.mutation.VideoURL(); ok {
  596. _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
  597. _node.VideoURL = value
  598. }
  599. if value, ok := ec.mutation.OrganizationID(); ok {
  600. _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
  601. _node.OrganizationID = value
  602. }
  603. if value, ok := ec.mutation.CategoryID(); ok {
  604. _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
  605. _node.CategoryID = value
  606. }
  607. if value, ok := ec.mutation.APIBase(); ok {
  608. _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
  609. _node.APIBase = value
  610. }
  611. if value, ok := ec.mutation.APIKey(); ok {
  612. _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
  613. _node.APIKey = value
  614. }
  615. if value, ok := ec.mutation.AiInfo(); ok {
  616. _spec.SetField(employee.FieldAiInfo, field.TypeString, value)
  617. _node.AiInfo = value
  618. }
  619. if value, ok := ec.mutation.IsVip(); ok {
  620. _spec.SetField(employee.FieldIsVip, field.TypeInt, value)
  621. _node.IsVip = value
  622. }
  623. if nodes := ec.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
  624. edge := &sqlgraph.EdgeSpec{
  625. Rel: sqlgraph.O2M,
  626. Inverse: false,
  627. Table: employee.EmWorkExperiencesTable,
  628. Columns: []string{employee.EmWorkExperiencesColumn},
  629. Bidi: false,
  630. Target: &sqlgraph.EdgeTarget{
  631. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  632. },
  633. }
  634. for _, k := range nodes {
  635. edge.Target.Nodes = append(edge.Target.Nodes, k)
  636. }
  637. _spec.Edges = append(_spec.Edges, edge)
  638. }
  639. if nodes := ec.mutation.EmTutorialIDs(); len(nodes) > 0 {
  640. edge := &sqlgraph.EdgeSpec{
  641. Rel: sqlgraph.O2M,
  642. Inverse: false,
  643. Table: employee.EmTutorialTable,
  644. Columns: []string{employee.EmTutorialColumn},
  645. Bidi: false,
  646. Target: &sqlgraph.EdgeTarget{
  647. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  648. },
  649. }
  650. for _, k := range nodes {
  651. edge.Target.Nodes = append(edge.Target.Nodes, k)
  652. }
  653. _spec.Edges = append(_spec.Edges, edge)
  654. }
  655. return _node, _spec
  656. }
  657. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  658. // of the `INSERT` statement. For example:
  659. //
  660. // client.Employee.Create().
  661. // SetCreatedAt(v).
  662. // OnConflict(
  663. // // Update the row with the new values
  664. // // the was proposed for insertion.
  665. // sql.ResolveWithNewValues(),
  666. // ).
  667. // // Override some of the fields with custom
  668. // // update values.
  669. // Update(func(u *ent.EmployeeUpsert) {
  670. // SetCreatedAt(v+v).
  671. // }).
  672. // Exec(ctx)
  673. func (ec *EmployeeCreate) OnConflict(opts ...sql.ConflictOption) *EmployeeUpsertOne {
  674. ec.conflict = opts
  675. return &EmployeeUpsertOne{
  676. create: ec,
  677. }
  678. }
  679. // OnConflictColumns calls `OnConflict` and configures the columns
  680. // as conflict target. Using this option is equivalent to using:
  681. //
  682. // client.Employee.Create().
  683. // OnConflict(sql.ConflictColumns(columns...)).
  684. // Exec(ctx)
  685. func (ec *EmployeeCreate) OnConflictColumns(columns ...string) *EmployeeUpsertOne {
  686. ec.conflict = append(ec.conflict, sql.ConflictColumns(columns...))
  687. return &EmployeeUpsertOne{
  688. create: ec,
  689. }
  690. }
  691. type (
  692. // EmployeeUpsertOne is the builder for "upsert"-ing
  693. // one Employee node.
  694. EmployeeUpsertOne struct {
  695. create *EmployeeCreate
  696. }
  697. // EmployeeUpsert is the "OnConflict" setter.
  698. EmployeeUpsert struct {
  699. *sql.UpdateSet
  700. }
  701. )
  702. // SetUpdatedAt sets the "updated_at" field.
  703. func (u *EmployeeUpsert) SetUpdatedAt(v time.Time) *EmployeeUpsert {
  704. u.Set(employee.FieldUpdatedAt, v)
  705. return u
  706. }
  707. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  708. func (u *EmployeeUpsert) UpdateUpdatedAt() *EmployeeUpsert {
  709. u.SetExcluded(employee.FieldUpdatedAt)
  710. return u
  711. }
  712. // SetDeletedAt sets the "deleted_at" field.
  713. func (u *EmployeeUpsert) SetDeletedAt(v time.Time) *EmployeeUpsert {
  714. u.Set(employee.FieldDeletedAt, v)
  715. return u
  716. }
  717. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  718. func (u *EmployeeUpsert) UpdateDeletedAt() *EmployeeUpsert {
  719. u.SetExcluded(employee.FieldDeletedAt)
  720. return u
  721. }
  722. // ClearDeletedAt clears the value of the "deleted_at" field.
  723. func (u *EmployeeUpsert) ClearDeletedAt() *EmployeeUpsert {
  724. u.SetNull(employee.FieldDeletedAt)
  725. return u
  726. }
  727. // SetTitle sets the "title" field.
  728. func (u *EmployeeUpsert) SetTitle(v string) *EmployeeUpsert {
  729. u.Set(employee.FieldTitle, v)
  730. return u
  731. }
  732. // UpdateTitle sets the "title" field to the value that was provided on create.
  733. func (u *EmployeeUpsert) UpdateTitle() *EmployeeUpsert {
  734. u.SetExcluded(employee.FieldTitle)
  735. return u
  736. }
  737. // SetAvatar sets the "avatar" field.
  738. func (u *EmployeeUpsert) SetAvatar(v string) *EmployeeUpsert {
  739. u.Set(employee.FieldAvatar, v)
  740. return u
  741. }
  742. // UpdateAvatar sets the "avatar" field to the value that was provided on create.
  743. func (u *EmployeeUpsert) UpdateAvatar() *EmployeeUpsert {
  744. u.SetExcluded(employee.FieldAvatar)
  745. return u
  746. }
  747. // SetTags sets the "tags" field.
  748. func (u *EmployeeUpsert) SetTags(v string) *EmployeeUpsert {
  749. u.Set(employee.FieldTags, v)
  750. return u
  751. }
  752. // UpdateTags sets the "tags" field to the value that was provided on create.
  753. func (u *EmployeeUpsert) UpdateTags() *EmployeeUpsert {
  754. u.SetExcluded(employee.FieldTags)
  755. return u
  756. }
  757. // SetHireCount sets the "hire_count" field.
  758. func (u *EmployeeUpsert) SetHireCount(v int) *EmployeeUpsert {
  759. u.Set(employee.FieldHireCount, v)
  760. return u
  761. }
  762. // UpdateHireCount sets the "hire_count" field to the value that was provided on create.
  763. func (u *EmployeeUpsert) UpdateHireCount() *EmployeeUpsert {
  764. u.SetExcluded(employee.FieldHireCount)
  765. return u
  766. }
  767. // AddHireCount adds v to the "hire_count" field.
  768. func (u *EmployeeUpsert) AddHireCount(v int) *EmployeeUpsert {
  769. u.Add(employee.FieldHireCount, v)
  770. return u
  771. }
  772. // SetServiceCount sets the "service_count" field.
  773. func (u *EmployeeUpsert) SetServiceCount(v int) *EmployeeUpsert {
  774. u.Set(employee.FieldServiceCount, v)
  775. return u
  776. }
  777. // UpdateServiceCount sets the "service_count" field to the value that was provided on create.
  778. func (u *EmployeeUpsert) UpdateServiceCount() *EmployeeUpsert {
  779. u.SetExcluded(employee.FieldServiceCount)
  780. return u
  781. }
  782. // AddServiceCount adds v to the "service_count" field.
  783. func (u *EmployeeUpsert) AddServiceCount(v int) *EmployeeUpsert {
  784. u.Add(employee.FieldServiceCount, v)
  785. return u
  786. }
  787. // SetAchievementCount sets the "achievement_count" field.
  788. func (u *EmployeeUpsert) SetAchievementCount(v int) *EmployeeUpsert {
  789. u.Set(employee.FieldAchievementCount, v)
  790. return u
  791. }
  792. // UpdateAchievementCount sets the "achievement_count" field to the value that was provided on create.
  793. func (u *EmployeeUpsert) UpdateAchievementCount() *EmployeeUpsert {
  794. u.SetExcluded(employee.FieldAchievementCount)
  795. return u
  796. }
  797. // AddAchievementCount adds v to the "achievement_count" field.
  798. func (u *EmployeeUpsert) AddAchievementCount(v int) *EmployeeUpsert {
  799. u.Add(employee.FieldAchievementCount, v)
  800. return u
  801. }
  802. // SetIntro sets the "intro" field.
  803. func (u *EmployeeUpsert) SetIntro(v string) *EmployeeUpsert {
  804. u.Set(employee.FieldIntro, v)
  805. return u
  806. }
  807. // UpdateIntro sets the "intro" field to the value that was provided on create.
  808. func (u *EmployeeUpsert) UpdateIntro() *EmployeeUpsert {
  809. u.SetExcluded(employee.FieldIntro)
  810. return u
  811. }
  812. // SetEstimate sets the "estimate" field.
  813. func (u *EmployeeUpsert) SetEstimate(v string) *EmployeeUpsert {
  814. u.Set(employee.FieldEstimate, v)
  815. return u
  816. }
  817. // UpdateEstimate sets the "estimate" field to the value that was provided on create.
  818. func (u *EmployeeUpsert) UpdateEstimate() *EmployeeUpsert {
  819. u.SetExcluded(employee.FieldEstimate)
  820. return u
  821. }
  822. // SetSkill sets the "skill" field.
  823. func (u *EmployeeUpsert) SetSkill(v string) *EmployeeUpsert {
  824. u.Set(employee.FieldSkill, v)
  825. return u
  826. }
  827. // UpdateSkill sets the "skill" field to the value that was provided on create.
  828. func (u *EmployeeUpsert) UpdateSkill() *EmployeeUpsert {
  829. u.SetExcluded(employee.FieldSkill)
  830. return u
  831. }
  832. // SetAbilityType sets the "ability_type" field.
  833. func (u *EmployeeUpsert) SetAbilityType(v string) *EmployeeUpsert {
  834. u.Set(employee.FieldAbilityType, v)
  835. return u
  836. }
  837. // UpdateAbilityType sets the "ability_type" field to the value that was provided on create.
  838. func (u *EmployeeUpsert) UpdateAbilityType() *EmployeeUpsert {
  839. u.SetExcluded(employee.FieldAbilityType)
  840. return u
  841. }
  842. // SetScene sets the "scene" field.
  843. func (u *EmployeeUpsert) SetScene(v string) *EmployeeUpsert {
  844. u.Set(employee.FieldScene, v)
  845. return u
  846. }
  847. // UpdateScene sets the "scene" field to the value that was provided on create.
  848. func (u *EmployeeUpsert) UpdateScene() *EmployeeUpsert {
  849. u.SetExcluded(employee.FieldScene)
  850. return u
  851. }
  852. // SetSwitchIn sets the "switch_in" field.
  853. func (u *EmployeeUpsert) SetSwitchIn(v string) *EmployeeUpsert {
  854. u.Set(employee.FieldSwitchIn, v)
  855. return u
  856. }
  857. // UpdateSwitchIn sets the "switch_in" field to the value that was provided on create.
  858. func (u *EmployeeUpsert) UpdateSwitchIn() *EmployeeUpsert {
  859. u.SetExcluded(employee.FieldSwitchIn)
  860. return u
  861. }
  862. // SetVideoURL sets the "video_url" field.
  863. func (u *EmployeeUpsert) SetVideoURL(v string) *EmployeeUpsert {
  864. u.Set(employee.FieldVideoURL, v)
  865. return u
  866. }
  867. // UpdateVideoURL sets the "video_url" field to the value that was provided on create.
  868. func (u *EmployeeUpsert) UpdateVideoURL() *EmployeeUpsert {
  869. u.SetExcluded(employee.FieldVideoURL)
  870. return u
  871. }
  872. // SetOrganizationID sets the "organization_id" field.
  873. func (u *EmployeeUpsert) SetOrganizationID(v uint64) *EmployeeUpsert {
  874. u.Set(employee.FieldOrganizationID, v)
  875. return u
  876. }
  877. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  878. func (u *EmployeeUpsert) UpdateOrganizationID() *EmployeeUpsert {
  879. u.SetExcluded(employee.FieldOrganizationID)
  880. return u
  881. }
  882. // AddOrganizationID adds v to the "organization_id" field.
  883. func (u *EmployeeUpsert) AddOrganizationID(v uint64) *EmployeeUpsert {
  884. u.Add(employee.FieldOrganizationID, v)
  885. return u
  886. }
  887. // SetCategoryID sets the "category_id" field.
  888. func (u *EmployeeUpsert) SetCategoryID(v uint64) *EmployeeUpsert {
  889. u.Set(employee.FieldCategoryID, v)
  890. return u
  891. }
  892. // UpdateCategoryID sets the "category_id" field to the value that was provided on create.
  893. func (u *EmployeeUpsert) UpdateCategoryID() *EmployeeUpsert {
  894. u.SetExcluded(employee.FieldCategoryID)
  895. return u
  896. }
  897. // AddCategoryID adds v to the "category_id" field.
  898. func (u *EmployeeUpsert) AddCategoryID(v uint64) *EmployeeUpsert {
  899. u.Add(employee.FieldCategoryID, v)
  900. return u
  901. }
  902. // SetAPIBase sets the "api_base" field.
  903. func (u *EmployeeUpsert) SetAPIBase(v string) *EmployeeUpsert {
  904. u.Set(employee.FieldAPIBase, v)
  905. return u
  906. }
  907. // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
  908. func (u *EmployeeUpsert) UpdateAPIBase() *EmployeeUpsert {
  909. u.SetExcluded(employee.FieldAPIBase)
  910. return u
  911. }
  912. // SetAPIKey sets the "api_key" field.
  913. func (u *EmployeeUpsert) SetAPIKey(v string) *EmployeeUpsert {
  914. u.Set(employee.FieldAPIKey, v)
  915. return u
  916. }
  917. // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
  918. func (u *EmployeeUpsert) UpdateAPIKey() *EmployeeUpsert {
  919. u.SetExcluded(employee.FieldAPIKey)
  920. return u
  921. }
  922. // SetAiInfo sets the "ai_info" field.
  923. func (u *EmployeeUpsert) SetAiInfo(v string) *EmployeeUpsert {
  924. u.Set(employee.FieldAiInfo, v)
  925. return u
  926. }
  927. // UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
  928. func (u *EmployeeUpsert) UpdateAiInfo() *EmployeeUpsert {
  929. u.SetExcluded(employee.FieldAiInfo)
  930. return u
  931. }
  932. // ClearAiInfo clears the value of the "ai_info" field.
  933. func (u *EmployeeUpsert) ClearAiInfo() *EmployeeUpsert {
  934. u.SetNull(employee.FieldAiInfo)
  935. return u
  936. }
  937. // SetIsVip sets the "is_vip" field.
  938. func (u *EmployeeUpsert) SetIsVip(v int) *EmployeeUpsert {
  939. u.Set(employee.FieldIsVip, v)
  940. return u
  941. }
  942. // UpdateIsVip sets the "is_vip" field to the value that was provided on create.
  943. func (u *EmployeeUpsert) UpdateIsVip() *EmployeeUpsert {
  944. u.SetExcluded(employee.FieldIsVip)
  945. return u
  946. }
  947. // AddIsVip adds v to the "is_vip" field.
  948. func (u *EmployeeUpsert) AddIsVip(v int) *EmployeeUpsert {
  949. u.Add(employee.FieldIsVip, v)
  950. return u
  951. }
  952. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  953. // Using this option is equivalent to using:
  954. //
  955. // client.Employee.Create().
  956. // OnConflict(
  957. // sql.ResolveWithNewValues(),
  958. // sql.ResolveWith(func(u *sql.UpdateSet) {
  959. // u.SetIgnore(employee.FieldID)
  960. // }),
  961. // ).
  962. // Exec(ctx)
  963. func (u *EmployeeUpsertOne) UpdateNewValues() *EmployeeUpsertOne {
  964. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  965. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  966. if _, exists := u.create.mutation.ID(); exists {
  967. s.SetIgnore(employee.FieldID)
  968. }
  969. if _, exists := u.create.mutation.CreatedAt(); exists {
  970. s.SetIgnore(employee.FieldCreatedAt)
  971. }
  972. }))
  973. return u
  974. }
  975. // Ignore sets each column to itself in case of conflict.
  976. // Using this option is equivalent to using:
  977. //
  978. // client.Employee.Create().
  979. // OnConflict(sql.ResolveWithIgnore()).
  980. // Exec(ctx)
  981. func (u *EmployeeUpsertOne) Ignore() *EmployeeUpsertOne {
  982. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  983. return u
  984. }
  985. // DoNothing configures the conflict_action to `DO NOTHING`.
  986. // Supported only by SQLite and PostgreSQL.
  987. func (u *EmployeeUpsertOne) DoNothing() *EmployeeUpsertOne {
  988. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  989. return u
  990. }
  991. // Update allows overriding fields `UPDATE` values. See the EmployeeCreate.OnConflict
  992. // documentation for more info.
  993. func (u *EmployeeUpsertOne) Update(set func(*EmployeeUpsert)) *EmployeeUpsertOne {
  994. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  995. set(&EmployeeUpsert{UpdateSet: update})
  996. }))
  997. return u
  998. }
  999. // SetUpdatedAt sets the "updated_at" field.
  1000. func (u *EmployeeUpsertOne) SetUpdatedAt(v time.Time) *EmployeeUpsertOne {
  1001. return u.Update(func(s *EmployeeUpsert) {
  1002. s.SetUpdatedAt(v)
  1003. })
  1004. }
  1005. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1006. func (u *EmployeeUpsertOne) UpdateUpdatedAt() *EmployeeUpsertOne {
  1007. return u.Update(func(s *EmployeeUpsert) {
  1008. s.UpdateUpdatedAt()
  1009. })
  1010. }
  1011. // SetDeletedAt sets the "deleted_at" field.
  1012. func (u *EmployeeUpsertOne) SetDeletedAt(v time.Time) *EmployeeUpsertOne {
  1013. return u.Update(func(s *EmployeeUpsert) {
  1014. s.SetDeletedAt(v)
  1015. })
  1016. }
  1017. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1018. func (u *EmployeeUpsertOne) UpdateDeletedAt() *EmployeeUpsertOne {
  1019. return u.Update(func(s *EmployeeUpsert) {
  1020. s.UpdateDeletedAt()
  1021. })
  1022. }
  1023. // ClearDeletedAt clears the value of the "deleted_at" field.
  1024. func (u *EmployeeUpsertOne) ClearDeletedAt() *EmployeeUpsertOne {
  1025. return u.Update(func(s *EmployeeUpsert) {
  1026. s.ClearDeletedAt()
  1027. })
  1028. }
  1029. // SetTitle sets the "title" field.
  1030. func (u *EmployeeUpsertOne) SetTitle(v string) *EmployeeUpsertOne {
  1031. return u.Update(func(s *EmployeeUpsert) {
  1032. s.SetTitle(v)
  1033. })
  1034. }
  1035. // UpdateTitle sets the "title" field to the value that was provided on create.
  1036. func (u *EmployeeUpsertOne) UpdateTitle() *EmployeeUpsertOne {
  1037. return u.Update(func(s *EmployeeUpsert) {
  1038. s.UpdateTitle()
  1039. })
  1040. }
  1041. // SetAvatar sets the "avatar" field.
  1042. func (u *EmployeeUpsertOne) SetAvatar(v string) *EmployeeUpsertOne {
  1043. return u.Update(func(s *EmployeeUpsert) {
  1044. s.SetAvatar(v)
  1045. })
  1046. }
  1047. // UpdateAvatar sets the "avatar" field to the value that was provided on create.
  1048. func (u *EmployeeUpsertOne) UpdateAvatar() *EmployeeUpsertOne {
  1049. return u.Update(func(s *EmployeeUpsert) {
  1050. s.UpdateAvatar()
  1051. })
  1052. }
  1053. // SetTags sets the "tags" field.
  1054. func (u *EmployeeUpsertOne) SetTags(v string) *EmployeeUpsertOne {
  1055. return u.Update(func(s *EmployeeUpsert) {
  1056. s.SetTags(v)
  1057. })
  1058. }
  1059. // UpdateTags sets the "tags" field to the value that was provided on create.
  1060. func (u *EmployeeUpsertOne) UpdateTags() *EmployeeUpsertOne {
  1061. return u.Update(func(s *EmployeeUpsert) {
  1062. s.UpdateTags()
  1063. })
  1064. }
  1065. // SetHireCount sets the "hire_count" field.
  1066. func (u *EmployeeUpsertOne) SetHireCount(v int) *EmployeeUpsertOne {
  1067. return u.Update(func(s *EmployeeUpsert) {
  1068. s.SetHireCount(v)
  1069. })
  1070. }
  1071. // AddHireCount adds v to the "hire_count" field.
  1072. func (u *EmployeeUpsertOne) AddHireCount(v int) *EmployeeUpsertOne {
  1073. return u.Update(func(s *EmployeeUpsert) {
  1074. s.AddHireCount(v)
  1075. })
  1076. }
  1077. // UpdateHireCount sets the "hire_count" field to the value that was provided on create.
  1078. func (u *EmployeeUpsertOne) UpdateHireCount() *EmployeeUpsertOne {
  1079. return u.Update(func(s *EmployeeUpsert) {
  1080. s.UpdateHireCount()
  1081. })
  1082. }
  1083. // SetServiceCount sets the "service_count" field.
  1084. func (u *EmployeeUpsertOne) SetServiceCount(v int) *EmployeeUpsertOne {
  1085. return u.Update(func(s *EmployeeUpsert) {
  1086. s.SetServiceCount(v)
  1087. })
  1088. }
  1089. // AddServiceCount adds v to the "service_count" field.
  1090. func (u *EmployeeUpsertOne) AddServiceCount(v int) *EmployeeUpsertOne {
  1091. return u.Update(func(s *EmployeeUpsert) {
  1092. s.AddServiceCount(v)
  1093. })
  1094. }
  1095. // UpdateServiceCount sets the "service_count" field to the value that was provided on create.
  1096. func (u *EmployeeUpsertOne) UpdateServiceCount() *EmployeeUpsertOne {
  1097. return u.Update(func(s *EmployeeUpsert) {
  1098. s.UpdateServiceCount()
  1099. })
  1100. }
  1101. // SetAchievementCount sets the "achievement_count" field.
  1102. func (u *EmployeeUpsertOne) SetAchievementCount(v int) *EmployeeUpsertOne {
  1103. return u.Update(func(s *EmployeeUpsert) {
  1104. s.SetAchievementCount(v)
  1105. })
  1106. }
  1107. // AddAchievementCount adds v to the "achievement_count" field.
  1108. func (u *EmployeeUpsertOne) AddAchievementCount(v int) *EmployeeUpsertOne {
  1109. return u.Update(func(s *EmployeeUpsert) {
  1110. s.AddAchievementCount(v)
  1111. })
  1112. }
  1113. // UpdateAchievementCount sets the "achievement_count" field to the value that was provided on create.
  1114. func (u *EmployeeUpsertOne) UpdateAchievementCount() *EmployeeUpsertOne {
  1115. return u.Update(func(s *EmployeeUpsert) {
  1116. s.UpdateAchievementCount()
  1117. })
  1118. }
  1119. // SetIntro sets the "intro" field.
  1120. func (u *EmployeeUpsertOne) SetIntro(v string) *EmployeeUpsertOne {
  1121. return u.Update(func(s *EmployeeUpsert) {
  1122. s.SetIntro(v)
  1123. })
  1124. }
  1125. // UpdateIntro sets the "intro" field to the value that was provided on create.
  1126. func (u *EmployeeUpsertOne) UpdateIntro() *EmployeeUpsertOne {
  1127. return u.Update(func(s *EmployeeUpsert) {
  1128. s.UpdateIntro()
  1129. })
  1130. }
  1131. // SetEstimate sets the "estimate" field.
  1132. func (u *EmployeeUpsertOne) SetEstimate(v string) *EmployeeUpsertOne {
  1133. return u.Update(func(s *EmployeeUpsert) {
  1134. s.SetEstimate(v)
  1135. })
  1136. }
  1137. // UpdateEstimate sets the "estimate" field to the value that was provided on create.
  1138. func (u *EmployeeUpsertOne) UpdateEstimate() *EmployeeUpsertOne {
  1139. return u.Update(func(s *EmployeeUpsert) {
  1140. s.UpdateEstimate()
  1141. })
  1142. }
  1143. // SetSkill sets the "skill" field.
  1144. func (u *EmployeeUpsertOne) SetSkill(v string) *EmployeeUpsertOne {
  1145. return u.Update(func(s *EmployeeUpsert) {
  1146. s.SetSkill(v)
  1147. })
  1148. }
  1149. // UpdateSkill sets the "skill" field to the value that was provided on create.
  1150. func (u *EmployeeUpsertOne) UpdateSkill() *EmployeeUpsertOne {
  1151. return u.Update(func(s *EmployeeUpsert) {
  1152. s.UpdateSkill()
  1153. })
  1154. }
  1155. // SetAbilityType sets the "ability_type" field.
  1156. func (u *EmployeeUpsertOne) SetAbilityType(v string) *EmployeeUpsertOne {
  1157. return u.Update(func(s *EmployeeUpsert) {
  1158. s.SetAbilityType(v)
  1159. })
  1160. }
  1161. // UpdateAbilityType sets the "ability_type" field to the value that was provided on create.
  1162. func (u *EmployeeUpsertOne) UpdateAbilityType() *EmployeeUpsertOne {
  1163. return u.Update(func(s *EmployeeUpsert) {
  1164. s.UpdateAbilityType()
  1165. })
  1166. }
  1167. // SetScene sets the "scene" field.
  1168. func (u *EmployeeUpsertOne) SetScene(v string) *EmployeeUpsertOne {
  1169. return u.Update(func(s *EmployeeUpsert) {
  1170. s.SetScene(v)
  1171. })
  1172. }
  1173. // UpdateScene sets the "scene" field to the value that was provided on create.
  1174. func (u *EmployeeUpsertOne) UpdateScene() *EmployeeUpsertOne {
  1175. return u.Update(func(s *EmployeeUpsert) {
  1176. s.UpdateScene()
  1177. })
  1178. }
  1179. // SetSwitchIn sets the "switch_in" field.
  1180. func (u *EmployeeUpsertOne) SetSwitchIn(v string) *EmployeeUpsertOne {
  1181. return u.Update(func(s *EmployeeUpsert) {
  1182. s.SetSwitchIn(v)
  1183. })
  1184. }
  1185. // UpdateSwitchIn sets the "switch_in" field to the value that was provided on create.
  1186. func (u *EmployeeUpsertOne) UpdateSwitchIn() *EmployeeUpsertOne {
  1187. return u.Update(func(s *EmployeeUpsert) {
  1188. s.UpdateSwitchIn()
  1189. })
  1190. }
  1191. // SetVideoURL sets the "video_url" field.
  1192. func (u *EmployeeUpsertOne) SetVideoURL(v string) *EmployeeUpsertOne {
  1193. return u.Update(func(s *EmployeeUpsert) {
  1194. s.SetVideoURL(v)
  1195. })
  1196. }
  1197. // UpdateVideoURL sets the "video_url" field to the value that was provided on create.
  1198. func (u *EmployeeUpsertOne) UpdateVideoURL() *EmployeeUpsertOne {
  1199. return u.Update(func(s *EmployeeUpsert) {
  1200. s.UpdateVideoURL()
  1201. })
  1202. }
  1203. // SetOrganizationID sets the "organization_id" field.
  1204. func (u *EmployeeUpsertOne) SetOrganizationID(v uint64) *EmployeeUpsertOne {
  1205. return u.Update(func(s *EmployeeUpsert) {
  1206. s.SetOrganizationID(v)
  1207. })
  1208. }
  1209. // AddOrganizationID adds v to the "organization_id" field.
  1210. func (u *EmployeeUpsertOne) AddOrganizationID(v uint64) *EmployeeUpsertOne {
  1211. return u.Update(func(s *EmployeeUpsert) {
  1212. s.AddOrganizationID(v)
  1213. })
  1214. }
  1215. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  1216. func (u *EmployeeUpsertOne) UpdateOrganizationID() *EmployeeUpsertOne {
  1217. return u.Update(func(s *EmployeeUpsert) {
  1218. s.UpdateOrganizationID()
  1219. })
  1220. }
  1221. // SetCategoryID sets the "category_id" field.
  1222. func (u *EmployeeUpsertOne) SetCategoryID(v uint64) *EmployeeUpsertOne {
  1223. return u.Update(func(s *EmployeeUpsert) {
  1224. s.SetCategoryID(v)
  1225. })
  1226. }
  1227. // AddCategoryID adds v to the "category_id" field.
  1228. func (u *EmployeeUpsertOne) AddCategoryID(v uint64) *EmployeeUpsertOne {
  1229. return u.Update(func(s *EmployeeUpsert) {
  1230. s.AddCategoryID(v)
  1231. })
  1232. }
  1233. // UpdateCategoryID sets the "category_id" field to the value that was provided on create.
  1234. func (u *EmployeeUpsertOne) UpdateCategoryID() *EmployeeUpsertOne {
  1235. return u.Update(func(s *EmployeeUpsert) {
  1236. s.UpdateCategoryID()
  1237. })
  1238. }
  1239. // SetAPIBase sets the "api_base" field.
  1240. func (u *EmployeeUpsertOne) SetAPIBase(v string) *EmployeeUpsertOne {
  1241. return u.Update(func(s *EmployeeUpsert) {
  1242. s.SetAPIBase(v)
  1243. })
  1244. }
  1245. // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
  1246. func (u *EmployeeUpsertOne) UpdateAPIBase() *EmployeeUpsertOne {
  1247. return u.Update(func(s *EmployeeUpsert) {
  1248. s.UpdateAPIBase()
  1249. })
  1250. }
  1251. // SetAPIKey sets the "api_key" field.
  1252. func (u *EmployeeUpsertOne) SetAPIKey(v string) *EmployeeUpsertOne {
  1253. return u.Update(func(s *EmployeeUpsert) {
  1254. s.SetAPIKey(v)
  1255. })
  1256. }
  1257. // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
  1258. func (u *EmployeeUpsertOne) UpdateAPIKey() *EmployeeUpsertOne {
  1259. return u.Update(func(s *EmployeeUpsert) {
  1260. s.UpdateAPIKey()
  1261. })
  1262. }
  1263. // SetAiInfo sets the "ai_info" field.
  1264. func (u *EmployeeUpsertOne) SetAiInfo(v string) *EmployeeUpsertOne {
  1265. return u.Update(func(s *EmployeeUpsert) {
  1266. s.SetAiInfo(v)
  1267. })
  1268. }
  1269. // UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
  1270. func (u *EmployeeUpsertOne) UpdateAiInfo() *EmployeeUpsertOne {
  1271. return u.Update(func(s *EmployeeUpsert) {
  1272. s.UpdateAiInfo()
  1273. })
  1274. }
  1275. // ClearAiInfo clears the value of the "ai_info" field.
  1276. func (u *EmployeeUpsertOne) ClearAiInfo() *EmployeeUpsertOne {
  1277. return u.Update(func(s *EmployeeUpsert) {
  1278. s.ClearAiInfo()
  1279. })
  1280. }
  1281. // SetIsVip sets the "is_vip" field.
  1282. func (u *EmployeeUpsertOne) SetIsVip(v int) *EmployeeUpsertOne {
  1283. return u.Update(func(s *EmployeeUpsert) {
  1284. s.SetIsVip(v)
  1285. })
  1286. }
  1287. // AddIsVip adds v to the "is_vip" field.
  1288. func (u *EmployeeUpsertOne) AddIsVip(v int) *EmployeeUpsertOne {
  1289. return u.Update(func(s *EmployeeUpsert) {
  1290. s.AddIsVip(v)
  1291. })
  1292. }
  1293. // UpdateIsVip sets the "is_vip" field to the value that was provided on create.
  1294. func (u *EmployeeUpsertOne) UpdateIsVip() *EmployeeUpsertOne {
  1295. return u.Update(func(s *EmployeeUpsert) {
  1296. s.UpdateIsVip()
  1297. })
  1298. }
  1299. // Exec executes the query.
  1300. func (u *EmployeeUpsertOne) Exec(ctx context.Context) error {
  1301. if len(u.create.conflict) == 0 {
  1302. return errors.New("ent: missing options for EmployeeCreate.OnConflict")
  1303. }
  1304. return u.create.Exec(ctx)
  1305. }
  1306. // ExecX is like Exec, but panics if an error occurs.
  1307. func (u *EmployeeUpsertOne) ExecX(ctx context.Context) {
  1308. if err := u.create.Exec(ctx); err != nil {
  1309. panic(err)
  1310. }
  1311. }
  1312. // Exec executes the UPSERT query and returns the inserted/updated ID.
  1313. func (u *EmployeeUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  1314. node, err := u.create.Save(ctx)
  1315. if err != nil {
  1316. return id, err
  1317. }
  1318. return node.ID, nil
  1319. }
  1320. // IDX is like ID, but panics if an error occurs.
  1321. func (u *EmployeeUpsertOne) IDX(ctx context.Context) uint64 {
  1322. id, err := u.ID(ctx)
  1323. if err != nil {
  1324. panic(err)
  1325. }
  1326. return id
  1327. }
  1328. // EmployeeCreateBulk is the builder for creating many Employee entities in bulk.
  1329. type EmployeeCreateBulk struct {
  1330. config
  1331. err error
  1332. builders []*EmployeeCreate
  1333. conflict []sql.ConflictOption
  1334. }
  1335. // Save creates the Employee entities in the database.
  1336. func (ecb *EmployeeCreateBulk) Save(ctx context.Context) ([]*Employee, error) {
  1337. if ecb.err != nil {
  1338. return nil, ecb.err
  1339. }
  1340. specs := make([]*sqlgraph.CreateSpec, len(ecb.builders))
  1341. nodes := make([]*Employee, len(ecb.builders))
  1342. mutators := make([]Mutator, len(ecb.builders))
  1343. for i := range ecb.builders {
  1344. func(i int, root context.Context) {
  1345. builder := ecb.builders[i]
  1346. builder.defaults()
  1347. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  1348. mutation, ok := m.(*EmployeeMutation)
  1349. if !ok {
  1350. return nil, fmt.Errorf("unexpected mutation type %T", m)
  1351. }
  1352. if err := builder.check(); err != nil {
  1353. return nil, err
  1354. }
  1355. builder.mutation = mutation
  1356. var err error
  1357. nodes[i], specs[i] = builder.createSpec()
  1358. if i < len(mutators)-1 {
  1359. _, err = mutators[i+1].Mutate(root, ecb.builders[i+1].mutation)
  1360. } else {
  1361. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  1362. spec.OnConflict = ecb.conflict
  1363. // Invoke the actual operation on the latest mutation in the chain.
  1364. if err = sqlgraph.BatchCreate(ctx, ecb.driver, spec); err != nil {
  1365. if sqlgraph.IsConstraintError(err) {
  1366. err = &ConstraintError{msg: err.Error(), wrap: err}
  1367. }
  1368. }
  1369. }
  1370. if err != nil {
  1371. return nil, err
  1372. }
  1373. mutation.id = &nodes[i].ID
  1374. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  1375. id := specs[i].ID.Value.(int64)
  1376. nodes[i].ID = uint64(id)
  1377. }
  1378. mutation.done = true
  1379. return nodes[i], nil
  1380. })
  1381. for i := len(builder.hooks) - 1; i >= 0; i-- {
  1382. mut = builder.hooks[i](mut)
  1383. }
  1384. mutators[i] = mut
  1385. }(i, ctx)
  1386. }
  1387. if len(mutators) > 0 {
  1388. if _, err := mutators[0].Mutate(ctx, ecb.builders[0].mutation); err != nil {
  1389. return nil, err
  1390. }
  1391. }
  1392. return nodes, nil
  1393. }
  1394. // SaveX is like Save, but panics if an error occurs.
  1395. func (ecb *EmployeeCreateBulk) SaveX(ctx context.Context) []*Employee {
  1396. v, err := ecb.Save(ctx)
  1397. if err != nil {
  1398. panic(err)
  1399. }
  1400. return v
  1401. }
  1402. // Exec executes the query.
  1403. func (ecb *EmployeeCreateBulk) Exec(ctx context.Context) error {
  1404. _, err := ecb.Save(ctx)
  1405. return err
  1406. }
  1407. // ExecX is like Exec, but panics if an error occurs.
  1408. func (ecb *EmployeeCreateBulk) ExecX(ctx context.Context) {
  1409. if err := ecb.Exec(ctx); err != nil {
  1410. panic(err)
  1411. }
  1412. }
  1413. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  1414. // of the `INSERT` statement. For example:
  1415. //
  1416. // client.Employee.CreateBulk(builders...).
  1417. // OnConflict(
  1418. // // Update the row with the new values
  1419. // // the was proposed for insertion.
  1420. // sql.ResolveWithNewValues(),
  1421. // ).
  1422. // // Override some of the fields with custom
  1423. // // update values.
  1424. // Update(func(u *ent.EmployeeUpsert) {
  1425. // SetCreatedAt(v+v).
  1426. // }).
  1427. // Exec(ctx)
  1428. func (ecb *EmployeeCreateBulk) OnConflict(opts ...sql.ConflictOption) *EmployeeUpsertBulk {
  1429. ecb.conflict = opts
  1430. return &EmployeeUpsertBulk{
  1431. create: ecb,
  1432. }
  1433. }
  1434. // OnConflictColumns calls `OnConflict` and configures the columns
  1435. // as conflict target. Using this option is equivalent to using:
  1436. //
  1437. // client.Employee.Create().
  1438. // OnConflict(sql.ConflictColumns(columns...)).
  1439. // Exec(ctx)
  1440. func (ecb *EmployeeCreateBulk) OnConflictColumns(columns ...string) *EmployeeUpsertBulk {
  1441. ecb.conflict = append(ecb.conflict, sql.ConflictColumns(columns...))
  1442. return &EmployeeUpsertBulk{
  1443. create: ecb,
  1444. }
  1445. }
  1446. // EmployeeUpsertBulk is the builder for "upsert"-ing
  1447. // a bulk of Employee nodes.
  1448. type EmployeeUpsertBulk struct {
  1449. create *EmployeeCreateBulk
  1450. }
  1451. // UpdateNewValues updates the mutable fields using the new values that
  1452. // were set on create. Using this option is equivalent to using:
  1453. //
  1454. // client.Employee.Create().
  1455. // OnConflict(
  1456. // sql.ResolveWithNewValues(),
  1457. // sql.ResolveWith(func(u *sql.UpdateSet) {
  1458. // u.SetIgnore(employee.FieldID)
  1459. // }),
  1460. // ).
  1461. // Exec(ctx)
  1462. func (u *EmployeeUpsertBulk) UpdateNewValues() *EmployeeUpsertBulk {
  1463. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1464. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1465. for _, b := range u.create.builders {
  1466. if _, exists := b.mutation.ID(); exists {
  1467. s.SetIgnore(employee.FieldID)
  1468. }
  1469. if _, exists := b.mutation.CreatedAt(); exists {
  1470. s.SetIgnore(employee.FieldCreatedAt)
  1471. }
  1472. }
  1473. }))
  1474. return u
  1475. }
  1476. // Ignore sets each column to itself in case of conflict.
  1477. // Using this option is equivalent to using:
  1478. //
  1479. // client.Employee.Create().
  1480. // OnConflict(sql.ResolveWithIgnore()).
  1481. // Exec(ctx)
  1482. func (u *EmployeeUpsertBulk) Ignore() *EmployeeUpsertBulk {
  1483. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1484. return u
  1485. }
  1486. // DoNothing configures the conflict_action to `DO NOTHING`.
  1487. // Supported only by SQLite and PostgreSQL.
  1488. func (u *EmployeeUpsertBulk) DoNothing() *EmployeeUpsertBulk {
  1489. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1490. return u
  1491. }
  1492. // Update allows overriding fields `UPDATE` values. See the EmployeeCreateBulk.OnConflict
  1493. // documentation for more info.
  1494. func (u *EmployeeUpsertBulk) Update(set func(*EmployeeUpsert)) *EmployeeUpsertBulk {
  1495. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1496. set(&EmployeeUpsert{UpdateSet: update})
  1497. }))
  1498. return u
  1499. }
  1500. // SetUpdatedAt sets the "updated_at" field.
  1501. func (u *EmployeeUpsertBulk) SetUpdatedAt(v time.Time) *EmployeeUpsertBulk {
  1502. return u.Update(func(s *EmployeeUpsert) {
  1503. s.SetUpdatedAt(v)
  1504. })
  1505. }
  1506. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1507. func (u *EmployeeUpsertBulk) UpdateUpdatedAt() *EmployeeUpsertBulk {
  1508. return u.Update(func(s *EmployeeUpsert) {
  1509. s.UpdateUpdatedAt()
  1510. })
  1511. }
  1512. // SetDeletedAt sets the "deleted_at" field.
  1513. func (u *EmployeeUpsertBulk) SetDeletedAt(v time.Time) *EmployeeUpsertBulk {
  1514. return u.Update(func(s *EmployeeUpsert) {
  1515. s.SetDeletedAt(v)
  1516. })
  1517. }
  1518. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1519. func (u *EmployeeUpsertBulk) UpdateDeletedAt() *EmployeeUpsertBulk {
  1520. return u.Update(func(s *EmployeeUpsert) {
  1521. s.UpdateDeletedAt()
  1522. })
  1523. }
  1524. // ClearDeletedAt clears the value of the "deleted_at" field.
  1525. func (u *EmployeeUpsertBulk) ClearDeletedAt() *EmployeeUpsertBulk {
  1526. return u.Update(func(s *EmployeeUpsert) {
  1527. s.ClearDeletedAt()
  1528. })
  1529. }
  1530. // SetTitle sets the "title" field.
  1531. func (u *EmployeeUpsertBulk) SetTitle(v string) *EmployeeUpsertBulk {
  1532. return u.Update(func(s *EmployeeUpsert) {
  1533. s.SetTitle(v)
  1534. })
  1535. }
  1536. // UpdateTitle sets the "title" field to the value that was provided on create.
  1537. func (u *EmployeeUpsertBulk) UpdateTitle() *EmployeeUpsertBulk {
  1538. return u.Update(func(s *EmployeeUpsert) {
  1539. s.UpdateTitle()
  1540. })
  1541. }
  1542. // SetAvatar sets the "avatar" field.
  1543. func (u *EmployeeUpsertBulk) SetAvatar(v string) *EmployeeUpsertBulk {
  1544. return u.Update(func(s *EmployeeUpsert) {
  1545. s.SetAvatar(v)
  1546. })
  1547. }
  1548. // UpdateAvatar sets the "avatar" field to the value that was provided on create.
  1549. func (u *EmployeeUpsertBulk) UpdateAvatar() *EmployeeUpsertBulk {
  1550. return u.Update(func(s *EmployeeUpsert) {
  1551. s.UpdateAvatar()
  1552. })
  1553. }
  1554. // SetTags sets the "tags" field.
  1555. func (u *EmployeeUpsertBulk) SetTags(v string) *EmployeeUpsertBulk {
  1556. return u.Update(func(s *EmployeeUpsert) {
  1557. s.SetTags(v)
  1558. })
  1559. }
  1560. // UpdateTags sets the "tags" field to the value that was provided on create.
  1561. func (u *EmployeeUpsertBulk) UpdateTags() *EmployeeUpsertBulk {
  1562. return u.Update(func(s *EmployeeUpsert) {
  1563. s.UpdateTags()
  1564. })
  1565. }
  1566. // SetHireCount sets the "hire_count" field.
  1567. func (u *EmployeeUpsertBulk) SetHireCount(v int) *EmployeeUpsertBulk {
  1568. return u.Update(func(s *EmployeeUpsert) {
  1569. s.SetHireCount(v)
  1570. })
  1571. }
  1572. // AddHireCount adds v to the "hire_count" field.
  1573. func (u *EmployeeUpsertBulk) AddHireCount(v int) *EmployeeUpsertBulk {
  1574. return u.Update(func(s *EmployeeUpsert) {
  1575. s.AddHireCount(v)
  1576. })
  1577. }
  1578. // UpdateHireCount sets the "hire_count" field to the value that was provided on create.
  1579. func (u *EmployeeUpsertBulk) UpdateHireCount() *EmployeeUpsertBulk {
  1580. return u.Update(func(s *EmployeeUpsert) {
  1581. s.UpdateHireCount()
  1582. })
  1583. }
  1584. // SetServiceCount sets the "service_count" field.
  1585. func (u *EmployeeUpsertBulk) SetServiceCount(v int) *EmployeeUpsertBulk {
  1586. return u.Update(func(s *EmployeeUpsert) {
  1587. s.SetServiceCount(v)
  1588. })
  1589. }
  1590. // AddServiceCount adds v to the "service_count" field.
  1591. func (u *EmployeeUpsertBulk) AddServiceCount(v int) *EmployeeUpsertBulk {
  1592. return u.Update(func(s *EmployeeUpsert) {
  1593. s.AddServiceCount(v)
  1594. })
  1595. }
  1596. // UpdateServiceCount sets the "service_count" field to the value that was provided on create.
  1597. func (u *EmployeeUpsertBulk) UpdateServiceCount() *EmployeeUpsertBulk {
  1598. return u.Update(func(s *EmployeeUpsert) {
  1599. s.UpdateServiceCount()
  1600. })
  1601. }
  1602. // SetAchievementCount sets the "achievement_count" field.
  1603. func (u *EmployeeUpsertBulk) SetAchievementCount(v int) *EmployeeUpsertBulk {
  1604. return u.Update(func(s *EmployeeUpsert) {
  1605. s.SetAchievementCount(v)
  1606. })
  1607. }
  1608. // AddAchievementCount adds v to the "achievement_count" field.
  1609. func (u *EmployeeUpsertBulk) AddAchievementCount(v int) *EmployeeUpsertBulk {
  1610. return u.Update(func(s *EmployeeUpsert) {
  1611. s.AddAchievementCount(v)
  1612. })
  1613. }
  1614. // UpdateAchievementCount sets the "achievement_count" field to the value that was provided on create.
  1615. func (u *EmployeeUpsertBulk) UpdateAchievementCount() *EmployeeUpsertBulk {
  1616. return u.Update(func(s *EmployeeUpsert) {
  1617. s.UpdateAchievementCount()
  1618. })
  1619. }
  1620. // SetIntro sets the "intro" field.
  1621. func (u *EmployeeUpsertBulk) SetIntro(v string) *EmployeeUpsertBulk {
  1622. return u.Update(func(s *EmployeeUpsert) {
  1623. s.SetIntro(v)
  1624. })
  1625. }
  1626. // UpdateIntro sets the "intro" field to the value that was provided on create.
  1627. func (u *EmployeeUpsertBulk) UpdateIntro() *EmployeeUpsertBulk {
  1628. return u.Update(func(s *EmployeeUpsert) {
  1629. s.UpdateIntro()
  1630. })
  1631. }
  1632. // SetEstimate sets the "estimate" field.
  1633. func (u *EmployeeUpsertBulk) SetEstimate(v string) *EmployeeUpsertBulk {
  1634. return u.Update(func(s *EmployeeUpsert) {
  1635. s.SetEstimate(v)
  1636. })
  1637. }
  1638. // UpdateEstimate sets the "estimate" field to the value that was provided on create.
  1639. func (u *EmployeeUpsertBulk) UpdateEstimate() *EmployeeUpsertBulk {
  1640. return u.Update(func(s *EmployeeUpsert) {
  1641. s.UpdateEstimate()
  1642. })
  1643. }
  1644. // SetSkill sets the "skill" field.
  1645. func (u *EmployeeUpsertBulk) SetSkill(v string) *EmployeeUpsertBulk {
  1646. return u.Update(func(s *EmployeeUpsert) {
  1647. s.SetSkill(v)
  1648. })
  1649. }
  1650. // UpdateSkill sets the "skill" field to the value that was provided on create.
  1651. func (u *EmployeeUpsertBulk) UpdateSkill() *EmployeeUpsertBulk {
  1652. return u.Update(func(s *EmployeeUpsert) {
  1653. s.UpdateSkill()
  1654. })
  1655. }
  1656. // SetAbilityType sets the "ability_type" field.
  1657. func (u *EmployeeUpsertBulk) SetAbilityType(v string) *EmployeeUpsertBulk {
  1658. return u.Update(func(s *EmployeeUpsert) {
  1659. s.SetAbilityType(v)
  1660. })
  1661. }
  1662. // UpdateAbilityType sets the "ability_type" field to the value that was provided on create.
  1663. func (u *EmployeeUpsertBulk) UpdateAbilityType() *EmployeeUpsertBulk {
  1664. return u.Update(func(s *EmployeeUpsert) {
  1665. s.UpdateAbilityType()
  1666. })
  1667. }
  1668. // SetScene sets the "scene" field.
  1669. func (u *EmployeeUpsertBulk) SetScene(v string) *EmployeeUpsertBulk {
  1670. return u.Update(func(s *EmployeeUpsert) {
  1671. s.SetScene(v)
  1672. })
  1673. }
  1674. // UpdateScene sets the "scene" field to the value that was provided on create.
  1675. func (u *EmployeeUpsertBulk) UpdateScene() *EmployeeUpsertBulk {
  1676. return u.Update(func(s *EmployeeUpsert) {
  1677. s.UpdateScene()
  1678. })
  1679. }
  1680. // SetSwitchIn sets the "switch_in" field.
  1681. func (u *EmployeeUpsertBulk) SetSwitchIn(v string) *EmployeeUpsertBulk {
  1682. return u.Update(func(s *EmployeeUpsert) {
  1683. s.SetSwitchIn(v)
  1684. })
  1685. }
  1686. // UpdateSwitchIn sets the "switch_in" field to the value that was provided on create.
  1687. func (u *EmployeeUpsertBulk) UpdateSwitchIn() *EmployeeUpsertBulk {
  1688. return u.Update(func(s *EmployeeUpsert) {
  1689. s.UpdateSwitchIn()
  1690. })
  1691. }
  1692. // SetVideoURL sets the "video_url" field.
  1693. func (u *EmployeeUpsertBulk) SetVideoURL(v string) *EmployeeUpsertBulk {
  1694. return u.Update(func(s *EmployeeUpsert) {
  1695. s.SetVideoURL(v)
  1696. })
  1697. }
  1698. // UpdateVideoURL sets the "video_url" field to the value that was provided on create.
  1699. func (u *EmployeeUpsertBulk) UpdateVideoURL() *EmployeeUpsertBulk {
  1700. return u.Update(func(s *EmployeeUpsert) {
  1701. s.UpdateVideoURL()
  1702. })
  1703. }
  1704. // SetOrganizationID sets the "organization_id" field.
  1705. func (u *EmployeeUpsertBulk) SetOrganizationID(v uint64) *EmployeeUpsertBulk {
  1706. return u.Update(func(s *EmployeeUpsert) {
  1707. s.SetOrganizationID(v)
  1708. })
  1709. }
  1710. // AddOrganizationID adds v to the "organization_id" field.
  1711. func (u *EmployeeUpsertBulk) AddOrganizationID(v uint64) *EmployeeUpsertBulk {
  1712. return u.Update(func(s *EmployeeUpsert) {
  1713. s.AddOrganizationID(v)
  1714. })
  1715. }
  1716. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  1717. func (u *EmployeeUpsertBulk) UpdateOrganizationID() *EmployeeUpsertBulk {
  1718. return u.Update(func(s *EmployeeUpsert) {
  1719. s.UpdateOrganizationID()
  1720. })
  1721. }
  1722. // SetCategoryID sets the "category_id" field.
  1723. func (u *EmployeeUpsertBulk) SetCategoryID(v uint64) *EmployeeUpsertBulk {
  1724. return u.Update(func(s *EmployeeUpsert) {
  1725. s.SetCategoryID(v)
  1726. })
  1727. }
  1728. // AddCategoryID adds v to the "category_id" field.
  1729. func (u *EmployeeUpsertBulk) AddCategoryID(v uint64) *EmployeeUpsertBulk {
  1730. return u.Update(func(s *EmployeeUpsert) {
  1731. s.AddCategoryID(v)
  1732. })
  1733. }
  1734. // UpdateCategoryID sets the "category_id" field to the value that was provided on create.
  1735. func (u *EmployeeUpsertBulk) UpdateCategoryID() *EmployeeUpsertBulk {
  1736. return u.Update(func(s *EmployeeUpsert) {
  1737. s.UpdateCategoryID()
  1738. })
  1739. }
  1740. // SetAPIBase sets the "api_base" field.
  1741. func (u *EmployeeUpsertBulk) SetAPIBase(v string) *EmployeeUpsertBulk {
  1742. return u.Update(func(s *EmployeeUpsert) {
  1743. s.SetAPIBase(v)
  1744. })
  1745. }
  1746. // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
  1747. func (u *EmployeeUpsertBulk) UpdateAPIBase() *EmployeeUpsertBulk {
  1748. return u.Update(func(s *EmployeeUpsert) {
  1749. s.UpdateAPIBase()
  1750. })
  1751. }
  1752. // SetAPIKey sets the "api_key" field.
  1753. func (u *EmployeeUpsertBulk) SetAPIKey(v string) *EmployeeUpsertBulk {
  1754. return u.Update(func(s *EmployeeUpsert) {
  1755. s.SetAPIKey(v)
  1756. })
  1757. }
  1758. // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
  1759. func (u *EmployeeUpsertBulk) UpdateAPIKey() *EmployeeUpsertBulk {
  1760. return u.Update(func(s *EmployeeUpsert) {
  1761. s.UpdateAPIKey()
  1762. })
  1763. }
  1764. // SetAiInfo sets the "ai_info" field.
  1765. func (u *EmployeeUpsertBulk) SetAiInfo(v string) *EmployeeUpsertBulk {
  1766. return u.Update(func(s *EmployeeUpsert) {
  1767. s.SetAiInfo(v)
  1768. })
  1769. }
  1770. // UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
  1771. func (u *EmployeeUpsertBulk) UpdateAiInfo() *EmployeeUpsertBulk {
  1772. return u.Update(func(s *EmployeeUpsert) {
  1773. s.UpdateAiInfo()
  1774. })
  1775. }
  1776. // ClearAiInfo clears the value of the "ai_info" field.
  1777. func (u *EmployeeUpsertBulk) ClearAiInfo() *EmployeeUpsertBulk {
  1778. return u.Update(func(s *EmployeeUpsert) {
  1779. s.ClearAiInfo()
  1780. })
  1781. }
  1782. // SetIsVip sets the "is_vip" field.
  1783. func (u *EmployeeUpsertBulk) SetIsVip(v int) *EmployeeUpsertBulk {
  1784. return u.Update(func(s *EmployeeUpsert) {
  1785. s.SetIsVip(v)
  1786. })
  1787. }
  1788. // AddIsVip adds v to the "is_vip" field.
  1789. func (u *EmployeeUpsertBulk) AddIsVip(v int) *EmployeeUpsertBulk {
  1790. return u.Update(func(s *EmployeeUpsert) {
  1791. s.AddIsVip(v)
  1792. })
  1793. }
  1794. // UpdateIsVip sets the "is_vip" field to the value that was provided on create.
  1795. func (u *EmployeeUpsertBulk) UpdateIsVip() *EmployeeUpsertBulk {
  1796. return u.Update(func(s *EmployeeUpsert) {
  1797. s.UpdateIsVip()
  1798. })
  1799. }
  1800. // Exec executes the query.
  1801. func (u *EmployeeUpsertBulk) Exec(ctx context.Context) error {
  1802. if u.create.err != nil {
  1803. return u.create.err
  1804. }
  1805. for i, b := range u.create.builders {
  1806. if len(b.conflict) != 0 {
  1807. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the EmployeeCreateBulk instead", i)
  1808. }
  1809. }
  1810. if len(u.create.conflict) == 0 {
  1811. return errors.New("ent: missing options for EmployeeCreateBulk.OnConflict")
  1812. }
  1813. return u.create.Exec(ctx)
  1814. }
  1815. // ExecX is like Exec, but panics if an error occurs.
  1816. func (u *EmployeeUpsertBulk) ExecX(ctx context.Context) {
  1817. if err := u.create.Exec(ctx); err != nil {
  1818. panic(err)
  1819. }
  1820. }