agentbase_update.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "wechat-api/ent/agentbase"
  8. "wechat-api/ent/predicate"
  9. "wechat-api/ent/wx"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/dialect/sql/sqljson"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // AgentBaseUpdate is the builder for updating AgentBase entities.
  16. type AgentBaseUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *AgentBaseMutation
  20. }
  21. // Where appends a list predicates to the AgentBaseUpdate builder.
  22. func (abu *AgentBaseUpdate) Where(ps ...predicate.AgentBase) *AgentBaseUpdate {
  23. abu.mutation.Where(ps...)
  24. return abu
  25. }
  26. // SetQ sets the "q" field.
  27. func (abu *AgentBaseUpdate) SetQ(s string) *AgentBaseUpdate {
  28. abu.mutation.SetQ(s)
  29. return abu
  30. }
  31. // SetNillableQ sets the "q" field if the given value is not nil.
  32. func (abu *AgentBaseUpdate) SetNillableQ(s *string) *AgentBaseUpdate {
  33. if s != nil {
  34. abu.SetQ(*s)
  35. }
  36. return abu
  37. }
  38. // ClearQ clears the value of the "q" field.
  39. func (abu *AgentBaseUpdate) ClearQ() *AgentBaseUpdate {
  40. abu.mutation.ClearQ()
  41. return abu
  42. }
  43. // SetA sets the "a" field.
  44. func (abu *AgentBaseUpdate) SetA(s string) *AgentBaseUpdate {
  45. abu.mutation.SetA(s)
  46. return abu
  47. }
  48. // SetNillableA sets the "a" field if the given value is not nil.
  49. func (abu *AgentBaseUpdate) SetNillableA(s *string) *AgentBaseUpdate {
  50. if s != nil {
  51. abu.SetA(*s)
  52. }
  53. return abu
  54. }
  55. // ClearA clears the value of the "a" field.
  56. func (abu *AgentBaseUpdate) ClearA() *AgentBaseUpdate {
  57. abu.mutation.ClearA()
  58. return abu
  59. }
  60. // SetChunkIndex sets the "chunk_index" field.
  61. func (abu *AgentBaseUpdate) SetChunkIndex(u uint64) *AgentBaseUpdate {
  62. abu.mutation.ResetChunkIndex()
  63. abu.mutation.SetChunkIndex(u)
  64. return abu
  65. }
  66. // SetNillableChunkIndex sets the "chunk_index" field if the given value is not nil.
  67. func (abu *AgentBaseUpdate) SetNillableChunkIndex(u *uint64) *AgentBaseUpdate {
  68. if u != nil {
  69. abu.SetChunkIndex(*u)
  70. }
  71. return abu
  72. }
  73. // AddChunkIndex adds u to the "chunk_index" field.
  74. func (abu *AgentBaseUpdate) AddChunkIndex(u int64) *AgentBaseUpdate {
  75. abu.mutation.AddChunkIndex(u)
  76. return abu
  77. }
  78. // SetIndexes sets the "indexes" field.
  79. func (abu *AgentBaseUpdate) SetIndexes(s []string) *AgentBaseUpdate {
  80. abu.mutation.SetIndexes(s)
  81. return abu
  82. }
  83. // AppendIndexes appends s to the "indexes" field.
  84. func (abu *AgentBaseUpdate) AppendIndexes(s []string) *AgentBaseUpdate {
  85. abu.mutation.AppendIndexes(s)
  86. return abu
  87. }
  88. // ClearIndexes clears the value of the "indexes" field.
  89. func (abu *AgentBaseUpdate) ClearIndexes() *AgentBaseUpdate {
  90. abu.mutation.ClearIndexes()
  91. return abu
  92. }
  93. // SetDatasetID sets the "dataset_id" field.
  94. func (abu *AgentBaseUpdate) SetDatasetID(s string) *AgentBaseUpdate {
  95. abu.mutation.SetDatasetID(s)
  96. return abu
  97. }
  98. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  99. func (abu *AgentBaseUpdate) SetNillableDatasetID(s *string) *AgentBaseUpdate {
  100. if s != nil {
  101. abu.SetDatasetID(*s)
  102. }
  103. return abu
  104. }
  105. // ClearDatasetID clears the value of the "dataset_id" field.
  106. func (abu *AgentBaseUpdate) ClearDatasetID() *AgentBaseUpdate {
  107. abu.mutation.ClearDatasetID()
  108. return abu
  109. }
  110. // SetCollectionID sets the "collection_id" field.
  111. func (abu *AgentBaseUpdate) SetCollectionID(s string) *AgentBaseUpdate {
  112. abu.mutation.SetCollectionID(s)
  113. return abu
  114. }
  115. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  116. func (abu *AgentBaseUpdate) SetNillableCollectionID(s *string) *AgentBaseUpdate {
  117. if s != nil {
  118. abu.SetCollectionID(*s)
  119. }
  120. return abu
  121. }
  122. // ClearCollectionID clears the value of the "collection_id" field.
  123. func (abu *AgentBaseUpdate) ClearCollectionID() *AgentBaseUpdate {
  124. abu.mutation.ClearCollectionID()
  125. return abu
  126. }
  127. // SetSourceName sets the "source_name" field.
  128. func (abu *AgentBaseUpdate) SetSourceName(s string) *AgentBaseUpdate {
  129. abu.mutation.SetSourceName(s)
  130. return abu
  131. }
  132. // SetNillableSourceName sets the "source_name" field if the given value is not nil.
  133. func (abu *AgentBaseUpdate) SetNillableSourceName(s *string) *AgentBaseUpdate {
  134. if s != nil {
  135. abu.SetSourceName(*s)
  136. }
  137. return abu
  138. }
  139. // ClearSourceName clears the value of the "source_name" field.
  140. func (abu *AgentBaseUpdate) ClearSourceName() *AgentBaseUpdate {
  141. abu.mutation.ClearSourceName()
  142. return abu
  143. }
  144. // SetCanWrite sets the "can_write" field.
  145. func (abu *AgentBaseUpdate) SetCanWrite(b []bool) *AgentBaseUpdate {
  146. abu.mutation.SetCanWrite(b)
  147. return abu
  148. }
  149. // AppendCanWrite appends b to the "can_write" field.
  150. func (abu *AgentBaseUpdate) AppendCanWrite(b []bool) *AgentBaseUpdate {
  151. abu.mutation.AppendCanWrite(b)
  152. return abu
  153. }
  154. // ClearCanWrite clears the value of the "can_write" field.
  155. func (abu *AgentBaseUpdate) ClearCanWrite() *AgentBaseUpdate {
  156. abu.mutation.ClearCanWrite()
  157. return abu
  158. }
  159. // SetIsOwner sets the "is_owner" field.
  160. func (abu *AgentBaseUpdate) SetIsOwner(b []bool) *AgentBaseUpdate {
  161. abu.mutation.SetIsOwner(b)
  162. return abu
  163. }
  164. // AppendIsOwner appends b to the "is_owner" field.
  165. func (abu *AgentBaseUpdate) AppendIsOwner(b []bool) *AgentBaseUpdate {
  166. abu.mutation.AppendIsOwner(b)
  167. return abu
  168. }
  169. // ClearIsOwner clears the value of the "is_owner" field.
  170. func (abu *AgentBaseUpdate) ClearIsOwner() *AgentBaseUpdate {
  171. abu.mutation.ClearIsOwner()
  172. return abu
  173. }
  174. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  175. func (abu *AgentBaseUpdate) AddWxAgentIDs(ids ...uint64) *AgentBaseUpdate {
  176. abu.mutation.AddWxAgentIDs(ids...)
  177. return abu
  178. }
  179. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  180. func (abu *AgentBaseUpdate) AddWxAgent(w ...*Wx) *AgentBaseUpdate {
  181. ids := make([]uint64, len(w))
  182. for i := range w {
  183. ids[i] = w[i].ID
  184. }
  185. return abu.AddWxAgentIDs(ids...)
  186. }
  187. // Mutation returns the AgentBaseMutation object of the builder.
  188. func (abu *AgentBaseUpdate) Mutation() *AgentBaseMutation {
  189. return abu.mutation
  190. }
  191. // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
  192. func (abu *AgentBaseUpdate) ClearWxAgent() *AgentBaseUpdate {
  193. abu.mutation.ClearWxAgent()
  194. return abu
  195. }
  196. // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
  197. func (abu *AgentBaseUpdate) RemoveWxAgentIDs(ids ...uint64) *AgentBaseUpdate {
  198. abu.mutation.RemoveWxAgentIDs(ids...)
  199. return abu
  200. }
  201. // RemoveWxAgent removes "wx_agent" edges to Wx entities.
  202. func (abu *AgentBaseUpdate) RemoveWxAgent(w ...*Wx) *AgentBaseUpdate {
  203. ids := make([]uint64, len(w))
  204. for i := range w {
  205. ids[i] = w[i].ID
  206. }
  207. return abu.RemoveWxAgentIDs(ids...)
  208. }
  209. // Save executes the query and returns the number of nodes affected by the update operation.
  210. func (abu *AgentBaseUpdate) Save(ctx context.Context) (int, error) {
  211. return withHooks(ctx, abu.sqlSave, abu.mutation, abu.hooks)
  212. }
  213. // SaveX is like Save, but panics if an error occurs.
  214. func (abu *AgentBaseUpdate) SaveX(ctx context.Context) int {
  215. affected, err := abu.Save(ctx)
  216. if err != nil {
  217. panic(err)
  218. }
  219. return affected
  220. }
  221. // Exec executes the query.
  222. func (abu *AgentBaseUpdate) Exec(ctx context.Context) error {
  223. _, err := abu.Save(ctx)
  224. return err
  225. }
  226. // ExecX is like Exec, but panics if an error occurs.
  227. func (abu *AgentBaseUpdate) ExecX(ctx context.Context) {
  228. if err := abu.Exec(ctx); err != nil {
  229. panic(err)
  230. }
  231. }
  232. // check runs all checks and user-defined validators on the builder.
  233. func (abu *AgentBaseUpdate) check() error {
  234. if v, ok := abu.mutation.ChunkIndex(); ok {
  235. if err := agentbase.ChunkIndexValidator(v); err != nil {
  236. return &ValidationError{Name: "chunk_index", err: fmt.Errorf(`ent: validator failed for field "AgentBase.chunk_index": %w`, err)}
  237. }
  238. }
  239. return nil
  240. }
  241. func (abu *AgentBaseUpdate) sqlSave(ctx context.Context) (n int, err error) {
  242. if err := abu.check(); err != nil {
  243. return n, err
  244. }
  245. _spec := sqlgraph.NewUpdateSpec(agentbase.Table, agentbase.Columns, sqlgraph.NewFieldSpec(agentbase.FieldID, field.TypeString))
  246. if ps := abu.mutation.predicates; len(ps) > 0 {
  247. _spec.Predicate = func(selector *sql.Selector) {
  248. for i := range ps {
  249. ps[i](selector)
  250. }
  251. }
  252. }
  253. if value, ok := abu.mutation.Q(); ok {
  254. _spec.SetField(agentbase.FieldQ, field.TypeString, value)
  255. }
  256. if abu.mutation.QCleared() {
  257. _spec.ClearField(agentbase.FieldQ, field.TypeString)
  258. }
  259. if value, ok := abu.mutation.A(); ok {
  260. _spec.SetField(agentbase.FieldA, field.TypeString, value)
  261. }
  262. if abu.mutation.ACleared() {
  263. _spec.ClearField(agentbase.FieldA, field.TypeString)
  264. }
  265. if value, ok := abu.mutation.ChunkIndex(); ok {
  266. _spec.SetField(agentbase.FieldChunkIndex, field.TypeUint64, value)
  267. }
  268. if value, ok := abu.mutation.AddedChunkIndex(); ok {
  269. _spec.AddField(agentbase.FieldChunkIndex, field.TypeUint64, value)
  270. }
  271. if value, ok := abu.mutation.Indexes(); ok {
  272. _spec.SetField(agentbase.FieldIndexes, field.TypeJSON, value)
  273. }
  274. if value, ok := abu.mutation.AppendedIndexes(); ok {
  275. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  276. sqljson.Append(u, agentbase.FieldIndexes, value)
  277. })
  278. }
  279. if abu.mutation.IndexesCleared() {
  280. _spec.ClearField(agentbase.FieldIndexes, field.TypeJSON)
  281. }
  282. if value, ok := abu.mutation.DatasetID(); ok {
  283. _spec.SetField(agentbase.FieldDatasetID, field.TypeString, value)
  284. }
  285. if abu.mutation.DatasetIDCleared() {
  286. _spec.ClearField(agentbase.FieldDatasetID, field.TypeString)
  287. }
  288. if value, ok := abu.mutation.CollectionID(); ok {
  289. _spec.SetField(agentbase.FieldCollectionID, field.TypeString, value)
  290. }
  291. if abu.mutation.CollectionIDCleared() {
  292. _spec.ClearField(agentbase.FieldCollectionID, field.TypeString)
  293. }
  294. if value, ok := abu.mutation.SourceName(); ok {
  295. _spec.SetField(agentbase.FieldSourceName, field.TypeString, value)
  296. }
  297. if abu.mutation.SourceNameCleared() {
  298. _spec.ClearField(agentbase.FieldSourceName, field.TypeString)
  299. }
  300. if value, ok := abu.mutation.CanWrite(); ok {
  301. _spec.SetField(agentbase.FieldCanWrite, field.TypeJSON, value)
  302. }
  303. if value, ok := abu.mutation.AppendedCanWrite(); ok {
  304. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  305. sqljson.Append(u, agentbase.FieldCanWrite, value)
  306. })
  307. }
  308. if abu.mutation.CanWriteCleared() {
  309. _spec.ClearField(agentbase.FieldCanWrite, field.TypeJSON)
  310. }
  311. if value, ok := abu.mutation.IsOwner(); ok {
  312. _spec.SetField(agentbase.FieldIsOwner, field.TypeJSON, value)
  313. }
  314. if value, ok := abu.mutation.AppendedIsOwner(); ok {
  315. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  316. sqljson.Append(u, agentbase.FieldIsOwner, value)
  317. })
  318. }
  319. if abu.mutation.IsOwnerCleared() {
  320. _spec.ClearField(agentbase.FieldIsOwner, field.TypeJSON)
  321. }
  322. if abu.mutation.WxAgentCleared() {
  323. edge := &sqlgraph.EdgeSpec{
  324. Rel: sqlgraph.O2M,
  325. Inverse: false,
  326. Table: agentbase.WxAgentTable,
  327. Columns: []string{agentbase.WxAgentColumn},
  328. Bidi: false,
  329. Target: &sqlgraph.EdgeTarget{
  330. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  331. },
  332. }
  333. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  334. }
  335. if nodes := abu.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !abu.mutation.WxAgentCleared() {
  336. edge := &sqlgraph.EdgeSpec{
  337. Rel: sqlgraph.O2M,
  338. Inverse: false,
  339. Table: agentbase.WxAgentTable,
  340. Columns: []string{agentbase.WxAgentColumn},
  341. Bidi: false,
  342. Target: &sqlgraph.EdgeTarget{
  343. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  344. },
  345. }
  346. for _, k := range nodes {
  347. edge.Target.Nodes = append(edge.Target.Nodes, k)
  348. }
  349. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  350. }
  351. if nodes := abu.mutation.WxAgentIDs(); len(nodes) > 0 {
  352. edge := &sqlgraph.EdgeSpec{
  353. Rel: sqlgraph.O2M,
  354. Inverse: false,
  355. Table: agentbase.WxAgentTable,
  356. Columns: []string{agentbase.WxAgentColumn},
  357. Bidi: false,
  358. Target: &sqlgraph.EdgeTarget{
  359. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  360. },
  361. }
  362. for _, k := range nodes {
  363. edge.Target.Nodes = append(edge.Target.Nodes, k)
  364. }
  365. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  366. }
  367. if n, err = sqlgraph.UpdateNodes(ctx, abu.driver, _spec); err != nil {
  368. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  369. err = &NotFoundError{agentbase.Label}
  370. } else if sqlgraph.IsConstraintError(err) {
  371. err = &ConstraintError{msg: err.Error(), wrap: err}
  372. }
  373. return 0, err
  374. }
  375. abu.mutation.done = true
  376. return n, nil
  377. }
  378. // AgentBaseUpdateOne is the builder for updating a single AgentBase entity.
  379. type AgentBaseUpdateOne struct {
  380. config
  381. fields []string
  382. hooks []Hook
  383. mutation *AgentBaseMutation
  384. }
  385. // SetQ sets the "q" field.
  386. func (abuo *AgentBaseUpdateOne) SetQ(s string) *AgentBaseUpdateOne {
  387. abuo.mutation.SetQ(s)
  388. return abuo
  389. }
  390. // SetNillableQ sets the "q" field if the given value is not nil.
  391. func (abuo *AgentBaseUpdateOne) SetNillableQ(s *string) *AgentBaseUpdateOne {
  392. if s != nil {
  393. abuo.SetQ(*s)
  394. }
  395. return abuo
  396. }
  397. // ClearQ clears the value of the "q" field.
  398. func (abuo *AgentBaseUpdateOne) ClearQ() *AgentBaseUpdateOne {
  399. abuo.mutation.ClearQ()
  400. return abuo
  401. }
  402. // SetA sets the "a" field.
  403. func (abuo *AgentBaseUpdateOne) SetA(s string) *AgentBaseUpdateOne {
  404. abuo.mutation.SetA(s)
  405. return abuo
  406. }
  407. // SetNillableA sets the "a" field if the given value is not nil.
  408. func (abuo *AgentBaseUpdateOne) SetNillableA(s *string) *AgentBaseUpdateOne {
  409. if s != nil {
  410. abuo.SetA(*s)
  411. }
  412. return abuo
  413. }
  414. // ClearA clears the value of the "a" field.
  415. func (abuo *AgentBaseUpdateOne) ClearA() *AgentBaseUpdateOne {
  416. abuo.mutation.ClearA()
  417. return abuo
  418. }
  419. // SetChunkIndex sets the "chunk_index" field.
  420. func (abuo *AgentBaseUpdateOne) SetChunkIndex(u uint64) *AgentBaseUpdateOne {
  421. abuo.mutation.ResetChunkIndex()
  422. abuo.mutation.SetChunkIndex(u)
  423. return abuo
  424. }
  425. // SetNillableChunkIndex sets the "chunk_index" field if the given value is not nil.
  426. func (abuo *AgentBaseUpdateOne) SetNillableChunkIndex(u *uint64) *AgentBaseUpdateOne {
  427. if u != nil {
  428. abuo.SetChunkIndex(*u)
  429. }
  430. return abuo
  431. }
  432. // AddChunkIndex adds u to the "chunk_index" field.
  433. func (abuo *AgentBaseUpdateOne) AddChunkIndex(u int64) *AgentBaseUpdateOne {
  434. abuo.mutation.AddChunkIndex(u)
  435. return abuo
  436. }
  437. // SetIndexes sets the "indexes" field.
  438. func (abuo *AgentBaseUpdateOne) SetIndexes(s []string) *AgentBaseUpdateOne {
  439. abuo.mutation.SetIndexes(s)
  440. return abuo
  441. }
  442. // AppendIndexes appends s to the "indexes" field.
  443. func (abuo *AgentBaseUpdateOne) AppendIndexes(s []string) *AgentBaseUpdateOne {
  444. abuo.mutation.AppendIndexes(s)
  445. return abuo
  446. }
  447. // ClearIndexes clears the value of the "indexes" field.
  448. func (abuo *AgentBaseUpdateOne) ClearIndexes() *AgentBaseUpdateOne {
  449. abuo.mutation.ClearIndexes()
  450. return abuo
  451. }
  452. // SetDatasetID sets the "dataset_id" field.
  453. func (abuo *AgentBaseUpdateOne) SetDatasetID(s string) *AgentBaseUpdateOne {
  454. abuo.mutation.SetDatasetID(s)
  455. return abuo
  456. }
  457. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  458. func (abuo *AgentBaseUpdateOne) SetNillableDatasetID(s *string) *AgentBaseUpdateOne {
  459. if s != nil {
  460. abuo.SetDatasetID(*s)
  461. }
  462. return abuo
  463. }
  464. // ClearDatasetID clears the value of the "dataset_id" field.
  465. func (abuo *AgentBaseUpdateOne) ClearDatasetID() *AgentBaseUpdateOne {
  466. abuo.mutation.ClearDatasetID()
  467. return abuo
  468. }
  469. // SetCollectionID sets the "collection_id" field.
  470. func (abuo *AgentBaseUpdateOne) SetCollectionID(s string) *AgentBaseUpdateOne {
  471. abuo.mutation.SetCollectionID(s)
  472. return abuo
  473. }
  474. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  475. func (abuo *AgentBaseUpdateOne) SetNillableCollectionID(s *string) *AgentBaseUpdateOne {
  476. if s != nil {
  477. abuo.SetCollectionID(*s)
  478. }
  479. return abuo
  480. }
  481. // ClearCollectionID clears the value of the "collection_id" field.
  482. func (abuo *AgentBaseUpdateOne) ClearCollectionID() *AgentBaseUpdateOne {
  483. abuo.mutation.ClearCollectionID()
  484. return abuo
  485. }
  486. // SetSourceName sets the "source_name" field.
  487. func (abuo *AgentBaseUpdateOne) SetSourceName(s string) *AgentBaseUpdateOne {
  488. abuo.mutation.SetSourceName(s)
  489. return abuo
  490. }
  491. // SetNillableSourceName sets the "source_name" field if the given value is not nil.
  492. func (abuo *AgentBaseUpdateOne) SetNillableSourceName(s *string) *AgentBaseUpdateOne {
  493. if s != nil {
  494. abuo.SetSourceName(*s)
  495. }
  496. return abuo
  497. }
  498. // ClearSourceName clears the value of the "source_name" field.
  499. func (abuo *AgentBaseUpdateOne) ClearSourceName() *AgentBaseUpdateOne {
  500. abuo.mutation.ClearSourceName()
  501. return abuo
  502. }
  503. // SetCanWrite sets the "can_write" field.
  504. func (abuo *AgentBaseUpdateOne) SetCanWrite(b []bool) *AgentBaseUpdateOne {
  505. abuo.mutation.SetCanWrite(b)
  506. return abuo
  507. }
  508. // AppendCanWrite appends b to the "can_write" field.
  509. func (abuo *AgentBaseUpdateOne) AppendCanWrite(b []bool) *AgentBaseUpdateOne {
  510. abuo.mutation.AppendCanWrite(b)
  511. return abuo
  512. }
  513. // ClearCanWrite clears the value of the "can_write" field.
  514. func (abuo *AgentBaseUpdateOne) ClearCanWrite() *AgentBaseUpdateOne {
  515. abuo.mutation.ClearCanWrite()
  516. return abuo
  517. }
  518. // SetIsOwner sets the "is_owner" field.
  519. func (abuo *AgentBaseUpdateOne) SetIsOwner(b []bool) *AgentBaseUpdateOne {
  520. abuo.mutation.SetIsOwner(b)
  521. return abuo
  522. }
  523. // AppendIsOwner appends b to the "is_owner" field.
  524. func (abuo *AgentBaseUpdateOne) AppendIsOwner(b []bool) *AgentBaseUpdateOne {
  525. abuo.mutation.AppendIsOwner(b)
  526. return abuo
  527. }
  528. // ClearIsOwner clears the value of the "is_owner" field.
  529. func (abuo *AgentBaseUpdateOne) ClearIsOwner() *AgentBaseUpdateOne {
  530. abuo.mutation.ClearIsOwner()
  531. return abuo
  532. }
  533. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  534. func (abuo *AgentBaseUpdateOne) AddWxAgentIDs(ids ...uint64) *AgentBaseUpdateOne {
  535. abuo.mutation.AddWxAgentIDs(ids...)
  536. return abuo
  537. }
  538. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  539. func (abuo *AgentBaseUpdateOne) AddWxAgent(w ...*Wx) *AgentBaseUpdateOne {
  540. ids := make([]uint64, len(w))
  541. for i := range w {
  542. ids[i] = w[i].ID
  543. }
  544. return abuo.AddWxAgentIDs(ids...)
  545. }
  546. // Mutation returns the AgentBaseMutation object of the builder.
  547. func (abuo *AgentBaseUpdateOne) Mutation() *AgentBaseMutation {
  548. return abuo.mutation
  549. }
  550. // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
  551. func (abuo *AgentBaseUpdateOne) ClearWxAgent() *AgentBaseUpdateOne {
  552. abuo.mutation.ClearWxAgent()
  553. return abuo
  554. }
  555. // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
  556. func (abuo *AgentBaseUpdateOne) RemoveWxAgentIDs(ids ...uint64) *AgentBaseUpdateOne {
  557. abuo.mutation.RemoveWxAgentIDs(ids...)
  558. return abuo
  559. }
  560. // RemoveWxAgent removes "wx_agent" edges to Wx entities.
  561. func (abuo *AgentBaseUpdateOne) RemoveWxAgent(w ...*Wx) *AgentBaseUpdateOne {
  562. ids := make([]uint64, len(w))
  563. for i := range w {
  564. ids[i] = w[i].ID
  565. }
  566. return abuo.RemoveWxAgentIDs(ids...)
  567. }
  568. // Where appends a list predicates to the AgentBaseUpdate builder.
  569. func (abuo *AgentBaseUpdateOne) Where(ps ...predicate.AgentBase) *AgentBaseUpdateOne {
  570. abuo.mutation.Where(ps...)
  571. return abuo
  572. }
  573. // Select allows selecting one or more fields (columns) of the returned entity.
  574. // The default is selecting all fields defined in the entity schema.
  575. func (abuo *AgentBaseUpdateOne) Select(field string, fields ...string) *AgentBaseUpdateOne {
  576. abuo.fields = append([]string{field}, fields...)
  577. return abuo
  578. }
  579. // Save executes the query and returns the updated AgentBase entity.
  580. func (abuo *AgentBaseUpdateOne) Save(ctx context.Context) (*AgentBase, error) {
  581. return withHooks(ctx, abuo.sqlSave, abuo.mutation, abuo.hooks)
  582. }
  583. // SaveX is like Save, but panics if an error occurs.
  584. func (abuo *AgentBaseUpdateOne) SaveX(ctx context.Context) *AgentBase {
  585. node, err := abuo.Save(ctx)
  586. if err != nil {
  587. panic(err)
  588. }
  589. return node
  590. }
  591. // Exec executes the query on the entity.
  592. func (abuo *AgentBaseUpdateOne) Exec(ctx context.Context) error {
  593. _, err := abuo.Save(ctx)
  594. return err
  595. }
  596. // ExecX is like Exec, but panics if an error occurs.
  597. func (abuo *AgentBaseUpdateOne) ExecX(ctx context.Context) {
  598. if err := abuo.Exec(ctx); err != nil {
  599. panic(err)
  600. }
  601. }
  602. // check runs all checks and user-defined validators on the builder.
  603. func (abuo *AgentBaseUpdateOne) check() error {
  604. if v, ok := abuo.mutation.ChunkIndex(); ok {
  605. if err := agentbase.ChunkIndexValidator(v); err != nil {
  606. return &ValidationError{Name: "chunk_index", err: fmt.Errorf(`ent: validator failed for field "AgentBase.chunk_index": %w`, err)}
  607. }
  608. }
  609. return nil
  610. }
  611. func (abuo *AgentBaseUpdateOne) sqlSave(ctx context.Context) (_node *AgentBase, err error) {
  612. if err := abuo.check(); err != nil {
  613. return _node, err
  614. }
  615. _spec := sqlgraph.NewUpdateSpec(agentbase.Table, agentbase.Columns, sqlgraph.NewFieldSpec(agentbase.FieldID, field.TypeString))
  616. id, ok := abuo.mutation.ID()
  617. if !ok {
  618. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AgentBase.id" for update`)}
  619. }
  620. _spec.Node.ID.Value = id
  621. if fields := abuo.fields; len(fields) > 0 {
  622. _spec.Node.Columns = make([]string, 0, len(fields))
  623. _spec.Node.Columns = append(_spec.Node.Columns, agentbase.FieldID)
  624. for _, f := range fields {
  625. if !agentbase.ValidColumn(f) {
  626. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  627. }
  628. if f != agentbase.FieldID {
  629. _spec.Node.Columns = append(_spec.Node.Columns, f)
  630. }
  631. }
  632. }
  633. if ps := abuo.mutation.predicates; len(ps) > 0 {
  634. _spec.Predicate = func(selector *sql.Selector) {
  635. for i := range ps {
  636. ps[i](selector)
  637. }
  638. }
  639. }
  640. if value, ok := abuo.mutation.Q(); ok {
  641. _spec.SetField(agentbase.FieldQ, field.TypeString, value)
  642. }
  643. if abuo.mutation.QCleared() {
  644. _spec.ClearField(agentbase.FieldQ, field.TypeString)
  645. }
  646. if value, ok := abuo.mutation.A(); ok {
  647. _spec.SetField(agentbase.FieldA, field.TypeString, value)
  648. }
  649. if abuo.mutation.ACleared() {
  650. _spec.ClearField(agentbase.FieldA, field.TypeString)
  651. }
  652. if value, ok := abuo.mutation.ChunkIndex(); ok {
  653. _spec.SetField(agentbase.FieldChunkIndex, field.TypeUint64, value)
  654. }
  655. if value, ok := abuo.mutation.AddedChunkIndex(); ok {
  656. _spec.AddField(agentbase.FieldChunkIndex, field.TypeUint64, value)
  657. }
  658. if value, ok := abuo.mutation.Indexes(); ok {
  659. _spec.SetField(agentbase.FieldIndexes, field.TypeJSON, value)
  660. }
  661. if value, ok := abuo.mutation.AppendedIndexes(); ok {
  662. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  663. sqljson.Append(u, agentbase.FieldIndexes, value)
  664. })
  665. }
  666. if abuo.mutation.IndexesCleared() {
  667. _spec.ClearField(agentbase.FieldIndexes, field.TypeJSON)
  668. }
  669. if value, ok := abuo.mutation.DatasetID(); ok {
  670. _spec.SetField(agentbase.FieldDatasetID, field.TypeString, value)
  671. }
  672. if abuo.mutation.DatasetIDCleared() {
  673. _spec.ClearField(agentbase.FieldDatasetID, field.TypeString)
  674. }
  675. if value, ok := abuo.mutation.CollectionID(); ok {
  676. _spec.SetField(agentbase.FieldCollectionID, field.TypeString, value)
  677. }
  678. if abuo.mutation.CollectionIDCleared() {
  679. _spec.ClearField(agentbase.FieldCollectionID, field.TypeString)
  680. }
  681. if value, ok := abuo.mutation.SourceName(); ok {
  682. _spec.SetField(agentbase.FieldSourceName, field.TypeString, value)
  683. }
  684. if abuo.mutation.SourceNameCleared() {
  685. _spec.ClearField(agentbase.FieldSourceName, field.TypeString)
  686. }
  687. if value, ok := abuo.mutation.CanWrite(); ok {
  688. _spec.SetField(agentbase.FieldCanWrite, field.TypeJSON, value)
  689. }
  690. if value, ok := abuo.mutation.AppendedCanWrite(); ok {
  691. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  692. sqljson.Append(u, agentbase.FieldCanWrite, value)
  693. })
  694. }
  695. if abuo.mutation.CanWriteCleared() {
  696. _spec.ClearField(agentbase.FieldCanWrite, field.TypeJSON)
  697. }
  698. if value, ok := abuo.mutation.IsOwner(); ok {
  699. _spec.SetField(agentbase.FieldIsOwner, field.TypeJSON, value)
  700. }
  701. if value, ok := abuo.mutation.AppendedIsOwner(); ok {
  702. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  703. sqljson.Append(u, agentbase.FieldIsOwner, value)
  704. })
  705. }
  706. if abuo.mutation.IsOwnerCleared() {
  707. _spec.ClearField(agentbase.FieldIsOwner, field.TypeJSON)
  708. }
  709. if abuo.mutation.WxAgentCleared() {
  710. edge := &sqlgraph.EdgeSpec{
  711. Rel: sqlgraph.O2M,
  712. Inverse: false,
  713. Table: agentbase.WxAgentTable,
  714. Columns: []string{agentbase.WxAgentColumn},
  715. Bidi: false,
  716. Target: &sqlgraph.EdgeTarget{
  717. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  718. },
  719. }
  720. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  721. }
  722. if nodes := abuo.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !abuo.mutation.WxAgentCleared() {
  723. edge := &sqlgraph.EdgeSpec{
  724. Rel: sqlgraph.O2M,
  725. Inverse: false,
  726. Table: agentbase.WxAgentTable,
  727. Columns: []string{agentbase.WxAgentColumn},
  728. Bidi: false,
  729. Target: &sqlgraph.EdgeTarget{
  730. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  731. },
  732. }
  733. for _, k := range nodes {
  734. edge.Target.Nodes = append(edge.Target.Nodes, k)
  735. }
  736. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  737. }
  738. if nodes := abuo.mutation.WxAgentIDs(); len(nodes) > 0 {
  739. edge := &sqlgraph.EdgeSpec{
  740. Rel: sqlgraph.O2M,
  741. Inverse: false,
  742. Table: agentbase.WxAgentTable,
  743. Columns: []string{agentbase.WxAgentColumn},
  744. Bidi: false,
  745. Target: &sqlgraph.EdgeTarget{
  746. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  747. },
  748. }
  749. for _, k := range nodes {
  750. edge.Target.Nodes = append(edge.Target.Nodes, k)
  751. }
  752. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  753. }
  754. _node = &AgentBase{config: abuo.config}
  755. _spec.Assign = _node.assignValues
  756. _spec.ScanValues = _node.scanValues
  757. if err = sqlgraph.UpdateNode(ctx, abuo.driver, _spec); err != nil {
  758. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  759. err = &NotFoundError{agentbase.Label}
  760. } else if sqlgraph.IsConstraintError(err) {
  761. err = &ConstraintError{msg: err.Error(), wrap: err}
  762. }
  763. return nil, err
  764. }
  765. abuo.mutation.done = true
  766. return _node, nil
  767. }