channelmonitor_create.go 63 KB

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