employee_create.go 62 KB

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