2 Star 0 Fork 0

广东宇凌网络科技有限公司/simple-iot-basic-rpc

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
device_create.go 73.57 KB
一键复制 编辑 原始数据 按行查看 历史
HienGee 提交于 2024-05-24 14:52 +08:00 . 设备增加操作状态字段
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"gitee.com/yuLingNet/simple-iot-basic-rpc/ent/company"
"gitee.com/yuLingNet/simple-iot-basic-rpc/ent/device"
"gitee.com/yuLingNet/simple-iot-basic-rpc/ent/deviceprop"
"gitee.com/yuLingNet/simple-iot-basic-rpc/ent/member"
"gitee.com/yuLingNet/simple-iot-basic-rpc/ent/product"
uuid "github.com/gofrs/uuid/v5"
)
// DeviceCreate is the builder for creating a Device entity.
type DeviceCreate struct {
config
mutation *DeviceMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (dc *DeviceCreate) SetCreatedAt(t time.Time) *DeviceCreate {
dc.mutation.SetCreatedAt(t)
return dc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableCreatedAt(t *time.Time) *DeviceCreate {
if t != nil {
dc.SetCreatedAt(*t)
}
return dc
}
// SetUpdatedAt sets the "updated_at" field.
func (dc *DeviceCreate) SetUpdatedAt(t time.Time) *DeviceCreate {
dc.mutation.SetUpdatedAt(t)
return dc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableUpdatedAt(t *time.Time) *DeviceCreate {
if t != nil {
dc.SetUpdatedAt(*t)
}
return dc
}
// SetStatus sets the "status" field.
func (dc *DeviceCreate) SetStatus(u uint8) *DeviceCreate {
dc.mutation.SetStatus(u)
return dc
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableStatus(u *uint8) *DeviceCreate {
if u != nil {
dc.SetStatus(*u)
}
return dc
}
// SetSort sets the "sort" field.
func (dc *DeviceCreate) SetSort(u uint32) *DeviceCreate {
dc.mutation.SetSort(u)
return dc
}
// SetNillableSort sets the "sort" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableSort(u *uint32) *DeviceCreate {
if u != nil {
dc.SetSort(*u)
}
return dc
}
// SetProductKey sets the "productKey" field.
func (dc *DeviceCreate) SetProductKey(s string) *DeviceCreate {
dc.mutation.SetProductKey(s)
return dc
}
// SetIotID sets the "iotID" field.
func (dc *DeviceCreate) SetIotID(s string) *DeviceCreate {
dc.mutation.SetIotID(s)
return dc
}
// SetDeviceName sets the "deviceName" field.
func (dc *DeviceCreate) SetDeviceName(s string) *DeviceCreate {
dc.mutation.SetDeviceName(s)
return dc
}
// SetDeviceSecret sets the "deviceSecret" field.
func (dc *DeviceCreate) SetDeviceSecret(s string) *DeviceCreate {
dc.mutation.SetDeviceSecret(s)
return dc
}
// SetNillableDeviceSecret sets the "deviceSecret" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableDeviceSecret(s *string) *DeviceCreate {
if s != nil {
dc.SetDeviceSecret(*s)
}
return dc
}
// SetDeviceStatus sets the "deviceStatus" field.
func (dc *DeviceCreate) SetDeviceStatus(s string) *DeviceCreate {
dc.mutation.SetDeviceStatus(s)
return dc
}
// SetNillableDeviceStatus sets the "deviceStatus" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableDeviceStatus(s *string) *DeviceCreate {
if s != nil {
dc.SetDeviceStatus(*s)
}
return dc
}
// SetNickname sets the "nickname" field.
func (dc *DeviceCreate) SetNickname(s string) *DeviceCreate {
dc.mutation.SetNickname(s)
return dc
}
// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableNickname(s *string) *DeviceCreate {
if s != nil {
dc.SetNickname(*s)
}
return dc
}
// SetGmtCreate sets the "gmtCreate" field.
func (dc *DeviceCreate) SetGmtCreate(s string) *DeviceCreate {
dc.mutation.SetGmtCreate(s)
return dc
}
// SetNillableGmtCreate sets the "gmtCreate" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableGmtCreate(s *string) *DeviceCreate {
if s != nil {
dc.SetGmtCreate(*s)
}
return dc
}
// SetGmtModified sets the "gmtModified" field.
func (dc *DeviceCreate) SetGmtModified(s string) *DeviceCreate {
dc.mutation.SetGmtModified(s)
return dc
}
// SetNillableGmtModified sets the "gmtModified" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableGmtModified(s *string) *DeviceCreate {
if s != nil {
dc.SetGmtModified(*s)
}
return dc
}
// SetUtcCreate sets the "utcCreate" field.
func (dc *DeviceCreate) SetUtcCreate(s string) *DeviceCreate {
dc.mutation.SetUtcCreate(s)
return dc
}
// SetNillableUtcCreate sets the "utcCreate" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableUtcCreate(s *string) *DeviceCreate {
if s != nil {
dc.SetUtcCreate(*s)
}
return dc
}
// SetUtcModified sets the "utcModified" field.
func (dc *DeviceCreate) SetUtcModified(s string) *DeviceCreate {
dc.mutation.SetUtcModified(s)
return dc
}
// SetNillableUtcModified sets the "utcModified" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableUtcModified(s *string) *DeviceCreate {
if s != nil {
dc.SetUtcModified(*s)
}
return dc
}
// SetOperationalStatusCode sets the "operationalStatusCode" field.
func (dc *DeviceCreate) SetOperationalStatusCode(s string) *DeviceCreate {
dc.mutation.SetOperationalStatusCode(s)
return dc
}
// SetNillableOperationalStatusCode sets the "operationalStatusCode" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableOperationalStatusCode(s *string) *DeviceCreate {
if s != nil {
dc.SetOperationalStatusCode(*s)
}
return dc
}
// SetOperationalStatus sets the "operationalStatus" field.
func (dc *DeviceCreate) SetOperationalStatus(s string) *DeviceCreate {
dc.mutation.SetOperationalStatus(s)
return dc
}
// SetNillableOperationalStatus sets the "operationalStatus" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableOperationalStatus(s *string) *DeviceCreate {
if s != nil {
dc.SetOperationalStatus(*s)
}
return dc
}
// SetTag sets the "tag" field.
func (dc *DeviceCreate) SetTag(u uint64) *DeviceCreate {
dc.mutation.SetTag(u)
return dc
}
// SetNillableTag sets the "tag" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableTag(u *uint64) *DeviceCreate {
if u != nil {
dc.SetTag(*u)
}
return dc
}
// SetFirmwareVersion sets the "firmwareVersion" field.
func (dc *DeviceCreate) SetFirmwareVersion(s string) *DeviceCreate {
dc.mutation.SetFirmwareVersion(s)
return dc
}
// SetNillableFirmwareVersion sets the "firmwareVersion" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableFirmwareVersion(s *string) *DeviceCreate {
if s != nil {
dc.SetFirmwareVersion(*s)
}
return dc
}
// SetGmtActive sets the "gmtActive" field.
func (dc *DeviceCreate) SetGmtActive(s string) *DeviceCreate {
dc.mutation.SetGmtActive(s)
return dc
}
// SetNillableGmtActive sets the "gmtActive" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableGmtActive(s *string) *DeviceCreate {
if s != nil {
dc.SetGmtActive(*s)
}
return dc
}
// SetGmtOnline sets the "gmtOnline" field.
func (dc *DeviceCreate) SetGmtOnline(s string) *DeviceCreate {
dc.mutation.SetGmtOnline(s)
return dc
}
// SetNillableGmtOnline sets the "gmtOnline" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableGmtOnline(s *string) *DeviceCreate {
if s != nil {
dc.SetGmtOnline(*s)
}
return dc
}
// SetIPAddress sets the "IPAddress" field.
func (dc *DeviceCreate) SetIPAddress(s string) *DeviceCreate {
dc.mutation.SetIPAddress(s)
return dc
}
// SetNillableIPAddress sets the "IPAddress" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableIPAddress(s *string) *DeviceCreate {
if s != nil {
dc.SetIPAddress(*s)
}
return dc
}
// SetNodeType sets the "nodeType" field.
func (dc *DeviceCreate) SetNodeType(i int32) *DeviceCreate {
dc.mutation.SetNodeType(i)
return dc
}
// SetNillableNodeType sets the "nodeType" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableNodeType(i *int32) *DeviceCreate {
if i != nil {
dc.SetNodeType(*i)
}
return dc
}
// SetOwner sets the "owner" field.
func (dc *DeviceCreate) SetOwner(b bool) *DeviceCreate {
dc.mutation.SetOwner(b)
return dc
}
// SetNillableOwner sets the "owner" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableOwner(b *bool) *DeviceCreate {
if b != nil {
dc.SetOwner(*b)
}
return dc
}
// SetProductName sets the "productName" field.
func (dc *DeviceCreate) SetProductName(s string) *DeviceCreate {
dc.mutation.SetProductName(s)
return dc
}
// SetNillableProductName sets the "productName" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableProductName(s *string) *DeviceCreate {
if s != nil {
dc.SetProductName(*s)
}
return dc
}
// SetRegion sets the "region" field.
func (dc *DeviceCreate) SetRegion(s string) *DeviceCreate {
dc.mutation.SetRegion(s)
return dc
}
// SetNillableRegion sets the "region" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableRegion(s *string) *DeviceCreate {
if s != nil {
dc.SetRegion(*s)
}
return dc
}
// SetUtcActive sets the "utcActive" field.
func (dc *DeviceCreate) SetUtcActive(s string) *DeviceCreate {
dc.mutation.SetUtcActive(s)
return dc
}
// SetNillableUtcActive sets the "utcActive" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableUtcActive(s *string) *DeviceCreate {
if s != nil {
dc.SetUtcActive(*s)
}
return dc
}
// SetUtcOnline sets the "utcOnline" field.
func (dc *DeviceCreate) SetUtcOnline(s string) *DeviceCreate {
dc.mutation.SetUtcOnline(s)
return dc
}
// SetNillableUtcOnline sets the "utcOnline" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableUtcOnline(s *string) *DeviceCreate {
if s != nil {
dc.SetUtcOnline(*s)
}
return dc
}
// SetID sets the "id" field.
func (dc *DeviceCreate) SetID(u uuid.UUID) *DeviceCreate {
dc.mutation.SetID(u)
return dc
}
// SetNillableID sets the "id" field if the given value is not nil.
func (dc *DeviceCreate) SetNillableID(u *uuid.UUID) *DeviceCreate {
if u != nil {
dc.SetID(*u)
}
return dc
}
// SetProductID sets the "product" edge to the Product entity by ID.
func (dc *DeviceCreate) SetProductID(id uuid.UUID) *DeviceCreate {
dc.mutation.SetProductID(id)
return dc
}
// SetNillableProductID sets the "product" edge to the Product entity by ID if the given value is not nil.
func (dc *DeviceCreate) SetNillableProductID(id *uuid.UUID) *DeviceCreate {
if id != nil {
dc = dc.SetProductID(*id)
}
return dc
}
// SetProduct sets the "product" edge to the Product entity.
func (dc *DeviceCreate) SetProduct(p *Product) *DeviceCreate {
return dc.SetProductID(p.ID)
}
// SetPropID sets the "prop" edge to the DeviceProp entity by ID.
func (dc *DeviceCreate) SetPropID(id uint64) *DeviceCreate {
dc.mutation.SetPropID(id)
return dc
}
// SetNillablePropID sets the "prop" edge to the DeviceProp entity by ID if the given value is not nil.
func (dc *DeviceCreate) SetNillablePropID(id *uint64) *DeviceCreate {
if id != nil {
dc = dc.SetPropID(*id)
}
return dc
}
// SetProp sets the "prop" edge to the DeviceProp entity.
func (dc *DeviceCreate) SetProp(d *DeviceProp) *DeviceCreate {
return dc.SetPropID(d.ID)
}
// AddCompanyIDs adds the "companies" edge to the Company entity by IDs.
func (dc *DeviceCreate) AddCompanyIDs(ids ...uint64) *DeviceCreate {
dc.mutation.AddCompanyIDs(ids...)
return dc
}
// AddCompanies adds the "companies" edges to the Company entity.
func (dc *DeviceCreate) AddCompanies(c ...*Company) *DeviceCreate {
ids := make([]uint64, len(c))
for i := range c {
ids[i] = c[i].ID
}
return dc.AddCompanyIDs(ids...)
}
// AddMemberIDs adds the "members" edge to the Member entity by IDs.
func (dc *DeviceCreate) AddMemberIDs(ids ...uuid.UUID) *DeviceCreate {
dc.mutation.AddMemberIDs(ids...)
return dc
}
// AddMembers adds the "members" edges to the Member entity.
func (dc *DeviceCreate) AddMembers(m ...*Member) *DeviceCreate {
ids := make([]uuid.UUID, len(m))
for i := range m {
ids[i] = m[i].ID
}
return dc.AddMemberIDs(ids...)
}
// Mutation returns the DeviceMutation object of the builder.
func (dc *DeviceCreate) Mutation() *DeviceMutation {
return dc.mutation
}
// Save creates the Device in the database.
func (dc *DeviceCreate) Save(ctx context.Context) (*Device, error) {
dc.defaults()
return withHooks(ctx, dc.sqlSave, dc.mutation, dc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (dc *DeviceCreate) SaveX(ctx context.Context) *Device {
v, err := dc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dc *DeviceCreate) Exec(ctx context.Context) error {
_, err := dc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dc *DeviceCreate) ExecX(ctx context.Context) {
if err := dc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dc *DeviceCreate) defaults() {
if _, ok := dc.mutation.CreatedAt(); !ok {
v := device.DefaultCreatedAt()
dc.mutation.SetCreatedAt(v)
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
v := device.DefaultUpdatedAt()
dc.mutation.SetUpdatedAt(v)
}
if _, ok := dc.mutation.Status(); !ok {
v := device.DefaultStatus
dc.mutation.SetStatus(v)
}
if _, ok := dc.mutation.Sort(); !ok {
v := device.DefaultSort
dc.mutation.SetSort(v)
}
if _, ok := dc.mutation.OperationalStatus(); !ok {
v := device.DefaultOperationalStatus
dc.mutation.SetOperationalStatus(v)
}
if _, ok := dc.mutation.NodeType(); !ok {
v := device.DefaultNodeType
dc.mutation.SetNodeType(v)
}
if _, ok := dc.mutation.Owner(); !ok {
v := device.DefaultOwner
dc.mutation.SetOwner(v)
}
if _, ok := dc.mutation.ID(); !ok {
v := device.DefaultID()
dc.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (dc *DeviceCreate) check() error {
if _, ok := dc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Device.created_at"`)}
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Device.updated_at"`)}
}
if _, ok := dc.mutation.Sort(); !ok {
return &ValidationError{Name: "sort", err: errors.New(`ent: missing required field "Device.sort"`)}
}
if _, ok := dc.mutation.ProductKey(); !ok {
return &ValidationError{Name: "productKey", err: errors.New(`ent: missing required field "Device.productKey"`)}
}
if _, ok := dc.mutation.IotID(); !ok {
return &ValidationError{Name: "iotID", err: errors.New(`ent: missing required field "Device.iotID"`)}
}
if _, ok := dc.mutation.DeviceName(); !ok {
return &ValidationError{Name: "deviceName", err: errors.New(`ent: missing required field "Device.deviceName"`)}
}
if _, ok := dc.mutation.NodeType(); !ok {
return &ValidationError{Name: "nodeType", err: errors.New(`ent: missing required field "Device.nodeType"`)}
}
return nil
}
func (dc *DeviceCreate) sqlSave(ctx context.Context) (*Device, error) {
if err := dc.check(); err != nil {
return nil, err
}
_node, _spec := dc.createSpec()
if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != nil {
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
_node.ID = *id
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
return nil, err
}
}
dc.mutation.id = &_node.ID
dc.mutation.done = true
return _node, nil
}
func (dc *DeviceCreate) createSpec() (*Device, *sqlgraph.CreateSpec) {
var (
_node = &Device{config: dc.config}
_spec = sqlgraph.NewCreateSpec(device.Table, sqlgraph.NewFieldSpec(device.FieldID, field.TypeUUID))
)
_spec.OnConflict = dc.conflict
if id, ok := dc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := dc.mutation.CreatedAt(); ok {
_spec.SetField(device.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := dc.mutation.UpdatedAt(); ok {
_spec.SetField(device.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := dc.mutation.Status(); ok {
_spec.SetField(device.FieldStatus, field.TypeUint8, value)
_node.Status = value
}
if value, ok := dc.mutation.Sort(); ok {
_spec.SetField(device.FieldSort, field.TypeUint32, value)
_node.Sort = value
}
if value, ok := dc.mutation.ProductKey(); ok {
_spec.SetField(device.FieldProductKey, field.TypeString, value)
_node.ProductKey = value
}
if value, ok := dc.mutation.IotID(); ok {
_spec.SetField(device.FieldIotID, field.TypeString, value)
_node.IotID = value
}
if value, ok := dc.mutation.DeviceName(); ok {
_spec.SetField(device.FieldDeviceName, field.TypeString, value)
_node.DeviceName = value
}
if value, ok := dc.mutation.DeviceSecret(); ok {
_spec.SetField(device.FieldDeviceSecret, field.TypeString, value)
_node.DeviceSecret = value
}
if value, ok := dc.mutation.DeviceStatus(); ok {
_spec.SetField(device.FieldDeviceStatus, field.TypeString, value)
_node.DeviceStatus = value
}
if value, ok := dc.mutation.Nickname(); ok {
_spec.SetField(device.FieldNickname, field.TypeString, value)
_node.Nickname = value
}
if value, ok := dc.mutation.GmtCreate(); ok {
_spec.SetField(device.FieldGmtCreate, field.TypeString, value)
_node.GmtCreate = value
}
if value, ok := dc.mutation.GmtModified(); ok {
_spec.SetField(device.FieldGmtModified, field.TypeString, value)
_node.GmtModified = value
}
if value, ok := dc.mutation.UtcCreate(); ok {
_spec.SetField(device.FieldUtcCreate, field.TypeString, value)
_node.UtcCreate = value
}
if value, ok := dc.mutation.UtcModified(); ok {
_spec.SetField(device.FieldUtcModified, field.TypeString, value)
_node.UtcModified = value
}
if value, ok := dc.mutation.OperationalStatusCode(); ok {
_spec.SetField(device.FieldOperationalStatusCode, field.TypeString, value)
_node.OperationalStatusCode = value
}
if value, ok := dc.mutation.OperationalStatus(); ok {
_spec.SetField(device.FieldOperationalStatus, field.TypeString, value)
_node.OperationalStatus = value
}
if value, ok := dc.mutation.Tag(); ok {
_spec.SetField(device.FieldTag, field.TypeUint64, value)
_node.Tag = value
}
if value, ok := dc.mutation.FirmwareVersion(); ok {
_spec.SetField(device.FieldFirmwareVersion, field.TypeString, value)
_node.FirmwareVersion = value
}
if value, ok := dc.mutation.GmtActive(); ok {
_spec.SetField(device.FieldGmtActive, field.TypeString, value)
_node.GmtActive = value
}
if value, ok := dc.mutation.GmtOnline(); ok {
_spec.SetField(device.FieldGmtOnline, field.TypeString, value)
_node.GmtOnline = value
}
if value, ok := dc.mutation.IPAddress(); ok {
_spec.SetField(device.FieldIPAddress, field.TypeString, value)
_node.IPAddress = value
}
if value, ok := dc.mutation.NodeType(); ok {
_spec.SetField(device.FieldNodeType, field.TypeInt32, value)
_node.NodeType = value
}
if value, ok := dc.mutation.Owner(); ok {
_spec.SetField(device.FieldOwner, field.TypeBool, value)
_node.Owner = value
}
if value, ok := dc.mutation.ProductName(); ok {
_spec.SetField(device.FieldProductName, field.TypeString, value)
_node.ProductName = value
}
if value, ok := dc.mutation.Region(); ok {
_spec.SetField(device.FieldRegion, field.TypeString, value)
_node.Region = value
}
if value, ok := dc.mutation.UtcActive(); ok {
_spec.SetField(device.FieldUtcActive, field.TypeString, value)
_node.UtcActive = value
}
if value, ok := dc.mutation.UtcOnline(); ok {
_spec.SetField(device.FieldUtcOnline, field.TypeString, value)
_node.UtcOnline = value
}
if nodes := dc.mutation.ProductIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: device.ProductTable,
Columns: []string{device.ProductColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(product.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.product_devices = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := dc.mutation.PropIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: false,
Table: device.PropTable,
Columns: []string{device.PropColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(deviceprop.FieldID, field.TypeUint64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := dc.mutation.CompaniesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: device.CompaniesTable,
Columns: device.CompaniesPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(company.FieldID, field.TypeUint64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := dc.mutation.MembersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: device.MembersTable,
Columns: device.MembersPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(member.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Device.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.DeviceUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dc *DeviceCreate) OnConflict(opts ...sql.ConflictOption) *DeviceUpsertOne {
dc.conflict = opts
return &DeviceUpsertOne{
create: dc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Device.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dc *DeviceCreate) OnConflictColumns(columns ...string) *DeviceUpsertOne {
dc.conflict = append(dc.conflict, sql.ConflictColumns(columns...))
return &DeviceUpsertOne{
create: dc,
}
}
type (
// DeviceUpsertOne is the builder for "upsert"-ing
// one Device node.
DeviceUpsertOne struct {
create *DeviceCreate
}
// DeviceUpsert is the "OnConflict" setter.
DeviceUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceUpsert) SetUpdatedAt(v time.Time) *DeviceUpsert {
u.Set(device.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateUpdatedAt() *DeviceUpsert {
u.SetExcluded(device.FieldUpdatedAt)
return u
}
// SetStatus sets the "status" field.
func (u *DeviceUpsert) SetStatus(v uint8) *DeviceUpsert {
u.Set(device.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateStatus() *DeviceUpsert {
u.SetExcluded(device.FieldStatus)
return u
}
// AddStatus adds v to the "status" field.
func (u *DeviceUpsert) AddStatus(v uint8) *DeviceUpsert {
u.Add(device.FieldStatus, v)
return u
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceUpsert) ClearStatus() *DeviceUpsert {
u.SetNull(device.FieldStatus)
return u
}
// SetSort sets the "sort" field.
func (u *DeviceUpsert) SetSort(v uint32) *DeviceUpsert {
u.Set(device.FieldSort, v)
return u
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateSort() *DeviceUpsert {
u.SetExcluded(device.FieldSort)
return u
}
// AddSort adds v to the "sort" field.
func (u *DeviceUpsert) AddSort(v uint32) *DeviceUpsert {
u.Add(device.FieldSort, v)
return u
}
// SetProductKey sets the "productKey" field.
func (u *DeviceUpsert) SetProductKey(v string) *DeviceUpsert {
u.Set(device.FieldProductKey, v)
return u
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateProductKey() *DeviceUpsert {
u.SetExcluded(device.FieldProductKey)
return u
}
// SetIotID sets the "iotID" field.
func (u *DeviceUpsert) SetIotID(v string) *DeviceUpsert {
u.Set(device.FieldIotID, v)
return u
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateIotID() *DeviceUpsert {
u.SetExcluded(device.FieldIotID)
return u
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceUpsert) SetDeviceName(v string) *DeviceUpsert {
u.Set(device.FieldDeviceName, v)
return u
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateDeviceName() *DeviceUpsert {
u.SetExcluded(device.FieldDeviceName)
return u
}
// SetDeviceSecret sets the "deviceSecret" field.
func (u *DeviceUpsert) SetDeviceSecret(v string) *DeviceUpsert {
u.Set(device.FieldDeviceSecret, v)
return u
}
// UpdateDeviceSecret sets the "deviceSecret" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateDeviceSecret() *DeviceUpsert {
u.SetExcluded(device.FieldDeviceSecret)
return u
}
// ClearDeviceSecret clears the value of the "deviceSecret" field.
func (u *DeviceUpsert) ClearDeviceSecret() *DeviceUpsert {
u.SetNull(device.FieldDeviceSecret)
return u
}
// SetDeviceStatus sets the "deviceStatus" field.
func (u *DeviceUpsert) SetDeviceStatus(v string) *DeviceUpsert {
u.Set(device.FieldDeviceStatus, v)
return u
}
// UpdateDeviceStatus sets the "deviceStatus" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateDeviceStatus() *DeviceUpsert {
u.SetExcluded(device.FieldDeviceStatus)
return u
}
// ClearDeviceStatus clears the value of the "deviceStatus" field.
func (u *DeviceUpsert) ClearDeviceStatus() *DeviceUpsert {
u.SetNull(device.FieldDeviceStatus)
return u
}
// SetNickname sets the "nickname" field.
func (u *DeviceUpsert) SetNickname(v string) *DeviceUpsert {
u.Set(device.FieldNickname, v)
return u
}
// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateNickname() *DeviceUpsert {
u.SetExcluded(device.FieldNickname)
return u
}
// ClearNickname clears the value of the "nickname" field.
func (u *DeviceUpsert) ClearNickname() *DeviceUpsert {
u.SetNull(device.FieldNickname)
return u
}
// SetGmtCreate sets the "gmtCreate" field.
func (u *DeviceUpsert) SetGmtCreate(v string) *DeviceUpsert {
u.Set(device.FieldGmtCreate, v)
return u
}
// UpdateGmtCreate sets the "gmtCreate" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateGmtCreate() *DeviceUpsert {
u.SetExcluded(device.FieldGmtCreate)
return u
}
// ClearGmtCreate clears the value of the "gmtCreate" field.
func (u *DeviceUpsert) ClearGmtCreate() *DeviceUpsert {
u.SetNull(device.FieldGmtCreate)
return u
}
// SetGmtModified sets the "gmtModified" field.
func (u *DeviceUpsert) SetGmtModified(v string) *DeviceUpsert {
u.Set(device.FieldGmtModified, v)
return u
}
// UpdateGmtModified sets the "gmtModified" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateGmtModified() *DeviceUpsert {
u.SetExcluded(device.FieldGmtModified)
return u
}
// ClearGmtModified clears the value of the "gmtModified" field.
func (u *DeviceUpsert) ClearGmtModified() *DeviceUpsert {
u.SetNull(device.FieldGmtModified)
return u
}
// SetUtcCreate sets the "utcCreate" field.
func (u *DeviceUpsert) SetUtcCreate(v string) *DeviceUpsert {
u.Set(device.FieldUtcCreate, v)
return u
}
// UpdateUtcCreate sets the "utcCreate" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateUtcCreate() *DeviceUpsert {
u.SetExcluded(device.FieldUtcCreate)
return u
}
// ClearUtcCreate clears the value of the "utcCreate" field.
func (u *DeviceUpsert) ClearUtcCreate() *DeviceUpsert {
u.SetNull(device.FieldUtcCreate)
return u
}
// SetUtcModified sets the "utcModified" field.
func (u *DeviceUpsert) SetUtcModified(v string) *DeviceUpsert {
u.Set(device.FieldUtcModified, v)
return u
}
// UpdateUtcModified sets the "utcModified" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateUtcModified() *DeviceUpsert {
u.SetExcluded(device.FieldUtcModified)
return u
}
// ClearUtcModified clears the value of the "utcModified" field.
func (u *DeviceUpsert) ClearUtcModified() *DeviceUpsert {
u.SetNull(device.FieldUtcModified)
return u
}
// SetOperationalStatusCode sets the "operationalStatusCode" field.
func (u *DeviceUpsert) SetOperationalStatusCode(v string) *DeviceUpsert {
u.Set(device.FieldOperationalStatusCode, v)
return u
}
// UpdateOperationalStatusCode sets the "operationalStatusCode" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateOperationalStatusCode() *DeviceUpsert {
u.SetExcluded(device.FieldOperationalStatusCode)
return u
}
// ClearOperationalStatusCode clears the value of the "operationalStatusCode" field.
func (u *DeviceUpsert) ClearOperationalStatusCode() *DeviceUpsert {
u.SetNull(device.FieldOperationalStatusCode)
return u
}
// SetOperationalStatus sets the "operationalStatus" field.
func (u *DeviceUpsert) SetOperationalStatus(v string) *DeviceUpsert {
u.Set(device.FieldOperationalStatus, v)
return u
}
// UpdateOperationalStatus sets the "operationalStatus" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateOperationalStatus() *DeviceUpsert {
u.SetExcluded(device.FieldOperationalStatus)
return u
}
// ClearOperationalStatus clears the value of the "operationalStatus" field.
func (u *DeviceUpsert) ClearOperationalStatus() *DeviceUpsert {
u.SetNull(device.FieldOperationalStatus)
return u
}
// SetTag sets the "tag" field.
func (u *DeviceUpsert) SetTag(v uint64) *DeviceUpsert {
u.Set(device.FieldTag, v)
return u
}
// UpdateTag sets the "tag" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateTag() *DeviceUpsert {
u.SetExcluded(device.FieldTag)
return u
}
// AddTag adds v to the "tag" field.
func (u *DeviceUpsert) AddTag(v uint64) *DeviceUpsert {
u.Add(device.FieldTag, v)
return u
}
// ClearTag clears the value of the "tag" field.
func (u *DeviceUpsert) ClearTag() *DeviceUpsert {
u.SetNull(device.FieldTag)
return u
}
// SetFirmwareVersion sets the "firmwareVersion" field.
func (u *DeviceUpsert) SetFirmwareVersion(v string) *DeviceUpsert {
u.Set(device.FieldFirmwareVersion, v)
return u
}
// UpdateFirmwareVersion sets the "firmwareVersion" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateFirmwareVersion() *DeviceUpsert {
u.SetExcluded(device.FieldFirmwareVersion)
return u
}
// ClearFirmwareVersion clears the value of the "firmwareVersion" field.
func (u *DeviceUpsert) ClearFirmwareVersion() *DeviceUpsert {
u.SetNull(device.FieldFirmwareVersion)
return u
}
// SetGmtActive sets the "gmtActive" field.
func (u *DeviceUpsert) SetGmtActive(v string) *DeviceUpsert {
u.Set(device.FieldGmtActive, v)
return u
}
// UpdateGmtActive sets the "gmtActive" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateGmtActive() *DeviceUpsert {
u.SetExcluded(device.FieldGmtActive)
return u
}
// ClearGmtActive clears the value of the "gmtActive" field.
func (u *DeviceUpsert) ClearGmtActive() *DeviceUpsert {
u.SetNull(device.FieldGmtActive)
return u
}
// SetGmtOnline sets the "gmtOnline" field.
func (u *DeviceUpsert) SetGmtOnline(v string) *DeviceUpsert {
u.Set(device.FieldGmtOnline, v)
return u
}
// UpdateGmtOnline sets the "gmtOnline" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateGmtOnline() *DeviceUpsert {
u.SetExcluded(device.FieldGmtOnline)
return u
}
// ClearGmtOnline clears the value of the "gmtOnline" field.
func (u *DeviceUpsert) ClearGmtOnline() *DeviceUpsert {
u.SetNull(device.FieldGmtOnline)
return u
}
// SetIPAddress sets the "IPAddress" field.
func (u *DeviceUpsert) SetIPAddress(v string) *DeviceUpsert {
u.Set(device.FieldIPAddress, v)
return u
}
// UpdateIPAddress sets the "IPAddress" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateIPAddress() *DeviceUpsert {
u.SetExcluded(device.FieldIPAddress)
return u
}
// ClearIPAddress clears the value of the "IPAddress" field.
func (u *DeviceUpsert) ClearIPAddress() *DeviceUpsert {
u.SetNull(device.FieldIPAddress)
return u
}
// SetNodeType sets the "nodeType" field.
func (u *DeviceUpsert) SetNodeType(v int32) *DeviceUpsert {
u.Set(device.FieldNodeType, v)
return u
}
// UpdateNodeType sets the "nodeType" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateNodeType() *DeviceUpsert {
u.SetExcluded(device.FieldNodeType)
return u
}
// AddNodeType adds v to the "nodeType" field.
func (u *DeviceUpsert) AddNodeType(v int32) *DeviceUpsert {
u.Add(device.FieldNodeType, v)
return u
}
// SetOwner sets the "owner" field.
func (u *DeviceUpsert) SetOwner(v bool) *DeviceUpsert {
u.Set(device.FieldOwner, v)
return u
}
// UpdateOwner sets the "owner" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateOwner() *DeviceUpsert {
u.SetExcluded(device.FieldOwner)
return u
}
// ClearOwner clears the value of the "owner" field.
func (u *DeviceUpsert) ClearOwner() *DeviceUpsert {
u.SetNull(device.FieldOwner)
return u
}
// SetProductName sets the "productName" field.
func (u *DeviceUpsert) SetProductName(v string) *DeviceUpsert {
u.Set(device.FieldProductName, v)
return u
}
// UpdateProductName sets the "productName" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateProductName() *DeviceUpsert {
u.SetExcluded(device.FieldProductName)
return u
}
// ClearProductName clears the value of the "productName" field.
func (u *DeviceUpsert) ClearProductName() *DeviceUpsert {
u.SetNull(device.FieldProductName)
return u
}
// SetRegion sets the "region" field.
func (u *DeviceUpsert) SetRegion(v string) *DeviceUpsert {
u.Set(device.FieldRegion, v)
return u
}
// UpdateRegion sets the "region" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateRegion() *DeviceUpsert {
u.SetExcluded(device.FieldRegion)
return u
}
// ClearRegion clears the value of the "region" field.
func (u *DeviceUpsert) ClearRegion() *DeviceUpsert {
u.SetNull(device.FieldRegion)
return u
}
// SetUtcActive sets the "utcActive" field.
func (u *DeviceUpsert) SetUtcActive(v string) *DeviceUpsert {
u.Set(device.FieldUtcActive, v)
return u
}
// UpdateUtcActive sets the "utcActive" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateUtcActive() *DeviceUpsert {
u.SetExcluded(device.FieldUtcActive)
return u
}
// ClearUtcActive clears the value of the "utcActive" field.
func (u *DeviceUpsert) ClearUtcActive() *DeviceUpsert {
u.SetNull(device.FieldUtcActive)
return u
}
// SetUtcOnline sets the "utcOnline" field.
func (u *DeviceUpsert) SetUtcOnline(v string) *DeviceUpsert {
u.Set(device.FieldUtcOnline, v)
return u
}
// UpdateUtcOnline sets the "utcOnline" field to the value that was provided on create.
func (u *DeviceUpsert) UpdateUtcOnline() *DeviceUpsert {
u.SetExcluded(device.FieldUtcOnline)
return u
}
// ClearUtcOnline clears the value of the "utcOnline" field.
func (u *DeviceUpsert) ClearUtcOnline() *DeviceUpsert {
u.SetNull(device.FieldUtcOnline)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
// client.Device.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(device.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeviceUpsertOne) UpdateNewValues() *DeviceUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.ID(); exists {
s.SetIgnore(device.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(device.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Device.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeviceUpsertOne) Ignore() *DeviceUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *DeviceUpsertOne) DoNothing() *DeviceUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeviceCreate.OnConflict
// documentation for more info.
func (u *DeviceUpsertOne) Update(set func(*DeviceUpsert)) *DeviceUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeviceUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceUpsertOne) SetUpdatedAt(v time.Time) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateUpdatedAt() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DeviceUpsertOne) SetStatus(v uint8) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetStatus(v)
})
}
// AddStatus adds v to the "status" field.
func (u *DeviceUpsertOne) AddStatus(v uint8) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.AddStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateStatus() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateStatus()
})
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceUpsertOne) ClearStatus() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearStatus()
})
}
// SetSort sets the "sort" field.
func (u *DeviceUpsertOne) SetSort(v uint32) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetSort(v)
})
}
// AddSort adds v to the "sort" field.
func (u *DeviceUpsertOne) AddSort(v uint32) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.AddSort(v)
})
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateSort() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateSort()
})
}
// SetProductKey sets the "productKey" field.
func (u *DeviceUpsertOne) SetProductKey(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetProductKey(v)
})
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateProductKey() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateProductKey()
})
}
// SetIotID sets the "iotID" field.
func (u *DeviceUpsertOne) SetIotID(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetIotID(v)
})
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateIotID() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateIotID()
})
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceUpsertOne) SetDeviceName(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetDeviceName(v)
})
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateDeviceName() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateDeviceName()
})
}
// SetDeviceSecret sets the "deviceSecret" field.
func (u *DeviceUpsertOne) SetDeviceSecret(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetDeviceSecret(v)
})
}
// UpdateDeviceSecret sets the "deviceSecret" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateDeviceSecret() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateDeviceSecret()
})
}
// ClearDeviceSecret clears the value of the "deviceSecret" field.
func (u *DeviceUpsertOne) ClearDeviceSecret() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearDeviceSecret()
})
}
// SetDeviceStatus sets the "deviceStatus" field.
func (u *DeviceUpsertOne) SetDeviceStatus(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetDeviceStatus(v)
})
}
// UpdateDeviceStatus sets the "deviceStatus" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateDeviceStatus() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateDeviceStatus()
})
}
// ClearDeviceStatus clears the value of the "deviceStatus" field.
func (u *DeviceUpsertOne) ClearDeviceStatus() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearDeviceStatus()
})
}
// SetNickname sets the "nickname" field.
func (u *DeviceUpsertOne) SetNickname(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetNickname(v)
})
}
// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateNickname() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateNickname()
})
}
// ClearNickname clears the value of the "nickname" field.
func (u *DeviceUpsertOne) ClearNickname() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearNickname()
})
}
// SetGmtCreate sets the "gmtCreate" field.
func (u *DeviceUpsertOne) SetGmtCreate(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtCreate(v)
})
}
// UpdateGmtCreate sets the "gmtCreate" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateGmtCreate() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtCreate()
})
}
// ClearGmtCreate clears the value of the "gmtCreate" field.
func (u *DeviceUpsertOne) ClearGmtCreate() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtCreate()
})
}
// SetGmtModified sets the "gmtModified" field.
func (u *DeviceUpsertOne) SetGmtModified(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtModified(v)
})
}
// UpdateGmtModified sets the "gmtModified" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateGmtModified() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtModified()
})
}
// ClearGmtModified clears the value of the "gmtModified" field.
func (u *DeviceUpsertOne) ClearGmtModified() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtModified()
})
}
// SetUtcCreate sets the "utcCreate" field.
func (u *DeviceUpsertOne) SetUtcCreate(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcCreate(v)
})
}
// UpdateUtcCreate sets the "utcCreate" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateUtcCreate() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcCreate()
})
}
// ClearUtcCreate clears the value of the "utcCreate" field.
func (u *DeviceUpsertOne) ClearUtcCreate() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcCreate()
})
}
// SetUtcModified sets the "utcModified" field.
func (u *DeviceUpsertOne) SetUtcModified(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcModified(v)
})
}
// UpdateUtcModified sets the "utcModified" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateUtcModified() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcModified()
})
}
// ClearUtcModified clears the value of the "utcModified" field.
func (u *DeviceUpsertOne) ClearUtcModified() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcModified()
})
}
// SetOperationalStatusCode sets the "operationalStatusCode" field.
func (u *DeviceUpsertOne) SetOperationalStatusCode(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetOperationalStatusCode(v)
})
}
// UpdateOperationalStatusCode sets the "operationalStatusCode" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateOperationalStatusCode() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateOperationalStatusCode()
})
}
// ClearOperationalStatusCode clears the value of the "operationalStatusCode" field.
func (u *DeviceUpsertOne) ClearOperationalStatusCode() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearOperationalStatusCode()
})
}
// SetOperationalStatus sets the "operationalStatus" field.
func (u *DeviceUpsertOne) SetOperationalStatus(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetOperationalStatus(v)
})
}
// UpdateOperationalStatus sets the "operationalStatus" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateOperationalStatus() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateOperationalStatus()
})
}
// ClearOperationalStatus clears the value of the "operationalStatus" field.
func (u *DeviceUpsertOne) ClearOperationalStatus() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearOperationalStatus()
})
}
// SetTag sets the "tag" field.
func (u *DeviceUpsertOne) SetTag(v uint64) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetTag(v)
})
}
// AddTag adds v to the "tag" field.
func (u *DeviceUpsertOne) AddTag(v uint64) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.AddTag(v)
})
}
// UpdateTag sets the "tag" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateTag() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateTag()
})
}
// ClearTag clears the value of the "tag" field.
func (u *DeviceUpsertOne) ClearTag() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearTag()
})
}
// SetFirmwareVersion sets the "firmwareVersion" field.
func (u *DeviceUpsertOne) SetFirmwareVersion(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetFirmwareVersion(v)
})
}
// UpdateFirmwareVersion sets the "firmwareVersion" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateFirmwareVersion() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateFirmwareVersion()
})
}
// ClearFirmwareVersion clears the value of the "firmwareVersion" field.
func (u *DeviceUpsertOne) ClearFirmwareVersion() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearFirmwareVersion()
})
}
// SetGmtActive sets the "gmtActive" field.
func (u *DeviceUpsertOne) SetGmtActive(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtActive(v)
})
}
// UpdateGmtActive sets the "gmtActive" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateGmtActive() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtActive()
})
}
// ClearGmtActive clears the value of the "gmtActive" field.
func (u *DeviceUpsertOne) ClearGmtActive() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtActive()
})
}
// SetGmtOnline sets the "gmtOnline" field.
func (u *DeviceUpsertOne) SetGmtOnline(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtOnline(v)
})
}
// UpdateGmtOnline sets the "gmtOnline" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateGmtOnline() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtOnline()
})
}
// ClearGmtOnline clears the value of the "gmtOnline" field.
func (u *DeviceUpsertOne) ClearGmtOnline() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtOnline()
})
}
// SetIPAddress sets the "IPAddress" field.
func (u *DeviceUpsertOne) SetIPAddress(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetIPAddress(v)
})
}
// UpdateIPAddress sets the "IPAddress" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateIPAddress() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateIPAddress()
})
}
// ClearIPAddress clears the value of the "IPAddress" field.
func (u *DeviceUpsertOne) ClearIPAddress() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearIPAddress()
})
}
// SetNodeType sets the "nodeType" field.
func (u *DeviceUpsertOne) SetNodeType(v int32) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetNodeType(v)
})
}
// AddNodeType adds v to the "nodeType" field.
func (u *DeviceUpsertOne) AddNodeType(v int32) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.AddNodeType(v)
})
}
// UpdateNodeType sets the "nodeType" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateNodeType() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateNodeType()
})
}
// SetOwner sets the "owner" field.
func (u *DeviceUpsertOne) SetOwner(v bool) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetOwner(v)
})
}
// UpdateOwner sets the "owner" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateOwner() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateOwner()
})
}
// ClearOwner clears the value of the "owner" field.
func (u *DeviceUpsertOne) ClearOwner() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearOwner()
})
}
// SetProductName sets the "productName" field.
func (u *DeviceUpsertOne) SetProductName(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetProductName(v)
})
}
// UpdateProductName sets the "productName" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateProductName() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateProductName()
})
}
// ClearProductName clears the value of the "productName" field.
func (u *DeviceUpsertOne) ClearProductName() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearProductName()
})
}
// SetRegion sets the "region" field.
func (u *DeviceUpsertOne) SetRegion(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetRegion(v)
})
}
// UpdateRegion sets the "region" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateRegion() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateRegion()
})
}
// ClearRegion clears the value of the "region" field.
func (u *DeviceUpsertOne) ClearRegion() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearRegion()
})
}
// SetUtcActive sets the "utcActive" field.
func (u *DeviceUpsertOne) SetUtcActive(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcActive(v)
})
}
// UpdateUtcActive sets the "utcActive" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateUtcActive() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcActive()
})
}
// ClearUtcActive clears the value of the "utcActive" field.
func (u *DeviceUpsertOne) ClearUtcActive() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcActive()
})
}
// SetUtcOnline sets the "utcOnline" field.
func (u *DeviceUpsertOne) SetUtcOnline(v string) *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcOnline(v)
})
}
// UpdateUtcOnline sets the "utcOnline" field to the value that was provided on create.
func (u *DeviceUpsertOne) UpdateUtcOnline() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcOnline()
})
}
// ClearUtcOnline clears the value of the "utcOnline" field.
func (u *DeviceUpsertOne) ClearUtcOnline() *DeviceUpsertOne {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcOnline()
})
}
// Exec executes the query.
func (u *DeviceUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeviceCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeviceUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *DeviceUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
if u.create.driver.Dialect() == dialect.MySQL {
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
// fields from the database since MySQL does not support the RETURNING clause.
return id, errors.New("ent: DeviceUpsertOne.ID is not supported by MySQL driver. Use DeviceUpsertOne.Exec instead")
}
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *DeviceUpsertOne) IDX(ctx context.Context) uuid.UUID {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// DeviceCreateBulk is the builder for creating many Device entities in bulk.
type DeviceCreateBulk struct {
config
err error
builders []*DeviceCreate
conflict []sql.ConflictOption
}
// Save creates the Device entities in the database.
func (dcb *DeviceCreateBulk) Save(ctx context.Context) ([]*Device, error) {
if dcb.err != nil {
return nil, dcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(dcb.builders))
nodes := make([]*Device, len(dcb.builders))
mutators := make([]Mutator, len(dcb.builders))
for i := range dcb.builders {
func(i int, root context.Context) {
builder := dcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DeviceMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, dcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = dcb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dcb.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, dcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dcb *DeviceCreateBulk) SaveX(ctx context.Context) []*Device {
v, err := dcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dcb *DeviceCreateBulk) Exec(ctx context.Context) error {
_, err := dcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dcb *DeviceCreateBulk) ExecX(ctx context.Context) {
if err := dcb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Device.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.DeviceUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dcb *DeviceCreateBulk) OnConflict(opts ...sql.ConflictOption) *DeviceUpsertBulk {
dcb.conflict = opts
return &DeviceUpsertBulk{
create: dcb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Device.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dcb *DeviceCreateBulk) OnConflictColumns(columns ...string) *DeviceUpsertBulk {
dcb.conflict = append(dcb.conflict, sql.ConflictColumns(columns...))
return &DeviceUpsertBulk{
create: dcb,
}
}
// DeviceUpsertBulk is the builder for "upsert"-ing
// a bulk of Device nodes.
type DeviceUpsertBulk struct {
create *DeviceCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Device.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(device.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeviceUpsertBulk) UpdateNewValues() *DeviceUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.ID(); exists {
s.SetIgnore(device.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(device.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Device.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeviceUpsertBulk) Ignore() *DeviceUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *DeviceUpsertBulk) DoNothing() *DeviceUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeviceCreateBulk.OnConflict
// documentation for more info.
func (u *DeviceUpsertBulk) Update(set func(*DeviceUpsert)) *DeviceUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeviceUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DeviceUpsertBulk) SetUpdatedAt(v time.Time) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateUpdatedAt() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DeviceUpsertBulk) SetStatus(v uint8) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetStatus(v)
})
}
// AddStatus adds v to the "status" field.
func (u *DeviceUpsertBulk) AddStatus(v uint8) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.AddStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateStatus() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateStatus()
})
}
// ClearStatus clears the value of the "status" field.
func (u *DeviceUpsertBulk) ClearStatus() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearStatus()
})
}
// SetSort sets the "sort" field.
func (u *DeviceUpsertBulk) SetSort(v uint32) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetSort(v)
})
}
// AddSort adds v to the "sort" field.
func (u *DeviceUpsertBulk) AddSort(v uint32) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.AddSort(v)
})
}
// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateSort() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateSort()
})
}
// SetProductKey sets the "productKey" field.
func (u *DeviceUpsertBulk) SetProductKey(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetProductKey(v)
})
}
// UpdateProductKey sets the "productKey" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateProductKey() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateProductKey()
})
}
// SetIotID sets the "iotID" field.
func (u *DeviceUpsertBulk) SetIotID(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetIotID(v)
})
}
// UpdateIotID sets the "iotID" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateIotID() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateIotID()
})
}
// SetDeviceName sets the "deviceName" field.
func (u *DeviceUpsertBulk) SetDeviceName(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetDeviceName(v)
})
}
// UpdateDeviceName sets the "deviceName" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateDeviceName() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateDeviceName()
})
}
// SetDeviceSecret sets the "deviceSecret" field.
func (u *DeviceUpsertBulk) SetDeviceSecret(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetDeviceSecret(v)
})
}
// UpdateDeviceSecret sets the "deviceSecret" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateDeviceSecret() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateDeviceSecret()
})
}
// ClearDeviceSecret clears the value of the "deviceSecret" field.
func (u *DeviceUpsertBulk) ClearDeviceSecret() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearDeviceSecret()
})
}
// SetDeviceStatus sets the "deviceStatus" field.
func (u *DeviceUpsertBulk) SetDeviceStatus(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetDeviceStatus(v)
})
}
// UpdateDeviceStatus sets the "deviceStatus" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateDeviceStatus() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateDeviceStatus()
})
}
// ClearDeviceStatus clears the value of the "deviceStatus" field.
func (u *DeviceUpsertBulk) ClearDeviceStatus() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearDeviceStatus()
})
}
// SetNickname sets the "nickname" field.
func (u *DeviceUpsertBulk) SetNickname(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetNickname(v)
})
}
// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateNickname() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateNickname()
})
}
// ClearNickname clears the value of the "nickname" field.
func (u *DeviceUpsertBulk) ClearNickname() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearNickname()
})
}
// SetGmtCreate sets the "gmtCreate" field.
func (u *DeviceUpsertBulk) SetGmtCreate(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtCreate(v)
})
}
// UpdateGmtCreate sets the "gmtCreate" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateGmtCreate() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtCreate()
})
}
// ClearGmtCreate clears the value of the "gmtCreate" field.
func (u *DeviceUpsertBulk) ClearGmtCreate() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtCreate()
})
}
// SetGmtModified sets the "gmtModified" field.
func (u *DeviceUpsertBulk) SetGmtModified(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtModified(v)
})
}
// UpdateGmtModified sets the "gmtModified" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateGmtModified() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtModified()
})
}
// ClearGmtModified clears the value of the "gmtModified" field.
func (u *DeviceUpsertBulk) ClearGmtModified() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtModified()
})
}
// SetUtcCreate sets the "utcCreate" field.
func (u *DeviceUpsertBulk) SetUtcCreate(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcCreate(v)
})
}
// UpdateUtcCreate sets the "utcCreate" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateUtcCreate() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcCreate()
})
}
// ClearUtcCreate clears the value of the "utcCreate" field.
func (u *DeviceUpsertBulk) ClearUtcCreate() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcCreate()
})
}
// SetUtcModified sets the "utcModified" field.
func (u *DeviceUpsertBulk) SetUtcModified(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcModified(v)
})
}
// UpdateUtcModified sets the "utcModified" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateUtcModified() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcModified()
})
}
// ClearUtcModified clears the value of the "utcModified" field.
func (u *DeviceUpsertBulk) ClearUtcModified() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcModified()
})
}
// SetOperationalStatusCode sets the "operationalStatusCode" field.
func (u *DeviceUpsertBulk) SetOperationalStatusCode(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetOperationalStatusCode(v)
})
}
// UpdateOperationalStatusCode sets the "operationalStatusCode" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateOperationalStatusCode() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateOperationalStatusCode()
})
}
// ClearOperationalStatusCode clears the value of the "operationalStatusCode" field.
func (u *DeviceUpsertBulk) ClearOperationalStatusCode() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearOperationalStatusCode()
})
}
// SetOperationalStatus sets the "operationalStatus" field.
func (u *DeviceUpsertBulk) SetOperationalStatus(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetOperationalStatus(v)
})
}
// UpdateOperationalStatus sets the "operationalStatus" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateOperationalStatus() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateOperationalStatus()
})
}
// ClearOperationalStatus clears the value of the "operationalStatus" field.
func (u *DeviceUpsertBulk) ClearOperationalStatus() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearOperationalStatus()
})
}
// SetTag sets the "tag" field.
func (u *DeviceUpsertBulk) SetTag(v uint64) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetTag(v)
})
}
// AddTag adds v to the "tag" field.
func (u *DeviceUpsertBulk) AddTag(v uint64) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.AddTag(v)
})
}
// UpdateTag sets the "tag" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateTag() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateTag()
})
}
// ClearTag clears the value of the "tag" field.
func (u *DeviceUpsertBulk) ClearTag() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearTag()
})
}
// SetFirmwareVersion sets the "firmwareVersion" field.
func (u *DeviceUpsertBulk) SetFirmwareVersion(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetFirmwareVersion(v)
})
}
// UpdateFirmwareVersion sets the "firmwareVersion" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateFirmwareVersion() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateFirmwareVersion()
})
}
// ClearFirmwareVersion clears the value of the "firmwareVersion" field.
func (u *DeviceUpsertBulk) ClearFirmwareVersion() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearFirmwareVersion()
})
}
// SetGmtActive sets the "gmtActive" field.
func (u *DeviceUpsertBulk) SetGmtActive(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtActive(v)
})
}
// UpdateGmtActive sets the "gmtActive" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateGmtActive() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtActive()
})
}
// ClearGmtActive clears the value of the "gmtActive" field.
func (u *DeviceUpsertBulk) ClearGmtActive() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtActive()
})
}
// SetGmtOnline sets the "gmtOnline" field.
func (u *DeviceUpsertBulk) SetGmtOnline(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetGmtOnline(v)
})
}
// UpdateGmtOnline sets the "gmtOnline" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateGmtOnline() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateGmtOnline()
})
}
// ClearGmtOnline clears the value of the "gmtOnline" field.
func (u *DeviceUpsertBulk) ClearGmtOnline() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearGmtOnline()
})
}
// SetIPAddress sets the "IPAddress" field.
func (u *DeviceUpsertBulk) SetIPAddress(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetIPAddress(v)
})
}
// UpdateIPAddress sets the "IPAddress" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateIPAddress() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateIPAddress()
})
}
// ClearIPAddress clears the value of the "IPAddress" field.
func (u *DeviceUpsertBulk) ClearIPAddress() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearIPAddress()
})
}
// SetNodeType sets the "nodeType" field.
func (u *DeviceUpsertBulk) SetNodeType(v int32) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetNodeType(v)
})
}
// AddNodeType adds v to the "nodeType" field.
func (u *DeviceUpsertBulk) AddNodeType(v int32) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.AddNodeType(v)
})
}
// UpdateNodeType sets the "nodeType" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateNodeType() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateNodeType()
})
}
// SetOwner sets the "owner" field.
func (u *DeviceUpsertBulk) SetOwner(v bool) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetOwner(v)
})
}
// UpdateOwner sets the "owner" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateOwner() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateOwner()
})
}
// ClearOwner clears the value of the "owner" field.
func (u *DeviceUpsertBulk) ClearOwner() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearOwner()
})
}
// SetProductName sets the "productName" field.
func (u *DeviceUpsertBulk) SetProductName(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetProductName(v)
})
}
// UpdateProductName sets the "productName" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateProductName() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateProductName()
})
}
// ClearProductName clears the value of the "productName" field.
func (u *DeviceUpsertBulk) ClearProductName() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearProductName()
})
}
// SetRegion sets the "region" field.
func (u *DeviceUpsertBulk) SetRegion(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetRegion(v)
})
}
// UpdateRegion sets the "region" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateRegion() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateRegion()
})
}
// ClearRegion clears the value of the "region" field.
func (u *DeviceUpsertBulk) ClearRegion() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearRegion()
})
}
// SetUtcActive sets the "utcActive" field.
func (u *DeviceUpsertBulk) SetUtcActive(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcActive(v)
})
}
// UpdateUtcActive sets the "utcActive" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateUtcActive() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcActive()
})
}
// ClearUtcActive clears the value of the "utcActive" field.
func (u *DeviceUpsertBulk) ClearUtcActive() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcActive()
})
}
// SetUtcOnline sets the "utcOnline" field.
func (u *DeviceUpsertBulk) SetUtcOnline(v string) *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.SetUtcOnline(v)
})
}
// UpdateUtcOnline sets the "utcOnline" field to the value that was provided on create.
func (u *DeviceUpsertBulk) UpdateUtcOnline() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.UpdateUtcOnline()
})
}
// ClearUtcOnline clears the value of the "utcOnline" field.
func (u *DeviceUpsertBulk) ClearUtcOnline() *DeviceUpsertBulk {
return u.Update(func(s *DeviceUpsert) {
s.ClearUtcOnline()
})
}
// Exec executes the query.
func (u *DeviceUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the DeviceCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeviceCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeviceUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yuLingNet/simple-iot-basic-rpc.git
git@gitee.com:yuLingNet/simple-iot-basic-rpc.git
yuLingNet
simple-iot-basic-rpc
simple-iot-basic-rpc
ca5a4cf0cee7

搜索帮助