mutation.go 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "sync"
  8. "time"
  9. "entgo.io/ent"
  10. "entgo.io/ent/dialect/sql"
  11. "github.com/suyuan32/simple-admin-job/ent/messagerecords"
  12. "github.com/suyuan32/simple-admin-job/ent/predicate"
  13. "github.com/suyuan32/simple-admin-job/ent/task"
  14. "github.com/suyuan32/simple-admin-job/ent/tasklog"
  15. )
  16. const (
  17. // Operation types.
  18. OpCreate = ent.OpCreate
  19. OpDelete = ent.OpDelete
  20. OpDeleteOne = ent.OpDeleteOne
  21. OpUpdate = ent.OpUpdate
  22. OpUpdateOne = ent.OpUpdateOne
  23. // Node types.
  24. TypeMessageRecords = "MessageRecords"
  25. TypeTask = "Task"
  26. TypeTaskLog = "TaskLog"
  27. )
  28. // MessageRecordsMutation represents an operation that mutates the MessageRecords nodes in the graph.
  29. type MessageRecordsMutation struct {
  30. config
  31. op Op
  32. typ string
  33. id *uint64
  34. created_at *time.Time
  35. updated_at *time.Time
  36. status *uint8
  37. addstatus *int8
  38. bot_wxid *string
  39. contact_id *uint64
  40. addcontact_id *int64
  41. contact_type *int
  42. addcontact_type *int
  43. contact_wxid *string
  44. content_type *int
  45. addcontent_type *int
  46. content *string
  47. error_detail *string
  48. send_time *time.Time
  49. source_type *int
  50. addsource_type *int
  51. source_id *uint64
  52. addsource_id *int64
  53. sub_source_id *uint64
  54. addsub_source_id *int64
  55. clearedFields map[string]struct{}
  56. done bool
  57. oldValue func(context.Context) (*MessageRecords, error)
  58. predicates []predicate.MessageRecords
  59. }
  60. var _ ent.Mutation = (*MessageRecordsMutation)(nil)
  61. // messagerecordsOption allows management of the mutation configuration using functional options.
  62. type messagerecordsOption func(*MessageRecordsMutation)
  63. // newMessageRecordsMutation creates new mutation for the MessageRecords entity.
  64. func newMessageRecordsMutation(c config, op Op, opts ...messagerecordsOption) *MessageRecordsMutation {
  65. m := &MessageRecordsMutation{
  66. config: c,
  67. op: op,
  68. typ: TypeMessageRecords,
  69. clearedFields: make(map[string]struct{}),
  70. }
  71. for _, opt := range opts {
  72. opt(m)
  73. }
  74. return m
  75. }
  76. // withMessageRecordsID sets the ID field of the mutation.
  77. func withMessageRecordsID(id uint64) messagerecordsOption {
  78. return func(m *MessageRecordsMutation) {
  79. var (
  80. err error
  81. once sync.Once
  82. value *MessageRecords
  83. )
  84. m.oldValue = func(ctx context.Context) (*MessageRecords, error) {
  85. once.Do(func() {
  86. if m.done {
  87. err = errors.New("querying old values post mutation is not allowed")
  88. } else {
  89. value, err = m.Client().MessageRecords.Get(ctx, id)
  90. }
  91. })
  92. return value, err
  93. }
  94. m.id = &id
  95. }
  96. }
  97. // withMessageRecords sets the old MessageRecords of the mutation.
  98. func withMessageRecords(node *MessageRecords) messagerecordsOption {
  99. return func(m *MessageRecordsMutation) {
  100. m.oldValue = func(context.Context) (*MessageRecords, error) {
  101. return node, nil
  102. }
  103. m.id = &node.ID
  104. }
  105. }
  106. // Client returns a new `ent.Client` from the mutation. If the mutation was
  107. // executed in a transaction (ent.Tx), a transactional client is returned.
  108. func (m MessageRecordsMutation) Client() *Client {
  109. client := &Client{config: m.config}
  110. client.init()
  111. return client
  112. }
  113. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  114. // it returns an error otherwise.
  115. func (m MessageRecordsMutation) Tx() (*Tx, error) {
  116. if _, ok := m.driver.(*txDriver); !ok {
  117. return nil, errors.New("ent: mutation is not running in a transaction")
  118. }
  119. tx := &Tx{config: m.config}
  120. tx.init()
  121. return tx, nil
  122. }
  123. // SetID sets the value of the id field. Note that this
  124. // operation is only accepted on creation of MessageRecords entities.
  125. func (m *MessageRecordsMutation) SetID(id uint64) {
  126. m.id = &id
  127. }
  128. // ID returns the ID value in the mutation. Note that the ID is only available
  129. // if it was provided to the builder or after it was returned from the database.
  130. func (m *MessageRecordsMutation) ID() (id uint64, exists bool) {
  131. if m.id == nil {
  132. return
  133. }
  134. return *m.id, true
  135. }
  136. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  137. // That means, if the mutation is applied within a transaction with an isolation level such
  138. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  139. // or updated by the mutation.
  140. func (m *MessageRecordsMutation) IDs(ctx context.Context) ([]uint64, error) {
  141. switch {
  142. case m.op.Is(OpUpdateOne | OpDeleteOne):
  143. id, exists := m.ID()
  144. if exists {
  145. return []uint64{id}, nil
  146. }
  147. fallthrough
  148. case m.op.Is(OpUpdate | OpDelete):
  149. return m.Client().MessageRecords.Query().Where(m.predicates...).IDs(ctx)
  150. default:
  151. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  152. }
  153. }
  154. // SetCreatedAt sets the "created_at" field.
  155. func (m *MessageRecordsMutation) SetCreatedAt(t time.Time) {
  156. m.created_at = &t
  157. }
  158. // CreatedAt returns the value of the "created_at" field in the mutation.
  159. func (m *MessageRecordsMutation) CreatedAt() (r time.Time, exists bool) {
  160. v := m.created_at
  161. if v == nil {
  162. return
  163. }
  164. return *v, true
  165. }
  166. // OldCreatedAt returns the old "created_at" field's value of the MessageRecords entity.
  167. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  168. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  169. func (m *MessageRecordsMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  170. if !m.op.Is(OpUpdateOne) {
  171. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  172. }
  173. if m.id == nil || m.oldValue == nil {
  174. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  175. }
  176. oldValue, err := m.oldValue(ctx)
  177. if err != nil {
  178. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  179. }
  180. return oldValue.CreatedAt, nil
  181. }
  182. // ResetCreatedAt resets all changes to the "created_at" field.
  183. func (m *MessageRecordsMutation) ResetCreatedAt() {
  184. m.created_at = nil
  185. }
  186. // SetUpdatedAt sets the "updated_at" field.
  187. func (m *MessageRecordsMutation) SetUpdatedAt(t time.Time) {
  188. m.updated_at = &t
  189. }
  190. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  191. func (m *MessageRecordsMutation) UpdatedAt() (r time.Time, exists bool) {
  192. v := m.updated_at
  193. if v == nil {
  194. return
  195. }
  196. return *v, true
  197. }
  198. // OldUpdatedAt returns the old "updated_at" field's value of the MessageRecords entity.
  199. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  200. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  201. func (m *MessageRecordsMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  202. if !m.op.Is(OpUpdateOne) {
  203. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  204. }
  205. if m.id == nil || m.oldValue == nil {
  206. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  207. }
  208. oldValue, err := m.oldValue(ctx)
  209. if err != nil {
  210. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  211. }
  212. return oldValue.UpdatedAt, nil
  213. }
  214. // ResetUpdatedAt resets all changes to the "updated_at" field.
  215. func (m *MessageRecordsMutation) ResetUpdatedAt() {
  216. m.updated_at = nil
  217. }
  218. // SetStatus sets the "status" field.
  219. func (m *MessageRecordsMutation) SetStatus(u uint8) {
  220. m.status = &u
  221. m.addstatus = nil
  222. }
  223. // Status returns the value of the "status" field in the mutation.
  224. func (m *MessageRecordsMutation) Status() (r uint8, exists bool) {
  225. v := m.status
  226. if v == nil {
  227. return
  228. }
  229. return *v, true
  230. }
  231. // OldStatus returns the old "status" field's value of the MessageRecords entity.
  232. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  233. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  234. func (m *MessageRecordsMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  235. if !m.op.Is(OpUpdateOne) {
  236. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  237. }
  238. if m.id == nil || m.oldValue == nil {
  239. return v, errors.New("OldStatus requires an ID field in the mutation")
  240. }
  241. oldValue, err := m.oldValue(ctx)
  242. if err != nil {
  243. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  244. }
  245. return oldValue.Status, nil
  246. }
  247. // AddStatus adds u to the "status" field.
  248. func (m *MessageRecordsMutation) AddStatus(u int8) {
  249. if m.addstatus != nil {
  250. *m.addstatus += u
  251. } else {
  252. m.addstatus = &u
  253. }
  254. }
  255. // AddedStatus returns the value that was added to the "status" field in this mutation.
  256. func (m *MessageRecordsMutation) AddedStatus() (r int8, exists bool) {
  257. v := m.addstatus
  258. if v == nil {
  259. return
  260. }
  261. return *v, true
  262. }
  263. // ClearStatus clears the value of the "status" field.
  264. func (m *MessageRecordsMutation) ClearStatus() {
  265. m.status = nil
  266. m.addstatus = nil
  267. m.clearedFields[messagerecords.FieldStatus] = struct{}{}
  268. }
  269. // StatusCleared returns if the "status" field was cleared in this mutation.
  270. func (m *MessageRecordsMutation) StatusCleared() bool {
  271. _, ok := m.clearedFields[messagerecords.FieldStatus]
  272. return ok
  273. }
  274. // ResetStatus resets all changes to the "status" field.
  275. func (m *MessageRecordsMutation) ResetStatus() {
  276. m.status = nil
  277. m.addstatus = nil
  278. delete(m.clearedFields, messagerecords.FieldStatus)
  279. }
  280. // SetBotWxid sets the "bot_wxid" field.
  281. func (m *MessageRecordsMutation) SetBotWxid(s string) {
  282. m.bot_wxid = &s
  283. }
  284. // BotWxid returns the value of the "bot_wxid" field in the mutation.
  285. func (m *MessageRecordsMutation) BotWxid() (r string, exists bool) {
  286. v := m.bot_wxid
  287. if v == nil {
  288. return
  289. }
  290. return *v, true
  291. }
  292. // OldBotWxid returns the old "bot_wxid" field's value of the MessageRecords entity.
  293. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  294. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  295. func (m *MessageRecordsMutation) OldBotWxid(ctx context.Context) (v string, err error) {
  296. if !m.op.Is(OpUpdateOne) {
  297. return v, errors.New("OldBotWxid is only allowed on UpdateOne operations")
  298. }
  299. if m.id == nil || m.oldValue == nil {
  300. return v, errors.New("OldBotWxid requires an ID field in the mutation")
  301. }
  302. oldValue, err := m.oldValue(ctx)
  303. if err != nil {
  304. return v, fmt.Errorf("querying old value for OldBotWxid: %w", err)
  305. }
  306. return oldValue.BotWxid, nil
  307. }
  308. // ResetBotWxid resets all changes to the "bot_wxid" field.
  309. func (m *MessageRecordsMutation) ResetBotWxid() {
  310. m.bot_wxid = nil
  311. }
  312. // SetContactID sets the "contact_id" field.
  313. func (m *MessageRecordsMutation) SetContactID(u uint64) {
  314. m.contact_id = &u
  315. m.addcontact_id = nil
  316. }
  317. // ContactID returns the value of the "contact_id" field in the mutation.
  318. func (m *MessageRecordsMutation) ContactID() (r uint64, exists bool) {
  319. v := m.contact_id
  320. if v == nil {
  321. return
  322. }
  323. return *v, true
  324. }
  325. // OldContactID returns the old "contact_id" field's value of the MessageRecords entity.
  326. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  327. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  328. func (m *MessageRecordsMutation) OldContactID(ctx context.Context) (v uint64, err error) {
  329. if !m.op.Is(OpUpdateOne) {
  330. return v, errors.New("OldContactID is only allowed on UpdateOne operations")
  331. }
  332. if m.id == nil || m.oldValue == nil {
  333. return v, errors.New("OldContactID requires an ID field in the mutation")
  334. }
  335. oldValue, err := m.oldValue(ctx)
  336. if err != nil {
  337. return v, fmt.Errorf("querying old value for OldContactID: %w", err)
  338. }
  339. return oldValue.ContactID, nil
  340. }
  341. // AddContactID adds u to the "contact_id" field.
  342. func (m *MessageRecordsMutation) AddContactID(u int64) {
  343. if m.addcontact_id != nil {
  344. *m.addcontact_id += u
  345. } else {
  346. m.addcontact_id = &u
  347. }
  348. }
  349. // AddedContactID returns the value that was added to the "contact_id" field in this mutation.
  350. func (m *MessageRecordsMutation) AddedContactID() (r int64, exists bool) {
  351. v := m.addcontact_id
  352. if v == nil {
  353. return
  354. }
  355. return *v, true
  356. }
  357. // ClearContactID clears the value of the "contact_id" field.
  358. func (m *MessageRecordsMutation) ClearContactID() {
  359. m.contact_id = nil
  360. m.addcontact_id = nil
  361. m.clearedFields[messagerecords.FieldContactID] = struct{}{}
  362. }
  363. // ContactIDCleared returns if the "contact_id" field was cleared in this mutation.
  364. func (m *MessageRecordsMutation) ContactIDCleared() bool {
  365. _, ok := m.clearedFields[messagerecords.FieldContactID]
  366. return ok
  367. }
  368. // ResetContactID resets all changes to the "contact_id" field.
  369. func (m *MessageRecordsMutation) ResetContactID() {
  370. m.contact_id = nil
  371. m.addcontact_id = nil
  372. delete(m.clearedFields, messagerecords.FieldContactID)
  373. }
  374. // SetContactType sets the "contact_type" field.
  375. func (m *MessageRecordsMutation) SetContactType(i int) {
  376. m.contact_type = &i
  377. m.addcontact_type = nil
  378. }
  379. // ContactType returns the value of the "contact_type" field in the mutation.
  380. func (m *MessageRecordsMutation) ContactType() (r int, exists bool) {
  381. v := m.contact_type
  382. if v == nil {
  383. return
  384. }
  385. return *v, true
  386. }
  387. // OldContactType returns the old "contact_type" field's value of the MessageRecords entity.
  388. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  389. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  390. func (m *MessageRecordsMutation) OldContactType(ctx context.Context) (v int, err error) {
  391. if !m.op.Is(OpUpdateOne) {
  392. return v, errors.New("OldContactType is only allowed on UpdateOne operations")
  393. }
  394. if m.id == nil || m.oldValue == nil {
  395. return v, errors.New("OldContactType requires an ID field in the mutation")
  396. }
  397. oldValue, err := m.oldValue(ctx)
  398. if err != nil {
  399. return v, fmt.Errorf("querying old value for OldContactType: %w", err)
  400. }
  401. return oldValue.ContactType, nil
  402. }
  403. // AddContactType adds i to the "contact_type" field.
  404. func (m *MessageRecordsMutation) AddContactType(i int) {
  405. if m.addcontact_type != nil {
  406. *m.addcontact_type += i
  407. } else {
  408. m.addcontact_type = &i
  409. }
  410. }
  411. // AddedContactType returns the value that was added to the "contact_type" field in this mutation.
  412. func (m *MessageRecordsMutation) AddedContactType() (r int, exists bool) {
  413. v := m.addcontact_type
  414. if v == nil {
  415. return
  416. }
  417. return *v, true
  418. }
  419. // ResetContactType resets all changes to the "contact_type" field.
  420. func (m *MessageRecordsMutation) ResetContactType() {
  421. m.contact_type = nil
  422. m.addcontact_type = nil
  423. }
  424. // SetContactWxid sets the "contact_wxid" field.
  425. func (m *MessageRecordsMutation) SetContactWxid(s string) {
  426. m.contact_wxid = &s
  427. }
  428. // ContactWxid returns the value of the "contact_wxid" field in the mutation.
  429. func (m *MessageRecordsMutation) ContactWxid() (r string, exists bool) {
  430. v := m.contact_wxid
  431. if v == nil {
  432. return
  433. }
  434. return *v, true
  435. }
  436. // OldContactWxid returns the old "contact_wxid" field's value of the MessageRecords entity.
  437. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  438. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  439. func (m *MessageRecordsMutation) OldContactWxid(ctx context.Context) (v string, err error) {
  440. if !m.op.Is(OpUpdateOne) {
  441. return v, errors.New("OldContactWxid is only allowed on UpdateOne operations")
  442. }
  443. if m.id == nil || m.oldValue == nil {
  444. return v, errors.New("OldContactWxid requires an ID field in the mutation")
  445. }
  446. oldValue, err := m.oldValue(ctx)
  447. if err != nil {
  448. return v, fmt.Errorf("querying old value for OldContactWxid: %w", err)
  449. }
  450. return oldValue.ContactWxid, nil
  451. }
  452. // ResetContactWxid resets all changes to the "contact_wxid" field.
  453. func (m *MessageRecordsMutation) ResetContactWxid() {
  454. m.contact_wxid = nil
  455. }
  456. // SetContentType sets the "content_type" field.
  457. func (m *MessageRecordsMutation) SetContentType(i int) {
  458. m.content_type = &i
  459. m.addcontent_type = nil
  460. }
  461. // ContentType returns the value of the "content_type" field in the mutation.
  462. func (m *MessageRecordsMutation) ContentType() (r int, exists bool) {
  463. v := m.content_type
  464. if v == nil {
  465. return
  466. }
  467. return *v, true
  468. }
  469. // OldContentType returns the old "content_type" field's value of the MessageRecords entity.
  470. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  471. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  472. func (m *MessageRecordsMutation) OldContentType(ctx context.Context) (v int, err error) {
  473. if !m.op.Is(OpUpdateOne) {
  474. return v, errors.New("OldContentType is only allowed on UpdateOne operations")
  475. }
  476. if m.id == nil || m.oldValue == nil {
  477. return v, errors.New("OldContentType requires an ID field in the mutation")
  478. }
  479. oldValue, err := m.oldValue(ctx)
  480. if err != nil {
  481. return v, fmt.Errorf("querying old value for OldContentType: %w", err)
  482. }
  483. return oldValue.ContentType, nil
  484. }
  485. // AddContentType adds i to the "content_type" field.
  486. func (m *MessageRecordsMutation) AddContentType(i int) {
  487. if m.addcontent_type != nil {
  488. *m.addcontent_type += i
  489. } else {
  490. m.addcontent_type = &i
  491. }
  492. }
  493. // AddedContentType returns the value that was added to the "content_type" field in this mutation.
  494. func (m *MessageRecordsMutation) AddedContentType() (r int, exists bool) {
  495. v := m.addcontent_type
  496. if v == nil {
  497. return
  498. }
  499. return *v, true
  500. }
  501. // ResetContentType resets all changes to the "content_type" field.
  502. func (m *MessageRecordsMutation) ResetContentType() {
  503. m.content_type = nil
  504. m.addcontent_type = nil
  505. }
  506. // SetContent sets the "content" field.
  507. func (m *MessageRecordsMutation) SetContent(s string) {
  508. m.content = &s
  509. }
  510. // Content returns the value of the "content" field in the mutation.
  511. func (m *MessageRecordsMutation) Content() (r string, exists bool) {
  512. v := m.content
  513. if v == nil {
  514. return
  515. }
  516. return *v, true
  517. }
  518. // OldContent returns the old "content" field's value of the MessageRecords entity.
  519. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  520. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  521. func (m *MessageRecordsMutation) OldContent(ctx context.Context) (v string, err error) {
  522. if !m.op.Is(OpUpdateOne) {
  523. return v, errors.New("OldContent is only allowed on UpdateOne operations")
  524. }
  525. if m.id == nil || m.oldValue == nil {
  526. return v, errors.New("OldContent requires an ID field in the mutation")
  527. }
  528. oldValue, err := m.oldValue(ctx)
  529. if err != nil {
  530. return v, fmt.Errorf("querying old value for OldContent: %w", err)
  531. }
  532. return oldValue.Content, nil
  533. }
  534. // ResetContent resets all changes to the "content" field.
  535. func (m *MessageRecordsMutation) ResetContent() {
  536. m.content = nil
  537. }
  538. // SetErrorDetail sets the "error_detail" field.
  539. func (m *MessageRecordsMutation) SetErrorDetail(s string) {
  540. m.error_detail = &s
  541. }
  542. // ErrorDetail returns the value of the "error_detail" field in the mutation.
  543. func (m *MessageRecordsMutation) ErrorDetail() (r string, exists bool) {
  544. v := m.error_detail
  545. if v == nil {
  546. return
  547. }
  548. return *v, true
  549. }
  550. // OldErrorDetail returns the old "error_detail" field's value of the MessageRecords entity.
  551. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  552. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  553. func (m *MessageRecordsMutation) OldErrorDetail(ctx context.Context) (v string, err error) {
  554. if !m.op.Is(OpUpdateOne) {
  555. return v, errors.New("OldErrorDetail is only allowed on UpdateOne operations")
  556. }
  557. if m.id == nil || m.oldValue == nil {
  558. return v, errors.New("OldErrorDetail requires an ID field in the mutation")
  559. }
  560. oldValue, err := m.oldValue(ctx)
  561. if err != nil {
  562. return v, fmt.Errorf("querying old value for OldErrorDetail: %w", err)
  563. }
  564. return oldValue.ErrorDetail, nil
  565. }
  566. // ResetErrorDetail resets all changes to the "error_detail" field.
  567. func (m *MessageRecordsMutation) ResetErrorDetail() {
  568. m.error_detail = nil
  569. }
  570. // SetSendTime sets the "send_time" field.
  571. func (m *MessageRecordsMutation) SetSendTime(t time.Time) {
  572. m.send_time = &t
  573. }
  574. // SendTime returns the value of the "send_time" field in the mutation.
  575. func (m *MessageRecordsMutation) SendTime() (r time.Time, exists bool) {
  576. v := m.send_time
  577. if v == nil {
  578. return
  579. }
  580. return *v, true
  581. }
  582. // OldSendTime returns the old "send_time" field's value of the MessageRecords entity.
  583. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  584. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  585. func (m *MessageRecordsMutation) OldSendTime(ctx context.Context) (v time.Time, err error) {
  586. if !m.op.Is(OpUpdateOne) {
  587. return v, errors.New("OldSendTime is only allowed on UpdateOne operations")
  588. }
  589. if m.id == nil || m.oldValue == nil {
  590. return v, errors.New("OldSendTime requires an ID field in the mutation")
  591. }
  592. oldValue, err := m.oldValue(ctx)
  593. if err != nil {
  594. return v, fmt.Errorf("querying old value for OldSendTime: %w", err)
  595. }
  596. return oldValue.SendTime, nil
  597. }
  598. // ClearSendTime clears the value of the "send_time" field.
  599. func (m *MessageRecordsMutation) ClearSendTime() {
  600. m.send_time = nil
  601. m.clearedFields[messagerecords.FieldSendTime] = struct{}{}
  602. }
  603. // SendTimeCleared returns if the "send_time" field was cleared in this mutation.
  604. func (m *MessageRecordsMutation) SendTimeCleared() bool {
  605. _, ok := m.clearedFields[messagerecords.FieldSendTime]
  606. return ok
  607. }
  608. // ResetSendTime resets all changes to the "send_time" field.
  609. func (m *MessageRecordsMutation) ResetSendTime() {
  610. m.send_time = nil
  611. delete(m.clearedFields, messagerecords.FieldSendTime)
  612. }
  613. // SetSourceType sets the "source_type" field.
  614. func (m *MessageRecordsMutation) SetSourceType(i int) {
  615. m.source_type = &i
  616. m.addsource_type = nil
  617. }
  618. // SourceType returns the value of the "source_type" field in the mutation.
  619. func (m *MessageRecordsMutation) SourceType() (r int, exists bool) {
  620. v := m.source_type
  621. if v == nil {
  622. return
  623. }
  624. return *v, true
  625. }
  626. // OldSourceType returns the old "source_type" field's value of the MessageRecords entity.
  627. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  628. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  629. func (m *MessageRecordsMutation) OldSourceType(ctx context.Context) (v int, err error) {
  630. if !m.op.Is(OpUpdateOne) {
  631. return v, errors.New("OldSourceType is only allowed on UpdateOne operations")
  632. }
  633. if m.id == nil || m.oldValue == nil {
  634. return v, errors.New("OldSourceType requires an ID field in the mutation")
  635. }
  636. oldValue, err := m.oldValue(ctx)
  637. if err != nil {
  638. return v, fmt.Errorf("querying old value for OldSourceType: %w", err)
  639. }
  640. return oldValue.SourceType, nil
  641. }
  642. // AddSourceType adds i to the "source_type" field.
  643. func (m *MessageRecordsMutation) AddSourceType(i int) {
  644. if m.addsource_type != nil {
  645. *m.addsource_type += i
  646. } else {
  647. m.addsource_type = &i
  648. }
  649. }
  650. // AddedSourceType returns the value that was added to the "source_type" field in this mutation.
  651. func (m *MessageRecordsMutation) AddedSourceType() (r int, exists bool) {
  652. v := m.addsource_type
  653. if v == nil {
  654. return
  655. }
  656. return *v, true
  657. }
  658. // ResetSourceType resets all changes to the "source_type" field.
  659. func (m *MessageRecordsMutation) ResetSourceType() {
  660. m.source_type = nil
  661. m.addsource_type = nil
  662. }
  663. // SetSourceID sets the "source_id" field.
  664. func (m *MessageRecordsMutation) SetSourceID(u uint64) {
  665. m.source_id = &u
  666. m.addsource_id = nil
  667. }
  668. // SourceID returns the value of the "source_id" field in the mutation.
  669. func (m *MessageRecordsMutation) SourceID() (r uint64, exists bool) {
  670. v := m.source_id
  671. if v == nil {
  672. return
  673. }
  674. return *v, true
  675. }
  676. // OldSourceID returns the old "source_id" field's value of the MessageRecords entity.
  677. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  678. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  679. func (m *MessageRecordsMutation) OldSourceID(ctx context.Context) (v uint64, err error) {
  680. if !m.op.Is(OpUpdateOne) {
  681. return v, errors.New("OldSourceID is only allowed on UpdateOne operations")
  682. }
  683. if m.id == nil || m.oldValue == nil {
  684. return v, errors.New("OldSourceID requires an ID field in the mutation")
  685. }
  686. oldValue, err := m.oldValue(ctx)
  687. if err != nil {
  688. return v, fmt.Errorf("querying old value for OldSourceID: %w", err)
  689. }
  690. return oldValue.SourceID, nil
  691. }
  692. // AddSourceID adds u to the "source_id" field.
  693. func (m *MessageRecordsMutation) AddSourceID(u int64) {
  694. if m.addsource_id != nil {
  695. *m.addsource_id += u
  696. } else {
  697. m.addsource_id = &u
  698. }
  699. }
  700. // AddedSourceID returns the value that was added to the "source_id" field in this mutation.
  701. func (m *MessageRecordsMutation) AddedSourceID() (r int64, exists bool) {
  702. v := m.addsource_id
  703. if v == nil {
  704. return
  705. }
  706. return *v, true
  707. }
  708. // ClearSourceID clears the value of the "source_id" field.
  709. func (m *MessageRecordsMutation) ClearSourceID() {
  710. m.source_id = nil
  711. m.addsource_id = nil
  712. m.clearedFields[messagerecords.FieldSourceID] = struct{}{}
  713. }
  714. // SourceIDCleared returns if the "source_id" field was cleared in this mutation.
  715. func (m *MessageRecordsMutation) SourceIDCleared() bool {
  716. _, ok := m.clearedFields[messagerecords.FieldSourceID]
  717. return ok
  718. }
  719. // ResetSourceID resets all changes to the "source_id" field.
  720. func (m *MessageRecordsMutation) ResetSourceID() {
  721. m.source_id = nil
  722. m.addsource_id = nil
  723. delete(m.clearedFields, messagerecords.FieldSourceID)
  724. }
  725. // SetSubSourceID sets the "sub_source_id" field.
  726. func (m *MessageRecordsMutation) SetSubSourceID(u uint64) {
  727. m.sub_source_id = &u
  728. m.addsub_source_id = nil
  729. }
  730. // SubSourceID returns the value of the "sub_source_id" field in the mutation.
  731. func (m *MessageRecordsMutation) SubSourceID() (r uint64, exists bool) {
  732. v := m.sub_source_id
  733. if v == nil {
  734. return
  735. }
  736. return *v, true
  737. }
  738. // OldSubSourceID returns the old "sub_source_id" field's value of the MessageRecords entity.
  739. // If the MessageRecords object wasn't provided to the builder, the object is fetched from the database.
  740. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  741. func (m *MessageRecordsMutation) OldSubSourceID(ctx context.Context) (v uint64, err error) {
  742. if !m.op.Is(OpUpdateOne) {
  743. return v, errors.New("OldSubSourceID is only allowed on UpdateOne operations")
  744. }
  745. if m.id == nil || m.oldValue == nil {
  746. return v, errors.New("OldSubSourceID requires an ID field in the mutation")
  747. }
  748. oldValue, err := m.oldValue(ctx)
  749. if err != nil {
  750. return v, fmt.Errorf("querying old value for OldSubSourceID: %w", err)
  751. }
  752. return oldValue.SubSourceID, nil
  753. }
  754. // AddSubSourceID adds u to the "sub_source_id" field.
  755. func (m *MessageRecordsMutation) AddSubSourceID(u int64) {
  756. if m.addsub_source_id != nil {
  757. *m.addsub_source_id += u
  758. } else {
  759. m.addsub_source_id = &u
  760. }
  761. }
  762. // AddedSubSourceID returns the value that was added to the "sub_source_id" field in this mutation.
  763. func (m *MessageRecordsMutation) AddedSubSourceID() (r int64, exists bool) {
  764. v := m.addsub_source_id
  765. if v == nil {
  766. return
  767. }
  768. return *v, true
  769. }
  770. // ClearSubSourceID clears the value of the "sub_source_id" field.
  771. func (m *MessageRecordsMutation) ClearSubSourceID() {
  772. m.sub_source_id = nil
  773. m.addsub_source_id = nil
  774. m.clearedFields[messagerecords.FieldSubSourceID] = struct{}{}
  775. }
  776. // SubSourceIDCleared returns if the "sub_source_id" field was cleared in this mutation.
  777. func (m *MessageRecordsMutation) SubSourceIDCleared() bool {
  778. _, ok := m.clearedFields[messagerecords.FieldSubSourceID]
  779. return ok
  780. }
  781. // ResetSubSourceID resets all changes to the "sub_source_id" field.
  782. func (m *MessageRecordsMutation) ResetSubSourceID() {
  783. m.sub_source_id = nil
  784. m.addsub_source_id = nil
  785. delete(m.clearedFields, messagerecords.FieldSubSourceID)
  786. }
  787. // Where appends a list predicates to the MessageRecordsMutation builder.
  788. func (m *MessageRecordsMutation) Where(ps ...predicate.MessageRecords) {
  789. m.predicates = append(m.predicates, ps...)
  790. }
  791. // WhereP appends storage-level predicates to the MessageRecordsMutation builder. Using this method,
  792. // users can use type-assertion to append predicates that do not depend on any generated package.
  793. func (m *MessageRecordsMutation) WhereP(ps ...func(*sql.Selector)) {
  794. p := make([]predicate.MessageRecords, len(ps))
  795. for i := range ps {
  796. p[i] = ps[i]
  797. }
  798. m.Where(p...)
  799. }
  800. // Op returns the operation name.
  801. func (m *MessageRecordsMutation) Op() Op {
  802. return m.op
  803. }
  804. // SetOp allows setting the mutation operation.
  805. func (m *MessageRecordsMutation) SetOp(op Op) {
  806. m.op = op
  807. }
  808. // Type returns the node type of this mutation (MessageRecords).
  809. func (m *MessageRecordsMutation) Type() string {
  810. return m.typ
  811. }
  812. // Fields returns all fields that were changed during this mutation. Note that in
  813. // order to get all numeric fields that were incremented/decremented, call
  814. // AddedFields().
  815. func (m *MessageRecordsMutation) Fields() []string {
  816. fields := make([]string, 0, 14)
  817. if m.created_at != nil {
  818. fields = append(fields, messagerecords.FieldCreatedAt)
  819. }
  820. if m.updated_at != nil {
  821. fields = append(fields, messagerecords.FieldUpdatedAt)
  822. }
  823. if m.status != nil {
  824. fields = append(fields, messagerecords.FieldStatus)
  825. }
  826. if m.bot_wxid != nil {
  827. fields = append(fields, messagerecords.FieldBotWxid)
  828. }
  829. if m.contact_id != nil {
  830. fields = append(fields, messagerecords.FieldContactID)
  831. }
  832. if m.contact_type != nil {
  833. fields = append(fields, messagerecords.FieldContactType)
  834. }
  835. if m.contact_wxid != nil {
  836. fields = append(fields, messagerecords.FieldContactWxid)
  837. }
  838. if m.content_type != nil {
  839. fields = append(fields, messagerecords.FieldContentType)
  840. }
  841. if m.content != nil {
  842. fields = append(fields, messagerecords.FieldContent)
  843. }
  844. if m.error_detail != nil {
  845. fields = append(fields, messagerecords.FieldErrorDetail)
  846. }
  847. if m.send_time != nil {
  848. fields = append(fields, messagerecords.FieldSendTime)
  849. }
  850. if m.source_type != nil {
  851. fields = append(fields, messagerecords.FieldSourceType)
  852. }
  853. if m.source_id != nil {
  854. fields = append(fields, messagerecords.FieldSourceID)
  855. }
  856. if m.sub_source_id != nil {
  857. fields = append(fields, messagerecords.FieldSubSourceID)
  858. }
  859. return fields
  860. }
  861. // Field returns the value of a field with the given name. The second boolean
  862. // return value indicates that this field was not set, or was not defined in the
  863. // schema.
  864. func (m *MessageRecordsMutation) Field(name string) (ent.Value, bool) {
  865. switch name {
  866. case messagerecords.FieldCreatedAt:
  867. return m.CreatedAt()
  868. case messagerecords.FieldUpdatedAt:
  869. return m.UpdatedAt()
  870. case messagerecords.FieldStatus:
  871. return m.Status()
  872. case messagerecords.FieldBotWxid:
  873. return m.BotWxid()
  874. case messagerecords.FieldContactID:
  875. return m.ContactID()
  876. case messagerecords.FieldContactType:
  877. return m.ContactType()
  878. case messagerecords.FieldContactWxid:
  879. return m.ContactWxid()
  880. case messagerecords.FieldContentType:
  881. return m.ContentType()
  882. case messagerecords.FieldContent:
  883. return m.Content()
  884. case messagerecords.FieldErrorDetail:
  885. return m.ErrorDetail()
  886. case messagerecords.FieldSendTime:
  887. return m.SendTime()
  888. case messagerecords.FieldSourceType:
  889. return m.SourceType()
  890. case messagerecords.FieldSourceID:
  891. return m.SourceID()
  892. case messagerecords.FieldSubSourceID:
  893. return m.SubSourceID()
  894. }
  895. return nil, false
  896. }
  897. // OldField returns the old value of the field from the database. An error is
  898. // returned if the mutation operation is not UpdateOne, or the query to the
  899. // database failed.
  900. func (m *MessageRecordsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  901. switch name {
  902. case messagerecords.FieldCreatedAt:
  903. return m.OldCreatedAt(ctx)
  904. case messagerecords.FieldUpdatedAt:
  905. return m.OldUpdatedAt(ctx)
  906. case messagerecords.FieldStatus:
  907. return m.OldStatus(ctx)
  908. case messagerecords.FieldBotWxid:
  909. return m.OldBotWxid(ctx)
  910. case messagerecords.FieldContactID:
  911. return m.OldContactID(ctx)
  912. case messagerecords.FieldContactType:
  913. return m.OldContactType(ctx)
  914. case messagerecords.FieldContactWxid:
  915. return m.OldContactWxid(ctx)
  916. case messagerecords.FieldContentType:
  917. return m.OldContentType(ctx)
  918. case messagerecords.FieldContent:
  919. return m.OldContent(ctx)
  920. case messagerecords.FieldErrorDetail:
  921. return m.OldErrorDetail(ctx)
  922. case messagerecords.FieldSendTime:
  923. return m.OldSendTime(ctx)
  924. case messagerecords.FieldSourceType:
  925. return m.OldSourceType(ctx)
  926. case messagerecords.FieldSourceID:
  927. return m.OldSourceID(ctx)
  928. case messagerecords.FieldSubSourceID:
  929. return m.OldSubSourceID(ctx)
  930. }
  931. return nil, fmt.Errorf("unknown MessageRecords field %s", name)
  932. }
  933. // SetField sets the value of a field with the given name. It returns an error if
  934. // the field is not defined in the schema, or if the type mismatched the field
  935. // type.
  936. func (m *MessageRecordsMutation) SetField(name string, value ent.Value) error {
  937. switch name {
  938. case messagerecords.FieldCreatedAt:
  939. v, ok := value.(time.Time)
  940. if !ok {
  941. return fmt.Errorf("unexpected type %T for field %s", value, name)
  942. }
  943. m.SetCreatedAt(v)
  944. return nil
  945. case messagerecords.FieldUpdatedAt:
  946. v, ok := value.(time.Time)
  947. if !ok {
  948. return fmt.Errorf("unexpected type %T for field %s", value, name)
  949. }
  950. m.SetUpdatedAt(v)
  951. return nil
  952. case messagerecords.FieldStatus:
  953. v, ok := value.(uint8)
  954. if !ok {
  955. return fmt.Errorf("unexpected type %T for field %s", value, name)
  956. }
  957. m.SetStatus(v)
  958. return nil
  959. case messagerecords.FieldBotWxid:
  960. v, ok := value.(string)
  961. if !ok {
  962. return fmt.Errorf("unexpected type %T for field %s", value, name)
  963. }
  964. m.SetBotWxid(v)
  965. return nil
  966. case messagerecords.FieldContactID:
  967. v, ok := value.(uint64)
  968. if !ok {
  969. return fmt.Errorf("unexpected type %T for field %s", value, name)
  970. }
  971. m.SetContactID(v)
  972. return nil
  973. case messagerecords.FieldContactType:
  974. v, ok := value.(int)
  975. if !ok {
  976. return fmt.Errorf("unexpected type %T for field %s", value, name)
  977. }
  978. m.SetContactType(v)
  979. return nil
  980. case messagerecords.FieldContactWxid:
  981. v, ok := value.(string)
  982. if !ok {
  983. return fmt.Errorf("unexpected type %T for field %s", value, name)
  984. }
  985. m.SetContactWxid(v)
  986. return nil
  987. case messagerecords.FieldContentType:
  988. v, ok := value.(int)
  989. if !ok {
  990. return fmt.Errorf("unexpected type %T for field %s", value, name)
  991. }
  992. m.SetContentType(v)
  993. return nil
  994. case messagerecords.FieldContent:
  995. v, ok := value.(string)
  996. if !ok {
  997. return fmt.Errorf("unexpected type %T for field %s", value, name)
  998. }
  999. m.SetContent(v)
  1000. return nil
  1001. case messagerecords.FieldErrorDetail:
  1002. v, ok := value.(string)
  1003. if !ok {
  1004. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1005. }
  1006. m.SetErrorDetail(v)
  1007. return nil
  1008. case messagerecords.FieldSendTime:
  1009. v, ok := value.(time.Time)
  1010. if !ok {
  1011. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1012. }
  1013. m.SetSendTime(v)
  1014. return nil
  1015. case messagerecords.FieldSourceType:
  1016. v, ok := value.(int)
  1017. if !ok {
  1018. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1019. }
  1020. m.SetSourceType(v)
  1021. return nil
  1022. case messagerecords.FieldSourceID:
  1023. v, ok := value.(uint64)
  1024. if !ok {
  1025. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1026. }
  1027. m.SetSourceID(v)
  1028. return nil
  1029. case messagerecords.FieldSubSourceID:
  1030. v, ok := value.(uint64)
  1031. if !ok {
  1032. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1033. }
  1034. m.SetSubSourceID(v)
  1035. return nil
  1036. }
  1037. return fmt.Errorf("unknown MessageRecords field %s", name)
  1038. }
  1039. // AddedFields returns all numeric fields that were incremented/decremented during
  1040. // this mutation.
  1041. func (m *MessageRecordsMutation) AddedFields() []string {
  1042. var fields []string
  1043. if m.addstatus != nil {
  1044. fields = append(fields, messagerecords.FieldStatus)
  1045. }
  1046. if m.addcontact_id != nil {
  1047. fields = append(fields, messagerecords.FieldContactID)
  1048. }
  1049. if m.addcontact_type != nil {
  1050. fields = append(fields, messagerecords.FieldContactType)
  1051. }
  1052. if m.addcontent_type != nil {
  1053. fields = append(fields, messagerecords.FieldContentType)
  1054. }
  1055. if m.addsource_type != nil {
  1056. fields = append(fields, messagerecords.FieldSourceType)
  1057. }
  1058. if m.addsource_id != nil {
  1059. fields = append(fields, messagerecords.FieldSourceID)
  1060. }
  1061. if m.addsub_source_id != nil {
  1062. fields = append(fields, messagerecords.FieldSubSourceID)
  1063. }
  1064. return fields
  1065. }
  1066. // AddedField returns the numeric value that was incremented/decremented on a field
  1067. // with the given name. The second boolean return value indicates that this field
  1068. // was not set, or was not defined in the schema.
  1069. func (m *MessageRecordsMutation) AddedField(name string) (ent.Value, bool) {
  1070. switch name {
  1071. case messagerecords.FieldStatus:
  1072. return m.AddedStatus()
  1073. case messagerecords.FieldContactID:
  1074. return m.AddedContactID()
  1075. case messagerecords.FieldContactType:
  1076. return m.AddedContactType()
  1077. case messagerecords.FieldContentType:
  1078. return m.AddedContentType()
  1079. case messagerecords.FieldSourceType:
  1080. return m.AddedSourceType()
  1081. case messagerecords.FieldSourceID:
  1082. return m.AddedSourceID()
  1083. case messagerecords.FieldSubSourceID:
  1084. return m.AddedSubSourceID()
  1085. }
  1086. return nil, false
  1087. }
  1088. // AddField adds the value to the field with the given name. It returns an error if
  1089. // the field is not defined in the schema, or if the type mismatched the field
  1090. // type.
  1091. func (m *MessageRecordsMutation) AddField(name string, value ent.Value) error {
  1092. switch name {
  1093. case messagerecords.FieldStatus:
  1094. v, ok := value.(int8)
  1095. if !ok {
  1096. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1097. }
  1098. m.AddStatus(v)
  1099. return nil
  1100. case messagerecords.FieldContactID:
  1101. v, ok := value.(int64)
  1102. if !ok {
  1103. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1104. }
  1105. m.AddContactID(v)
  1106. return nil
  1107. case messagerecords.FieldContactType:
  1108. v, ok := value.(int)
  1109. if !ok {
  1110. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1111. }
  1112. m.AddContactType(v)
  1113. return nil
  1114. case messagerecords.FieldContentType:
  1115. v, ok := value.(int)
  1116. if !ok {
  1117. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1118. }
  1119. m.AddContentType(v)
  1120. return nil
  1121. case messagerecords.FieldSourceType:
  1122. v, ok := value.(int)
  1123. if !ok {
  1124. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1125. }
  1126. m.AddSourceType(v)
  1127. return nil
  1128. case messagerecords.FieldSourceID:
  1129. v, ok := value.(int64)
  1130. if !ok {
  1131. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1132. }
  1133. m.AddSourceID(v)
  1134. return nil
  1135. case messagerecords.FieldSubSourceID:
  1136. v, ok := value.(int64)
  1137. if !ok {
  1138. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1139. }
  1140. m.AddSubSourceID(v)
  1141. return nil
  1142. }
  1143. return fmt.Errorf("unknown MessageRecords numeric field %s", name)
  1144. }
  1145. // ClearedFields returns all nullable fields that were cleared during this
  1146. // mutation.
  1147. func (m *MessageRecordsMutation) ClearedFields() []string {
  1148. var fields []string
  1149. if m.FieldCleared(messagerecords.FieldStatus) {
  1150. fields = append(fields, messagerecords.FieldStatus)
  1151. }
  1152. if m.FieldCleared(messagerecords.FieldContactID) {
  1153. fields = append(fields, messagerecords.FieldContactID)
  1154. }
  1155. if m.FieldCleared(messagerecords.FieldSendTime) {
  1156. fields = append(fields, messagerecords.FieldSendTime)
  1157. }
  1158. if m.FieldCleared(messagerecords.FieldSourceID) {
  1159. fields = append(fields, messagerecords.FieldSourceID)
  1160. }
  1161. if m.FieldCleared(messagerecords.FieldSubSourceID) {
  1162. fields = append(fields, messagerecords.FieldSubSourceID)
  1163. }
  1164. return fields
  1165. }
  1166. // FieldCleared returns a boolean indicating if a field with the given name was
  1167. // cleared in this mutation.
  1168. func (m *MessageRecordsMutation) FieldCleared(name string) bool {
  1169. _, ok := m.clearedFields[name]
  1170. return ok
  1171. }
  1172. // ClearField clears the value of the field with the given name. It returns an
  1173. // error if the field is not defined in the schema.
  1174. func (m *MessageRecordsMutation) ClearField(name string) error {
  1175. switch name {
  1176. case messagerecords.FieldStatus:
  1177. m.ClearStatus()
  1178. return nil
  1179. case messagerecords.FieldContactID:
  1180. m.ClearContactID()
  1181. return nil
  1182. case messagerecords.FieldSendTime:
  1183. m.ClearSendTime()
  1184. return nil
  1185. case messagerecords.FieldSourceID:
  1186. m.ClearSourceID()
  1187. return nil
  1188. case messagerecords.FieldSubSourceID:
  1189. m.ClearSubSourceID()
  1190. return nil
  1191. }
  1192. return fmt.Errorf("unknown MessageRecords nullable field %s", name)
  1193. }
  1194. // ResetField resets all changes in the mutation for the field with the given name.
  1195. // It returns an error if the field is not defined in the schema.
  1196. func (m *MessageRecordsMutation) ResetField(name string) error {
  1197. switch name {
  1198. case messagerecords.FieldCreatedAt:
  1199. m.ResetCreatedAt()
  1200. return nil
  1201. case messagerecords.FieldUpdatedAt:
  1202. m.ResetUpdatedAt()
  1203. return nil
  1204. case messagerecords.FieldStatus:
  1205. m.ResetStatus()
  1206. return nil
  1207. case messagerecords.FieldBotWxid:
  1208. m.ResetBotWxid()
  1209. return nil
  1210. case messagerecords.FieldContactID:
  1211. m.ResetContactID()
  1212. return nil
  1213. case messagerecords.FieldContactType:
  1214. m.ResetContactType()
  1215. return nil
  1216. case messagerecords.FieldContactWxid:
  1217. m.ResetContactWxid()
  1218. return nil
  1219. case messagerecords.FieldContentType:
  1220. m.ResetContentType()
  1221. return nil
  1222. case messagerecords.FieldContent:
  1223. m.ResetContent()
  1224. return nil
  1225. case messagerecords.FieldErrorDetail:
  1226. m.ResetErrorDetail()
  1227. return nil
  1228. case messagerecords.FieldSendTime:
  1229. m.ResetSendTime()
  1230. return nil
  1231. case messagerecords.FieldSourceType:
  1232. m.ResetSourceType()
  1233. return nil
  1234. case messagerecords.FieldSourceID:
  1235. m.ResetSourceID()
  1236. return nil
  1237. case messagerecords.FieldSubSourceID:
  1238. m.ResetSubSourceID()
  1239. return nil
  1240. }
  1241. return fmt.Errorf("unknown MessageRecords field %s", name)
  1242. }
  1243. // AddedEdges returns all edge names that were set/added in this mutation.
  1244. func (m *MessageRecordsMutation) AddedEdges() []string {
  1245. edges := make([]string, 0, 0)
  1246. return edges
  1247. }
  1248. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1249. // name in this mutation.
  1250. func (m *MessageRecordsMutation) AddedIDs(name string) []ent.Value {
  1251. return nil
  1252. }
  1253. // RemovedEdges returns all edge names that were removed in this mutation.
  1254. func (m *MessageRecordsMutation) RemovedEdges() []string {
  1255. edges := make([]string, 0, 0)
  1256. return edges
  1257. }
  1258. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  1259. // the given name in this mutation.
  1260. func (m *MessageRecordsMutation) RemovedIDs(name string) []ent.Value {
  1261. return nil
  1262. }
  1263. // ClearedEdges returns all edge names that were cleared in this mutation.
  1264. func (m *MessageRecordsMutation) ClearedEdges() []string {
  1265. edges := make([]string, 0, 0)
  1266. return edges
  1267. }
  1268. // EdgeCleared returns a boolean which indicates if the edge with the given name
  1269. // was cleared in this mutation.
  1270. func (m *MessageRecordsMutation) EdgeCleared(name string) bool {
  1271. return false
  1272. }
  1273. // ClearEdge clears the value of the edge with the given name. It returns an error
  1274. // if that edge is not defined in the schema.
  1275. func (m *MessageRecordsMutation) ClearEdge(name string) error {
  1276. return fmt.Errorf("unknown MessageRecords unique edge %s", name)
  1277. }
  1278. // ResetEdge resets all changes to the edge with the given name in this mutation.
  1279. // It returns an error if the edge is not defined in the schema.
  1280. func (m *MessageRecordsMutation) ResetEdge(name string) error {
  1281. return fmt.Errorf("unknown MessageRecords edge %s", name)
  1282. }
  1283. // TaskMutation represents an operation that mutates the Task nodes in the graph.
  1284. type TaskMutation struct {
  1285. config
  1286. op Op
  1287. typ string
  1288. id *uint64
  1289. created_at *time.Time
  1290. updated_at *time.Time
  1291. status *uint8
  1292. addstatus *int8
  1293. name *string
  1294. task_group *string
  1295. cron_expression *string
  1296. pattern *string
  1297. payload *string
  1298. clearedFields map[string]struct{}
  1299. task_logs map[uint64]struct{}
  1300. removedtask_logs map[uint64]struct{}
  1301. clearedtask_logs bool
  1302. done bool
  1303. oldValue func(context.Context) (*Task, error)
  1304. predicates []predicate.Task
  1305. }
  1306. var _ ent.Mutation = (*TaskMutation)(nil)
  1307. // taskOption allows management of the mutation configuration using functional options.
  1308. type taskOption func(*TaskMutation)
  1309. // newTaskMutation creates new mutation for the Task entity.
  1310. func newTaskMutation(c config, op Op, opts ...taskOption) *TaskMutation {
  1311. m := &TaskMutation{
  1312. config: c,
  1313. op: op,
  1314. typ: TypeTask,
  1315. clearedFields: make(map[string]struct{}),
  1316. }
  1317. for _, opt := range opts {
  1318. opt(m)
  1319. }
  1320. return m
  1321. }
  1322. // withTaskID sets the ID field of the mutation.
  1323. func withTaskID(id uint64) taskOption {
  1324. return func(m *TaskMutation) {
  1325. var (
  1326. err error
  1327. once sync.Once
  1328. value *Task
  1329. )
  1330. m.oldValue = func(ctx context.Context) (*Task, error) {
  1331. once.Do(func() {
  1332. if m.done {
  1333. err = errors.New("querying old values post mutation is not allowed")
  1334. } else {
  1335. value, err = m.Client().Task.Get(ctx, id)
  1336. }
  1337. })
  1338. return value, err
  1339. }
  1340. m.id = &id
  1341. }
  1342. }
  1343. // withTask sets the old Task of the mutation.
  1344. func withTask(node *Task) taskOption {
  1345. return func(m *TaskMutation) {
  1346. m.oldValue = func(context.Context) (*Task, error) {
  1347. return node, nil
  1348. }
  1349. m.id = &node.ID
  1350. }
  1351. }
  1352. // Client returns a new `ent.Client` from the mutation. If the mutation was
  1353. // executed in a transaction (ent.Tx), a transactional client is returned.
  1354. func (m TaskMutation) Client() *Client {
  1355. client := &Client{config: m.config}
  1356. client.init()
  1357. return client
  1358. }
  1359. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  1360. // it returns an error otherwise.
  1361. func (m TaskMutation) Tx() (*Tx, error) {
  1362. if _, ok := m.driver.(*txDriver); !ok {
  1363. return nil, errors.New("ent: mutation is not running in a transaction")
  1364. }
  1365. tx := &Tx{config: m.config}
  1366. tx.init()
  1367. return tx, nil
  1368. }
  1369. // SetID sets the value of the id field. Note that this
  1370. // operation is only accepted on creation of Task entities.
  1371. func (m *TaskMutation) SetID(id uint64) {
  1372. m.id = &id
  1373. }
  1374. // ID returns the ID value in the mutation. Note that the ID is only available
  1375. // if it was provided to the builder or after it was returned from the database.
  1376. func (m *TaskMutation) ID() (id uint64, exists bool) {
  1377. if m.id == nil {
  1378. return
  1379. }
  1380. return *m.id, true
  1381. }
  1382. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  1383. // That means, if the mutation is applied within a transaction with an isolation level such
  1384. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  1385. // or updated by the mutation.
  1386. func (m *TaskMutation) IDs(ctx context.Context) ([]uint64, error) {
  1387. switch {
  1388. case m.op.Is(OpUpdateOne | OpDeleteOne):
  1389. id, exists := m.ID()
  1390. if exists {
  1391. return []uint64{id}, nil
  1392. }
  1393. fallthrough
  1394. case m.op.Is(OpUpdate | OpDelete):
  1395. return m.Client().Task.Query().Where(m.predicates...).IDs(ctx)
  1396. default:
  1397. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  1398. }
  1399. }
  1400. // SetCreatedAt sets the "created_at" field.
  1401. func (m *TaskMutation) SetCreatedAt(t time.Time) {
  1402. m.created_at = &t
  1403. }
  1404. // CreatedAt returns the value of the "created_at" field in the mutation.
  1405. func (m *TaskMutation) CreatedAt() (r time.Time, exists bool) {
  1406. v := m.created_at
  1407. if v == nil {
  1408. return
  1409. }
  1410. return *v, true
  1411. }
  1412. // OldCreatedAt returns the old "created_at" field's value of the Task entity.
  1413. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1414. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1415. func (m *TaskMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  1416. if !m.op.Is(OpUpdateOne) {
  1417. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  1418. }
  1419. if m.id == nil || m.oldValue == nil {
  1420. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  1421. }
  1422. oldValue, err := m.oldValue(ctx)
  1423. if err != nil {
  1424. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  1425. }
  1426. return oldValue.CreatedAt, nil
  1427. }
  1428. // ResetCreatedAt resets all changes to the "created_at" field.
  1429. func (m *TaskMutation) ResetCreatedAt() {
  1430. m.created_at = nil
  1431. }
  1432. // SetUpdatedAt sets the "updated_at" field.
  1433. func (m *TaskMutation) SetUpdatedAt(t time.Time) {
  1434. m.updated_at = &t
  1435. }
  1436. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  1437. func (m *TaskMutation) UpdatedAt() (r time.Time, exists bool) {
  1438. v := m.updated_at
  1439. if v == nil {
  1440. return
  1441. }
  1442. return *v, true
  1443. }
  1444. // OldUpdatedAt returns the old "updated_at" field's value of the Task entity.
  1445. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1446. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1447. func (m *TaskMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  1448. if !m.op.Is(OpUpdateOne) {
  1449. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  1450. }
  1451. if m.id == nil || m.oldValue == nil {
  1452. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  1453. }
  1454. oldValue, err := m.oldValue(ctx)
  1455. if err != nil {
  1456. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  1457. }
  1458. return oldValue.UpdatedAt, nil
  1459. }
  1460. // ResetUpdatedAt resets all changes to the "updated_at" field.
  1461. func (m *TaskMutation) ResetUpdatedAt() {
  1462. m.updated_at = nil
  1463. }
  1464. // SetStatus sets the "status" field.
  1465. func (m *TaskMutation) SetStatus(u uint8) {
  1466. m.status = &u
  1467. m.addstatus = nil
  1468. }
  1469. // Status returns the value of the "status" field in the mutation.
  1470. func (m *TaskMutation) Status() (r uint8, exists bool) {
  1471. v := m.status
  1472. if v == nil {
  1473. return
  1474. }
  1475. return *v, true
  1476. }
  1477. // OldStatus returns the old "status" field's value of the Task entity.
  1478. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1479. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1480. func (m *TaskMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  1481. if !m.op.Is(OpUpdateOne) {
  1482. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  1483. }
  1484. if m.id == nil || m.oldValue == nil {
  1485. return v, errors.New("OldStatus requires an ID field in the mutation")
  1486. }
  1487. oldValue, err := m.oldValue(ctx)
  1488. if err != nil {
  1489. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  1490. }
  1491. return oldValue.Status, nil
  1492. }
  1493. // AddStatus adds u to the "status" field.
  1494. func (m *TaskMutation) AddStatus(u int8) {
  1495. if m.addstatus != nil {
  1496. *m.addstatus += u
  1497. } else {
  1498. m.addstatus = &u
  1499. }
  1500. }
  1501. // AddedStatus returns the value that was added to the "status" field in this mutation.
  1502. func (m *TaskMutation) AddedStatus() (r int8, exists bool) {
  1503. v := m.addstatus
  1504. if v == nil {
  1505. return
  1506. }
  1507. return *v, true
  1508. }
  1509. // ClearStatus clears the value of the "status" field.
  1510. func (m *TaskMutation) ClearStatus() {
  1511. m.status = nil
  1512. m.addstatus = nil
  1513. m.clearedFields[task.FieldStatus] = struct{}{}
  1514. }
  1515. // StatusCleared returns if the "status" field was cleared in this mutation.
  1516. func (m *TaskMutation) StatusCleared() bool {
  1517. _, ok := m.clearedFields[task.FieldStatus]
  1518. return ok
  1519. }
  1520. // ResetStatus resets all changes to the "status" field.
  1521. func (m *TaskMutation) ResetStatus() {
  1522. m.status = nil
  1523. m.addstatus = nil
  1524. delete(m.clearedFields, task.FieldStatus)
  1525. }
  1526. // SetName sets the "name" field.
  1527. func (m *TaskMutation) SetName(s string) {
  1528. m.name = &s
  1529. }
  1530. // Name returns the value of the "name" field in the mutation.
  1531. func (m *TaskMutation) Name() (r string, exists bool) {
  1532. v := m.name
  1533. if v == nil {
  1534. return
  1535. }
  1536. return *v, true
  1537. }
  1538. // OldName returns the old "name" field's value of the Task entity.
  1539. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1540. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1541. func (m *TaskMutation) OldName(ctx context.Context) (v string, err error) {
  1542. if !m.op.Is(OpUpdateOne) {
  1543. return v, errors.New("OldName is only allowed on UpdateOne operations")
  1544. }
  1545. if m.id == nil || m.oldValue == nil {
  1546. return v, errors.New("OldName requires an ID field in the mutation")
  1547. }
  1548. oldValue, err := m.oldValue(ctx)
  1549. if err != nil {
  1550. return v, fmt.Errorf("querying old value for OldName: %w", err)
  1551. }
  1552. return oldValue.Name, nil
  1553. }
  1554. // ResetName resets all changes to the "name" field.
  1555. func (m *TaskMutation) ResetName() {
  1556. m.name = nil
  1557. }
  1558. // SetTaskGroup sets the "task_group" field.
  1559. func (m *TaskMutation) SetTaskGroup(s string) {
  1560. m.task_group = &s
  1561. }
  1562. // TaskGroup returns the value of the "task_group" field in the mutation.
  1563. func (m *TaskMutation) TaskGroup() (r string, exists bool) {
  1564. v := m.task_group
  1565. if v == nil {
  1566. return
  1567. }
  1568. return *v, true
  1569. }
  1570. // OldTaskGroup returns the old "task_group" field's value of the Task entity.
  1571. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1572. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1573. func (m *TaskMutation) OldTaskGroup(ctx context.Context) (v string, err error) {
  1574. if !m.op.Is(OpUpdateOne) {
  1575. return v, errors.New("OldTaskGroup is only allowed on UpdateOne operations")
  1576. }
  1577. if m.id == nil || m.oldValue == nil {
  1578. return v, errors.New("OldTaskGroup requires an ID field in the mutation")
  1579. }
  1580. oldValue, err := m.oldValue(ctx)
  1581. if err != nil {
  1582. return v, fmt.Errorf("querying old value for OldTaskGroup: %w", err)
  1583. }
  1584. return oldValue.TaskGroup, nil
  1585. }
  1586. // ResetTaskGroup resets all changes to the "task_group" field.
  1587. func (m *TaskMutation) ResetTaskGroup() {
  1588. m.task_group = nil
  1589. }
  1590. // SetCronExpression sets the "cron_expression" field.
  1591. func (m *TaskMutation) SetCronExpression(s string) {
  1592. m.cron_expression = &s
  1593. }
  1594. // CronExpression returns the value of the "cron_expression" field in the mutation.
  1595. func (m *TaskMutation) CronExpression() (r string, exists bool) {
  1596. v := m.cron_expression
  1597. if v == nil {
  1598. return
  1599. }
  1600. return *v, true
  1601. }
  1602. // OldCronExpression returns the old "cron_expression" field's value of the Task entity.
  1603. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1604. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1605. func (m *TaskMutation) OldCronExpression(ctx context.Context) (v string, err error) {
  1606. if !m.op.Is(OpUpdateOne) {
  1607. return v, errors.New("OldCronExpression is only allowed on UpdateOne operations")
  1608. }
  1609. if m.id == nil || m.oldValue == nil {
  1610. return v, errors.New("OldCronExpression requires an ID field in the mutation")
  1611. }
  1612. oldValue, err := m.oldValue(ctx)
  1613. if err != nil {
  1614. return v, fmt.Errorf("querying old value for OldCronExpression: %w", err)
  1615. }
  1616. return oldValue.CronExpression, nil
  1617. }
  1618. // ResetCronExpression resets all changes to the "cron_expression" field.
  1619. func (m *TaskMutation) ResetCronExpression() {
  1620. m.cron_expression = nil
  1621. }
  1622. // SetPattern sets the "pattern" field.
  1623. func (m *TaskMutation) SetPattern(s string) {
  1624. m.pattern = &s
  1625. }
  1626. // Pattern returns the value of the "pattern" field in the mutation.
  1627. func (m *TaskMutation) Pattern() (r string, exists bool) {
  1628. v := m.pattern
  1629. if v == nil {
  1630. return
  1631. }
  1632. return *v, true
  1633. }
  1634. // OldPattern returns the old "pattern" field's value of the Task entity.
  1635. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1636. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1637. func (m *TaskMutation) OldPattern(ctx context.Context) (v string, err error) {
  1638. if !m.op.Is(OpUpdateOne) {
  1639. return v, errors.New("OldPattern is only allowed on UpdateOne operations")
  1640. }
  1641. if m.id == nil || m.oldValue == nil {
  1642. return v, errors.New("OldPattern requires an ID field in the mutation")
  1643. }
  1644. oldValue, err := m.oldValue(ctx)
  1645. if err != nil {
  1646. return v, fmt.Errorf("querying old value for OldPattern: %w", err)
  1647. }
  1648. return oldValue.Pattern, nil
  1649. }
  1650. // ResetPattern resets all changes to the "pattern" field.
  1651. func (m *TaskMutation) ResetPattern() {
  1652. m.pattern = nil
  1653. }
  1654. // SetPayload sets the "payload" field.
  1655. func (m *TaskMutation) SetPayload(s string) {
  1656. m.payload = &s
  1657. }
  1658. // Payload returns the value of the "payload" field in the mutation.
  1659. func (m *TaskMutation) Payload() (r string, exists bool) {
  1660. v := m.payload
  1661. if v == nil {
  1662. return
  1663. }
  1664. return *v, true
  1665. }
  1666. // OldPayload returns the old "payload" field's value of the Task entity.
  1667. // If the Task object wasn't provided to the builder, the object is fetched from the database.
  1668. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1669. func (m *TaskMutation) OldPayload(ctx context.Context) (v string, err error) {
  1670. if !m.op.Is(OpUpdateOne) {
  1671. return v, errors.New("OldPayload is only allowed on UpdateOne operations")
  1672. }
  1673. if m.id == nil || m.oldValue == nil {
  1674. return v, errors.New("OldPayload requires an ID field in the mutation")
  1675. }
  1676. oldValue, err := m.oldValue(ctx)
  1677. if err != nil {
  1678. return v, fmt.Errorf("querying old value for OldPayload: %w", err)
  1679. }
  1680. return oldValue.Payload, nil
  1681. }
  1682. // ResetPayload resets all changes to the "payload" field.
  1683. func (m *TaskMutation) ResetPayload() {
  1684. m.payload = nil
  1685. }
  1686. // AddTaskLogIDs adds the "task_logs" edge to the TaskLog entity by ids.
  1687. func (m *TaskMutation) AddTaskLogIDs(ids ...uint64) {
  1688. if m.task_logs == nil {
  1689. m.task_logs = make(map[uint64]struct{})
  1690. }
  1691. for i := range ids {
  1692. m.task_logs[ids[i]] = struct{}{}
  1693. }
  1694. }
  1695. // ClearTaskLogs clears the "task_logs" edge to the TaskLog entity.
  1696. func (m *TaskMutation) ClearTaskLogs() {
  1697. m.clearedtask_logs = true
  1698. }
  1699. // TaskLogsCleared reports if the "task_logs" edge to the TaskLog entity was cleared.
  1700. func (m *TaskMutation) TaskLogsCleared() bool {
  1701. return m.clearedtask_logs
  1702. }
  1703. // RemoveTaskLogIDs removes the "task_logs" edge to the TaskLog entity by IDs.
  1704. func (m *TaskMutation) RemoveTaskLogIDs(ids ...uint64) {
  1705. if m.removedtask_logs == nil {
  1706. m.removedtask_logs = make(map[uint64]struct{})
  1707. }
  1708. for i := range ids {
  1709. delete(m.task_logs, ids[i])
  1710. m.removedtask_logs[ids[i]] = struct{}{}
  1711. }
  1712. }
  1713. // RemovedTaskLogs returns the removed IDs of the "task_logs" edge to the TaskLog entity.
  1714. func (m *TaskMutation) RemovedTaskLogsIDs() (ids []uint64) {
  1715. for id := range m.removedtask_logs {
  1716. ids = append(ids, id)
  1717. }
  1718. return
  1719. }
  1720. // TaskLogsIDs returns the "task_logs" edge IDs in the mutation.
  1721. func (m *TaskMutation) TaskLogsIDs() (ids []uint64) {
  1722. for id := range m.task_logs {
  1723. ids = append(ids, id)
  1724. }
  1725. return
  1726. }
  1727. // ResetTaskLogs resets all changes to the "task_logs" edge.
  1728. func (m *TaskMutation) ResetTaskLogs() {
  1729. m.task_logs = nil
  1730. m.clearedtask_logs = false
  1731. m.removedtask_logs = nil
  1732. }
  1733. // Where appends a list predicates to the TaskMutation builder.
  1734. func (m *TaskMutation) Where(ps ...predicate.Task) {
  1735. m.predicates = append(m.predicates, ps...)
  1736. }
  1737. // WhereP appends storage-level predicates to the TaskMutation builder. Using this method,
  1738. // users can use type-assertion to append predicates that do not depend on any generated package.
  1739. func (m *TaskMutation) WhereP(ps ...func(*sql.Selector)) {
  1740. p := make([]predicate.Task, len(ps))
  1741. for i := range ps {
  1742. p[i] = ps[i]
  1743. }
  1744. m.Where(p...)
  1745. }
  1746. // Op returns the operation name.
  1747. func (m *TaskMutation) Op() Op {
  1748. return m.op
  1749. }
  1750. // SetOp allows setting the mutation operation.
  1751. func (m *TaskMutation) SetOp(op Op) {
  1752. m.op = op
  1753. }
  1754. // Type returns the node type of this mutation (Task).
  1755. func (m *TaskMutation) Type() string {
  1756. return m.typ
  1757. }
  1758. // Fields returns all fields that were changed during this mutation. Note that in
  1759. // order to get all numeric fields that were incremented/decremented, call
  1760. // AddedFields().
  1761. func (m *TaskMutation) Fields() []string {
  1762. fields := make([]string, 0, 8)
  1763. if m.created_at != nil {
  1764. fields = append(fields, task.FieldCreatedAt)
  1765. }
  1766. if m.updated_at != nil {
  1767. fields = append(fields, task.FieldUpdatedAt)
  1768. }
  1769. if m.status != nil {
  1770. fields = append(fields, task.FieldStatus)
  1771. }
  1772. if m.name != nil {
  1773. fields = append(fields, task.FieldName)
  1774. }
  1775. if m.task_group != nil {
  1776. fields = append(fields, task.FieldTaskGroup)
  1777. }
  1778. if m.cron_expression != nil {
  1779. fields = append(fields, task.FieldCronExpression)
  1780. }
  1781. if m.pattern != nil {
  1782. fields = append(fields, task.FieldPattern)
  1783. }
  1784. if m.payload != nil {
  1785. fields = append(fields, task.FieldPayload)
  1786. }
  1787. return fields
  1788. }
  1789. // Field returns the value of a field with the given name. The second boolean
  1790. // return value indicates that this field was not set, or was not defined in the
  1791. // schema.
  1792. func (m *TaskMutation) Field(name string) (ent.Value, bool) {
  1793. switch name {
  1794. case task.FieldCreatedAt:
  1795. return m.CreatedAt()
  1796. case task.FieldUpdatedAt:
  1797. return m.UpdatedAt()
  1798. case task.FieldStatus:
  1799. return m.Status()
  1800. case task.FieldName:
  1801. return m.Name()
  1802. case task.FieldTaskGroup:
  1803. return m.TaskGroup()
  1804. case task.FieldCronExpression:
  1805. return m.CronExpression()
  1806. case task.FieldPattern:
  1807. return m.Pattern()
  1808. case task.FieldPayload:
  1809. return m.Payload()
  1810. }
  1811. return nil, false
  1812. }
  1813. // OldField returns the old value of the field from the database. An error is
  1814. // returned if the mutation operation is not UpdateOne, or the query to the
  1815. // database failed.
  1816. func (m *TaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  1817. switch name {
  1818. case task.FieldCreatedAt:
  1819. return m.OldCreatedAt(ctx)
  1820. case task.FieldUpdatedAt:
  1821. return m.OldUpdatedAt(ctx)
  1822. case task.FieldStatus:
  1823. return m.OldStatus(ctx)
  1824. case task.FieldName:
  1825. return m.OldName(ctx)
  1826. case task.FieldTaskGroup:
  1827. return m.OldTaskGroup(ctx)
  1828. case task.FieldCronExpression:
  1829. return m.OldCronExpression(ctx)
  1830. case task.FieldPattern:
  1831. return m.OldPattern(ctx)
  1832. case task.FieldPayload:
  1833. return m.OldPayload(ctx)
  1834. }
  1835. return nil, fmt.Errorf("unknown Task field %s", name)
  1836. }
  1837. // SetField sets the value of a field with the given name. It returns an error if
  1838. // the field is not defined in the schema, or if the type mismatched the field
  1839. // type.
  1840. func (m *TaskMutation) SetField(name string, value ent.Value) error {
  1841. switch name {
  1842. case task.FieldCreatedAt:
  1843. v, ok := value.(time.Time)
  1844. if !ok {
  1845. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1846. }
  1847. m.SetCreatedAt(v)
  1848. return nil
  1849. case task.FieldUpdatedAt:
  1850. v, ok := value.(time.Time)
  1851. if !ok {
  1852. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1853. }
  1854. m.SetUpdatedAt(v)
  1855. return nil
  1856. case task.FieldStatus:
  1857. v, ok := value.(uint8)
  1858. if !ok {
  1859. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1860. }
  1861. m.SetStatus(v)
  1862. return nil
  1863. case task.FieldName:
  1864. v, ok := value.(string)
  1865. if !ok {
  1866. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1867. }
  1868. m.SetName(v)
  1869. return nil
  1870. case task.FieldTaskGroup:
  1871. v, ok := value.(string)
  1872. if !ok {
  1873. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1874. }
  1875. m.SetTaskGroup(v)
  1876. return nil
  1877. case task.FieldCronExpression:
  1878. v, ok := value.(string)
  1879. if !ok {
  1880. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1881. }
  1882. m.SetCronExpression(v)
  1883. return nil
  1884. case task.FieldPattern:
  1885. v, ok := value.(string)
  1886. if !ok {
  1887. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1888. }
  1889. m.SetPattern(v)
  1890. return nil
  1891. case task.FieldPayload:
  1892. v, ok := value.(string)
  1893. if !ok {
  1894. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1895. }
  1896. m.SetPayload(v)
  1897. return nil
  1898. }
  1899. return fmt.Errorf("unknown Task field %s", name)
  1900. }
  1901. // AddedFields returns all numeric fields that were incremented/decremented during
  1902. // this mutation.
  1903. func (m *TaskMutation) AddedFields() []string {
  1904. var fields []string
  1905. if m.addstatus != nil {
  1906. fields = append(fields, task.FieldStatus)
  1907. }
  1908. return fields
  1909. }
  1910. // AddedField returns the numeric value that was incremented/decremented on a field
  1911. // with the given name. The second boolean return value indicates that this field
  1912. // was not set, or was not defined in the schema.
  1913. func (m *TaskMutation) AddedField(name string) (ent.Value, bool) {
  1914. switch name {
  1915. case task.FieldStatus:
  1916. return m.AddedStatus()
  1917. }
  1918. return nil, false
  1919. }
  1920. // AddField adds the value to the field with the given name. It returns an error if
  1921. // the field is not defined in the schema, or if the type mismatched the field
  1922. // type.
  1923. func (m *TaskMutation) AddField(name string, value ent.Value) error {
  1924. switch name {
  1925. case task.FieldStatus:
  1926. v, ok := value.(int8)
  1927. if !ok {
  1928. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1929. }
  1930. m.AddStatus(v)
  1931. return nil
  1932. }
  1933. return fmt.Errorf("unknown Task numeric field %s", name)
  1934. }
  1935. // ClearedFields returns all nullable fields that were cleared during this
  1936. // mutation.
  1937. func (m *TaskMutation) ClearedFields() []string {
  1938. var fields []string
  1939. if m.FieldCleared(task.FieldStatus) {
  1940. fields = append(fields, task.FieldStatus)
  1941. }
  1942. return fields
  1943. }
  1944. // FieldCleared returns a boolean indicating if a field with the given name was
  1945. // cleared in this mutation.
  1946. func (m *TaskMutation) FieldCleared(name string) bool {
  1947. _, ok := m.clearedFields[name]
  1948. return ok
  1949. }
  1950. // ClearField clears the value of the field with the given name. It returns an
  1951. // error if the field is not defined in the schema.
  1952. func (m *TaskMutation) ClearField(name string) error {
  1953. switch name {
  1954. case task.FieldStatus:
  1955. m.ClearStatus()
  1956. return nil
  1957. }
  1958. return fmt.Errorf("unknown Task nullable field %s", name)
  1959. }
  1960. // ResetField resets all changes in the mutation for the field with the given name.
  1961. // It returns an error if the field is not defined in the schema.
  1962. func (m *TaskMutation) ResetField(name string) error {
  1963. switch name {
  1964. case task.FieldCreatedAt:
  1965. m.ResetCreatedAt()
  1966. return nil
  1967. case task.FieldUpdatedAt:
  1968. m.ResetUpdatedAt()
  1969. return nil
  1970. case task.FieldStatus:
  1971. m.ResetStatus()
  1972. return nil
  1973. case task.FieldName:
  1974. m.ResetName()
  1975. return nil
  1976. case task.FieldTaskGroup:
  1977. m.ResetTaskGroup()
  1978. return nil
  1979. case task.FieldCronExpression:
  1980. m.ResetCronExpression()
  1981. return nil
  1982. case task.FieldPattern:
  1983. m.ResetPattern()
  1984. return nil
  1985. case task.FieldPayload:
  1986. m.ResetPayload()
  1987. return nil
  1988. }
  1989. return fmt.Errorf("unknown Task field %s", name)
  1990. }
  1991. // AddedEdges returns all edge names that were set/added in this mutation.
  1992. func (m *TaskMutation) AddedEdges() []string {
  1993. edges := make([]string, 0, 1)
  1994. if m.task_logs != nil {
  1995. edges = append(edges, task.EdgeTaskLogs)
  1996. }
  1997. return edges
  1998. }
  1999. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  2000. // name in this mutation.
  2001. func (m *TaskMutation) AddedIDs(name string) []ent.Value {
  2002. switch name {
  2003. case task.EdgeTaskLogs:
  2004. ids := make([]ent.Value, 0, len(m.task_logs))
  2005. for id := range m.task_logs {
  2006. ids = append(ids, id)
  2007. }
  2008. return ids
  2009. }
  2010. return nil
  2011. }
  2012. // RemovedEdges returns all edge names that were removed in this mutation.
  2013. func (m *TaskMutation) RemovedEdges() []string {
  2014. edges := make([]string, 0, 1)
  2015. if m.removedtask_logs != nil {
  2016. edges = append(edges, task.EdgeTaskLogs)
  2017. }
  2018. return edges
  2019. }
  2020. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  2021. // the given name in this mutation.
  2022. func (m *TaskMutation) RemovedIDs(name string) []ent.Value {
  2023. switch name {
  2024. case task.EdgeTaskLogs:
  2025. ids := make([]ent.Value, 0, len(m.removedtask_logs))
  2026. for id := range m.removedtask_logs {
  2027. ids = append(ids, id)
  2028. }
  2029. return ids
  2030. }
  2031. return nil
  2032. }
  2033. // ClearedEdges returns all edge names that were cleared in this mutation.
  2034. func (m *TaskMutation) ClearedEdges() []string {
  2035. edges := make([]string, 0, 1)
  2036. if m.clearedtask_logs {
  2037. edges = append(edges, task.EdgeTaskLogs)
  2038. }
  2039. return edges
  2040. }
  2041. // EdgeCleared returns a boolean which indicates if the edge with the given name
  2042. // was cleared in this mutation.
  2043. func (m *TaskMutation) EdgeCleared(name string) bool {
  2044. switch name {
  2045. case task.EdgeTaskLogs:
  2046. return m.clearedtask_logs
  2047. }
  2048. return false
  2049. }
  2050. // ClearEdge clears the value of the edge with the given name. It returns an error
  2051. // if that edge is not defined in the schema.
  2052. func (m *TaskMutation) ClearEdge(name string) error {
  2053. switch name {
  2054. }
  2055. return fmt.Errorf("unknown Task unique edge %s", name)
  2056. }
  2057. // ResetEdge resets all changes to the edge with the given name in this mutation.
  2058. // It returns an error if the edge is not defined in the schema.
  2059. func (m *TaskMutation) ResetEdge(name string) error {
  2060. switch name {
  2061. case task.EdgeTaskLogs:
  2062. m.ResetTaskLogs()
  2063. return nil
  2064. }
  2065. return fmt.Errorf("unknown Task edge %s", name)
  2066. }
  2067. // TaskLogMutation represents an operation that mutates the TaskLog nodes in the graph.
  2068. type TaskLogMutation struct {
  2069. config
  2070. op Op
  2071. typ string
  2072. id *uint64
  2073. started_at *time.Time
  2074. finished_at *time.Time
  2075. result *uint8
  2076. addresult *int8
  2077. clearedFields map[string]struct{}
  2078. tasks *uint64
  2079. clearedtasks bool
  2080. done bool
  2081. oldValue func(context.Context) (*TaskLog, error)
  2082. predicates []predicate.TaskLog
  2083. }
  2084. var _ ent.Mutation = (*TaskLogMutation)(nil)
  2085. // tasklogOption allows management of the mutation configuration using functional options.
  2086. type tasklogOption func(*TaskLogMutation)
  2087. // newTaskLogMutation creates new mutation for the TaskLog entity.
  2088. func newTaskLogMutation(c config, op Op, opts ...tasklogOption) *TaskLogMutation {
  2089. m := &TaskLogMutation{
  2090. config: c,
  2091. op: op,
  2092. typ: TypeTaskLog,
  2093. clearedFields: make(map[string]struct{}),
  2094. }
  2095. for _, opt := range opts {
  2096. opt(m)
  2097. }
  2098. return m
  2099. }
  2100. // withTaskLogID sets the ID field of the mutation.
  2101. func withTaskLogID(id uint64) tasklogOption {
  2102. return func(m *TaskLogMutation) {
  2103. var (
  2104. err error
  2105. once sync.Once
  2106. value *TaskLog
  2107. )
  2108. m.oldValue = func(ctx context.Context) (*TaskLog, error) {
  2109. once.Do(func() {
  2110. if m.done {
  2111. err = errors.New("querying old values post mutation is not allowed")
  2112. } else {
  2113. value, err = m.Client().TaskLog.Get(ctx, id)
  2114. }
  2115. })
  2116. return value, err
  2117. }
  2118. m.id = &id
  2119. }
  2120. }
  2121. // withTaskLog sets the old TaskLog of the mutation.
  2122. func withTaskLog(node *TaskLog) tasklogOption {
  2123. return func(m *TaskLogMutation) {
  2124. m.oldValue = func(context.Context) (*TaskLog, error) {
  2125. return node, nil
  2126. }
  2127. m.id = &node.ID
  2128. }
  2129. }
  2130. // Client returns a new `ent.Client` from the mutation. If the mutation was
  2131. // executed in a transaction (ent.Tx), a transactional client is returned.
  2132. func (m TaskLogMutation) Client() *Client {
  2133. client := &Client{config: m.config}
  2134. client.init()
  2135. return client
  2136. }
  2137. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  2138. // it returns an error otherwise.
  2139. func (m TaskLogMutation) Tx() (*Tx, error) {
  2140. if _, ok := m.driver.(*txDriver); !ok {
  2141. return nil, errors.New("ent: mutation is not running in a transaction")
  2142. }
  2143. tx := &Tx{config: m.config}
  2144. tx.init()
  2145. return tx, nil
  2146. }
  2147. // SetID sets the value of the id field. Note that this
  2148. // operation is only accepted on creation of TaskLog entities.
  2149. func (m *TaskLogMutation) SetID(id uint64) {
  2150. m.id = &id
  2151. }
  2152. // ID returns the ID value in the mutation. Note that the ID is only available
  2153. // if it was provided to the builder or after it was returned from the database.
  2154. func (m *TaskLogMutation) ID() (id uint64, exists bool) {
  2155. if m.id == nil {
  2156. return
  2157. }
  2158. return *m.id, true
  2159. }
  2160. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  2161. // That means, if the mutation is applied within a transaction with an isolation level such
  2162. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  2163. // or updated by the mutation.
  2164. func (m *TaskLogMutation) IDs(ctx context.Context) ([]uint64, error) {
  2165. switch {
  2166. case m.op.Is(OpUpdateOne | OpDeleteOne):
  2167. id, exists := m.ID()
  2168. if exists {
  2169. return []uint64{id}, nil
  2170. }
  2171. fallthrough
  2172. case m.op.Is(OpUpdate | OpDelete):
  2173. return m.Client().TaskLog.Query().Where(m.predicates...).IDs(ctx)
  2174. default:
  2175. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  2176. }
  2177. }
  2178. // SetStartedAt sets the "started_at" field.
  2179. func (m *TaskLogMutation) SetStartedAt(t time.Time) {
  2180. m.started_at = &t
  2181. }
  2182. // StartedAt returns the value of the "started_at" field in the mutation.
  2183. func (m *TaskLogMutation) StartedAt() (r time.Time, exists bool) {
  2184. v := m.started_at
  2185. if v == nil {
  2186. return
  2187. }
  2188. return *v, true
  2189. }
  2190. // OldStartedAt returns the old "started_at" field's value of the TaskLog entity.
  2191. // If the TaskLog object wasn't provided to the builder, the object is fetched from the database.
  2192. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2193. func (m *TaskLogMutation) OldStartedAt(ctx context.Context) (v time.Time, err error) {
  2194. if !m.op.Is(OpUpdateOne) {
  2195. return v, errors.New("OldStartedAt is only allowed on UpdateOne operations")
  2196. }
  2197. if m.id == nil || m.oldValue == nil {
  2198. return v, errors.New("OldStartedAt requires an ID field in the mutation")
  2199. }
  2200. oldValue, err := m.oldValue(ctx)
  2201. if err != nil {
  2202. return v, fmt.Errorf("querying old value for OldStartedAt: %w", err)
  2203. }
  2204. return oldValue.StartedAt, nil
  2205. }
  2206. // ResetStartedAt resets all changes to the "started_at" field.
  2207. func (m *TaskLogMutation) ResetStartedAt() {
  2208. m.started_at = nil
  2209. }
  2210. // SetFinishedAt sets the "finished_at" field.
  2211. func (m *TaskLogMutation) SetFinishedAt(t time.Time) {
  2212. m.finished_at = &t
  2213. }
  2214. // FinishedAt returns the value of the "finished_at" field in the mutation.
  2215. func (m *TaskLogMutation) FinishedAt() (r time.Time, exists bool) {
  2216. v := m.finished_at
  2217. if v == nil {
  2218. return
  2219. }
  2220. return *v, true
  2221. }
  2222. // OldFinishedAt returns the old "finished_at" field's value of the TaskLog entity.
  2223. // If the TaskLog object wasn't provided to the builder, the object is fetched from the database.
  2224. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2225. func (m *TaskLogMutation) OldFinishedAt(ctx context.Context) (v time.Time, err error) {
  2226. if !m.op.Is(OpUpdateOne) {
  2227. return v, errors.New("OldFinishedAt is only allowed on UpdateOne operations")
  2228. }
  2229. if m.id == nil || m.oldValue == nil {
  2230. return v, errors.New("OldFinishedAt requires an ID field in the mutation")
  2231. }
  2232. oldValue, err := m.oldValue(ctx)
  2233. if err != nil {
  2234. return v, fmt.Errorf("querying old value for OldFinishedAt: %w", err)
  2235. }
  2236. return oldValue.FinishedAt, nil
  2237. }
  2238. // ResetFinishedAt resets all changes to the "finished_at" field.
  2239. func (m *TaskLogMutation) ResetFinishedAt() {
  2240. m.finished_at = nil
  2241. }
  2242. // SetResult sets the "result" field.
  2243. func (m *TaskLogMutation) SetResult(u uint8) {
  2244. m.result = &u
  2245. m.addresult = nil
  2246. }
  2247. // Result returns the value of the "result" field in the mutation.
  2248. func (m *TaskLogMutation) Result() (r uint8, exists bool) {
  2249. v := m.result
  2250. if v == nil {
  2251. return
  2252. }
  2253. return *v, true
  2254. }
  2255. // OldResult returns the old "result" field's value of the TaskLog entity.
  2256. // If the TaskLog object wasn't provided to the builder, the object is fetched from the database.
  2257. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2258. func (m *TaskLogMutation) OldResult(ctx context.Context) (v uint8, err error) {
  2259. if !m.op.Is(OpUpdateOne) {
  2260. return v, errors.New("OldResult is only allowed on UpdateOne operations")
  2261. }
  2262. if m.id == nil || m.oldValue == nil {
  2263. return v, errors.New("OldResult requires an ID field in the mutation")
  2264. }
  2265. oldValue, err := m.oldValue(ctx)
  2266. if err != nil {
  2267. return v, fmt.Errorf("querying old value for OldResult: %w", err)
  2268. }
  2269. return oldValue.Result, nil
  2270. }
  2271. // AddResult adds u to the "result" field.
  2272. func (m *TaskLogMutation) AddResult(u int8) {
  2273. if m.addresult != nil {
  2274. *m.addresult += u
  2275. } else {
  2276. m.addresult = &u
  2277. }
  2278. }
  2279. // AddedResult returns the value that was added to the "result" field in this mutation.
  2280. func (m *TaskLogMutation) AddedResult() (r int8, exists bool) {
  2281. v := m.addresult
  2282. if v == nil {
  2283. return
  2284. }
  2285. return *v, true
  2286. }
  2287. // ResetResult resets all changes to the "result" field.
  2288. func (m *TaskLogMutation) ResetResult() {
  2289. m.result = nil
  2290. m.addresult = nil
  2291. }
  2292. // SetTasksID sets the "tasks" edge to the Task entity by id.
  2293. func (m *TaskLogMutation) SetTasksID(id uint64) {
  2294. m.tasks = &id
  2295. }
  2296. // ClearTasks clears the "tasks" edge to the Task entity.
  2297. func (m *TaskLogMutation) ClearTasks() {
  2298. m.clearedtasks = true
  2299. }
  2300. // TasksCleared reports if the "tasks" edge to the Task entity was cleared.
  2301. func (m *TaskLogMutation) TasksCleared() bool {
  2302. return m.clearedtasks
  2303. }
  2304. // TasksID returns the "tasks" edge ID in the mutation.
  2305. func (m *TaskLogMutation) TasksID() (id uint64, exists bool) {
  2306. if m.tasks != nil {
  2307. return *m.tasks, true
  2308. }
  2309. return
  2310. }
  2311. // TasksIDs returns the "tasks" edge IDs in the mutation.
  2312. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  2313. // TasksID instead. It exists only for internal usage by the builders.
  2314. func (m *TaskLogMutation) TasksIDs() (ids []uint64) {
  2315. if id := m.tasks; id != nil {
  2316. ids = append(ids, *id)
  2317. }
  2318. return
  2319. }
  2320. // ResetTasks resets all changes to the "tasks" edge.
  2321. func (m *TaskLogMutation) ResetTasks() {
  2322. m.tasks = nil
  2323. m.clearedtasks = false
  2324. }
  2325. // Where appends a list predicates to the TaskLogMutation builder.
  2326. func (m *TaskLogMutation) Where(ps ...predicate.TaskLog) {
  2327. m.predicates = append(m.predicates, ps...)
  2328. }
  2329. // WhereP appends storage-level predicates to the TaskLogMutation builder. Using this method,
  2330. // users can use type-assertion to append predicates that do not depend on any generated package.
  2331. func (m *TaskLogMutation) WhereP(ps ...func(*sql.Selector)) {
  2332. p := make([]predicate.TaskLog, len(ps))
  2333. for i := range ps {
  2334. p[i] = ps[i]
  2335. }
  2336. m.Where(p...)
  2337. }
  2338. // Op returns the operation name.
  2339. func (m *TaskLogMutation) Op() Op {
  2340. return m.op
  2341. }
  2342. // SetOp allows setting the mutation operation.
  2343. func (m *TaskLogMutation) SetOp(op Op) {
  2344. m.op = op
  2345. }
  2346. // Type returns the node type of this mutation (TaskLog).
  2347. func (m *TaskLogMutation) Type() string {
  2348. return m.typ
  2349. }
  2350. // Fields returns all fields that were changed during this mutation. Note that in
  2351. // order to get all numeric fields that were incremented/decremented, call
  2352. // AddedFields().
  2353. func (m *TaskLogMutation) Fields() []string {
  2354. fields := make([]string, 0, 3)
  2355. if m.started_at != nil {
  2356. fields = append(fields, tasklog.FieldStartedAt)
  2357. }
  2358. if m.finished_at != nil {
  2359. fields = append(fields, tasklog.FieldFinishedAt)
  2360. }
  2361. if m.result != nil {
  2362. fields = append(fields, tasklog.FieldResult)
  2363. }
  2364. return fields
  2365. }
  2366. // Field returns the value of a field with the given name. The second boolean
  2367. // return value indicates that this field was not set, or was not defined in the
  2368. // schema.
  2369. func (m *TaskLogMutation) Field(name string) (ent.Value, bool) {
  2370. switch name {
  2371. case tasklog.FieldStartedAt:
  2372. return m.StartedAt()
  2373. case tasklog.FieldFinishedAt:
  2374. return m.FinishedAt()
  2375. case tasklog.FieldResult:
  2376. return m.Result()
  2377. }
  2378. return nil, false
  2379. }
  2380. // OldField returns the old value of the field from the database. An error is
  2381. // returned if the mutation operation is not UpdateOne, or the query to the
  2382. // database failed.
  2383. func (m *TaskLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  2384. switch name {
  2385. case tasklog.FieldStartedAt:
  2386. return m.OldStartedAt(ctx)
  2387. case tasklog.FieldFinishedAt:
  2388. return m.OldFinishedAt(ctx)
  2389. case tasklog.FieldResult:
  2390. return m.OldResult(ctx)
  2391. }
  2392. return nil, fmt.Errorf("unknown TaskLog field %s", name)
  2393. }
  2394. // SetField sets the value of a field with the given name. It returns an error if
  2395. // the field is not defined in the schema, or if the type mismatched the field
  2396. // type.
  2397. func (m *TaskLogMutation) SetField(name string, value ent.Value) error {
  2398. switch name {
  2399. case tasklog.FieldStartedAt:
  2400. v, ok := value.(time.Time)
  2401. if !ok {
  2402. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2403. }
  2404. m.SetStartedAt(v)
  2405. return nil
  2406. case tasklog.FieldFinishedAt:
  2407. v, ok := value.(time.Time)
  2408. if !ok {
  2409. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2410. }
  2411. m.SetFinishedAt(v)
  2412. return nil
  2413. case tasklog.FieldResult:
  2414. v, ok := value.(uint8)
  2415. if !ok {
  2416. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2417. }
  2418. m.SetResult(v)
  2419. return nil
  2420. }
  2421. return fmt.Errorf("unknown TaskLog field %s", name)
  2422. }
  2423. // AddedFields returns all numeric fields that were incremented/decremented during
  2424. // this mutation.
  2425. func (m *TaskLogMutation) AddedFields() []string {
  2426. var fields []string
  2427. if m.addresult != nil {
  2428. fields = append(fields, tasklog.FieldResult)
  2429. }
  2430. return fields
  2431. }
  2432. // AddedField returns the numeric value that was incremented/decremented on a field
  2433. // with the given name. The second boolean return value indicates that this field
  2434. // was not set, or was not defined in the schema.
  2435. func (m *TaskLogMutation) AddedField(name string) (ent.Value, bool) {
  2436. switch name {
  2437. case tasklog.FieldResult:
  2438. return m.AddedResult()
  2439. }
  2440. return nil, false
  2441. }
  2442. // AddField adds the value to the field with the given name. It returns an error if
  2443. // the field is not defined in the schema, or if the type mismatched the field
  2444. // type.
  2445. func (m *TaskLogMutation) AddField(name string, value ent.Value) error {
  2446. switch name {
  2447. case tasklog.FieldResult:
  2448. v, ok := value.(int8)
  2449. if !ok {
  2450. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2451. }
  2452. m.AddResult(v)
  2453. return nil
  2454. }
  2455. return fmt.Errorf("unknown TaskLog numeric field %s", name)
  2456. }
  2457. // ClearedFields returns all nullable fields that were cleared during this
  2458. // mutation.
  2459. func (m *TaskLogMutation) ClearedFields() []string {
  2460. return nil
  2461. }
  2462. // FieldCleared returns a boolean indicating if a field with the given name was
  2463. // cleared in this mutation.
  2464. func (m *TaskLogMutation) FieldCleared(name string) bool {
  2465. _, ok := m.clearedFields[name]
  2466. return ok
  2467. }
  2468. // ClearField clears the value of the field with the given name. It returns an
  2469. // error if the field is not defined in the schema.
  2470. func (m *TaskLogMutation) ClearField(name string) error {
  2471. return fmt.Errorf("unknown TaskLog nullable field %s", name)
  2472. }
  2473. // ResetField resets all changes in the mutation for the field with the given name.
  2474. // It returns an error if the field is not defined in the schema.
  2475. func (m *TaskLogMutation) ResetField(name string) error {
  2476. switch name {
  2477. case tasklog.FieldStartedAt:
  2478. m.ResetStartedAt()
  2479. return nil
  2480. case tasklog.FieldFinishedAt:
  2481. m.ResetFinishedAt()
  2482. return nil
  2483. case tasklog.FieldResult:
  2484. m.ResetResult()
  2485. return nil
  2486. }
  2487. return fmt.Errorf("unknown TaskLog field %s", name)
  2488. }
  2489. // AddedEdges returns all edge names that were set/added in this mutation.
  2490. func (m *TaskLogMutation) AddedEdges() []string {
  2491. edges := make([]string, 0, 1)
  2492. if m.tasks != nil {
  2493. edges = append(edges, tasklog.EdgeTasks)
  2494. }
  2495. return edges
  2496. }
  2497. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  2498. // name in this mutation.
  2499. func (m *TaskLogMutation) AddedIDs(name string) []ent.Value {
  2500. switch name {
  2501. case tasklog.EdgeTasks:
  2502. if id := m.tasks; id != nil {
  2503. return []ent.Value{*id}
  2504. }
  2505. }
  2506. return nil
  2507. }
  2508. // RemovedEdges returns all edge names that were removed in this mutation.
  2509. func (m *TaskLogMutation) RemovedEdges() []string {
  2510. edges := make([]string, 0, 1)
  2511. return edges
  2512. }
  2513. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  2514. // the given name in this mutation.
  2515. func (m *TaskLogMutation) RemovedIDs(name string) []ent.Value {
  2516. return nil
  2517. }
  2518. // ClearedEdges returns all edge names that were cleared in this mutation.
  2519. func (m *TaskLogMutation) ClearedEdges() []string {
  2520. edges := make([]string, 0, 1)
  2521. if m.clearedtasks {
  2522. edges = append(edges, tasklog.EdgeTasks)
  2523. }
  2524. return edges
  2525. }
  2526. // EdgeCleared returns a boolean which indicates if the edge with the given name
  2527. // was cleared in this mutation.
  2528. func (m *TaskLogMutation) EdgeCleared(name string) bool {
  2529. switch name {
  2530. case tasklog.EdgeTasks:
  2531. return m.clearedtasks
  2532. }
  2533. return false
  2534. }
  2535. // ClearEdge clears the value of the edge with the given name. It returns an error
  2536. // if that edge is not defined in the schema.
  2537. func (m *TaskLogMutation) ClearEdge(name string) error {
  2538. switch name {
  2539. case tasklog.EdgeTasks:
  2540. m.ClearTasks()
  2541. return nil
  2542. }
  2543. return fmt.Errorf("unknown TaskLog unique edge %s", name)
  2544. }
  2545. // ResetEdge resets all changes to the edge with the given name in this mutation.
  2546. // It returns an error if the edge is not defined in the schema.
  2547. func (m *TaskLogMutation) ResetEdge(name string) error {
  2548. switch name {
  2549. case tasklog.EdgeTasks:
  2550. m.ResetTasks()
  2551. return nil
  2552. }
  2553. return fmt.Errorf("unknown TaskLog edge %s", name)
  2554. }