employee_create.go 60 KB

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