From cd6b4667ac4635805cb658f3ab3e05ea78bbb68c Mon Sep 17 00:00:00 2001 From: it512 Date: Sat, 26 Oct 2024 08:45:20 +0800 Subject: [PATCH] -all --- adv/cmd/h3/main.go | 12 + adv/go.mod | 31 + adv/go.sum | 88 ++ adv/latlng/h3.go | 32 + adv/loc/conv.go | 212 +++ adv/loc/haversine.go | 25 + adv/loc/latlng.go | 64 + adv/lua/lua.go | 1 + adv/orm/dbop.go | 35 + adv/orm/ent/adv.go | 274 ++++ adv/orm/ent/adv/adv.go | 211 +++ adv/orm/ent/adv/where.go | 1041 ++++++++++++++ adv/orm/ent/adv_create.go | 1240 ++++++++++++++++ adv/orm/ent/adv_delete.go | 88 ++ adv/orm/ent/adv_query.go | 528 +++++++ adv/orm/ent/adv_update.go | 600 ++++++++ adv/orm/ent/client.go | 510 +++++++ adv/orm/ent/ent.go | 610 ++++++++ adv/orm/ent/entql.go | 293 ++++ adv/orm/ent/enttest/enttest.go | 84 ++ adv/orm/ent/hook/hook.go | 211 +++ adv/orm/ent/mall.go | 219 +++ adv/orm/ent/mall/mall.go | 161 +++ adv/orm/ent/mall/where.go | 741 ++++++++++ adv/orm/ent/mall_create.go | 1018 +++++++++++++ adv/orm/ent/mall_delete.go | 88 ++ adv/orm/ent/mall_query.go | 528 +++++++ adv/orm/ent/mall_update.go | 502 +++++++ adv/orm/ent/migrate/migrate.go | 64 + adv/orm/ent/migrate/schema.go | 112 ++ adv/orm/ent/mutation.go | 2150 ++++++++++++++++++++++++++++ adv/orm/ent/predicate/predicate.go | 13 + adv/orm/ent/privacy/privacy.go | 215 +++ adv/orm/ent/runtime.go | 264 ++++ adv/orm/ent/runtime/runtime.go | 10 + adv/orm/ent/tx.go | 239 ++++ adv/orm/generate.go | 3 + adv/orm/pg.go | 28 + adv/orm/schema/adv.go | 152 ++ adv/orm/schema/mall.go | 115 ++ adv/orm/schema/x/util.go | 44 + 41 files changed, 12856 insertions(+) create mode 100644 adv/cmd/h3/main.go create mode 100644 adv/go.mod create mode 100644 adv/go.sum create mode 100644 adv/latlng/h3.go create mode 100644 adv/loc/conv.go create mode 100644 adv/loc/haversine.go create mode 100644 adv/loc/latlng.go create mode 100644 adv/lua/lua.go create mode 100644 adv/orm/dbop.go create mode 100644 adv/orm/ent/adv.go create mode 100644 adv/orm/ent/adv/adv.go create mode 100644 adv/orm/ent/adv/where.go create mode 100644 adv/orm/ent/adv_create.go create mode 100644 adv/orm/ent/adv_delete.go create mode 100644 adv/orm/ent/adv_query.go create mode 100644 adv/orm/ent/adv_update.go create mode 100644 adv/orm/ent/client.go create mode 100644 adv/orm/ent/ent.go create mode 100644 adv/orm/ent/entql.go create mode 100644 adv/orm/ent/enttest/enttest.go create mode 100644 adv/orm/ent/hook/hook.go create mode 100644 adv/orm/ent/mall.go create mode 100644 adv/orm/ent/mall/mall.go create mode 100644 adv/orm/ent/mall/where.go create mode 100644 adv/orm/ent/mall_create.go create mode 100644 adv/orm/ent/mall_delete.go create mode 100644 adv/orm/ent/mall_query.go create mode 100644 adv/orm/ent/mall_update.go create mode 100644 adv/orm/ent/migrate/migrate.go create mode 100644 adv/orm/ent/migrate/schema.go create mode 100644 adv/orm/ent/mutation.go create mode 100644 adv/orm/ent/predicate/predicate.go create mode 100644 adv/orm/ent/privacy/privacy.go create mode 100644 adv/orm/ent/runtime.go create mode 100644 adv/orm/ent/runtime/runtime.go create mode 100644 adv/orm/ent/tx.go create mode 100644 adv/orm/generate.go create mode 100644 adv/orm/pg.go create mode 100644 adv/orm/schema/adv.go create mode 100644 adv/orm/schema/mall.go create mode 100644 adv/orm/schema/x/util.go diff --git a/adv/cmd/h3/main.go b/adv/cmd/h3/main.go new file mode 100644 index 0000000..8e45768 --- /dev/null +++ b/adv/cmd/h3/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "fmt" + + "github.com/twiglab/crm/adv/latlng" +) + +func main() { + l := latlng.ToIndex(37.775938728915946, -122.41795063018799) + fmt.Println(l) +} diff --git a/adv/go.mod b/adv/go.mod new file mode 100644 index 0000000..bc999b8 --- /dev/null +++ b/adv/go.mod @@ -0,0 +1,31 @@ +module github.com/twiglab/crm/adv + +go 1.23.1 + +require ( + entgo.io/ent v0.14.1 + github.com/google/uuid v1.6.0 + github.com/jackc/pgx/v5 v5.7.1 + github.com/uber/h3-go/v4 v4.1.2 +) + +require ( + ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect + github.com/agext/levenshtein v1.2.1 // indirect + github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/go-openapi/inflect v0.19.0 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/hashicorp/hcl/v2 v2.13.0 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect + github.com/rogpeppe/go-internal v1.13.1 // indirect + github.com/stretchr/testify v1.9.0 // indirect + github.com/yuin/gopher-lua v1.1.1 // indirect + github.com/zclconf/go-cty v1.8.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/text v0.18.0 // indirect +) diff --git a/adv/go.sum b/adv/go.sum new file mode 100644 index 0000000..19a485a --- /dev/null +++ b/adv/go.sum @@ -0,0 +1,88 @@ +ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrlIISQ4JTH1mRWuE5ZZ14= +ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU= +entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s= +entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco= +github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= +github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= +github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= +github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs= +github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= +github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= +github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/uber/h3-go/v4 v4.1.2 h1:QHGEcldBZArx51UyTkQprFMUXaIlEkLV88zWUt8u2LY= +github.com/uber/h3-go/v4 v4.1.2/go.mod h1:VDpXVn4NLetBoISLEbiTVNstwW00bhHolV8I+jx9G+4= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= +github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= +github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA= +github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/adv/latlng/h3.go b/adv/latlng/h3.go new file mode 100644 index 0000000..01ada51 --- /dev/null +++ b/adv/latlng/h3.go @@ -0,0 +1,32 @@ +package latlng + +import ( + "fmt" + + "github.com/uber/h3-go/v4" +) + +type Index struct { + Index6 string + Index7 string + Index8 string + + Lat, Lng float64 +} + +func ToIndex(lat, lng float64) Index { + latLng := h3.NewLatLng(lat, lng) + + index6 := fmt.Sprint(latLng.Cell(6)) + index7 := fmt.Sprint(latLng.Cell(7)) + index8 := fmt.Sprint(latLng.Cell(8)) + + return Index{ + Index6: index6, + Index7: index7, + Index8: index8, + + Lat: lat, + Lng: lng, + } +} diff --git a/adv/loc/conv.go b/adv/loc/conv.go new file mode 100644 index 0000000..b79d990 --- /dev/null +++ b/adv/loc/conv.go @@ -0,0 +1,212 @@ +package loc + +/* +百度地图API 百度坐标 +腾讯搜搜地图API 火星坐标 +搜狐搜狗地图API 搜狗坐标 +阿里云地图API 火星坐标 +图吧MapBar地图API 图吧坐标 +高德MapABC地图API 火星坐标 +灵图51ditu地图API 火星坐标 +*/ + +import ( + "math" +) + +// GPSUtil is a utility class for GPS calculations. +// 小写方法是私有方法,大写方法是公有方法 可根据需要调整 +type GPSUtil struct { +} + +const ( + pi = math.Pi // 3.1415926535897932384626 // 圆周率 + x_pi = math.Pi * 3000.0 / 180.0 // 圆周率对应的经纬度偏移 + a = 6378245.0 // 长半轴 + ee = 0.00669342162296594323 // 扁率 +) + +func transformLat(x, y float64) float64 { + ret := -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*math.Sqrt(math.Abs(x)) + ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 + ret += (20.0*math.Sin(y*pi) + 40.0*math.Sin(y/3.0*pi)) * 2.0 / 3.0 + ret += (160.0*math.Sin(y/12.0*pi) + 320*math.Sin(y*pi/30.0)) * 2.0 / 3.0 + return ret +} + +func (receiver *GPSUtil) transformLat(x, y float64) float64 { + ret := -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*math.Sqrt(math.Abs(x)) + ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 + ret += (20.0*math.Sin(y*pi) + 40.0*math.Sin(y/3.0*pi)) * 2.0 / 3.0 + ret += (160.0*math.Sin(y/12.0*pi) + 320*math.Sin(y*pi/30.0)) * 2.0 / 3.0 + return ret +} + +func transformlng(x, y float64) float64 { + ret := 300.0 + x + 2.0*y + 0.1*x*x + 0.1*x*y + 0.1*math.Sqrt(math.Abs(x)) + ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 + ret += (20.0*math.Sin(x*pi) + 40.0*math.Sin(x/3.0*pi)) * 2.0 / 3.0 + ret += (150.0*math.Sin(x/12.0*pi) + 300.0*math.Sin(x/30.0*pi)) * 2.0 / 3.0 + return ret +} + +func (receiver *GPSUtil) transformlng(x, y float64) float64 { + ret := 300.0 + x + 2.0*y + 0.1*x*x + 0.1*x*y + 0.1*math.Sqrt(math.Abs(x)) + ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 + ret += (20.0*math.Sin(x*pi) + 40.0*math.Sin(x/3.0*pi)) * 2.0 / 3.0 + ret += (150.0*math.Sin(x/12.0*pi) + 300.0*math.Sin(x/30.0*pi)) * 2.0 / 3.0 + return ret +} + +func outOfChina(lat, lng float64) bool { + if lng < 72.004 || lng > 137.8347 { + return true + } + if lat < 0.8293 || lat > 55.8271 { + return true + } + return false +} + +func (receiver *GPSUtil) outOfChina(lat, lng float64) bool { + if lng < 72.004 || lng > 137.8347 { + return true + } + if lat < 0.8293 || lat > 55.8271 { + return true + } + return false +} + +func transform(lat, lng float64) (float64, float64) { + if outOfChina(lat, lng) { + return 0.0, 0.0 + } + dLat := transformLat(lng-105.0, lat-35.0) + dlng := transformlng(lng-105.0, lat-35.0) + radLat := lat / 180.0 * pi + magic := math.Sin(radLat) + magic = 1 - ee*magic*magic + SqrtMagic := math.Sqrt(magic) + dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) + dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) + mgLat := lat + dLat + mglng := lng + dlng + return mgLat, mglng +} + +func (receiver *GPSUtil) transform(lat, lng float64) []float64 { + if receiver.outOfChina(lat, lng) { + return []float64{lat, lng} + } + dLat := receiver.transformLat(lng-105.0, lat-35.0) + dlng := receiver.transformlng(lng-105.0, lat-35.0) + radLat := lat / 180.0 * pi + magic := math.Sin(radLat) + magic = 1 - ee*magic*magic + SqrtMagic := math.Sqrt(magic) + dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) + dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) + mgLat := lat + dLat + mglng := lng + dlng + return []float64{mgLat, mglng} +} + +// WGS84_To_Gcj02 84 to 火星坐标系 (GCJ-02) World Geodetic System ==> Mars Geodetic System +// @param lat +// @param lng +// @return +func WGS84_To_Gcj02(lat, lng float64) (float64, float64) { + if outOfChina(lat, lng) { + return 0.0, 0.0 + } + dLat := transformLat(lng-105.0, lat-35.0) + dlng := transformlng(lng-105.0, lat-35.0) + radLat := lat / 180.0 * pi + magic := math.Sin(radLat) + magic = 1 - ee*magic*magic + SqrtMagic := math.Sqrt(magic) + dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) + dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) + mgLat := lat + dLat + mglng := lng + dlng + return mgLat, mglng +} + +func (receiver *GPSUtil) WGS84_To_Gcj02(lat, lng float64) []float64 { + if receiver.outOfChina(lat, lng) { + return []float64{lat, lng} + } + dLat := receiver.transformLat(lng-105.0, lat-35.0) + dlng := receiver.transformlng(lng-105.0, lat-35.0) + radLat := lat / 180.0 * pi + magic := math.Sin(radLat) + magic = 1 - ee*magic*magic + SqrtMagic := math.Sqrt(magic) + dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) + dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) + mgLat := lat + dLat + mglng := lng + dlng + return []float64{mgLat, mglng} +} + +// GCJ02_To_WGS84 +// 火星坐标系 (GCJ-02) to WGS84 +// @param lng +// @param lat +// @return +func (receiver *GPSUtil) GCJ02_To_WGS84(lat, lng float64) []float64 { + gps := receiver.transform(lat, lng) + lngtitude := lng*2 - gps[1] + latitude := lat*2 - gps[0] + return []float64{latitude, lngtitude} +} + +/** + * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 将 GCJ-02 坐标转换成 BD-09 坐标 + * + * @param lat + * @param lng + */ +func (receiver *GPSUtil) gcj02_To_Bd09(lat, lng float64) []float64 { + x := lng + y := lat + z := math.Sqrt(x*x+y*y) + 0.00002*math.Sin(y*x_pi) + theta := math.Atan2(y, x) + 0.000003*math.Cos(x*x_pi) + templng := z*math.Cos(theta) + 0.0065 + tempLat := z*math.Sin(theta) + 0.006 + gps := []float64{tempLat, templng} + return gps +} + +/** + * * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 * * 将 BD-09 坐标转换成GCJ-02 坐标 * * @param + * bd_lat * @param bd_lng * @return + */ +func (receiver *GPSUtil) bd09_To_Gcj02(lat, lng float64) []float64 { + x := lng - 0.0065 + y := lat - 0.006 + z := math.Sqrt(x*x+y*y) - 0.00002*math.Sin(y*x_pi) + theta := math.Atan2(y, x) - 0.000003*math.Cos(x*x_pi) + templng := z * math.Cos(theta) + tempLat := z * math.Sin(theta) + gps := []float64{tempLat, templng} + return gps +} + +/**将WGS84转为bd09 + * @param lat + * @param lng + * @return + */ +func (receiver *GPSUtil) WGS84_To_bd09(lat, lng float64) []float64 { + gcj02 := receiver.WGS84_To_Gcj02(lat, lng) + bd09 := receiver.gcj02_To_Bd09(gcj02[0], gcj02[1]) + return bd09 +} + +func (receiver *GPSUtil) bd09_To_WGS84(lat, lng float64) []float64 { + gcj02 := receiver.bd09_To_Gcj02(lat, lng) + WGS84 := receiver.GCJ02_To_WGS84(gcj02[0], gcj02[1]) + return WGS84 +} diff --git a/adv/loc/haversine.go b/adv/loc/haversine.go new file mode 100644 index 0000000..972e734 --- /dev/null +++ b/adv/loc/haversine.go @@ -0,0 +1,25 @@ +package loc + +import "math" + +const rad = math.Pi / 180 + +func haversine(θ float64) float64 { + return .5 * (1 - math.Cos(θ)) +} + +type pos struct { + φ float64 // latitude, radians + ψ float64 // longitude, radians +} + +func degPos(lat, lon float64) pos { + return pos{lat * rad, lon * rad} +} + +const rEarth = 6372.8 * 1000 // m + +func hsDist(p1, p2 pos) float64 { + return 2 * rEarth * math.Asin(math.Sqrt(haversine(p2.φ-p1.φ)+ + math.Cos(p1.φ)*math.Cos(p2.φ)*haversine(p2.ψ-p1.ψ))) +} diff --git a/adv/loc/latlng.go b/adv/loc/latlng.go new file mode 100644 index 0000000..73aa22d --- /dev/null +++ b/adv/loc/latlng.go @@ -0,0 +1,64 @@ +package loc + +import ( + "errors" + "fmt" + "strconv" + "strings" +) + +// 坐标-经纬度 +type Coord struct { + Lat float64 + Lng float64 +} + +func (origin Coord) Distance(q Coord) float64 { + pos1, pos2 := degPos(origin.Lat, origin.Lng), degPos(q.Lat, q.Lng) + return hsDist(pos1, pos2) +} + +func (origin Coord) InChina() bool { + return (origin.Lat > 3.85 && origin.Lat < 53.56) && (origin.Lng > 73.65 && origin.Lng < 135.05) +} + +func (c *Coord) From(latlng string) (err error) { + bs := strings.SplitN(latlng, ",", 2) + if len(bs) != 2 { + return errors.New("invail coord") + } + c.Lat, _ = strconv.ParseFloat(bs[0], 64) + c.Lng, _ = strconv.ParseFloat(bs[1], 64) + return nil +} + +func (c *Coord) FromWGS84(latlng string) error { + bs := strings.SplitN(latlng, ",", 2) + if len(bs) != 2 { + return errors.New("invail coord") + } + lat, err := strconv.ParseFloat(bs[0], 64) + if err != nil { + return err + } + lng, err := strconv.ParseFloat(bs[1], 64) + if err != nil { + return err + } + + c.Lat, c.Lng = WGS84_To_Gcj02(lat, lng) + return nil +} + +func (origin Coord) String() string { + return fmt.Sprintf("lat = %f, lng = %f", origin.Lat, origin.Lng) +} + +func China() Coord { + return Coord{Lat: 39.92, Lng: 116.46} +} + +// 中国的经纬度范围大约为:纬度3.86~53.55,经度73.66~135.05 +// 北京行政中心的纬度为39.92,经度为116.46 + +var CHINA = China() diff --git a/adv/lua/lua.go b/adv/lua/lua.go new file mode 100644 index 0000000..07534cc --- /dev/null +++ b/adv/lua/lua.go @@ -0,0 +1 @@ +package lua diff --git a/adv/orm/dbop.go b/adv/orm/dbop.go new file mode 100644 index 0000000..12fa35d --- /dev/null +++ b/adv/orm/dbop.go @@ -0,0 +1,35 @@ +package orm + +import ( + "context" + "time" + + "github.com/twiglab/crm/adv/orm/ent" + "github.com/twiglab/crm/adv/orm/ent/adv" +) + +type Param struct { + Index7 string + Now time.Time +} + +type AdvDBOP struct { + client *ent.Client +} + +func NewAdvDBOP(client *ent.Client) *AdvDBOP { + return &AdvDBOP{client: client} +} + +func (dbop *AdvDBOP) SelectAdvNearBy(ctx context.Context, param Param) ([]*ent.Adv, error) { + q := dbop.client.Adv.Query() + q.Where( + adv.H3Index7EQ(param.Index7), + adv.StartTimeGT(param.Now), + adv.EndTimeLT(param.Now), + adv.StatusEQ(1), + ) + // q.Order() + + return q.All(ctx) +} diff --git a/adv/orm/ent/adv.go b/adv/orm/ent/adv.go new file mode 100644 index 0000000..9ef00c7 --- /dev/null +++ b/adv/orm/ent/adv.go @@ -0,0 +1,274 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/adv" +) + +// Adv is the model entity for the Adv schema. +type Adv struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // CreateTime holds the value of the "create_time" field. + CreateTime time.Time `json:"create_time,omitempty"` + // UpdateTime holds the value of the "update_time" field. + UpdateTime time.Time `json:"update_time,omitempty"` + // Code holds the value of the "code" field. + Code string `json:"code,omitempty"` + // MallCode holds the value of the "mall_code" field. + MallCode string `json:"mall_code,omitempty"` + // MallName holds the value of the "mall_name" field. + MallName string `json:"mall_name,omitempty"` + // H3Index6 holds the value of the "h3_index_6" field. + H3Index6 string `json:"h3_index_6,omitempty"` + // H3Index7 holds the value of the "h3_index_7" field. + H3Index7 string `json:"h3_index_7,omitempty"` + // H3Index8 holds the value of the "h3_index_8" field. + H3Index8 string `json:"h3_index_8,omitempty"` + // ImgPath holds the value of the "img_path" field. + ImgPath string `json:"img_path,omitempty"` + // URL holds the value of the "url" field. + URL string `json:"url,omitempty"` + // Ruler holds the value of the "ruler" field. + Ruler string `json:"ruler,omitempty"` + // Ord holds the value of the "ord" field. + Ord int `json:"ord,omitempty"` + // Memo holds the value of the "memo" field. + Memo string `json:"memo,omitempty"` + // StartTime holds the value of the "start_time" field. + StartTime time.Time `json:"start_time,omitempty"` + // EndTime holds the value of the "end_time" field. + EndTime time.Time `json:"end_time,omitempty"` + // Status holds the value of the "status" field. + Status int `json:"status,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Adv) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case adv.FieldOrd, adv.FieldStatus: + values[i] = new(sql.NullInt64) + case adv.FieldCode, adv.FieldMallCode, adv.FieldMallName, adv.FieldH3Index6, adv.FieldH3Index7, adv.FieldH3Index8, adv.FieldImgPath, adv.FieldURL, adv.FieldRuler, adv.FieldMemo: + values[i] = new(sql.NullString) + case adv.FieldCreateTime, adv.FieldUpdateTime, adv.FieldStartTime, adv.FieldEndTime: + values[i] = new(sql.NullTime) + case adv.FieldID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Adv fields. +func (a *Adv) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case adv.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + a.ID = *value + } + case adv.FieldCreateTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field create_time", values[i]) + } else if value.Valid { + a.CreateTime = value.Time + } + case adv.FieldUpdateTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field update_time", values[i]) + } else if value.Valid { + a.UpdateTime = value.Time + } + case adv.FieldCode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field code", values[i]) + } else if value.Valid { + a.Code = value.String + } + case adv.FieldMallCode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mall_code", values[i]) + } else if value.Valid { + a.MallCode = value.String + } + case adv.FieldMallName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mall_name", values[i]) + } else if value.Valid { + a.MallName = value.String + } + case adv.FieldH3Index6: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field h3_index_6", values[i]) + } else if value.Valid { + a.H3Index6 = value.String + } + case adv.FieldH3Index7: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field h3_index_7", values[i]) + } else if value.Valid { + a.H3Index7 = value.String + } + case adv.FieldH3Index8: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field h3_index_8", values[i]) + } else if value.Valid { + a.H3Index8 = value.String + } + case adv.FieldImgPath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field img_path", values[i]) + } else if value.Valid { + a.ImgPath = value.String + } + case adv.FieldURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field url", values[i]) + } else if value.Valid { + a.URL = value.String + } + case adv.FieldRuler: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field ruler", values[i]) + } else if value.Valid { + a.Ruler = value.String + } + case adv.FieldOrd: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field ord", values[i]) + } else if value.Valid { + a.Ord = int(value.Int64) + } + case adv.FieldMemo: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field memo", values[i]) + } else if value.Valid { + a.Memo = value.String + } + case adv.FieldStartTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field start_time", values[i]) + } else if value.Valid { + a.StartTime = value.Time + } + case adv.FieldEndTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field end_time", values[i]) + } else if value.Valid { + a.EndTime = value.Time + } + case adv.FieldStatus: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field status", values[i]) + } else if value.Valid { + a.Status = int(value.Int64) + } + default: + a.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Adv. +// This includes values selected through modifiers, order, etc. +func (a *Adv) Value(name string) (ent.Value, error) { + return a.selectValues.Get(name) +} + +// Update returns a builder for updating this Adv. +// Note that you need to call Adv.Unwrap() before calling this method if this Adv +// was returned from a transaction, and the transaction was committed or rolled back. +func (a *Adv) Update() *AdvUpdateOne { + return NewAdvClient(a.config).UpdateOne(a) +} + +// Unwrap unwraps the Adv entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (a *Adv) Unwrap() *Adv { + _tx, ok := a.config.driver.(*txDriver) + if !ok { + panic("ent: Adv is not a transactional entity") + } + a.config.driver = _tx.drv + return a +} + +// String implements the fmt.Stringer. +func (a *Adv) String() string { + var builder strings.Builder + builder.WriteString("Adv(") + builder.WriteString(fmt.Sprintf("id=%v, ", a.ID)) + builder.WriteString("create_time=") + builder.WriteString(a.CreateTime.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("update_time=") + builder.WriteString(a.UpdateTime.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("code=") + builder.WriteString(a.Code) + builder.WriteString(", ") + builder.WriteString("mall_code=") + builder.WriteString(a.MallCode) + builder.WriteString(", ") + builder.WriteString("mall_name=") + builder.WriteString(a.MallName) + builder.WriteString(", ") + builder.WriteString("h3_index_6=") + builder.WriteString(a.H3Index6) + builder.WriteString(", ") + builder.WriteString("h3_index_7=") + builder.WriteString(a.H3Index7) + builder.WriteString(", ") + builder.WriteString("h3_index_8=") + builder.WriteString(a.H3Index8) + builder.WriteString(", ") + builder.WriteString("img_path=") + builder.WriteString(a.ImgPath) + builder.WriteString(", ") + builder.WriteString("url=") + builder.WriteString(a.URL) + builder.WriteString(", ") + builder.WriteString("ruler=") + builder.WriteString(a.Ruler) + builder.WriteString(", ") + builder.WriteString("ord=") + builder.WriteString(fmt.Sprintf("%v", a.Ord)) + builder.WriteString(", ") + builder.WriteString("memo=") + builder.WriteString(a.Memo) + builder.WriteString(", ") + builder.WriteString("start_time=") + builder.WriteString(a.StartTime.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("end_time=") + builder.WriteString(a.EndTime.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(fmt.Sprintf("%v", a.Status)) + builder.WriteByte(')') + return builder.String() +} + +// Advs is a parsable slice of Adv. +type Advs []*Adv diff --git a/adv/orm/ent/adv/adv.go b/adv/orm/ent/adv/adv.go new file mode 100644 index 0000000..bb43bdc --- /dev/null +++ b/adv/orm/ent/adv/adv.go @@ -0,0 +1,211 @@ +// Code generated by ent, DO NOT EDIT. + +package adv + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the adv type in the database. + Label = "adv" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreateTime holds the string denoting the create_time field in the database. + FieldCreateTime = "create_time" + // FieldUpdateTime holds the string denoting the update_time field in the database. + FieldUpdateTime = "update_time" + // FieldCode holds the string denoting the code field in the database. + FieldCode = "code" + // FieldMallCode holds the string denoting the mall_code field in the database. + FieldMallCode = "mall_code" + // FieldMallName holds the string denoting the mall_name field in the database. + FieldMallName = "mall_name" + // FieldH3Index6 holds the string denoting the h3_index_6 field in the database. + FieldH3Index6 = "h3_index_6" + // FieldH3Index7 holds the string denoting the h3_index_7 field in the database. + FieldH3Index7 = "h3_index_7" + // FieldH3Index8 holds the string denoting the h3_index_8 field in the database. + FieldH3Index8 = "h3_index_8" + // FieldImgPath holds the string denoting the img_path field in the database. + FieldImgPath = "img_path" + // FieldURL holds the string denoting the url field in the database. + FieldURL = "url" + // FieldRuler holds the string denoting the ruler field in the database. + FieldRuler = "ruler" + // FieldOrd holds the string denoting the ord field in the database. + FieldOrd = "ord" + // FieldMemo holds the string denoting the memo field in the database. + FieldMemo = "memo" + // FieldStartTime holds the string denoting the start_time field in the database. + FieldStartTime = "start_time" + // FieldEndTime holds the string denoting the end_time field in the database. + FieldEndTime = "end_time" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // Table holds the table name of the adv in the database. + Table = "t_adv" +) + +// Columns holds all SQL columns for adv fields. +var Columns = []string{ + FieldID, + FieldCreateTime, + FieldUpdateTime, + FieldCode, + FieldMallCode, + FieldMallName, + FieldH3Index6, + FieldH3Index7, + FieldH3Index8, + FieldImgPath, + FieldURL, + FieldRuler, + FieldOrd, + FieldMemo, + FieldStartTime, + FieldEndTime, + FieldStatus, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreateTime holds the default value on creation for the "create_time" field. + DefaultCreateTime func() time.Time + // DefaultUpdateTime holds the default value on creation for the "update_time" field. + DefaultUpdateTime func() time.Time + // UpdateDefaultUpdateTime holds the default value on update for the "update_time" field. + UpdateDefaultUpdateTime func() time.Time + // DefaultCode holds the default value on creation for the "code" field. + DefaultCode func() string + // CodeValidator is a validator for the "code" field. It is called by the builders before save. + CodeValidator func(string) error + // MallCodeValidator is a validator for the "mall_code" field. It is called by the builders before save. + MallCodeValidator func(string) error + // MallNameValidator is a validator for the "mall_name" field. It is called by the builders before save. + MallNameValidator func(string) error + // H3Index6Validator is a validator for the "h3_index_6" field. It is called by the builders before save. + H3Index6Validator func(string) error + // H3Index7Validator is a validator for the "h3_index_7" field. It is called by the builders before save. + H3Index7Validator func(string) error + // H3Index8Validator is a validator for the "h3_index_8" field. It is called by the builders before save. + H3Index8Validator func(string) error + // ImgPathValidator is a validator for the "img_path" field. It is called by the builders before save. + ImgPathValidator func(string) error + // URLValidator is a validator for the "url" field. It is called by the builders before save. + URLValidator func(string) error + // RulerValidator is a validator for the "ruler" field. It is called by the builders before save. + RulerValidator func(string) error + // DefaultOrd holds the default value on creation for the "ord" field. + DefaultOrd int + // MemoValidator is a validator for the "memo" field. It is called by the builders before save. + MemoValidator func(string) error + // DefaultStartTime holds the default value on creation for the "start_time" field. + DefaultStartTime func() time.Time + // DefaultEndTime holds the default value on creation for the "end_time" field. + DefaultEndTime func() time.Time + // DefaultStatus holds the default value on creation for the "status" field. + DefaultStatus int + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the Adv queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreateTime orders the results by the create_time field. +func ByCreateTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreateTime, opts...).ToFunc() +} + +// ByUpdateTime orders the results by the update_time field. +func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdateTime, opts...).ToFunc() +} + +// ByCode orders the results by the code field. +func ByCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCode, opts...).ToFunc() +} + +// ByMallCode orders the results by the mall_code field. +func ByMallCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMallCode, opts...).ToFunc() +} + +// ByMallName orders the results by the mall_name field. +func ByMallName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMallName, opts...).ToFunc() +} + +// ByH3Index6 orders the results by the h3_index_6 field. +func ByH3Index6(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldH3Index6, opts...).ToFunc() +} + +// ByH3Index7 orders the results by the h3_index_7 field. +func ByH3Index7(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldH3Index7, opts...).ToFunc() +} + +// ByH3Index8 orders the results by the h3_index_8 field. +func ByH3Index8(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldH3Index8, opts...).ToFunc() +} + +// ByImgPath orders the results by the img_path field. +func ByImgPath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldImgPath, opts...).ToFunc() +} + +// ByURL orders the results by the url field. +func ByURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldURL, opts...).ToFunc() +} + +// ByRuler orders the results by the ruler field. +func ByRuler(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRuler, opts...).ToFunc() +} + +// ByOrd orders the results by the ord field. +func ByOrd(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOrd, opts...).ToFunc() +} + +// ByMemo orders the results by the memo field. +func ByMemo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMemo, opts...).ToFunc() +} + +// ByStartTime orders the results by the start_time field. +func ByStartTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStartTime, opts...).ToFunc() +} + +// ByEndTime orders the results by the end_time field. +func ByEndTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEndTime, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} diff --git a/adv/orm/ent/adv/where.go b/adv/orm/ent/adv/where.go new file mode 100644 index 0000000..2527af5 --- /dev/null +++ b/adv/orm/ent/adv/where.go @@ -0,0 +1,1041 @@ +// Code generated by ent, DO NOT EDIT. + +package adv + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldID, id)) +} + +// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ. +func CreateTime(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldCreateTime, v)) +} + +// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ. +func UpdateTime(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldUpdateTime, v)) +} + +// Code applies equality check predicate on the "code" field. It's identical to CodeEQ. +func Code(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldCode, v)) +} + +// MallCode applies equality check predicate on the "mall_code" field. It's identical to MallCodeEQ. +func MallCode(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldMallCode, v)) +} + +// MallName applies equality check predicate on the "mall_name" field. It's identical to MallNameEQ. +func MallName(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldMallName, v)) +} + +// H3Index6 applies equality check predicate on the "h3_index_6" field. It's identical to H3Index6EQ. +func H3Index6(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldH3Index6, v)) +} + +// H3Index7 applies equality check predicate on the "h3_index_7" field. It's identical to H3Index7EQ. +func H3Index7(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldH3Index7, v)) +} + +// H3Index8 applies equality check predicate on the "h3_index_8" field. It's identical to H3Index8EQ. +func H3Index8(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldH3Index8, v)) +} + +// ImgPath applies equality check predicate on the "img_path" field. It's identical to ImgPathEQ. +func ImgPath(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldImgPath, v)) +} + +// URL applies equality check predicate on the "url" field. It's identical to URLEQ. +func URL(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldURL, v)) +} + +// Ruler applies equality check predicate on the "ruler" field. It's identical to RulerEQ. +func Ruler(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldRuler, v)) +} + +// Ord applies equality check predicate on the "ord" field. It's identical to OrdEQ. +func Ord(v int) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldOrd, v)) +} + +// Memo applies equality check predicate on the "memo" field. It's identical to MemoEQ. +func Memo(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldMemo, v)) +} + +// StartTime applies equality check predicate on the "start_time" field. It's identical to StartTimeEQ. +func StartTime(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldStartTime, v)) +} + +// EndTime applies equality check predicate on the "end_time" field. It's identical to EndTimeEQ. +func EndTime(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldEndTime, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v int) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldStatus, v)) +} + +// CreateTimeEQ applies the EQ predicate on the "create_time" field. +func CreateTimeEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldCreateTime, v)) +} + +// CreateTimeNEQ applies the NEQ predicate on the "create_time" field. +func CreateTimeNEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldCreateTime, v)) +} + +// CreateTimeIn applies the In predicate on the "create_time" field. +func CreateTimeIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldCreateTime, vs...)) +} + +// CreateTimeNotIn applies the NotIn predicate on the "create_time" field. +func CreateTimeNotIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldCreateTime, vs...)) +} + +// CreateTimeGT applies the GT predicate on the "create_time" field. +func CreateTimeGT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldCreateTime, v)) +} + +// CreateTimeGTE applies the GTE predicate on the "create_time" field. +func CreateTimeGTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldCreateTime, v)) +} + +// CreateTimeLT applies the LT predicate on the "create_time" field. +func CreateTimeLT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldCreateTime, v)) +} + +// CreateTimeLTE applies the LTE predicate on the "create_time" field. +func CreateTimeLTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldCreateTime, v)) +} + +// UpdateTimeEQ applies the EQ predicate on the "update_time" field. +func UpdateTimeEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldUpdateTime, v)) +} + +// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field. +func UpdateTimeNEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldUpdateTime, v)) +} + +// UpdateTimeIn applies the In predicate on the "update_time" field. +func UpdateTimeIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldUpdateTime, vs...)) +} + +// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field. +func UpdateTimeNotIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldUpdateTime, vs...)) +} + +// UpdateTimeGT applies the GT predicate on the "update_time" field. +func UpdateTimeGT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldUpdateTime, v)) +} + +// UpdateTimeGTE applies the GTE predicate on the "update_time" field. +func UpdateTimeGTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldUpdateTime, v)) +} + +// UpdateTimeLT applies the LT predicate on the "update_time" field. +func UpdateTimeLT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldUpdateTime, v)) +} + +// UpdateTimeLTE applies the LTE predicate on the "update_time" field. +func UpdateTimeLTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldUpdateTime, v)) +} + +// CodeEQ applies the EQ predicate on the "code" field. +func CodeEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldCode, v)) +} + +// CodeNEQ applies the NEQ predicate on the "code" field. +func CodeNEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldCode, v)) +} + +// CodeIn applies the In predicate on the "code" field. +func CodeIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldCode, vs...)) +} + +// CodeNotIn applies the NotIn predicate on the "code" field. +func CodeNotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldCode, vs...)) +} + +// CodeGT applies the GT predicate on the "code" field. +func CodeGT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldCode, v)) +} + +// CodeGTE applies the GTE predicate on the "code" field. +func CodeGTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldCode, v)) +} + +// CodeLT applies the LT predicate on the "code" field. +func CodeLT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldCode, v)) +} + +// CodeLTE applies the LTE predicate on the "code" field. +func CodeLTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldCode, v)) +} + +// CodeContains applies the Contains predicate on the "code" field. +func CodeContains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldCode, v)) +} + +// CodeHasPrefix applies the HasPrefix predicate on the "code" field. +func CodeHasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldCode, v)) +} + +// CodeHasSuffix applies the HasSuffix predicate on the "code" field. +func CodeHasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldCode, v)) +} + +// CodeEqualFold applies the EqualFold predicate on the "code" field. +func CodeEqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldCode, v)) +} + +// CodeContainsFold applies the ContainsFold predicate on the "code" field. +func CodeContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldCode, v)) +} + +// MallCodeEQ applies the EQ predicate on the "mall_code" field. +func MallCodeEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldMallCode, v)) +} + +// MallCodeNEQ applies the NEQ predicate on the "mall_code" field. +func MallCodeNEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldMallCode, v)) +} + +// MallCodeIn applies the In predicate on the "mall_code" field. +func MallCodeIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldMallCode, vs...)) +} + +// MallCodeNotIn applies the NotIn predicate on the "mall_code" field. +func MallCodeNotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldMallCode, vs...)) +} + +// MallCodeGT applies the GT predicate on the "mall_code" field. +func MallCodeGT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldMallCode, v)) +} + +// MallCodeGTE applies the GTE predicate on the "mall_code" field. +func MallCodeGTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldMallCode, v)) +} + +// MallCodeLT applies the LT predicate on the "mall_code" field. +func MallCodeLT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldMallCode, v)) +} + +// MallCodeLTE applies the LTE predicate on the "mall_code" field. +func MallCodeLTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldMallCode, v)) +} + +// MallCodeContains applies the Contains predicate on the "mall_code" field. +func MallCodeContains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldMallCode, v)) +} + +// MallCodeHasPrefix applies the HasPrefix predicate on the "mall_code" field. +func MallCodeHasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldMallCode, v)) +} + +// MallCodeHasSuffix applies the HasSuffix predicate on the "mall_code" field. +func MallCodeHasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldMallCode, v)) +} + +// MallCodeEqualFold applies the EqualFold predicate on the "mall_code" field. +func MallCodeEqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldMallCode, v)) +} + +// MallCodeContainsFold applies the ContainsFold predicate on the "mall_code" field. +func MallCodeContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldMallCode, v)) +} + +// MallNameEQ applies the EQ predicate on the "mall_name" field. +func MallNameEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldMallName, v)) +} + +// MallNameNEQ applies the NEQ predicate on the "mall_name" field. +func MallNameNEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldMallName, v)) +} + +// MallNameIn applies the In predicate on the "mall_name" field. +func MallNameIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldMallName, vs...)) +} + +// MallNameNotIn applies the NotIn predicate on the "mall_name" field. +func MallNameNotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldMallName, vs...)) +} + +// MallNameGT applies the GT predicate on the "mall_name" field. +func MallNameGT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldMallName, v)) +} + +// MallNameGTE applies the GTE predicate on the "mall_name" field. +func MallNameGTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldMallName, v)) +} + +// MallNameLT applies the LT predicate on the "mall_name" field. +func MallNameLT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldMallName, v)) +} + +// MallNameLTE applies the LTE predicate on the "mall_name" field. +func MallNameLTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldMallName, v)) +} + +// MallNameContains applies the Contains predicate on the "mall_name" field. +func MallNameContains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldMallName, v)) +} + +// MallNameHasPrefix applies the HasPrefix predicate on the "mall_name" field. +func MallNameHasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldMallName, v)) +} + +// MallNameHasSuffix applies the HasSuffix predicate on the "mall_name" field. +func MallNameHasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldMallName, v)) +} + +// MallNameEqualFold applies the EqualFold predicate on the "mall_name" field. +func MallNameEqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldMallName, v)) +} + +// MallNameContainsFold applies the ContainsFold predicate on the "mall_name" field. +func MallNameContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldMallName, v)) +} + +// H3Index6EQ applies the EQ predicate on the "h3_index_6" field. +func H3Index6EQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldH3Index6, v)) +} + +// H3Index6NEQ applies the NEQ predicate on the "h3_index_6" field. +func H3Index6NEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldH3Index6, v)) +} + +// H3Index6In applies the In predicate on the "h3_index_6" field. +func H3Index6In(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldH3Index6, vs...)) +} + +// H3Index6NotIn applies the NotIn predicate on the "h3_index_6" field. +func H3Index6NotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldH3Index6, vs...)) +} + +// H3Index6GT applies the GT predicate on the "h3_index_6" field. +func H3Index6GT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldH3Index6, v)) +} + +// H3Index6GTE applies the GTE predicate on the "h3_index_6" field. +func H3Index6GTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldH3Index6, v)) +} + +// H3Index6LT applies the LT predicate on the "h3_index_6" field. +func H3Index6LT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldH3Index6, v)) +} + +// H3Index6LTE applies the LTE predicate on the "h3_index_6" field. +func H3Index6LTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldH3Index6, v)) +} + +// H3Index6Contains applies the Contains predicate on the "h3_index_6" field. +func H3Index6Contains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldH3Index6, v)) +} + +// H3Index6HasPrefix applies the HasPrefix predicate on the "h3_index_6" field. +func H3Index6HasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldH3Index6, v)) +} + +// H3Index6HasSuffix applies the HasSuffix predicate on the "h3_index_6" field. +func H3Index6HasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldH3Index6, v)) +} + +// H3Index6EqualFold applies the EqualFold predicate on the "h3_index_6" field. +func H3Index6EqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldH3Index6, v)) +} + +// H3Index6ContainsFold applies the ContainsFold predicate on the "h3_index_6" field. +func H3Index6ContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldH3Index6, v)) +} + +// H3Index7EQ applies the EQ predicate on the "h3_index_7" field. +func H3Index7EQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldH3Index7, v)) +} + +// H3Index7NEQ applies the NEQ predicate on the "h3_index_7" field. +func H3Index7NEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldH3Index7, v)) +} + +// H3Index7In applies the In predicate on the "h3_index_7" field. +func H3Index7In(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldH3Index7, vs...)) +} + +// H3Index7NotIn applies the NotIn predicate on the "h3_index_7" field. +func H3Index7NotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldH3Index7, vs...)) +} + +// H3Index7GT applies the GT predicate on the "h3_index_7" field. +func H3Index7GT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldH3Index7, v)) +} + +// H3Index7GTE applies the GTE predicate on the "h3_index_7" field. +func H3Index7GTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldH3Index7, v)) +} + +// H3Index7LT applies the LT predicate on the "h3_index_7" field. +func H3Index7LT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldH3Index7, v)) +} + +// H3Index7LTE applies the LTE predicate on the "h3_index_7" field. +func H3Index7LTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldH3Index7, v)) +} + +// H3Index7Contains applies the Contains predicate on the "h3_index_7" field. +func H3Index7Contains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldH3Index7, v)) +} + +// H3Index7HasPrefix applies the HasPrefix predicate on the "h3_index_7" field. +func H3Index7HasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldH3Index7, v)) +} + +// H3Index7HasSuffix applies the HasSuffix predicate on the "h3_index_7" field. +func H3Index7HasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldH3Index7, v)) +} + +// H3Index7EqualFold applies the EqualFold predicate on the "h3_index_7" field. +func H3Index7EqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldH3Index7, v)) +} + +// H3Index7ContainsFold applies the ContainsFold predicate on the "h3_index_7" field. +func H3Index7ContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldH3Index7, v)) +} + +// H3Index8EQ applies the EQ predicate on the "h3_index_8" field. +func H3Index8EQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldH3Index8, v)) +} + +// H3Index8NEQ applies the NEQ predicate on the "h3_index_8" field. +func H3Index8NEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldH3Index8, v)) +} + +// H3Index8In applies the In predicate on the "h3_index_8" field. +func H3Index8In(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldH3Index8, vs...)) +} + +// H3Index8NotIn applies the NotIn predicate on the "h3_index_8" field. +func H3Index8NotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldH3Index8, vs...)) +} + +// H3Index8GT applies the GT predicate on the "h3_index_8" field. +func H3Index8GT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldH3Index8, v)) +} + +// H3Index8GTE applies the GTE predicate on the "h3_index_8" field. +func H3Index8GTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldH3Index8, v)) +} + +// H3Index8LT applies the LT predicate on the "h3_index_8" field. +func H3Index8LT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldH3Index8, v)) +} + +// H3Index8LTE applies the LTE predicate on the "h3_index_8" field. +func H3Index8LTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldH3Index8, v)) +} + +// H3Index8Contains applies the Contains predicate on the "h3_index_8" field. +func H3Index8Contains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldH3Index8, v)) +} + +// H3Index8HasPrefix applies the HasPrefix predicate on the "h3_index_8" field. +func H3Index8HasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldH3Index8, v)) +} + +// H3Index8HasSuffix applies the HasSuffix predicate on the "h3_index_8" field. +func H3Index8HasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldH3Index8, v)) +} + +// H3Index8EqualFold applies the EqualFold predicate on the "h3_index_8" field. +func H3Index8EqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldH3Index8, v)) +} + +// H3Index8ContainsFold applies the ContainsFold predicate on the "h3_index_8" field. +func H3Index8ContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldH3Index8, v)) +} + +// ImgPathEQ applies the EQ predicate on the "img_path" field. +func ImgPathEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldImgPath, v)) +} + +// ImgPathNEQ applies the NEQ predicate on the "img_path" field. +func ImgPathNEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldImgPath, v)) +} + +// ImgPathIn applies the In predicate on the "img_path" field. +func ImgPathIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldImgPath, vs...)) +} + +// ImgPathNotIn applies the NotIn predicate on the "img_path" field. +func ImgPathNotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldImgPath, vs...)) +} + +// ImgPathGT applies the GT predicate on the "img_path" field. +func ImgPathGT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldImgPath, v)) +} + +// ImgPathGTE applies the GTE predicate on the "img_path" field. +func ImgPathGTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldImgPath, v)) +} + +// ImgPathLT applies the LT predicate on the "img_path" field. +func ImgPathLT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldImgPath, v)) +} + +// ImgPathLTE applies the LTE predicate on the "img_path" field. +func ImgPathLTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldImgPath, v)) +} + +// ImgPathContains applies the Contains predicate on the "img_path" field. +func ImgPathContains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldImgPath, v)) +} + +// ImgPathHasPrefix applies the HasPrefix predicate on the "img_path" field. +func ImgPathHasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldImgPath, v)) +} + +// ImgPathHasSuffix applies the HasSuffix predicate on the "img_path" field. +func ImgPathHasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldImgPath, v)) +} + +// ImgPathEqualFold applies the EqualFold predicate on the "img_path" field. +func ImgPathEqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldImgPath, v)) +} + +// ImgPathContainsFold applies the ContainsFold predicate on the "img_path" field. +func ImgPathContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldImgPath, v)) +} + +// URLEQ applies the EQ predicate on the "url" field. +func URLEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldURL, v)) +} + +// URLNEQ applies the NEQ predicate on the "url" field. +func URLNEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldURL, v)) +} + +// URLIn applies the In predicate on the "url" field. +func URLIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldURL, vs...)) +} + +// URLNotIn applies the NotIn predicate on the "url" field. +func URLNotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldURL, vs...)) +} + +// URLGT applies the GT predicate on the "url" field. +func URLGT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldURL, v)) +} + +// URLGTE applies the GTE predicate on the "url" field. +func URLGTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldURL, v)) +} + +// URLLT applies the LT predicate on the "url" field. +func URLLT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldURL, v)) +} + +// URLLTE applies the LTE predicate on the "url" field. +func URLLTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldURL, v)) +} + +// URLContains applies the Contains predicate on the "url" field. +func URLContains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldURL, v)) +} + +// URLHasPrefix applies the HasPrefix predicate on the "url" field. +func URLHasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldURL, v)) +} + +// URLHasSuffix applies the HasSuffix predicate on the "url" field. +func URLHasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldURL, v)) +} + +// URLEqualFold applies the EqualFold predicate on the "url" field. +func URLEqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldURL, v)) +} + +// URLContainsFold applies the ContainsFold predicate on the "url" field. +func URLContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldURL, v)) +} + +// RulerEQ applies the EQ predicate on the "ruler" field. +func RulerEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldRuler, v)) +} + +// RulerNEQ applies the NEQ predicate on the "ruler" field. +func RulerNEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldRuler, v)) +} + +// RulerIn applies the In predicate on the "ruler" field. +func RulerIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldRuler, vs...)) +} + +// RulerNotIn applies the NotIn predicate on the "ruler" field. +func RulerNotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldRuler, vs...)) +} + +// RulerGT applies the GT predicate on the "ruler" field. +func RulerGT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldRuler, v)) +} + +// RulerGTE applies the GTE predicate on the "ruler" field. +func RulerGTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldRuler, v)) +} + +// RulerLT applies the LT predicate on the "ruler" field. +func RulerLT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldRuler, v)) +} + +// RulerLTE applies the LTE predicate on the "ruler" field. +func RulerLTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldRuler, v)) +} + +// RulerContains applies the Contains predicate on the "ruler" field. +func RulerContains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldRuler, v)) +} + +// RulerHasPrefix applies the HasPrefix predicate on the "ruler" field. +func RulerHasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldRuler, v)) +} + +// RulerHasSuffix applies the HasSuffix predicate on the "ruler" field. +func RulerHasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldRuler, v)) +} + +// RulerEqualFold applies the EqualFold predicate on the "ruler" field. +func RulerEqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldRuler, v)) +} + +// RulerContainsFold applies the ContainsFold predicate on the "ruler" field. +func RulerContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldRuler, v)) +} + +// OrdEQ applies the EQ predicate on the "ord" field. +func OrdEQ(v int) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldOrd, v)) +} + +// OrdNEQ applies the NEQ predicate on the "ord" field. +func OrdNEQ(v int) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldOrd, v)) +} + +// OrdIn applies the In predicate on the "ord" field. +func OrdIn(vs ...int) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldOrd, vs...)) +} + +// OrdNotIn applies the NotIn predicate on the "ord" field. +func OrdNotIn(vs ...int) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldOrd, vs...)) +} + +// OrdGT applies the GT predicate on the "ord" field. +func OrdGT(v int) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldOrd, v)) +} + +// OrdGTE applies the GTE predicate on the "ord" field. +func OrdGTE(v int) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldOrd, v)) +} + +// OrdLT applies the LT predicate on the "ord" field. +func OrdLT(v int) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldOrd, v)) +} + +// OrdLTE applies the LTE predicate on the "ord" field. +func OrdLTE(v int) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldOrd, v)) +} + +// MemoEQ applies the EQ predicate on the "memo" field. +func MemoEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldMemo, v)) +} + +// MemoNEQ applies the NEQ predicate on the "memo" field. +func MemoNEQ(v string) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldMemo, v)) +} + +// MemoIn applies the In predicate on the "memo" field. +func MemoIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldMemo, vs...)) +} + +// MemoNotIn applies the NotIn predicate on the "memo" field. +func MemoNotIn(vs ...string) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldMemo, vs...)) +} + +// MemoGT applies the GT predicate on the "memo" field. +func MemoGT(v string) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldMemo, v)) +} + +// MemoGTE applies the GTE predicate on the "memo" field. +func MemoGTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldMemo, v)) +} + +// MemoLT applies the LT predicate on the "memo" field. +func MemoLT(v string) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldMemo, v)) +} + +// MemoLTE applies the LTE predicate on the "memo" field. +func MemoLTE(v string) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldMemo, v)) +} + +// MemoContains applies the Contains predicate on the "memo" field. +func MemoContains(v string) predicate.Adv { + return predicate.Adv(sql.FieldContains(FieldMemo, v)) +} + +// MemoHasPrefix applies the HasPrefix predicate on the "memo" field. +func MemoHasPrefix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasPrefix(FieldMemo, v)) +} + +// MemoHasSuffix applies the HasSuffix predicate on the "memo" field. +func MemoHasSuffix(v string) predicate.Adv { + return predicate.Adv(sql.FieldHasSuffix(FieldMemo, v)) +} + +// MemoEqualFold applies the EqualFold predicate on the "memo" field. +func MemoEqualFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldEqualFold(FieldMemo, v)) +} + +// MemoContainsFold applies the ContainsFold predicate on the "memo" field. +func MemoContainsFold(v string) predicate.Adv { + return predicate.Adv(sql.FieldContainsFold(FieldMemo, v)) +} + +// StartTimeEQ applies the EQ predicate on the "start_time" field. +func StartTimeEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldStartTime, v)) +} + +// StartTimeNEQ applies the NEQ predicate on the "start_time" field. +func StartTimeNEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldStartTime, v)) +} + +// StartTimeIn applies the In predicate on the "start_time" field. +func StartTimeIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldStartTime, vs...)) +} + +// StartTimeNotIn applies the NotIn predicate on the "start_time" field. +func StartTimeNotIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldStartTime, vs...)) +} + +// StartTimeGT applies the GT predicate on the "start_time" field. +func StartTimeGT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldStartTime, v)) +} + +// StartTimeGTE applies the GTE predicate on the "start_time" field. +func StartTimeGTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldStartTime, v)) +} + +// StartTimeLT applies the LT predicate on the "start_time" field. +func StartTimeLT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldStartTime, v)) +} + +// StartTimeLTE applies the LTE predicate on the "start_time" field. +func StartTimeLTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldStartTime, v)) +} + +// EndTimeEQ applies the EQ predicate on the "end_time" field. +func EndTimeEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldEndTime, v)) +} + +// EndTimeNEQ applies the NEQ predicate on the "end_time" field. +func EndTimeNEQ(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldEndTime, v)) +} + +// EndTimeIn applies the In predicate on the "end_time" field. +func EndTimeIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldEndTime, vs...)) +} + +// EndTimeNotIn applies the NotIn predicate on the "end_time" field. +func EndTimeNotIn(vs ...time.Time) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldEndTime, vs...)) +} + +// EndTimeGT applies the GT predicate on the "end_time" field. +func EndTimeGT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldEndTime, v)) +} + +// EndTimeGTE applies the GTE predicate on the "end_time" field. +func EndTimeGTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldEndTime, v)) +} + +// EndTimeLT applies the LT predicate on the "end_time" field. +func EndTimeLT(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldEndTime, v)) +} + +// EndTimeLTE applies the LTE predicate on the "end_time" field. +func EndTimeLTE(v time.Time) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldEndTime, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v int) predicate.Adv { + return predicate.Adv(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v int) predicate.Adv { + return predicate.Adv(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...int) predicate.Adv { + return predicate.Adv(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...int) predicate.Adv { + return predicate.Adv(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v int) predicate.Adv { + return predicate.Adv(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v int) predicate.Adv { + return predicate.Adv(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v int) predicate.Adv { + return predicate.Adv(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v int) predicate.Adv { + return predicate.Adv(sql.FieldLTE(FieldStatus, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Adv) predicate.Adv { + return predicate.Adv(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Adv) predicate.Adv { + return predicate.Adv(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Adv) predicate.Adv { + return predicate.Adv(sql.NotPredicates(p)) +} diff --git a/adv/orm/ent/adv_create.go b/adv/orm/ent/adv_create.go new file mode 100644 index 0000000..cf4e536 --- /dev/null +++ b/adv/orm/ent/adv_create.go @@ -0,0 +1,1240 @@ +// 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" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/adv" +) + +// AdvCreate is the builder for creating a Adv entity. +type AdvCreate struct { + config + mutation *AdvMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetCreateTime sets the "create_time" field. +func (ac *AdvCreate) SetCreateTime(t time.Time) *AdvCreate { + ac.mutation.SetCreateTime(t) + return ac +} + +// SetNillableCreateTime sets the "create_time" field if the given value is not nil. +func (ac *AdvCreate) SetNillableCreateTime(t *time.Time) *AdvCreate { + if t != nil { + ac.SetCreateTime(*t) + } + return ac +} + +// SetUpdateTime sets the "update_time" field. +func (ac *AdvCreate) SetUpdateTime(t time.Time) *AdvCreate { + ac.mutation.SetUpdateTime(t) + return ac +} + +// SetNillableUpdateTime sets the "update_time" field if the given value is not nil. +func (ac *AdvCreate) SetNillableUpdateTime(t *time.Time) *AdvCreate { + if t != nil { + ac.SetUpdateTime(*t) + } + return ac +} + +// SetCode sets the "code" field. +func (ac *AdvCreate) SetCode(s string) *AdvCreate { + ac.mutation.SetCode(s) + return ac +} + +// SetNillableCode sets the "code" field if the given value is not nil. +func (ac *AdvCreate) SetNillableCode(s *string) *AdvCreate { + if s != nil { + ac.SetCode(*s) + } + return ac +} + +// SetMallCode sets the "mall_code" field. +func (ac *AdvCreate) SetMallCode(s string) *AdvCreate { + ac.mutation.SetMallCode(s) + return ac +} + +// SetMallName sets the "mall_name" field. +func (ac *AdvCreate) SetMallName(s string) *AdvCreate { + ac.mutation.SetMallName(s) + return ac +} + +// SetH3Index6 sets the "h3_index_6" field. +func (ac *AdvCreate) SetH3Index6(s string) *AdvCreate { + ac.mutation.SetH3Index6(s) + return ac +} + +// SetH3Index7 sets the "h3_index_7" field. +func (ac *AdvCreate) SetH3Index7(s string) *AdvCreate { + ac.mutation.SetH3Index7(s) + return ac +} + +// SetH3Index8 sets the "h3_index_8" field. +func (ac *AdvCreate) SetH3Index8(s string) *AdvCreate { + ac.mutation.SetH3Index8(s) + return ac +} + +// SetImgPath sets the "img_path" field. +func (ac *AdvCreate) SetImgPath(s string) *AdvCreate { + ac.mutation.SetImgPath(s) + return ac +} + +// SetURL sets the "url" field. +func (ac *AdvCreate) SetURL(s string) *AdvCreate { + ac.mutation.SetURL(s) + return ac +} + +// SetRuler sets the "ruler" field. +func (ac *AdvCreate) SetRuler(s string) *AdvCreate { + ac.mutation.SetRuler(s) + return ac +} + +// SetOrd sets the "ord" field. +func (ac *AdvCreate) SetOrd(i int) *AdvCreate { + ac.mutation.SetOrd(i) + return ac +} + +// SetNillableOrd sets the "ord" field if the given value is not nil. +func (ac *AdvCreate) SetNillableOrd(i *int) *AdvCreate { + if i != nil { + ac.SetOrd(*i) + } + return ac +} + +// SetMemo sets the "memo" field. +func (ac *AdvCreate) SetMemo(s string) *AdvCreate { + ac.mutation.SetMemo(s) + return ac +} + +// SetStartTime sets the "start_time" field. +func (ac *AdvCreate) SetStartTime(t time.Time) *AdvCreate { + ac.mutation.SetStartTime(t) + return ac +} + +// SetNillableStartTime sets the "start_time" field if the given value is not nil. +func (ac *AdvCreate) SetNillableStartTime(t *time.Time) *AdvCreate { + if t != nil { + ac.SetStartTime(*t) + } + return ac +} + +// SetEndTime sets the "end_time" field. +func (ac *AdvCreate) SetEndTime(t time.Time) *AdvCreate { + ac.mutation.SetEndTime(t) + return ac +} + +// SetNillableEndTime sets the "end_time" field if the given value is not nil. +func (ac *AdvCreate) SetNillableEndTime(t *time.Time) *AdvCreate { + if t != nil { + ac.SetEndTime(*t) + } + return ac +} + +// SetStatus sets the "status" field. +func (ac *AdvCreate) SetStatus(i int) *AdvCreate { + ac.mutation.SetStatus(i) + return ac +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (ac *AdvCreate) SetNillableStatus(i *int) *AdvCreate { + if i != nil { + ac.SetStatus(*i) + } + return ac +} + +// SetID sets the "id" field. +func (ac *AdvCreate) SetID(u uuid.UUID) *AdvCreate { + ac.mutation.SetID(u) + return ac +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (ac *AdvCreate) SetNillableID(u *uuid.UUID) *AdvCreate { + if u != nil { + ac.SetID(*u) + } + return ac +} + +// Mutation returns the AdvMutation object of the builder. +func (ac *AdvCreate) Mutation() *AdvMutation { + return ac.mutation +} + +// Save creates the Adv in the database. +func (ac *AdvCreate) Save(ctx context.Context) (*Adv, error) { + ac.defaults() + return withHooks(ctx, ac.sqlSave, ac.mutation, ac.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (ac *AdvCreate) SaveX(ctx context.Context) *Adv { + v, err := ac.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (ac *AdvCreate) Exec(ctx context.Context) error { + _, err := ac.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ac *AdvCreate) ExecX(ctx context.Context) { + if err := ac.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (ac *AdvCreate) defaults() { + if _, ok := ac.mutation.CreateTime(); !ok { + v := adv.DefaultCreateTime() + ac.mutation.SetCreateTime(v) + } + if _, ok := ac.mutation.UpdateTime(); !ok { + v := adv.DefaultUpdateTime() + ac.mutation.SetUpdateTime(v) + } + if _, ok := ac.mutation.Code(); !ok { + v := adv.DefaultCode() + ac.mutation.SetCode(v) + } + if _, ok := ac.mutation.Ord(); !ok { + v := adv.DefaultOrd + ac.mutation.SetOrd(v) + } + if _, ok := ac.mutation.StartTime(); !ok { + v := adv.DefaultStartTime() + ac.mutation.SetStartTime(v) + } + if _, ok := ac.mutation.EndTime(); !ok { + v := adv.DefaultEndTime() + ac.mutation.SetEndTime(v) + } + if _, ok := ac.mutation.Status(); !ok { + v := adv.DefaultStatus + ac.mutation.SetStatus(v) + } + if _, ok := ac.mutation.ID(); !ok { + v := adv.DefaultID() + ac.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (ac *AdvCreate) check() error { + if _, ok := ac.mutation.CreateTime(); !ok { + return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "Adv.create_time"`)} + } + if _, ok := ac.mutation.UpdateTime(); !ok { + return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "Adv.update_time"`)} + } + if _, ok := ac.mutation.Code(); !ok { + return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "Adv.code"`)} + } + if v, ok := ac.mutation.Code(); ok { + if err := adv.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Adv.code": %w`, err)} + } + } + if _, ok := ac.mutation.MallCode(); !ok { + return &ValidationError{Name: "mall_code", err: errors.New(`ent: missing required field "Adv.mall_code"`)} + } + if v, ok := ac.mutation.MallCode(); ok { + if err := adv.MallCodeValidator(v); err != nil { + return &ValidationError{Name: "mall_code", err: fmt.Errorf(`ent: validator failed for field "Adv.mall_code": %w`, err)} + } + } + if _, ok := ac.mutation.MallName(); !ok { + return &ValidationError{Name: "mall_name", err: errors.New(`ent: missing required field "Adv.mall_name"`)} + } + if v, ok := ac.mutation.MallName(); ok { + if err := adv.MallNameValidator(v); err != nil { + return &ValidationError{Name: "mall_name", err: fmt.Errorf(`ent: validator failed for field "Adv.mall_name": %w`, err)} + } + } + if _, ok := ac.mutation.H3Index6(); !ok { + return &ValidationError{Name: "h3_index_6", err: errors.New(`ent: missing required field "Adv.h3_index_6"`)} + } + if v, ok := ac.mutation.H3Index6(); ok { + if err := adv.H3Index6Validator(v); err != nil { + return &ValidationError{Name: "h3_index_6", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_6": %w`, err)} + } + } + if _, ok := ac.mutation.H3Index7(); !ok { + return &ValidationError{Name: "h3_index_7", err: errors.New(`ent: missing required field "Adv.h3_index_7"`)} + } + if v, ok := ac.mutation.H3Index7(); ok { + if err := adv.H3Index7Validator(v); err != nil { + return &ValidationError{Name: "h3_index_7", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_7": %w`, err)} + } + } + if _, ok := ac.mutation.H3Index8(); !ok { + return &ValidationError{Name: "h3_index_8", err: errors.New(`ent: missing required field "Adv.h3_index_8"`)} + } + if v, ok := ac.mutation.H3Index8(); ok { + if err := adv.H3Index8Validator(v); err != nil { + return &ValidationError{Name: "h3_index_8", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_8": %w`, err)} + } + } + if _, ok := ac.mutation.ImgPath(); !ok { + return &ValidationError{Name: "img_path", err: errors.New(`ent: missing required field "Adv.img_path"`)} + } + if v, ok := ac.mutation.ImgPath(); ok { + if err := adv.ImgPathValidator(v); err != nil { + return &ValidationError{Name: "img_path", err: fmt.Errorf(`ent: validator failed for field "Adv.img_path": %w`, err)} + } + } + if _, ok := ac.mutation.URL(); !ok { + return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "Adv.url"`)} + } + if v, ok := ac.mutation.URL(); ok { + if err := adv.URLValidator(v); err != nil { + return &ValidationError{Name: "url", err: fmt.Errorf(`ent: validator failed for field "Adv.url": %w`, err)} + } + } + if _, ok := ac.mutation.Ruler(); !ok { + return &ValidationError{Name: "ruler", err: errors.New(`ent: missing required field "Adv.ruler"`)} + } + if v, ok := ac.mutation.Ruler(); ok { + if err := adv.RulerValidator(v); err != nil { + return &ValidationError{Name: "ruler", err: fmt.Errorf(`ent: validator failed for field "Adv.ruler": %w`, err)} + } + } + if _, ok := ac.mutation.Ord(); !ok { + return &ValidationError{Name: "ord", err: errors.New(`ent: missing required field "Adv.ord"`)} + } + if _, ok := ac.mutation.Memo(); !ok { + return &ValidationError{Name: "memo", err: errors.New(`ent: missing required field "Adv.memo"`)} + } + if v, ok := ac.mutation.Memo(); ok { + if err := adv.MemoValidator(v); err != nil { + return &ValidationError{Name: "memo", err: fmt.Errorf(`ent: validator failed for field "Adv.memo": %w`, err)} + } + } + if _, ok := ac.mutation.StartTime(); !ok { + return &ValidationError{Name: "start_time", err: errors.New(`ent: missing required field "Adv.start_time"`)} + } + if _, ok := ac.mutation.EndTime(); !ok { + return &ValidationError{Name: "end_time", err: errors.New(`ent: missing required field "Adv.end_time"`)} + } + if _, ok := ac.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Adv.status"`)} + } + return nil +} + +func (ac *AdvCreate) sqlSave(ctx context.Context) (*Adv, error) { + if err := ac.check(); err != nil { + return nil, err + } + _node, _spec := ac.createSpec() + if err := sqlgraph.CreateNode(ctx, ac.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 + } + } + ac.mutation.id = &_node.ID + ac.mutation.done = true + return _node, nil +} + +func (ac *AdvCreate) createSpec() (*Adv, *sqlgraph.CreateSpec) { + var ( + _node = &Adv{config: ac.config} + _spec = sqlgraph.NewCreateSpec(adv.Table, sqlgraph.NewFieldSpec(adv.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = ac.conflict + if id, ok := ac.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := ac.mutation.CreateTime(); ok { + _spec.SetField(adv.FieldCreateTime, field.TypeTime, value) + _node.CreateTime = value + } + if value, ok := ac.mutation.UpdateTime(); ok { + _spec.SetField(adv.FieldUpdateTime, field.TypeTime, value) + _node.UpdateTime = value + } + if value, ok := ac.mutation.Code(); ok { + _spec.SetField(adv.FieldCode, field.TypeString, value) + _node.Code = value + } + if value, ok := ac.mutation.MallCode(); ok { + _spec.SetField(adv.FieldMallCode, field.TypeString, value) + _node.MallCode = value + } + if value, ok := ac.mutation.MallName(); ok { + _spec.SetField(adv.FieldMallName, field.TypeString, value) + _node.MallName = value + } + if value, ok := ac.mutation.H3Index6(); ok { + _spec.SetField(adv.FieldH3Index6, field.TypeString, value) + _node.H3Index6 = value + } + if value, ok := ac.mutation.H3Index7(); ok { + _spec.SetField(adv.FieldH3Index7, field.TypeString, value) + _node.H3Index7 = value + } + if value, ok := ac.mutation.H3Index8(); ok { + _spec.SetField(adv.FieldH3Index8, field.TypeString, value) + _node.H3Index8 = value + } + if value, ok := ac.mutation.ImgPath(); ok { + _spec.SetField(adv.FieldImgPath, field.TypeString, value) + _node.ImgPath = value + } + if value, ok := ac.mutation.URL(); ok { + _spec.SetField(adv.FieldURL, field.TypeString, value) + _node.URL = value + } + if value, ok := ac.mutation.Ruler(); ok { + _spec.SetField(adv.FieldRuler, field.TypeString, value) + _node.Ruler = value + } + if value, ok := ac.mutation.Ord(); ok { + _spec.SetField(adv.FieldOrd, field.TypeInt, value) + _node.Ord = value + } + if value, ok := ac.mutation.Memo(); ok { + _spec.SetField(adv.FieldMemo, field.TypeString, value) + _node.Memo = value + } + if value, ok := ac.mutation.StartTime(); ok { + _spec.SetField(adv.FieldStartTime, field.TypeTime, value) + _node.StartTime = value + } + if value, ok := ac.mutation.EndTime(); ok { + _spec.SetField(adv.FieldEndTime, field.TypeTime, value) + _node.EndTime = value + } + if value, ok := ac.mutation.Status(); ok { + _spec.SetField(adv.FieldStatus, field.TypeInt, value) + _node.Status = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Adv.Create(). +// SetCreateTime(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.AdvUpsert) { +// SetCreateTime(v+v). +// }). +// Exec(ctx) +func (ac *AdvCreate) OnConflict(opts ...sql.ConflictOption) *AdvUpsertOne { + ac.conflict = opts + return &AdvUpsertOne{ + create: ac, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Adv.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (ac *AdvCreate) OnConflictColumns(columns ...string) *AdvUpsertOne { + ac.conflict = append(ac.conflict, sql.ConflictColumns(columns...)) + return &AdvUpsertOne{ + create: ac, + } +} + +type ( + // AdvUpsertOne is the builder for "upsert"-ing + // one Adv node. + AdvUpsertOne struct { + create *AdvCreate + } + + // AdvUpsert is the "OnConflict" setter. + AdvUpsert struct { + *sql.UpdateSet + } +) + +// SetUpdateTime sets the "update_time" field. +func (u *AdvUpsert) SetUpdateTime(v time.Time) *AdvUpsert { + u.Set(adv.FieldUpdateTime, v) + return u +} + +// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. +func (u *AdvUpsert) UpdateUpdateTime() *AdvUpsert { + u.SetExcluded(adv.FieldUpdateTime) + return u +} + +// SetMallName sets the "mall_name" field. +func (u *AdvUpsert) SetMallName(v string) *AdvUpsert { + u.Set(adv.FieldMallName, v) + return u +} + +// UpdateMallName sets the "mall_name" field to the value that was provided on create. +func (u *AdvUpsert) UpdateMallName() *AdvUpsert { + u.SetExcluded(adv.FieldMallName) + return u +} + +// SetH3Index6 sets the "h3_index_6" field. +func (u *AdvUpsert) SetH3Index6(v string) *AdvUpsert { + u.Set(adv.FieldH3Index6, v) + return u +} + +// UpdateH3Index6 sets the "h3_index_6" field to the value that was provided on create. +func (u *AdvUpsert) UpdateH3Index6() *AdvUpsert { + u.SetExcluded(adv.FieldH3Index6) + return u +} + +// SetH3Index7 sets the "h3_index_7" field. +func (u *AdvUpsert) SetH3Index7(v string) *AdvUpsert { + u.Set(adv.FieldH3Index7, v) + return u +} + +// UpdateH3Index7 sets the "h3_index_7" field to the value that was provided on create. +func (u *AdvUpsert) UpdateH3Index7() *AdvUpsert { + u.SetExcluded(adv.FieldH3Index7) + return u +} + +// SetH3Index8 sets the "h3_index_8" field. +func (u *AdvUpsert) SetH3Index8(v string) *AdvUpsert { + u.Set(adv.FieldH3Index8, v) + return u +} + +// UpdateH3Index8 sets the "h3_index_8" field to the value that was provided on create. +func (u *AdvUpsert) UpdateH3Index8() *AdvUpsert { + u.SetExcluded(adv.FieldH3Index8) + return u +} + +// SetRuler sets the "ruler" field. +func (u *AdvUpsert) SetRuler(v string) *AdvUpsert { + u.Set(adv.FieldRuler, v) + return u +} + +// UpdateRuler sets the "ruler" field to the value that was provided on create. +func (u *AdvUpsert) UpdateRuler() *AdvUpsert { + u.SetExcluded(adv.FieldRuler) + return u +} + +// SetOrd sets the "ord" field. +func (u *AdvUpsert) SetOrd(v int) *AdvUpsert { + u.Set(adv.FieldOrd, v) + return u +} + +// UpdateOrd sets the "ord" field to the value that was provided on create. +func (u *AdvUpsert) UpdateOrd() *AdvUpsert { + u.SetExcluded(adv.FieldOrd) + return u +} + +// AddOrd adds v to the "ord" field. +func (u *AdvUpsert) AddOrd(v int) *AdvUpsert { + u.Add(adv.FieldOrd, v) + return u +} + +// SetMemo sets the "memo" field. +func (u *AdvUpsert) SetMemo(v string) *AdvUpsert { + u.Set(adv.FieldMemo, v) + return u +} + +// UpdateMemo sets the "memo" field to the value that was provided on create. +func (u *AdvUpsert) UpdateMemo() *AdvUpsert { + u.SetExcluded(adv.FieldMemo) + return u +} + +// SetStatus sets the "status" field. +func (u *AdvUpsert) SetStatus(v int) *AdvUpsert { + u.Set(adv.FieldStatus, v) + return u +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *AdvUpsert) UpdateStatus() *AdvUpsert { + u.SetExcluded(adv.FieldStatus) + return u +} + +// AddStatus adds v to the "status" field. +func (u *AdvUpsert) AddStatus(v int) *AdvUpsert { + u.Add(adv.FieldStatus, v) + 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.Adv.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(adv.FieldID) +// }), +// ). +// Exec(ctx) +func (u *AdvUpsertOne) UpdateNewValues() *AdvUpsertOne { + 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(adv.FieldID) + } + if _, exists := u.create.mutation.CreateTime(); exists { + s.SetIgnore(adv.FieldCreateTime) + } + if _, exists := u.create.mutation.Code(); exists { + s.SetIgnore(adv.FieldCode) + } + if _, exists := u.create.mutation.MallCode(); exists { + s.SetIgnore(adv.FieldMallCode) + } + if _, exists := u.create.mutation.ImgPath(); exists { + s.SetIgnore(adv.FieldImgPath) + } + if _, exists := u.create.mutation.URL(); exists { + s.SetIgnore(adv.FieldURL) + } + if _, exists := u.create.mutation.StartTime(); exists { + s.SetIgnore(adv.FieldStartTime) + } + if _, exists := u.create.mutation.EndTime(); exists { + s.SetIgnore(adv.FieldEndTime) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Adv.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *AdvUpsertOne) Ignore() *AdvUpsertOne { + 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 *AdvUpsertOne) DoNothing() *AdvUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the AdvCreate.OnConflict +// documentation for more info. +func (u *AdvUpsertOne) Update(set func(*AdvUpsert)) *AdvUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&AdvUpsert{UpdateSet: update}) + })) + return u +} + +// SetUpdateTime sets the "update_time" field. +func (u *AdvUpsertOne) SetUpdateTime(v time.Time) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetUpdateTime(v) + }) +} + +// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateUpdateTime() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateUpdateTime() + }) +} + +// SetMallName sets the "mall_name" field. +func (u *AdvUpsertOne) SetMallName(v string) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetMallName(v) + }) +} + +// UpdateMallName sets the "mall_name" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateMallName() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateMallName() + }) +} + +// SetH3Index6 sets the "h3_index_6" field. +func (u *AdvUpsertOne) SetH3Index6(v string) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetH3Index6(v) + }) +} + +// UpdateH3Index6 sets the "h3_index_6" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateH3Index6() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateH3Index6() + }) +} + +// SetH3Index7 sets the "h3_index_7" field. +func (u *AdvUpsertOne) SetH3Index7(v string) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetH3Index7(v) + }) +} + +// UpdateH3Index7 sets the "h3_index_7" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateH3Index7() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateH3Index7() + }) +} + +// SetH3Index8 sets the "h3_index_8" field. +func (u *AdvUpsertOne) SetH3Index8(v string) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetH3Index8(v) + }) +} + +// UpdateH3Index8 sets the "h3_index_8" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateH3Index8() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateH3Index8() + }) +} + +// SetRuler sets the "ruler" field. +func (u *AdvUpsertOne) SetRuler(v string) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetRuler(v) + }) +} + +// UpdateRuler sets the "ruler" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateRuler() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateRuler() + }) +} + +// SetOrd sets the "ord" field. +func (u *AdvUpsertOne) SetOrd(v int) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetOrd(v) + }) +} + +// AddOrd adds v to the "ord" field. +func (u *AdvUpsertOne) AddOrd(v int) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.AddOrd(v) + }) +} + +// UpdateOrd sets the "ord" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateOrd() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateOrd() + }) +} + +// SetMemo sets the "memo" field. +func (u *AdvUpsertOne) SetMemo(v string) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetMemo(v) + }) +} + +// UpdateMemo sets the "memo" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateMemo() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateMemo() + }) +} + +// SetStatus sets the "status" field. +func (u *AdvUpsertOne) SetStatus(v int) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.SetStatus(v) + }) +} + +// AddStatus adds v to the "status" field. +func (u *AdvUpsertOne) AddStatus(v int) *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.AddStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *AdvUpsertOne) UpdateStatus() *AdvUpsertOne { + return u.Update(func(s *AdvUpsert) { + s.UpdateStatus() + }) +} + +// Exec executes the query. +func (u *AdvUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for AdvCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *AdvUpsertOne) 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 *AdvUpsertOne) 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: AdvUpsertOne.ID is not supported by MySQL driver. Use AdvUpsertOne.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 *AdvUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// AdvCreateBulk is the builder for creating many Adv entities in bulk. +type AdvCreateBulk struct { + config + err error + builders []*AdvCreate + conflict []sql.ConflictOption +} + +// Save creates the Adv entities in the database. +func (acb *AdvCreateBulk) Save(ctx context.Context) ([]*Adv, error) { + if acb.err != nil { + return nil, acb.err + } + specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) + nodes := make([]*Adv, len(acb.builders)) + mutators := make([]Mutator, len(acb.builders)) + for i := range acb.builders { + func(i int, root context.Context) { + builder := acb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AdvMutation) + 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, acb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = acb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, acb.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, acb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (acb *AdvCreateBulk) SaveX(ctx context.Context) []*Adv { + v, err := acb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (acb *AdvCreateBulk) Exec(ctx context.Context) error { + _, err := acb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (acb *AdvCreateBulk) ExecX(ctx context.Context) { + if err := acb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Adv.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.AdvUpsert) { +// SetCreateTime(v+v). +// }). +// Exec(ctx) +func (acb *AdvCreateBulk) OnConflict(opts ...sql.ConflictOption) *AdvUpsertBulk { + acb.conflict = opts + return &AdvUpsertBulk{ + create: acb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Adv.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (acb *AdvCreateBulk) OnConflictColumns(columns ...string) *AdvUpsertBulk { + acb.conflict = append(acb.conflict, sql.ConflictColumns(columns...)) + return &AdvUpsertBulk{ + create: acb, + } +} + +// AdvUpsertBulk is the builder for "upsert"-ing +// a bulk of Adv nodes. +type AdvUpsertBulk struct { + create *AdvCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.Adv.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(adv.FieldID) +// }), +// ). +// Exec(ctx) +func (u *AdvUpsertBulk) UpdateNewValues() *AdvUpsertBulk { + 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(adv.FieldID) + } + if _, exists := b.mutation.CreateTime(); exists { + s.SetIgnore(adv.FieldCreateTime) + } + if _, exists := b.mutation.Code(); exists { + s.SetIgnore(adv.FieldCode) + } + if _, exists := b.mutation.MallCode(); exists { + s.SetIgnore(adv.FieldMallCode) + } + if _, exists := b.mutation.ImgPath(); exists { + s.SetIgnore(adv.FieldImgPath) + } + if _, exists := b.mutation.URL(); exists { + s.SetIgnore(adv.FieldURL) + } + if _, exists := b.mutation.StartTime(); exists { + s.SetIgnore(adv.FieldStartTime) + } + if _, exists := b.mutation.EndTime(); exists { + s.SetIgnore(adv.FieldEndTime) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Adv.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *AdvUpsertBulk) Ignore() *AdvUpsertBulk { + 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 *AdvUpsertBulk) DoNothing() *AdvUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the AdvCreateBulk.OnConflict +// documentation for more info. +func (u *AdvUpsertBulk) Update(set func(*AdvUpsert)) *AdvUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&AdvUpsert{UpdateSet: update}) + })) + return u +} + +// SetUpdateTime sets the "update_time" field. +func (u *AdvUpsertBulk) SetUpdateTime(v time.Time) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetUpdateTime(v) + }) +} + +// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateUpdateTime() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateUpdateTime() + }) +} + +// SetMallName sets the "mall_name" field. +func (u *AdvUpsertBulk) SetMallName(v string) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetMallName(v) + }) +} + +// UpdateMallName sets the "mall_name" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateMallName() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateMallName() + }) +} + +// SetH3Index6 sets the "h3_index_6" field. +func (u *AdvUpsertBulk) SetH3Index6(v string) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetH3Index6(v) + }) +} + +// UpdateH3Index6 sets the "h3_index_6" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateH3Index6() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateH3Index6() + }) +} + +// SetH3Index7 sets the "h3_index_7" field. +func (u *AdvUpsertBulk) SetH3Index7(v string) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetH3Index7(v) + }) +} + +// UpdateH3Index7 sets the "h3_index_7" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateH3Index7() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateH3Index7() + }) +} + +// SetH3Index8 sets the "h3_index_8" field. +func (u *AdvUpsertBulk) SetH3Index8(v string) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetH3Index8(v) + }) +} + +// UpdateH3Index8 sets the "h3_index_8" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateH3Index8() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateH3Index8() + }) +} + +// SetRuler sets the "ruler" field. +func (u *AdvUpsertBulk) SetRuler(v string) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetRuler(v) + }) +} + +// UpdateRuler sets the "ruler" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateRuler() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateRuler() + }) +} + +// SetOrd sets the "ord" field. +func (u *AdvUpsertBulk) SetOrd(v int) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetOrd(v) + }) +} + +// AddOrd adds v to the "ord" field. +func (u *AdvUpsertBulk) AddOrd(v int) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.AddOrd(v) + }) +} + +// UpdateOrd sets the "ord" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateOrd() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateOrd() + }) +} + +// SetMemo sets the "memo" field. +func (u *AdvUpsertBulk) SetMemo(v string) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetMemo(v) + }) +} + +// UpdateMemo sets the "memo" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateMemo() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateMemo() + }) +} + +// SetStatus sets the "status" field. +func (u *AdvUpsertBulk) SetStatus(v int) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.SetStatus(v) + }) +} + +// AddStatus adds v to the "status" field. +func (u *AdvUpsertBulk) AddStatus(v int) *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.AddStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *AdvUpsertBulk) UpdateStatus() *AdvUpsertBulk { + return u.Update(func(s *AdvUpsert) { + s.UpdateStatus() + }) +} + +// Exec executes the query. +func (u *AdvUpsertBulk) 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 AdvCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for AdvCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *AdvUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/adv/orm/ent/adv_delete.go b/adv/orm/ent/adv_delete.go new file mode 100644 index 0000000..587407f --- /dev/null +++ b/adv/orm/ent/adv_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// AdvDelete is the builder for deleting a Adv entity. +type AdvDelete struct { + config + hooks []Hook + mutation *AdvMutation +} + +// Where appends a list predicates to the AdvDelete builder. +func (ad *AdvDelete) Where(ps ...predicate.Adv) *AdvDelete { + ad.mutation.Where(ps...) + return ad +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (ad *AdvDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, ad.sqlExec, ad.mutation, ad.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (ad *AdvDelete) ExecX(ctx context.Context) int { + n, err := ad.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (ad *AdvDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(adv.Table, sqlgraph.NewFieldSpec(adv.FieldID, field.TypeUUID)) + if ps := ad.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, ad.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + ad.mutation.done = true + return affected, err +} + +// AdvDeleteOne is the builder for deleting a single Adv entity. +type AdvDeleteOne struct { + ad *AdvDelete +} + +// Where appends a list predicates to the AdvDelete builder. +func (ado *AdvDeleteOne) Where(ps ...predicate.Adv) *AdvDeleteOne { + ado.ad.mutation.Where(ps...) + return ado +} + +// Exec executes the deletion query. +func (ado *AdvDeleteOne) Exec(ctx context.Context) error { + n, err := ado.ad.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{adv.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ado *AdvDeleteOne) ExecX(ctx context.Context) { + if err := ado.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/adv/orm/ent/adv_query.go b/adv/orm/ent/adv_query.go new file mode 100644 index 0000000..d30cfc3 --- /dev/null +++ b/adv/orm/ent/adv_query.go @@ -0,0 +1,528 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// AdvQuery is the builder for querying Adv entities. +type AdvQuery struct { + config + ctx *QueryContext + order []adv.OrderOption + inters []Interceptor + predicates []predicate.Adv + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the AdvQuery builder. +func (aq *AdvQuery) Where(ps ...predicate.Adv) *AdvQuery { + aq.predicates = append(aq.predicates, ps...) + return aq +} + +// Limit the number of records to be returned by this query. +func (aq *AdvQuery) Limit(limit int) *AdvQuery { + aq.ctx.Limit = &limit + return aq +} + +// Offset to start from. +func (aq *AdvQuery) Offset(offset int) *AdvQuery { + aq.ctx.Offset = &offset + return aq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (aq *AdvQuery) Unique(unique bool) *AdvQuery { + aq.ctx.Unique = &unique + return aq +} + +// Order specifies how the records should be ordered. +func (aq *AdvQuery) Order(o ...adv.OrderOption) *AdvQuery { + aq.order = append(aq.order, o...) + return aq +} + +// First returns the first Adv entity from the query. +// Returns a *NotFoundError when no Adv was found. +func (aq *AdvQuery) First(ctx context.Context) (*Adv, error) { + nodes, err := aq.Limit(1).All(setContextOp(ctx, aq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{adv.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (aq *AdvQuery) FirstX(ctx context.Context) *Adv { + node, err := aq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Adv ID from the query. +// Returns a *NotFoundError when no Adv ID was found. +func (aq *AdvQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = aq.Limit(1).IDs(setContextOp(ctx, aq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{adv.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (aq *AdvQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := aq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Adv entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Adv entity is found. +// Returns a *NotFoundError when no Adv entities are found. +func (aq *AdvQuery) Only(ctx context.Context) (*Adv, error) { + nodes, err := aq.Limit(2).All(setContextOp(ctx, aq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{adv.Label} + default: + return nil, &NotSingularError{adv.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (aq *AdvQuery) OnlyX(ctx context.Context) *Adv { + node, err := aq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Adv ID in the query. +// Returns a *NotSingularError when more than one Adv ID is found. +// Returns a *NotFoundError when no entities are found. +func (aq *AdvQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = aq.Limit(2).IDs(setContextOp(ctx, aq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{adv.Label} + default: + err = &NotSingularError{adv.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (aq *AdvQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := aq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Advs. +func (aq *AdvQuery) All(ctx context.Context) ([]*Adv, error) { + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryAll) + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Adv, *AdvQuery]() + return withInterceptors[[]*Adv](ctx, aq, qr, aq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (aq *AdvQuery) AllX(ctx context.Context) []*Adv { + nodes, err := aq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Adv IDs. +func (aq *AdvQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if aq.ctx.Unique == nil && aq.path != nil { + aq.Unique(true) + } + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryIDs) + if err = aq.Select(adv.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (aq *AdvQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := aq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (aq *AdvQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryCount) + if err := aq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, aq, querierCount[*AdvQuery](), aq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (aq *AdvQuery) CountX(ctx context.Context) int { + count, err := aq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (aq *AdvQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryExist) + switch _, err := aq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (aq *AdvQuery) ExistX(ctx context.Context) bool { + exist, err := aq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AdvQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (aq *AdvQuery) Clone() *AdvQuery { + if aq == nil { + return nil + } + return &AdvQuery{ + config: aq.config, + ctx: aq.ctx.Clone(), + order: append([]adv.OrderOption{}, aq.order...), + inters: append([]Interceptor{}, aq.inters...), + predicates: append([]predicate.Adv{}, aq.predicates...), + // clone intermediate query. + sql: aq.sql.Clone(), + path: aq.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// CreateTime time.Time `json:"create_time,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Adv.Query(). +// GroupBy(adv.FieldCreateTime). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (aq *AdvQuery) GroupBy(field string, fields ...string) *AdvGroupBy { + aq.ctx.Fields = append([]string{field}, fields...) + grbuild := &AdvGroupBy{build: aq} + grbuild.flds = &aq.ctx.Fields + grbuild.label = adv.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// CreateTime time.Time `json:"create_time,omitempty"` +// } +// +// client.Adv.Query(). +// Select(adv.FieldCreateTime). +// Scan(ctx, &v) +func (aq *AdvQuery) Select(fields ...string) *AdvSelect { + aq.ctx.Fields = append(aq.ctx.Fields, fields...) + sbuild := &AdvSelect{AdvQuery: aq} + sbuild.label = adv.Label + sbuild.flds, sbuild.scan = &aq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AdvSelect configured with the given aggregations. +func (aq *AdvQuery) Aggregate(fns ...AggregateFunc) *AdvSelect { + return aq.Select().Aggregate(fns...) +} + +func (aq *AdvQuery) prepareQuery(ctx context.Context) error { + for _, inter := range aq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, aq); err != nil { + return err + } + } + } + for _, f := range aq.ctx.Fields { + if !adv.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if aq.path != nil { + prev, err := aq.path(ctx) + if err != nil { + return err + } + aq.sql = prev + } + return nil +} + +func (aq *AdvQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Adv, error) { + var ( + nodes = []*Adv{} + _spec = aq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Adv).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Adv{config: aq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (aq *AdvQuery) sqlCount(ctx context.Context) (int, error) { + _spec := aq.querySpec() + _spec.Node.Columns = aq.ctx.Fields + if len(aq.ctx.Fields) > 0 { + _spec.Unique = aq.ctx.Unique != nil && *aq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, aq.driver, _spec) +} + +func (aq *AdvQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(adv.Table, adv.Columns, sqlgraph.NewFieldSpec(adv.FieldID, field.TypeUUID)) + _spec.From = aq.sql + if unique := aq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if aq.path != nil { + _spec.Unique = true + } + if fields := aq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, adv.FieldID) + for i := range fields { + if fields[i] != adv.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := aq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := aq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := aq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := aq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (aq *AdvQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(aq.driver.Dialect()) + t1 := builder.Table(adv.Table) + columns := aq.ctx.Fields + if len(columns) == 0 { + columns = adv.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if aq.sql != nil { + selector = aq.sql + selector.Select(selector.Columns(columns...)...) + } + if aq.ctx.Unique != nil && *aq.ctx.Unique { + selector.Distinct() + } + for _, p := range aq.predicates { + p(selector) + } + for _, p := range aq.order { + p(selector) + } + if offset := aq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := aq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// AdvGroupBy is the group-by builder for Adv entities. +type AdvGroupBy struct { + selector + build *AdvQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (agb *AdvGroupBy) Aggregate(fns ...AggregateFunc) *AdvGroupBy { + agb.fns = append(agb.fns, fns...) + return agb +} + +// Scan applies the selector query and scans the result into the given value. +func (agb *AdvGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, agb.build.ctx, ent.OpQueryGroupBy) + if err := agb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AdvQuery, *AdvGroupBy](ctx, agb.build, agb, agb.build.inters, v) +} + +func (agb *AdvGroupBy) sqlScan(ctx context.Context, root *AdvQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(agb.fns)) + for _, fn := range agb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*agb.flds)+len(agb.fns)) + for _, f := range *agb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*agb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := agb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// AdvSelect is the builder for selecting fields of Adv entities. +type AdvSelect struct { + *AdvQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (as *AdvSelect) Aggregate(fns ...AggregateFunc) *AdvSelect { + as.fns = append(as.fns, fns...) + return as +} + +// Scan applies the selector query and scans the result into the given value. +func (as *AdvSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, as.ctx, ent.OpQuerySelect) + if err := as.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AdvQuery, *AdvSelect](ctx, as.AdvQuery, as, as.inters, v) +} + +func (as *AdvSelect) sqlScan(ctx context.Context, root *AdvQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(as.fns)) + for _, fn := range as.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*as.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := as.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/adv/orm/ent/adv_update.go b/adv/orm/ent/adv_update.go new file mode 100644 index 0000000..e513751 --- /dev/null +++ b/adv/orm/ent/adv_update.go @@ -0,0 +1,600 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// AdvUpdate is the builder for updating Adv entities. +type AdvUpdate struct { + config + hooks []Hook + mutation *AdvMutation +} + +// Where appends a list predicates to the AdvUpdate builder. +func (au *AdvUpdate) Where(ps ...predicate.Adv) *AdvUpdate { + au.mutation.Where(ps...) + return au +} + +// SetUpdateTime sets the "update_time" field. +func (au *AdvUpdate) SetUpdateTime(t time.Time) *AdvUpdate { + au.mutation.SetUpdateTime(t) + return au +} + +// SetMallName sets the "mall_name" field. +func (au *AdvUpdate) SetMallName(s string) *AdvUpdate { + au.mutation.SetMallName(s) + return au +} + +// SetNillableMallName sets the "mall_name" field if the given value is not nil. +func (au *AdvUpdate) SetNillableMallName(s *string) *AdvUpdate { + if s != nil { + au.SetMallName(*s) + } + return au +} + +// SetH3Index6 sets the "h3_index_6" field. +func (au *AdvUpdate) SetH3Index6(s string) *AdvUpdate { + au.mutation.SetH3Index6(s) + return au +} + +// SetNillableH3Index6 sets the "h3_index_6" field if the given value is not nil. +func (au *AdvUpdate) SetNillableH3Index6(s *string) *AdvUpdate { + if s != nil { + au.SetH3Index6(*s) + } + return au +} + +// SetH3Index7 sets the "h3_index_7" field. +func (au *AdvUpdate) SetH3Index7(s string) *AdvUpdate { + au.mutation.SetH3Index7(s) + return au +} + +// SetNillableH3Index7 sets the "h3_index_7" field if the given value is not nil. +func (au *AdvUpdate) SetNillableH3Index7(s *string) *AdvUpdate { + if s != nil { + au.SetH3Index7(*s) + } + return au +} + +// SetH3Index8 sets the "h3_index_8" field. +func (au *AdvUpdate) SetH3Index8(s string) *AdvUpdate { + au.mutation.SetH3Index8(s) + return au +} + +// SetNillableH3Index8 sets the "h3_index_8" field if the given value is not nil. +func (au *AdvUpdate) SetNillableH3Index8(s *string) *AdvUpdate { + if s != nil { + au.SetH3Index8(*s) + } + return au +} + +// SetRuler sets the "ruler" field. +func (au *AdvUpdate) SetRuler(s string) *AdvUpdate { + au.mutation.SetRuler(s) + return au +} + +// SetNillableRuler sets the "ruler" field if the given value is not nil. +func (au *AdvUpdate) SetNillableRuler(s *string) *AdvUpdate { + if s != nil { + au.SetRuler(*s) + } + return au +} + +// SetOrd sets the "ord" field. +func (au *AdvUpdate) SetOrd(i int) *AdvUpdate { + au.mutation.ResetOrd() + au.mutation.SetOrd(i) + return au +} + +// SetNillableOrd sets the "ord" field if the given value is not nil. +func (au *AdvUpdate) SetNillableOrd(i *int) *AdvUpdate { + if i != nil { + au.SetOrd(*i) + } + return au +} + +// AddOrd adds i to the "ord" field. +func (au *AdvUpdate) AddOrd(i int) *AdvUpdate { + au.mutation.AddOrd(i) + return au +} + +// SetMemo sets the "memo" field. +func (au *AdvUpdate) SetMemo(s string) *AdvUpdate { + au.mutation.SetMemo(s) + return au +} + +// SetNillableMemo sets the "memo" field if the given value is not nil. +func (au *AdvUpdate) SetNillableMemo(s *string) *AdvUpdate { + if s != nil { + au.SetMemo(*s) + } + return au +} + +// SetStatus sets the "status" field. +func (au *AdvUpdate) SetStatus(i int) *AdvUpdate { + au.mutation.ResetStatus() + au.mutation.SetStatus(i) + return au +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (au *AdvUpdate) SetNillableStatus(i *int) *AdvUpdate { + if i != nil { + au.SetStatus(*i) + } + return au +} + +// AddStatus adds i to the "status" field. +func (au *AdvUpdate) AddStatus(i int) *AdvUpdate { + au.mutation.AddStatus(i) + return au +} + +// Mutation returns the AdvMutation object of the builder. +func (au *AdvUpdate) Mutation() *AdvMutation { + return au.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (au *AdvUpdate) Save(ctx context.Context) (int, error) { + au.defaults() + return withHooks(ctx, au.sqlSave, au.mutation, au.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (au *AdvUpdate) SaveX(ctx context.Context) int { + affected, err := au.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (au *AdvUpdate) Exec(ctx context.Context) error { + _, err := au.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (au *AdvUpdate) ExecX(ctx context.Context) { + if err := au.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (au *AdvUpdate) defaults() { + if _, ok := au.mutation.UpdateTime(); !ok { + v := adv.UpdateDefaultUpdateTime() + au.mutation.SetUpdateTime(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (au *AdvUpdate) check() error { + if v, ok := au.mutation.MallName(); ok { + if err := adv.MallNameValidator(v); err != nil { + return &ValidationError{Name: "mall_name", err: fmt.Errorf(`ent: validator failed for field "Adv.mall_name": %w`, err)} + } + } + if v, ok := au.mutation.H3Index6(); ok { + if err := adv.H3Index6Validator(v); err != nil { + return &ValidationError{Name: "h3_index_6", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_6": %w`, err)} + } + } + if v, ok := au.mutation.H3Index7(); ok { + if err := adv.H3Index7Validator(v); err != nil { + return &ValidationError{Name: "h3_index_7", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_7": %w`, err)} + } + } + if v, ok := au.mutation.H3Index8(); ok { + if err := adv.H3Index8Validator(v); err != nil { + return &ValidationError{Name: "h3_index_8", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_8": %w`, err)} + } + } + if v, ok := au.mutation.Ruler(); ok { + if err := adv.RulerValidator(v); err != nil { + return &ValidationError{Name: "ruler", err: fmt.Errorf(`ent: validator failed for field "Adv.ruler": %w`, err)} + } + } + if v, ok := au.mutation.Memo(); ok { + if err := adv.MemoValidator(v); err != nil { + return &ValidationError{Name: "memo", err: fmt.Errorf(`ent: validator failed for field "Adv.memo": %w`, err)} + } + } + return nil +} + +func (au *AdvUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := au.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(adv.Table, adv.Columns, sqlgraph.NewFieldSpec(adv.FieldID, field.TypeUUID)) + if ps := au.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := au.mutation.UpdateTime(); ok { + _spec.SetField(adv.FieldUpdateTime, field.TypeTime, value) + } + if value, ok := au.mutation.MallName(); ok { + _spec.SetField(adv.FieldMallName, field.TypeString, value) + } + if value, ok := au.mutation.H3Index6(); ok { + _spec.SetField(adv.FieldH3Index6, field.TypeString, value) + } + if value, ok := au.mutation.H3Index7(); ok { + _spec.SetField(adv.FieldH3Index7, field.TypeString, value) + } + if value, ok := au.mutation.H3Index8(); ok { + _spec.SetField(adv.FieldH3Index8, field.TypeString, value) + } + if value, ok := au.mutation.Ruler(); ok { + _spec.SetField(adv.FieldRuler, field.TypeString, value) + } + if value, ok := au.mutation.Ord(); ok { + _spec.SetField(adv.FieldOrd, field.TypeInt, value) + } + if value, ok := au.mutation.AddedOrd(); ok { + _spec.AddField(adv.FieldOrd, field.TypeInt, value) + } + if value, ok := au.mutation.Memo(); ok { + _spec.SetField(adv.FieldMemo, field.TypeString, value) + } + if value, ok := au.mutation.Status(); ok { + _spec.SetField(adv.FieldStatus, field.TypeInt, value) + } + if value, ok := au.mutation.AddedStatus(); ok { + _spec.AddField(adv.FieldStatus, field.TypeInt, value) + } + if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{adv.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + au.mutation.done = true + return n, nil +} + +// AdvUpdateOne is the builder for updating a single Adv entity. +type AdvUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AdvMutation +} + +// SetUpdateTime sets the "update_time" field. +func (auo *AdvUpdateOne) SetUpdateTime(t time.Time) *AdvUpdateOne { + auo.mutation.SetUpdateTime(t) + return auo +} + +// SetMallName sets the "mall_name" field. +func (auo *AdvUpdateOne) SetMallName(s string) *AdvUpdateOne { + auo.mutation.SetMallName(s) + return auo +} + +// SetNillableMallName sets the "mall_name" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableMallName(s *string) *AdvUpdateOne { + if s != nil { + auo.SetMallName(*s) + } + return auo +} + +// SetH3Index6 sets the "h3_index_6" field. +func (auo *AdvUpdateOne) SetH3Index6(s string) *AdvUpdateOne { + auo.mutation.SetH3Index6(s) + return auo +} + +// SetNillableH3Index6 sets the "h3_index_6" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableH3Index6(s *string) *AdvUpdateOne { + if s != nil { + auo.SetH3Index6(*s) + } + return auo +} + +// SetH3Index7 sets the "h3_index_7" field. +func (auo *AdvUpdateOne) SetH3Index7(s string) *AdvUpdateOne { + auo.mutation.SetH3Index7(s) + return auo +} + +// SetNillableH3Index7 sets the "h3_index_7" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableH3Index7(s *string) *AdvUpdateOne { + if s != nil { + auo.SetH3Index7(*s) + } + return auo +} + +// SetH3Index8 sets the "h3_index_8" field. +func (auo *AdvUpdateOne) SetH3Index8(s string) *AdvUpdateOne { + auo.mutation.SetH3Index8(s) + return auo +} + +// SetNillableH3Index8 sets the "h3_index_8" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableH3Index8(s *string) *AdvUpdateOne { + if s != nil { + auo.SetH3Index8(*s) + } + return auo +} + +// SetRuler sets the "ruler" field. +func (auo *AdvUpdateOne) SetRuler(s string) *AdvUpdateOne { + auo.mutation.SetRuler(s) + return auo +} + +// SetNillableRuler sets the "ruler" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableRuler(s *string) *AdvUpdateOne { + if s != nil { + auo.SetRuler(*s) + } + return auo +} + +// SetOrd sets the "ord" field. +func (auo *AdvUpdateOne) SetOrd(i int) *AdvUpdateOne { + auo.mutation.ResetOrd() + auo.mutation.SetOrd(i) + return auo +} + +// SetNillableOrd sets the "ord" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableOrd(i *int) *AdvUpdateOne { + if i != nil { + auo.SetOrd(*i) + } + return auo +} + +// AddOrd adds i to the "ord" field. +func (auo *AdvUpdateOne) AddOrd(i int) *AdvUpdateOne { + auo.mutation.AddOrd(i) + return auo +} + +// SetMemo sets the "memo" field. +func (auo *AdvUpdateOne) SetMemo(s string) *AdvUpdateOne { + auo.mutation.SetMemo(s) + return auo +} + +// SetNillableMemo sets the "memo" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableMemo(s *string) *AdvUpdateOne { + if s != nil { + auo.SetMemo(*s) + } + return auo +} + +// SetStatus sets the "status" field. +func (auo *AdvUpdateOne) SetStatus(i int) *AdvUpdateOne { + auo.mutation.ResetStatus() + auo.mutation.SetStatus(i) + return auo +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (auo *AdvUpdateOne) SetNillableStatus(i *int) *AdvUpdateOne { + if i != nil { + auo.SetStatus(*i) + } + return auo +} + +// AddStatus adds i to the "status" field. +func (auo *AdvUpdateOne) AddStatus(i int) *AdvUpdateOne { + auo.mutation.AddStatus(i) + return auo +} + +// Mutation returns the AdvMutation object of the builder. +func (auo *AdvUpdateOne) Mutation() *AdvMutation { + return auo.mutation +} + +// Where appends a list predicates to the AdvUpdate builder. +func (auo *AdvUpdateOne) Where(ps ...predicate.Adv) *AdvUpdateOne { + auo.mutation.Where(ps...) + return auo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (auo *AdvUpdateOne) Select(field string, fields ...string) *AdvUpdateOne { + auo.fields = append([]string{field}, fields...) + return auo +} + +// Save executes the query and returns the updated Adv entity. +func (auo *AdvUpdateOne) Save(ctx context.Context) (*Adv, error) { + auo.defaults() + return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (auo *AdvUpdateOne) SaveX(ctx context.Context) *Adv { + node, err := auo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (auo *AdvUpdateOne) Exec(ctx context.Context) error { + _, err := auo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (auo *AdvUpdateOne) ExecX(ctx context.Context) { + if err := auo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (auo *AdvUpdateOne) defaults() { + if _, ok := auo.mutation.UpdateTime(); !ok { + v := adv.UpdateDefaultUpdateTime() + auo.mutation.SetUpdateTime(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (auo *AdvUpdateOne) check() error { + if v, ok := auo.mutation.MallName(); ok { + if err := adv.MallNameValidator(v); err != nil { + return &ValidationError{Name: "mall_name", err: fmt.Errorf(`ent: validator failed for field "Adv.mall_name": %w`, err)} + } + } + if v, ok := auo.mutation.H3Index6(); ok { + if err := adv.H3Index6Validator(v); err != nil { + return &ValidationError{Name: "h3_index_6", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_6": %w`, err)} + } + } + if v, ok := auo.mutation.H3Index7(); ok { + if err := adv.H3Index7Validator(v); err != nil { + return &ValidationError{Name: "h3_index_7", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_7": %w`, err)} + } + } + if v, ok := auo.mutation.H3Index8(); ok { + if err := adv.H3Index8Validator(v); err != nil { + return &ValidationError{Name: "h3_index_8", err: fmt.Errorf(`ent: validator failed for field "Adv.h3_index_8": %w`, err)} + } + } + if v, ok := auo.mutation.Ruler(); ok { + if err := adv.RulerValidator(v); err != nil { + return &ValidationError{Name: "ruler", err: fmt.Errorf(`ent: validator failed for field "Adv.ruler": %w`, err)} + } + } + if v, ok := auo.mutation.Memo(); ok { + if err := adv.MemoValidator(v); err != nil { + return &ValidationError{Name: "memo", err: fmt.Errorf(`ent: validator failed for field "Adv.memo": %w`, err)} + } + } + return nil +} + +func (auo *AdvUpdateOne) sqlSave(ctx context.Context) (_node *Adv, err error) { + if err := auo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(adv.Table, adv.Columns, sqlgraph.NewFieldSpec(adv.FieldID, field.TypeUUID)) + id, ok := auo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Adv.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := auo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, adv.FieldID) + for _, f := range fields { + if !adv.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != adv.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := auo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := auo.mutation.UpdateTime(); ok { + _spec.SetField(adv.FieldUpdateTime, field.TypeTime, value) + } + if value, ok := auo.mutation.MallName(); ok { + _spec.SetField(adv.FieldMallName, field.TypeString, value) + } + if value, ok := auo.mutation.H3Index6(); ok { + _spec.SetField(adv.FieldH3Index6, field.TypeString, value) + } + if value, ok := auo.mutation.H3Index7(); ok { + _spec.SetField(adv.FieldH3Index7, field.TypeString, value) + } + if value, ok := auo.mutation.H3Index8(); ok { + _spec.SetField(adv.FieldH3Index8, field.TypeString, value) + } + if value, ok := auo.mutation.Ruler(); ok { + _spec.SetField(adv.FieldRuler, field.TypeString, value) + } + if value, ok := auo.mutation.Ord(); ok { + _spec.SetField(adv.FieldOrd, field.TypeInt, value) + } + if value, ok := auo.mutation.AddedOrd(); ok { + _spec.AddField(adv.FieldOrd, field.TypeInt, value) + } + if value, ok := auo.mutation.Memo(); ok { + _spec.SetField(adv.FieldMemo, field.TypeString, value) + } + if value, ok := auo.mutation.Status(); ok { + _spec.SetField(adv.FieldStatus, field.TypeInt, value) + } + if value, ok := auo.mutation.AddedStatus(); ok { + _spec.AddField(adv.FieldStatus, field.TypeInt, value) + } + _node = &Adv{config: auo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{adv.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + auo.mutation.done = true + return _node, nil +} diff --git a/adv/orm/ent/client.go b/adv/orm/ent/client.go new file mode 100644 index 0000000..e3c6713 --- /dev/null +++ b/adv/orm/ent/client.go @@ -0,0 +1,510 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "log" + "reflect" + + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/migrate" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/mall" + + stdsql "database/sql" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // Adv is the client for interacting with the Adv builders. + Adv *AdvClient + // Mall is the client for interacting with the Mall builders. + Mall *MallClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + client := &Client{config: newConfig(opts...)} + client.init() + return client +} + +func (c *Client) init() { + c.Schema = migrate.NewSchema(c.driver) + c.Adv = NewAdvClient(c.config) + c.Mall = NewMallClient(c.config) +} + +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// newConfig creates a new config for the client. +func newConfig(opts ...Option) config { + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} + cfg.options(opts...) + return cfg +} + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +// Open opens a database/sql.DB specified by the driver name and +// the data source name, and returns a new client attached to it. +// Optional parameters can be added for configuring the client. +func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { + switch driverName { + case dialect.MySQL, dialect.Postgres, dialect.SQLite: + drv, err := sql.Open(driverName, dataSourceName) + if err != nil { + return nil, err + } + return NewClient(append(options, Driver(drv))...), nil + default: + return nil, fmt.Errorf("unsupported driver: %q", driverName) + } +} + +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + +// Tx returns a new transactional client. The provided context +// is used until the transaction is committed or rolled back. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, ErrTxStarted + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = tx + return &Tx{ + ctx: ctx, + config: cfg, + Adv: NewAdvClient(cfg), + Mall: NewMallClient(cfg), + }, nil +} + +// BeginTx returns a transactional client with specified options. +func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, errors.New("ent: cannot start a transaction within a transaction") + } + tx, err := c.driver.(interface { + BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) + }).BeginTx(ctx, opts) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = &txDriver{tx: tx, drv: c.driver} + return &Tx{ + ctx: ctx, + config: cfg, + Adv: NewAdvClient(cfg), + Mall: NewMallClient(cfg), + }, nil +} + +// Debug returns a new debug-client. It's used to get verbose logging on specific operations. +// +// client.Debug(). +// Adv. +// Query(). +// Count(ctx) +func (c *Client) Debug() *Client { + if c.debug { + return c + } + cfg := c.config + cfg.driver = dialect.Debug(c.driver, c.log) + client := &Client{config: cfg} + client.init() + return client +} + +// Close closes the database connection and prevents new queries from starting. +func (c *Client) Close() error { + return c.driver.Close() +} + +// Use adds the mutation hooks to all the entity clients. +// In order to add hooks to a specific client, call: `client.Node.Use(...)`. +func (c *Client) Use(hooks ...Hook) { + c.Adv.Use(hooks...) + c.Mall.Use(hooks...) +} + +// Intercept adds the query interceptors to all the entity clients. +// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. +func (c *Client) Intercept(interceptors ...Interceptor) { + c.Adv.Intercept(interceptors...) + c.Mall.Intercept(interceptors...) +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *AdvMutation: + return c.Adv.mutate(ctx, m) + case *MallMutation: + return c.Mall.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + +// AdvClient is a client for the Adv schema. +type AdvClient struct { + config +} + +// NewAdvClient returns a client for the Adv from the given config. +func NewAdvClient(c config) *AdvClient { + return &AdvClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `adv.Hooks(f(g(h())))`. +func (c *AdvClient) Use(hooks ...Hook) { + c.hooks.Adv = append(c.hooks.Adv, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `adv.Intercept(f(g(h())))`. +func (c *AdvClient) Intercept(interceptors ...Interceptor) { + c.inters.Adv = append(c.inters.Adv, interceptors...) +} + +// Create returns a builder for creating a Adv entity. +func (c *AdvClient) Create() *AdvCreate { + mutation := newAdvMutation(c.config, OpCreate) + return &AdvCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Adv entities. +func (c *AdvClient) CreateBulk(builders ...*AdvCreate) *AdvCreateBulk { + return &AdvCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *AdvClient) MapCreateBulk(slice any, setFunc func(*AdvCreate, int)) *AdvCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AdvCreateBulk{err: fmt.Errorf("calling to AdvClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AdvCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AdvCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Adv. +func (c *AdvClient) Update() *AdvUpdate { + mutation := newAdvMutation(c.config, OpUpdate) + return &AdvUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AdvClient) UpdateOne(a *Adv) *AdvUpdateOne { + mutation := newAdvMutation(c.config, OpUpdateOne, withAdv(a)) + return &AdvUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AdvClient) UpdateOneID(id uuid.UUID) *AdvUpdateOne { + mutation := newAdvMutation(c.config, OpUpdateOne, withAdvID(id)) + return &AdvUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Adv. +func (c *AdvClient) Delete() *AdvDelete { + mutation := newAdvMutation(c.config, OpDelete) + return &AdvDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *AdvClient) DeleteOne(a *Adv) *AdvDeleteOne { + return c.DeleteOneID(a.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *AdvClient) DeleteOneID(id uuid.UUID) *AdvDeleteOne { + builder := c.Delete().Where(adv.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AdvDeleteOne{builder} +} + +// Query returns a query builder for Adv. +func (c *AdvClient) Query() *AdvQuery { + return &AdvQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeAdv}, + inters: c.Interceptors(), + } +} + +// Get returns a Adv entity by its id. +func (c *AdvClient) Get(ctx context.Context, id uuid.UUID) (*Adv, error) { + return c.Query().Where(adv.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AdvClient) GetX(ctx context.Context, id uuid.UUID) *Adv { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *AdvClient) Hooks() []Hook { + return c.hooks.Adv +} + +// Interceptors returns the client interceptors. +func (c *AdvClient) Interceptors() []Interceptor { + return c.inters.Adv +} + +func (c *AdvClient) mutate(ctx context.Context, m *AdvMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AdvCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AdvUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AdvUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AdvDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Adv mutation op: %q", m.Op()) + } +} + +// MallClient is a client for the Mall schema. +type MallClient struct { + config +} + +// NewMallClient returns a client for the Mall from the given config. +func NewMallClient(c config) *MallClient { + return &MallClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `mall.Hooks(f(g(h())))`. +func (c *MallClient) Use(hooks ...Hook) { + c.hooks.Mall = append(c.hooks.Mall, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `mall.Intercept(f(g(h())))`. +func (c *MallClient) Intercept(interceptors ...Interceptor) { + c.inters.Mall = append(c.inters.Mall, interceptors...) +} + +// Create returns a builder for creating a Mall entity. +func (c *MallClient) Create() *MallCreate { + mutation := newMallMutation(c.config, OpCreate) + return &MallCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Mall entities. +func (c *MallClient) CreateBulk(builders ...*MallCreate) *MallCreateBulk { + return &MallCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *MallClient) MapCreateBulk(slice any, setFunc func(*MallCreate, int)) *MallCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &MallCreateBulk{err: fmt.Errorf("calling to MallClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*MallCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &MallCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Mall. +func (c *MallClient) Update() *MallUpdate { + mutation := newMallMutation(c.config, OpUpdate) + return &MallUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *MallClient) UpdateOne(m *Mall) *MallUpdateOne { + mutation := newMallMutation(c.config, OpUpdateOne, withMall(m)) + return &MallUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *MallClient) UpdateOneID(id uuid.UUID) *MallUpdateOne { + mutation := newMallMutation(c.config, OpUpdateOne, withMallID(id)) + return &MallUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Mall. +func (c *MallClient) Delete() *MallDelete { + mutation := newMallMutation(c.config, OpDelete) + return &MallDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *MallClient) DeleteOne(m *Mall) *MallDeleteOne { + return c.DeleteOneID(m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *MallClient) DeleteOneID(id uuid.UUID) *MallDeleteOne { + builder := c.Delete().Where(mall.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &MallDeleteOne{builder} +} + +// Query returns a query builder for Mall. +func (c *MallClient) Query() *MallQuery { + return &MallQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeMall}, + inters: c.Interceptors(), + } +} + +// Get returns a Mall entity by its id. +func (c *MallClient) Get(ctx context.Context, id uuid.UUID) (*Mall, error) { + return c.Query().Where(mall.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *MallClient) GetX(ctx context.Context, id uuid.UUID) *Mall { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *MallClient) Hooks() []Hook { + return c.hooks.Mall +} + +// Interceptors returns the client interceptors. +func (c *MallClient) Interceptors() []Interceptor { + return c.inters.Mall +} + +func (c *MallClient) mutate(ctx context.Context, m *MallMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&MallCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&MallUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&MallUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&MallDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Mall mutation op: %q", m.Op()) + } +} + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + Adv, Mall []ent.Hook + } + inters struct { + Adv, Mall []ent.Interceptor + } +) + +// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it. +// See, database/sql#DB.ExecContext for more information. +func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { + ex, ok := c.driver.(interface { + ExecContext(context.Context, string, ...any) (stdsql.Result, error) + }) + if !ok { + return nil, fmt.Errorf("Driver.ExecContext is not supported") + } + return ex.ExecContext(ctx, query, args...) +} + +// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it. +// See, database/sql#DB.QueryContext for more information. +func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { + q, ok := c.driver.(interface { + QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) + }) + if !ok { + return nil, fmt.Errorf("Driver.QueryContext is not supported") + } + return q.QueryContext(ctx, query, args...) +} diff --git a/adv/orm/ent/ent.go b/adv/orm/ent/ent.go new file mode 100644 index 0000000..3de4e0c --- /dev/null +++ b/adv/orm/ent/ent.go @@ -0,0 +1,610 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "reflect" + "sync" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/mall" +) + +// ent aliases to avoid import conflicts in user's code. +type ( + Op = ent.Op + Hook = ent.Hook + Value = ent.Value + Query = ent.Query + QueryContext = ent.QueryContext + Querier = ent.Querier + QuerierFunc = ent.QuerierFunc + Interceptor = ent.Interceptor + InterceptFunc = ent.InterceptFunc + Traverser = ent.Traverser + TraverseFunc = ent.TraverseFunc + Policy = ent.Policy + Mutator = ent.Mutator + Mutation = ent.Mutation + MutateFunc = ent.MutateFunc +) + +type clientCtxKey struct{} + +// FromContext returns a Client stored inside a context, or nil if there isn't one. +func FromContext(ctx context.Context) *Client { + c, _ := ctx.Value(clientCtxKey{}).(*Client) + return c +} + +// NewContext returns a new context with the given Client attached. +func NewContext(parent context.Context, c *Client) context.Context { + return context.WithValue(parent, clientCtxKey{}, c) +} + +type txCtxKey struct{} + +// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. +func TxFromContext(ctx context.Context) *Tx { + tx, _ := ctx.Value(txCtxKey{}).(*Tx) + return tx +} + +// NewTxContext returns a new context with the given Tx attached. +func NewTxContext(parent context.Context, tx *Tx) context.Context { + return context.WithValue(parent, txCtxKey{}, tx) +} + +// OrderFunc applies an ordering on the sql selector. +// Deprecated: Use Asc/Desc functions or the package builders instead. +type OrderFunc func(*sql.Selector) + +var ( + initCheck sync.Once + columnCheck sql.ColumnCheck +) + +// checkColumn checks if the column exists in the given table. +func checkColumn(table, column string) error { + initCheck.Do(func() { + columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ + adv.Table: adv.ValidColumn, + mall.Table: mall.ValidColumn, + }) + }) + return columnCheck(table, column) +} + +// Asc applies the given fields in ASC order. +func Asc(fields ...string) func(*sql.Selector) { + return func(s *sql.Selector) { + for _, f := range fields { + if err := checkColumn(s.TableName(), f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Asc(s.C(f))) + } + } +} + +// Desc applies the given fields in DESC order. +func Desc(fields ...string) func(*sql.Selector) { + return func(s *sql.Selector) { + for _, f := range fields { + if err := checkColumn(s.TableName(), f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Desc(s.C(f))) + } + } +} + +// AggregateFunc applies an aggregation step on the group-by traversal/selector. +type AggregateFunc func(*sql.Selector) string + +// As is a pseudo aggregation function for renaming another other functions with custom names. For example: +// +// GroupBy(field1, field2). +// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). +// Scan(ctx, &v) +func As(fn AggregateFunc, end string) AggregateFunc { + return func(s *sql.Selector) string { + return sql.As(fn(s), end) + } +} + +// Count applies the "count" aggregation function on each group. +func Count() AggregateFunc { + return func(s *sql.Selector) string { + return sql.Count("*") + } +} + +// Max applies the "max" aggregation function on the given field of each group. +func Max(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Max(s.C(field)) + } +} + +// Mean applies the "mean" aggregation function on the given field of each group. +func Mean(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Avg(s.C(field)) + } +} + +// Min applies the "min" aggregation function on the given field of each group. +func Min(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Min(s.C(field)) + } +} + +// Sum applies the "sum" aggregation function on the given field of each group. +func Sum(field string) AggregateFunc { + return func(s *sql.Selector) string { + if err := checkColumn(s.TableName(), field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Sum(s.C(field)) + } +} + +// ValidationError returns when validating a field or edge fails. +type ValidationError struct { + Name string // Field or edge name. + err error +} + +// Error implements the error interface. +func (e *ValidationError) Error() string { + return e.err.Error() +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ValidationError) Unwrap() error { + return e.err +} + +// IsValidationError returns a boolean indicating whether the error is a validation error. +func IsValidationError(err error) bool { + if err == nil { + return false + } + var e *ValidationError + return errors.As(err, &e) +} + +// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. +type NotFoundError struct { + label string +} + +// Error implements the error interface. +func (e *NotFoundError) Error() string { + return "ent: " + e.label + " not found" +} + +// IsNotFound returns a boolean indicating whether the error is a not found error. +func IsNotFound(err error) bool { + if err == nil { + return false + } + var e *NotFoundError + return errors.As(err, &e) +} + +// MaskNotFound masks not found error. +func MaskNotFound(err error) error { + if IsNotFound(err) { + return nil + } + return err +} + +// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. +type NotSingularError struct { + label string +} + +// Error implements the error interface. +func (e *NotSingularError) Error() string { + return "ent: " + e.label + " not singular" +} + +// IsNotSingular returns a boolean indicating whether the error is a not singular error. +func IsNotSingular(err error) bool { + if err == nil { + return false + } + var e *NotSingularError + return errors.As(err, &e) +} + +// NotLoadedError returns when trying to get a node that was not loaded by the query. +type NotLoadedError struct { + edge string +} + +// Error implements the error interface. +func (e *NotLoadedError) Error() string { + return "ent: " + e.edge + " edge was not loaded" +} + +// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. +func IsNotLoaded(err error) bool { + if err == nil { + return false + } + var e *NotLoadedError + return errors.As(err, &e) +} + +// ConstraintError returns when trying to create/update one or more entities and +// one or more of their constraints failed. For example, violation of edge or +// field uniqueness. +type ConstraintError struct { + msg string + wrap error +} + +// Error implements the error interface. +func (e ConstraintError) Error() string { + return "ent: constraint failed: " + e.msg +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ConstraintError) Unwrap() error { + return e.wrap +} + +// IsConstraintError returns a boolean indicating whether the error is a constraint failure. +func IsConstraintError(err error) bool { + if err == nil { + return false + } + var e *ConstraintError + return errors.As(err, &e) +} + +// selector embedded by the different Select/GroupBy builders. +type selector struct { + label string + flds *[]string + fns []AggregateFunc + scan func(context.Context, any) error +} + +// ScanX is like Scan, but panics if an error occurs. +func (s *selector) ScanX(ctx context.Context, v any) { + if err := s.scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (s *selector) Strings(ctx context.Context) ([]string, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (s *selector) StringsX(ctx context.Context) []string { + v, err := s.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (s *selector) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = s.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (s *selector) StringX(ctx context.Context) string { + v, err := s.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (s *selector) Ints(ctx context.Context) ([]int, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (s *selector) IntsX(ctx context.Context) []int { + v, err := s.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (s *selector) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = s.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (s *selector) IntX(ctx context.Context) int { + v, err := s.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (s *selector) Float64s(ctx context.Context) ([]float64, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (s *selector) Float64sX(ctx context.Context) []float64 { + v, err := s.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (s *selector) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = s.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (s *selector) Float64X(ctx context.Context) float64 { + v, err := s.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (s *selector) Bools(ctx context.Context) ([]bool, error) { + if len(*s.flds) > 1 { + return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := s.scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (s *selector) BoolsX(ctx context.Context) []bool { + v, err := s.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (s *selector) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = s.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{s.label} + default: + err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (s *selector) BoolX(ctx context.Context) bool { + v, err := s.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +// withHooks invokes the builder operation with the given hooks, if any. +func withHooks[V Value, M any, PM interface { + *M + Mutation +}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) { + if len(hooks) == 0 { + return exec(ctx) + } + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutationT, ok := any(m).(PM) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + // Set the mutation to the builder. + *mutation = *mutationT + return exec(ctx) + }) + for i := len(hooks) - 1; i >= 0; i-- { + if hooks[i] == nil { + return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = hooks[i](mut) + } + v, err := mut.Mutate(ctx, mutation) + if err != nil { + return value, err + } + nv, ok := v.(V) + if !ok { + return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation) + } + return nv, nil +} + +// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist. +func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context { + if ent.QueryFromContext(ctx) == nil { + qc.Op = op + ctx = ent.NewQueryContext(ctx, qc) + } + return ctx +} + +func querierAll[V Value, Q interface { + sqlAll(context.Context, ...queryHook) (V, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlAll(ctx) + }) +} + +func querierCount[Q interface { + sqlCount(context.Context) (int, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlCount(ctx) + }) +} + +func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) { + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + rv, err := qr.Query(ctx, q) + if err != nil { + return v, err + } + vt, ok := rv.(V) + if !ok { + return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v) + } + return vt, nil +} + +func scanWithInterceptors[Q1 ent.Query, Q2 interface { + sqlScan(context.Context, Q1, any) error +}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error { + rv := reflect.ValueOf(v) + var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q1) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + if err := selectOrGroup.sqlScan(ctx, query, v); err != nil { + return nil, err + } + if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() { + return rv.Elem().Interface(), nil + } + return v, nil + }) + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + vv, err := qr.Query(ctx, rootQuery) + if err != nil { + return err + } + switch rv2 := reflect.ValueOf(vv); { + case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer: + case rv.Type() == rv2.Type(): + rv.Elem().Set(rv2.Elem()) + case rv.Elem().Type() == rv2.Type(): + rv.Elem().Set(rv2) + } + return nil +} + +// queryHook describes an internal hook for the different sqlAll methods. +type queryHook func(context.Context, *sqlgraph.QuerySpec) diff --git a/adv/orm/ent/entql.go b/adv/orm/ent/entql.go new file mode 100644 index 0000000..8b6e929 --- /dev/null +++ b/adv/orm/ent/entql.go @@ -0,0 +1,293 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/mall" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/entql" + "entgo.io/ent/schema/field" +) + +// schemaGraph holds a representation of ent/schema at runtime. +var schemaGraph = func() *sqlgraph.Schema { + graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 2)} + graph.Nodes[0] = &sqlgraph.Node{ + NodeSpec: sqlgraph.NodeSpec{ + Table: adv.Table, + Columns: adv.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: adv.FieldID, + }, + }, + Type: "Adv", + Fields: map[string]*sqlgraph.FieldSpec{ + adv.FieldCreateTime: {Type: field.TypeTime, Column: adv.FieldCreateTime}, + adv.FieldUpdateTime: {Type: field.TypeTime, Column: adv.FieldUpdateTime}, + adv.FieldCode: {Type: field.TypeString, Column: adv.FieldCode}, + adv.FieldMallCode: {Type: field.TypeString, Column: adv.FieldMallCode}, + adv.FieldMallName: {Type: field.TypeString, Column: adv.FieldMallName}, + adv.FieldH3Index6: {Type: field.TypeString, Column: adv.FieldH3Index6}, + adv.FieldH3Index7: {Type: field.TypeString, Column: adv.FieldH3Index7}, + adv.FieldH3Index8: {Type: field.TypeString, Column: adv.FieldH3Index8}, + adv.FieldImgPath: {Type: field.TypeString, Column: adv.FieldImgPath}, + adv.FieldURL: {Type: field.TypeString, Column: adv.FieldURL}, + adv.FieldRuler: {Type: field.TypeString, Column: adv.FieldRuler}, + adv.FieldOrd: {Type: field.TypeInt, Column: adv.FieldOrd}, + adv.FieldMemo: {Type: field.TypeString, Column: adv.FieldMemo}, + adv.FieldStartTime: {Type: field.TypeTime, Column: adv.FieldStartTime}, + adv.FieldEndTime: {Type: field.TypeTime, Column: adv.FieldEndTime}, + adv.FieldStatus: {Type: field.TypeInt, Column: adv.FieldStatus}, + }, + } + graph.Nodes[1] = &sqlgraph.Node{ + NodeSpec: sqlgraph.NodeSpec{ + Table: mall.Table, + Columns: mall.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: mall.FieldID, + }, + }, + Type: "Mall", + Fields: map[string]*sqlgraph.FieldSpec{ + mall.FieldCreateTime: {Type: field.TypeTime, Column: mall.FieldCreateTime}, + mall.FieldUpdateTime: {Type: field.TypeTime, Column: mall.FieldUpdateTime}, + mall.FieldCode: {Type: field.TypeString, Column: mall.FieldCode}, + mall.FieldMallCode: {Type: field.TypeString, Column: mall.FieldMallCode}, + mall.FieldMallName: {Type: field.TypeString, Column: mall.FieldMallName}, + mall.FieldH3Index6: {Type: field.TypeString, Column: mall.FieldH3Index6}, + mall.FieldH3Index7: {Type: field.TypeString, Column: mall.FieldH3Index7}, + mall.FieldH3Index8: {Type: field.TypeString, Column: mall.FieldH3Index8}, + mall.FieldMemo: {Type: field.TypeString, Column: mall.FieldMemo}, + mall.FieldStartTime: {Type: field.TypeTime, Column: mall.FieldStartTime}, + mall.FieldStatus: {Type: field.TypeInt, Column: mall.FieldStatus}, + }, + } + return graph +}() + +// predicateAdder wraps the addPredicate method. +// All update, update-one and query builders implement this interface. +type predicateAdder interface { + addPredicate(func(s *sql.Selector)) +} + +// addPredicate implements the predicateAdder interface. +func (aq *AdvQuery) addPredicate(pred func(s *sql.Selector)) { + aq.predicates = append(aq.predicates, pred) +} + +// Filter returns a Filter implementation to apply filters on the AdvQuery builder. +func (aq *AdvQuery) Filter() *AdvFilter { + return &AdvFilter{config: aq.config, predicateAdder: aq} +} + +// addPredicate implements the predicateAdder interface. +func (m *AdvMutation) addPredicate(pred func(s *sql.Selector)) { + m.predicates = append(m.predicates, pred) +} + +// Filter returns an entql.Where implementation to apply filters on the AdvMutation builder. +func (m *AdvMutation) Filter() *AdvFilter { + return &AdvFilter{config: m.config, predicateAdder: m} +} + +// AdvFilter provides a generic filtering capability at runtime for AdvQuery. +type AdvFilter struct { + predicateAdder + config +} + +// Where applies the entql predicate on the query filter. +func (f *AdvFilter) Where(p entql.P) { + f.addPredicate(func(s *sql.Selector) { + if err := schemaGraph.EvalP(schemaGraph.Nodes[0].Type, p, s); err != nil { + s.AddError(err) + } + }) +} + +// WhereID applies the entql [16]byte predicate on the id field. +func (f *AdvFilter) WhereID(p entql.ValueP) { + f.Where(p.Field(adv.FieldID)) +} + +// WhereCreateTime applies the entql time.Time predicate on the create_time field. +func (f *AdvFilter) WhereCreateTime(p entql.TimeP) { + f.Where(p.Field(adv.FieldCreateTime)) +} + +// WhereUpdateTime applies the entql time.Time predicate on the update_time field. +func (f *AdvFilter) WhereUpdateTime(p entql.TimeP) { + f.Where(p.Field(adv.FieldUpdateTime)) +} + +// WhereCode applies the entql string predicate on the code field. +func (f *AdvFilter) WhereCode(p entql.StringP) { + f.Where(p.Field(adv.FieldCode)) +} + +// WhereMallCode applies the entql string predicate on the mall_code field. +func (f *AdvFilter) WhereMallCode(p entql.StringP) { + f.Where(p.Field(adv.FieldMallCode)) +} + +// WhereMallName applies the entql string predicate on the mall_name field. +func (f *AdvFilter) WhereMallName(p entql.StringP) { + f.Where(p.Field(adv.FieldMallName)) +} + +// WhereH3Index6 applies the entql string predicate on the h3_index_6 field. +func (f *AdvFilter) WhereH3Index6(p entql.StringP) { + f.Where(p.Field(adv.FieldH3Index6)) +} + +// WhereH3Index7 applies the entql string predicate on the h3_index_7 field. +func (f *AdvFilter) WhereH3Index7(p entql.StringP) { + f.Where(p.Field(adv.FieldH3Index7)) +} + +// WhereH3Index8 applies the entql string predicate on the h3_index_8 field. +func (f *AdvFilter) WhereH3Index8(p entql.StringP) { + f.Where(p.Field(adv.FieldH3Index8)) +} + +// WhereImgPath applies the entql string predicate on the img_path field. +func (f *AdvFilter) WhereImgPath(p entql.StringP) { + f.Where(p.Field(adv.FieldImgPath)) +} + +// WhereURL applies the entql string predicate on the url field. +func (f *AdvFilter) WhereURL(p entql.StringP) { + f.Where(p.Field(adv.FieldURL)) +} + +// WhereRuler applies the entql string predicate on the ruler field. +func (f *AdvFilter) WhereRuler(p entql.StringP) { + f.Where(p.Field(adv.FieldRuler)) +} + +// WhereOrd applies the entql int predicate on the ord field. +func (f *AdvFilter) WhereOrd(p entql.IntP) { + f.Where(p.Field(adv.FieldOrd)) +} + +// WhereMemo applies the entql string predicate on the memo field. +func (f *AdvFilter) WhereMemo(p entql.StringP) { + f.Where(p.Field(adv.FieldMemo)) +} + +// WhereStartTime applies the entql time.Time predicate on the start_time field. +func (f *AdvFilter) WhereStartTime(p entql.TimeP) { + f.Where(p.Field(adv.FieldStartTime)) +} + +// WhereEndTime applies the entql time.Time predicate on the end_time field. +func (f *AdvFilter) WhereEndTime(p entql.TimeP) { + f.Where(p.Field(adv.FieldEndTime)) +} + +// WhereStatus applies the entql int predicate on the status field. +func (f *AdvFilter) WhereStatus(p entql.IntP) { + f.Where(p.Field(adv.FieldStatus)) +} + +// addPredicate implements the predicateAdder interface. +func (mq *MallQuery) addPredicate(pred func(s *sql.Selector)) { + mq.predicates = append(mq.predicates, pred) +} + +// Filter returns a Filter implementation to apply filters on the MallQuery builder. +func (mq *MallQuery) Filter() *MallFilter { + return &MallFilter{config: mq.config, predicateAdder: mq} +} + +// addPredicate implements the predicateAdder interface. +func (m *MallMutation) addPredicate(pred func(s *sql.Selector)) { + m.predicates = append(m.predicates, pred) +} + +// Filter returns an entql.Where implementation to apply filters on the MallMutation builder. +func (m *MallMutation) Filter() *MallFilter { + return &MallFilter{config: m.config, predicateAdder: m} +} + +// MallFilter provides a generic filtering capability at runtime for MallQuery. +type MallFilter struct { + predicateAdder + config +} + +// Where applies the entql predicate on the query filter. +func (f *MallFilter) Where(p entql.P) { + f.addPredicate(func(s *sql.Selector) { + if err := schemaGraph.EvalP(schemaGraph.Nodes[1].Type, p, s); err != nil { + s.AddError(err) + } + }) +} + +// WhereID applies the entql [16]byte predicate on the id field. +func (f *MallFilter) WhereID(p entql.ValueP) { + f.Where(p.Field(mall.FieldID)) +} + +// WhereCreateTime applies the entql time.Time predicate on the create_time field. +func (f *MallFilter) WhereCreateTime(p entql.TimeP) { + f.Where(p.Field(mall.FieldCreateTime)) +} + +// WhereUpdateTime applies the entql time.Time predicate on the update_time field. +func (f *MallFilter) WhereUpdateTime(p entql.TimeP) { + f.Where(p.Field(mall.FieldUpdateTime)) +} + +// WhereCode applies the entql string predicate on the code field. +func (f *MallFilter) WhereCode(p entql.StringP) { + f.Where(p.Field(mall.FieldCode)) +} + +// WhereMallCode applies the entql string predicate on the mall_code field. +func (f *MallFilter) WhereMallCode(p entql.StringP) { + f.Where(p.Field(mall.FieldMallCode)) +} + +// WhereMallName applies the entql string predicate on the mall_name field. +func (f *MallFilter) WhereMallName(p entql.StringP) { + f.Where(p.Field(mall.FieldMallName)) +} + +// WhereH3Index6 applies the entql string predicate on the h3_index_6 field. +func (f *MallFilter) WhereH3Index6(p entql.StringP) { + f.Where(p.Field(mall.FieldH3Index6)) +} + +// WhereH3Index7 applies the entql string predicate on the h3_index_7 field. +func (f *MallFilter) WhereH3Index7(p entql.StringP) { + f.Where(p.Field(mall.FieldH3Index7)) +} + +// WhereH3Index8 applies the entql string predicate on the h3_index_8 field. +func (f *MallFilter) WhereH3Index8(p entql.StringP) { + f.Where(p.Field(mall.FieldH3Index8)) +} + +// WhereMemo applies the entql string predicate on the memo field. +func (f *MallFilter) WhereMemo(p entql.StringP) { + f.Where(p.Field(mall.FieldMemo)) +} + +// WhereStartTime applies the entql time.Time predicate on the start_time field. +func (f *MallFilter) WhereStartTime(p entql.TimeP) { + f.Where(p.Field(mall.FieldStartTime)) +} + +// WhereStatus applies the entql int predicate on the status field. +func (f *MallFilter) WhereStatus(p entql.IntP) { + f.Where(p.Field(mall.FieldStatus)) +} diff --git a/adv/orm/ent/enttest/enttest.go b/adv/orm/ent/enttest/enttest.go new file mode 100644 index 0000000..461be0b --- /dev/null +++ b/adv/orm/ent/enttest/enttest.go @@ -0,0 +1,84 @@ +// Code generated by ent, DO NOT EDIT. + +package enttest + +import ( + "context" + + "github.com/twiglab/crm/adv/orm/ent" + // required by schema hooks. + _ "github.com/twiglab/crm/adv/orm/ent/runtime" + + "entgo.io/ent/dialect/sql/schema" + "github.com/twiglab/crm/adv/orm/ent/migrate" +) + +type ( + // TestingT is the interface that is shared between + // testing.T and testing.B and used by enttest. + TestingT interface { + FailNow() + Error(...any) + } + + // Option configures client creation. + Option func(*options) + + options struct { + opts []ent.Option + migrateOpts []schema.MigrateOption + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...ent.Option) Option { + return func(o *options) { + o.opts = append(o.opts, opts...) + } +} + +// WithMigrateOptions forwards options to auto migration. +func WithMigrateOptions(opts ...schema.MigrateOption) Option { + return func(o *options) { + o.migrateOpts = append(o.migrateOpts, opts...) + } +} + +func newOptions(opts []Option) *options { + o := &options{} + for _, opt := range opts { + opt(o) + } + return o +} + +// Open calls ent.Open and auto-run migration. +func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { + o := newOptions(opts) + c, err := ent.Open(driverName, dataSourceName, o.opts...) + if err != nil { + t.Error(err) + t.FailNow() + } + migrateSchema(t, c, o) + return c +} + +// NewClient calls ent.NewClient and auto-run migration. +func NewClient(t TestingT, opts ...Option) *ent.Client { + o := newOptions(opts) + c := ent.NewClient(o.opts...) + migrateSchema(t, c, o) + return c +} +func migrateSchema(t TestingT, c *ent.Client, o *options) { + tables, err := schema.CopyTables(migrate.Tables) + if err != nil { + t.Error(err) + t.FailNow() + } + if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } +} diff --git a/adv/orm/ent/hook/hook.go b/adv/orm/ent/hook/hook.go new file mode 100644 index 0000000..2277f42 --- /dev/null +++ b/adv/orm/ent/hook/hook.go @@ -0,0 +1,211 @@ +// Code generated by ent, DO NOT EDIT. + +package hook + +import ( + "context" + "fmt" + + "github.com/twiglab/crm/adv/orm/ent" +) + +// The AdvFunc type is an adapter to allow the use of ordinary +// function as Adv mutator. +type AdvFunc func(context.Context, *ent.AdvMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f AdvFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.AdvMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AdvMutation", m) +} + +// The MallFunc type is an adapter to allow the use of ordinary +// function as Mall mutator. +type MallFunc func(context.Context, *ent.MallMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f MallFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.MallMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MallMutation", m) +} + +// Condition is a hook condition function. +type Condition func(context.Context, ent.Mutation) bool + +// And groups conditions with the AND operator. +func And(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if !first(ctx, m) || !second(ctx, m) { + return false + } + for _, cond := range rest { + if !cond(ctx, m) { + return false + } + } + return true + } +} + +// Or groups conditions with the OR operator. +func Or(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if first(ctx, m) || second(ctx, m) { + return true + } + for _, cond := range rest { + if cond(ctx, m) { + return true + } + } + return false + } +} + +// Not negates a given condition. +func Not(cond Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + return !cond(ctx, m) + } +} + +// HasOp is a condition testing mutation operation. +func HasOp(op ent.Op) Condition { + return func(_ context.Context, m ent.Mutation) bool { + return m.Op().Is(op) + } +} + +// HasAddedFields is a condition validating `.AddedField` on fields. +func HasAddedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.AddedField(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.AddedField(field); !exists { + return false + } + } + return true + } +} + +// HasClearedFields is a condition validating `.FieldCleared` on fields. +func HasClearedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if exists := m.FieldCleared(field); !exists { + return false + } + for _, field := range fields { + if exists := m.FieldCleared(field); !exists { + return false + } + } + return true + } +} + +// HasFields is a condition validating `.Field` on fields. +func HasFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.Field(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.Field(field); !exists { + return false + } + } + return true + } +} + +// If executes the given hook under condition. +// +// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) +func If(hk ent.Hook, cond Condition) ent.Hook { + return func(next ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if cond(ctx, m) { + return hk(next).Mutate(ctx, m) + } + return next.Mutate(ctx, m) + }) + } +} + +// On executes the given hook only for the given operation. +// +// hook.On(Log, ent.Delete|ent.Create) +func On(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, HasOp(op)) +} + +// Unless skips the given hook only for the given operation. +// +// hook.Unless(Log, ent.Update|ent.UpdateOne) +func Unless(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, Not(HasOp(op))) +} + +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + +// Reject returns a hook that rejects all operations that match op. +// +// func (T) Hooks() []ent.Hook { +// return []ent.Hook{ +// Reject(ent.Delete|ent.Update), +// } +// } +func Reject(op ent.Op) ent.Hook { + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) + return On(hk, op) +} + +// Chain acts as a list of hooks and is effectively immutable. +// Once created, it will always hold the same set of hooks in the same order. +type Chain struct { + hooks []ent.Hook +} + +// NewChain creates a new chain of hooks. +func NewChain(hooks ...ent.Hook) Chain { + return Chain{append([]ent.Hook(nil), hooks...)} +} + +// Hook chains the list of hooks and returns the final hook. +func (c Chain) Hook() ent.Hook { + return func(mutator ent.Mutator) ent.Mutator { + for i := len(c.hooks) - 1; i >= 0; i-- { + mutator = c.hooks[i](mutator) + } + return mutator + } +} + +// Append extends a chain, adding the specified hook +// as the last ones in the mutation flow. +func (c Chain) Append(hooks ...ent.Hook) Chain { + newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) + newHooks = append(newHooks, c.hooks...) + newHooks = append(newHooks, hooks...) + return Chain{newHooks} +} + +// Extend extends a chain, adding the specified chain +// as the last ones in the mutation flow. +func (c Chain) Extend(chain Chain) Chain { + return c.Append(chain.hooks...) +} diff --git a/adv/orm/ent/mall.go b/adv/orm/ent/mall.go new file mode 100644 index 0000000..1d1fb39 --- /dev/null +++ b/adv/orm/ent/mall.go @@ -0,0 +1,219 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/mall" +) + +// Mall is the model entity for the Mall schema. +type Mall struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // CreateTime holds the value of the "create_time" field. + CreateTime time.Time `json:"create_time,omitempty"` + // UpdateTime holds the value of the "update_time" field. + UpdateTime time.Time `json:"update_time,omitempty"` + // Code holds the value of the "code" field. + Code string `json:"code,omitempty"` + // MallCode holds the value of the "mall_code" field. + MallCode string `json:"mall_code,omitempty"` + // MallName holds the value of the "mall_name" field. + MallName string `json:"mall_name,omitempty"` + // H3Index6 holds the value of the "h3_index_6" field. + H3Index6 string `json:"h3_index_6,omitempty"` + // H3Index7 holds the value of the "h3_index_7" field. + H3Index7 string `json:"h3_index_7,omitempty"` + // H3Index8 holds the value of the "h3_index_8" field. + H3Index8 string `json:"h3_index_8,omitempty"` + // Memo holds the value of the "memo" field. + Memo string `json:"memo,omitempty"` + // StartTime holds the value of the "start_time" field. + StartTime time.Time `json:"start_time,omitempty"` + // Status holds the value of the "status" field. + Status int `json:"status,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Mall) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case mall.FieldStatus: + values[i] = new(sql.NullInt64) + case mall.FieldCode, mall.FieldMallCode, mall.FieldMallName, mall.FieldH3Index6, mall.FieldH3Index7, mall.FieldH3Index8, mall.FieldMemo: + values[i] = new(sql.NullString) + case mall.FieldCreateTime, mall.FieldUpdateTime, mall.FieldStartTime: + values[i] = new(sql.NullTime) + case mall.FieldID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Mall fields. +func (m *Mall) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case mall.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + m.ID = *value + } + case mall.FieldCreateTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field create_time", values[i]) + } else if value.Valid { + m.CreateTime = value.Time + } + case mall.FieldUpdateTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field update_time", values[i]) + } else if value.Valid { + m.UpdateTime = value.Time + } + case mall.FieldCode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field code", values[i]) + } else if value.Valid { + m.Code = value.String + } + case mall.FieldMallCode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mall_code", values[i]) + } else if value.Valid { + m.MallCode = value.String + } + case mall.FieldMallName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mall_name", values[i]) + } else if value.Valid { + m.MallName = value.String + } + case mall.FieldH3Index6: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field h3_index_6", values[i]) + } else if value.Valid { + m.H3Index6 = value.String + } + case mall.FieldH3Index7: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field h3_index_7", values[i]) + } else if value.Valid { + m.H3Index7 = value.String + } + case mall.FieldH3Index8: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field h3_index_8", values[i]) + } else if value.Valid { + m.H3Index8 = value.String + } + case mall.FieldMemo: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field memo", values[i]) + } else if value.Valid { + m.Memo = value.String + } + case mall.FieldStartTime: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field start_time", values[i]) + } else if value.Valid { + m.StartTime = value.Time + } + case mall.FieldStatus: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field status", values[i]) + } else if value.Valid { + m.Status = int(value.Int64) + } + default: + m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Mall. +// This includes values selected through modifiers, order, etc. +func (m *Mall) Value(name string) (ent.Value, error) { + return m.selectValues.Get(name) +} + +// Update returns a builder for updating this Mall. +// Note that you need to call Mall.Unwrap() before calling this method if this Mall +// was returned from a transaction, and the transaction was committed or rolled back. +func (m *Mall) Update() *MallUpdateOne { + return NewMallClient(m.config).UpdateOne(m) +} + +// Unwrap unwraps the Mall entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (m *Mall) Unwrap() *Mall { + _tx, ok := m.config.driver.(*txDriver) + if !ok { + panic("ent: Mall is not a transactional entity") + } + m.config.driver = _tx.drv + return m +} + +// String implements the fmt.Stringer. +func (m *Mall) String() string { + var builder strings.Builder + builder.WriteString("Mall(") + builder.WriteString(fmt.Sprintf("id=%v, ", m.ID)) + builder.WriteString("create_time=") + builder.WriteString(m.CreateTime.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("update_time=") + builder.WriteString(m.UpdateTime.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("code=") + builder.WriteString(m.Code) + builder.WriteString(", ") + builder.WriteString("mall_code=") + builder.WriteString(m.MallCode) + builder.WriteString(", ") + builder.WriteString("mall_name=") + builder.WriteString(m.MallName) + builder.WriteString(", ") + builder.WriteString("h3_index_6=") + builder.WriteString(m.H3Index6) + builder.WriteString(", ") + builder.WriteString("h3_index_7=") + builder.WriteString(m.H3Index7) + builder.WriteString(", ") + builder.WriteString("h3_index_8=") + builder.WriteString(m.H3Index8) + builder.WriteString(", ") + builder.WriteString("memo=") + builder.WriteString(m.Memo) + builder.WriteString(", ") + builder.WriteString("start_time=") + builder.WriteString(m.StartTime.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(fmt.Sprintf("%v", m.Status)) + builder.WriteByte(')') + return builder.String() +} + +// Malls is a parsable slice of Mall. +type Malls []*Mall diff --git a/adv/orm/ent/mall/mall.go b/adv/orm/ent/mall/mall.go new file mode 100644 index 0000000..3d5db39 --- /dev/null +++ b/adv/orm/ent/mall/mall.go @@ -0,0 +1,161 @@ +// Code generated by ent, DO NOT EDIT. + +package mall + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the mall type in the database. + Label = "mall" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreateTime holds the string denoting the create_time field in the database. + FieldCreateTime = "create_time" + // FieldUpdateTime holds the string denoting the update_time field in the database. + FieldUpdateTime = "update_time" + // FieldCode holds the string denoting the code field in the database. + FieldCode = "code" + // FieldMallCode holds the string denoting the mall_code field in the database. + FieldMallCode = "mall_code" + // FieldMallName holds the string denoting the mall_name field in the database. + FieldMallName = "mall_name" + // FieldH3Index6 holds the string denoting the h3_index_6 field in the database. + FieldH3Index6 = "h3_index_6" + // FieldH3Index7 holds the string denoting the h3_index_7 field in the database. + FieldH3Index7 = "h3_index_7" + // FieldH3Index8 holds the string denoting the h3_index_8 field in the database. + FieldH3Index8 = "h3_index_8" + // FieldMemo holds the string denoting the memo field in the database. + FieldMemo = "memo" + // FieldStartTime holds the string denoting the start_time field in the database. + FieldStartTime = "start_time" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // Table holds the table name of the mall in the database. + Table = "t_mall" +) + +// Columns holds all SQL columns for mall fields. +var Columns = []string{ + FieldID, + FieldCreateTime, + FieldUpdateTime, + FieldCode, + FieldMallCode, + FieldMallName, + FieldH3Index6, + FieldH3Index7, + FieldH3Index8, + FieldMemo, + FieldStartTime, + FieldStatus, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreateTime holds the default value on creation for the "create_time" field. + DefaultCreateTime func() time.Time + // DefaultUpdateTime holds the default value on creation for the "update_time" field. + DefaultUpdateTime func() time.Time + // UpdateDefaultUpdateTime holds the default value on update for the "update_time" field. + UpdateDefaultUpdateTime func() time.Time + // DefaultCode holds the default value on creation for the "code" field. + DefaultCode func() string + // CodeValidator is a validator for the "code" field. It is called by the builders before save. + CodeValidator func(string) error + // MallCodeValidator is a validator for the "mall_code" field. It is called by the builders before save. + MallCodeValidator func(string) error + // MallNameValidator is a validator for the "mall_name" field. It is called by the builders before save. + MallNameValidator func(string) error + // H3Index6Validator is a validator for the "h3_index_6" field. It is called by the builders before save. + H3Index6Validator func(string) error + // H3Index7Validator is a validator for the "h3_index_7" field. It is called by the builders before save. + H3Index7Validator func(string) error + // H3Index8Validator is a validator for the "h3_index_8" field. It is called by the builders before save. + H3Index8Validator func(string) error + // MemoValidator is a validator for the "memo" field. It is called by the builders before save. + MemoValidator func(string) error + // DefaultStartTime holds the default value on creation for the "start_time" field. + DefaultStartTime func() time.Time + // DefaultStatus holds the default value on creation for the "status" field. + DefaultStatus int + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the Mall queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreateTime orders the results by the create_time field. +func ByCreateTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreateTime, opts...).ToFunc() +} + +// ByUpdateTime orders the results by the update_time field. +func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdateTime, opts...).ToFunc() +} + +// ByCode orders the results by the code field. +func ByCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCode, opts...).ToFunc() +} + +// ByMallCode orders the results by the mall_code field. +func ByMallCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMallCode, opts...).ToFunc() +} + +// ByMallName orders the results by the mall_name field. +func ByMallName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMallName, opts...).ToFunc() +} + +// ByH3Index6 orders the results by the h3_index_6 field. +func ByH3Index6(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldH3Index6, opts...).ToFunc() +} + +// ByH3Index7 orders the results by the h3_index_7 field. +func ByH3Index7(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldH3Index7, opts...).ToFunc() +} + +// ByH3Index8 orders the results by the h3_index_8 field. +func ByH3Index8(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldH3Index8, opts...).ToFunc() +} + +// ByMemo orders the results by the memo field. +func ByMemo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMemo, opts...).ToFunc() +} + +// ByStartTime orders the results by the start_time field. +func ByStartTime(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStartTime, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} diff --git a/adv/orm/ent/mall/where.go b/adv/orm/ent/mall/where.go new file mode 100644 index 0000000..265de4b --- /dev/null +++ b/adv/orm/ent/mall/where.go @@ -0,0 +1,741 @@ +// Code generated by ent, DO NOT EDIT. + +package mall + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldID, id)) +} + +// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ. +func CreateTime(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldCreateTime, v)) +} + +// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ. +func UpdateTime(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldUpdateTime, v)) +} + +// Code applies equality check predicate on the "code" field. It's identical to CodeEQ. +func Code(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldCode, v)) +} + +// MallCode applies equality check predicate on the "mall_code" field. It's identical to MallCodeEQ. +func MallCode(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldMallCode, v)) +} + +// MallName applies equality check predicate on the "mall_name" field. It's identical to MallNameEQ. +func MallName(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldMallName, v)) +} + +// H3Index6 applies equality check predicate on the "h3_index_6" field. It's identical to H3Index6EQ. +func H3Index6(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldH3Index6, v)) +} + +// H3Index7 applies equality check predicate on the "h3_index_7" field. It's identical to H3Index7EQ. +func H3Index7(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldH3Index7, v)) +} + +// H3Index8 applies equality check predicate on the "h3_index_8" field. It's identical to H3Index8EQ. +func H3Index8(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldH3Index8, v)) +} + +// Memo applies equality check predicate on the "memo" field. It's identical to MemoEQ. +func Memo(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldMemo, v)) +} + +// StartTime applies equality check predicate on the "start_time" field. It's identical to StartTimeEQ. +func StartTime(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldStartTime, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v int) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldStatus, v)) +} + +// CreateTimeEQ applies the EQ predicate on the "create_time" field. +func CreateTimeEQ(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldCreateTime, v)) +} + +// CreateTimeNEQ applies the NEQ predicate on the "create_time" field. +func CreateTimeNEQ(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldCreateTime, v)) +} + +// CreateTimeIn applies the In predicate on the "create_time" field. +func CreateTimeIn(vs ...time.Time) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldCreateTime, vs...)) +} + +// CreateTimeNotIn applies the NotIn predicate on the "create_time" field. +func CreateTimeNotIn(vs ...time.Time) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldCreateTime, vs...)) +} + +// CreateTimeGT applies the GT predicate on the "create_time" field. +func CreateTimeGT(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldCreateTime, v)) +} + +// CreateTimeGTE applies the GTE predicate on the "create_time" field. +func CreateTimeGTE(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldCreateTime, v)) +} + +// CreateTimeLT applies the LT predicate on the "create_time" field. +func CreateTimeLT(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldCreateTime, v)) +} + +// CreateTimeLTE applies the LTE predicate on the "create_time" field. +func CreateTimeLTE(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldCreateTime, v)) +} + +// UpdateTimeEQ applies the EQ predicate on the "update_time" field. +func UpdateTimeEQ(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldUpdateTime, v)) +} + +// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field. +func UpdateTimeNEQ(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldUpdateTime, v)) +} + +// UpdateTimeIn applies the In predicate on the "update_time" field. +func UpdateTimeIn(vs ...time.Time) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldUpdateTime, vs...)) +} + +// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field. +func UpdateTimeNotIn(vs ...time.Time) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldUpdateTime, vs...)) +} + +// UpdateTimeGT applies the GT predicate on the "update_time" field. +func UpdateTimeGT(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldUpdateTime, v)) +} + +// UpdateTimeGTE applies the GTE predicate on the "update_time" field. +func UpdateTimeGTE(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldUpdateTime, v)) +} + +// UpdateTimeLT applies the LT predicate on the "update_time" field. +func UpdateTimeLT(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldUpdateTime, v)) +} + +// UpdateTimeLTE applies the LTE predicate on the "update_time" field. +func UpdateTimeLTE(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldUpdateTime, v)) +} + +// CodeEQ applies the EQ predicate on the "code" field. +func CodeEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldCode, v)) +} + +// CodeNEQ applies the NEQ predicate on the "code" field. +func CodeNEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldCode, v)) +} + +// CodeIn applies the In predicate on the "code" field. +func CodeIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldCode, vs...)) +} + +// CodeNotIn applies the NotIn predicate on the "code" field. +func CodeNotIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldCode, vs...)) +} + +// CodeGT applies the GT predicate on the "code" field. +func CodeGT(v string) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldCode, v)) +} + +// CodeGTE applies the GTE predicate on the "code" field. +func CodeGTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldCode, v)) +} + +// CodeLT applies the LT predicate on the "code" field. +func CodeLT(v string) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldCode, v)) +} + +// CodeLTE applies the LTE predicate on the "code" field. +func CodeLTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldCode, v)) +} + +// CodeContains applies the Contains predicate on the "code" field. +func CodeContains(v string) predicate.Mall { + return predicate.Mall(sql.FieldContains(FieldCode, v)) +} + +// CodeHasPrefix applies the HasPrefix predicate on the "code" field. +func CodeHasPrefix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasPrefix(FieldCode, v)) +} + +// CodeHasSuffix applies the HasSuffix predicate on the "code" field. +func CodeHasSuffix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasSuffix(FieldCode, v)) +} + +// CodeEqualFold applies the EqualFold predicate on the "code" field. +func CodeEqualFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldEqualFold(FieldCode, v)) +} + +// CodeContainsFold applies the ContainsFold predicate on the "code" field. +func CodeContainsFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldContainsFold(FieldCode, v)) +} + +// MallCodeEQ applies the EQ predicate on the "mall_code" field. +func MallCodeEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldMallCode, v)) +} + +// MallCodeNEQ applies the NEQ predicate on the "mall_code" field. +func MallCodeNEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldMallCode, v)) +} + +// MallCodeIn applies the In predicate on the "mall_code" field. +func MallCodeIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldMallCode, vs...)) +} + +// MallCodeNotIn applies the NotIn predicate on the "mall_code" field. +func MallCodeNotIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldMallCode, vs...)) +} + +// MallCodeGT applies the GT predicate on the "mall_code" field. +func MallCodeGT(v string) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldMallCode, v)) +} + +// MallCodeGTE applies the GTE predicate on the "mall_code" field. +func MallCodeGTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldMallCode, v)) +} + +// MallCodeLT applies the LT predicate on the "mall_code" field. +func MallCodeLT(v string) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldMallCode, v)) +} + +// MallCodeLTE applies the LTE predicate on the "mall_code" field. +func MallCodeLTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldMallCode, v)) +} + +// MallCodeContains applies the Contains predicate on the "mall_code" field. +func MallCodeContains(v string) predicate.Mall { + return predicate.Mall(sql.FieldContains(FieldMallCode, v)) +} + +// MallCodeHasPrefix applies the HasPrefix predicate on the "mall_code" field. +func MallCodeHasPrefix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasPrefix(FieldMallCode, v)) +} + +// MallCodeHasSuffix applies the HasSuffix predicate on the "mall_code" field. +func MallCodeHasSuffix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasSuffix(FieldMallCode, v)) +} + +// MallCodeEqualFold applies the EqualFold predicate on the "mall_code" field. +func MallCodeEqualFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldEqualFold(FieldMallCode, v)) +} + +// MallCodeContainsFold applies the ContainsFold predicate on the "mall_code" field. +func MallCodeContainsFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldContainsFold(FieldMallCode, v)) +} + +// MallNameEQ applies the EQ predicate on the "mall_name" field. +func MallNameEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldMallName, v)) +} + +// MallNameNEQ applies the NEQ predicate on the "mall_name" field. +func MallNameNEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldMallName, v)) +} + +// MallNameIn applies the In predicate on the "mall_name" field. +func MallNameIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldMallName, vs...)) +} + +// MallNameNotIn applies the NotIn predicate on the "mall_name" field. +func MallNameNotIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldMallName, vs...)) +} + +// MallNameGT applies the GT predicate on the "mall_name" field. +func MallNameGT(v string) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldMallName, v)) +} + +// MallNameGTE applies the GTE predicate on the "mall_name" field. +func MallNameGTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldMallName, v)) +} + +// MallNameLT applies the LT predicate on the "mall_name" field. +func MallNameLT(v string) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldMallName, v)) +} + +// MallNameLTE applies the LTE predicate on the "mall_name" field. +func MallNameLTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldMallName, v)) +} + +// MallNameContains applies the Contains predicate on the "mall_name" field. +func MallNameContains(v string) predicate.Mall { + return predicate.Mall(sql.FieldContains(FieldMallName, v)) +} + +// MallNameHasPrefix applies the HasPrefix predicate on the "mall_name" field. +func MallNameHasPrefix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasPrefix(FieldMallName, v)) +} + +// MallNameHasSuffix applies the HasSuffix predicate on the "mall_name" field. +func MallNameHasSuffix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasSuffix(FieldMallName, v)) +} + +// MallNameEqualFold applies the EqualFold predicate on the "mall_name" field. +func MallNameEqualFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldEqualFold(FieldMallName, v)) +} + +// MallNameContainsFold applies the ContainsFold predicate on the "mall_name" field. +func MallNameContainsFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldContainsFold(FieldMallName, v)) +} + +// H3Index6EQ applies the EQ predicate on the "h3_index_6" field. +func H3Index6EQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldH3Index6, v)) +} + +// H3Index6NEQ applies the NEQ predicate on the "h3_index_6" field. +func H3Index6NEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldH3Index6, v)) +} + +// H3Index6In applies the In predicate on the "h3_index_6" field. +func H3Index6In(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldH3Index6, vs...)) +} + +// H3Index6NotIn applies the NotIn predicate on the "h3_index_6" field. +func H3Index6NotIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldH3Index6, vs...)) +} + +// H3Index6GT applies the GT predicate on the "h3_index_6" field. +func H3Index6GT(v string) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldH3Index6, v)) +} + +// H3Index6GTE applies the GTE predicate on the "h3_index_6" field. +func H3Index6GTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldH3Index6, v)) +} + +// H3Index6LT applies the LT predicate on the "h3_index_6" field. +func H3Index6LT(v string) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldH3Index6, v)) +} + +// H3Index6LTE applies the LTE predicate on the "h3_index_6" field. +func H3Index6LTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldH3Index6, v)) +} + +// H3Index6Contains applies the Contains predicate on the "h3_index_6" field. +func H3Index6Contains(v string) predicate.Mall { + return predicate.Mall(sql.FieldContains(FieldH3Index6, v)) +} + +// H3Index6HasPrefix applies the HasPrefix predicate on the "h3_index_6" field. +func H3Index6HasPrefix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasPrefix(FieldH3Index6, v)) +} + +// H3Index6HasSuffix applies the HasSuffix predicate on the "h3_index_6" field. +func H3Index6HasSuffix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasSuffix(FieldH3Index6, v)) +} + +// H3Index6EqualFold applies the EqualFold predicate on the "h3_index_6" field. +func H3Index6EqualFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldEqualFold(FieldH3Index6, v)) +} + +// H3Index6ContainsFold applies the ContainsFold predicate on the "h3_index_6" field. +func H3Index6ContainsFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldContainsFold(FieldH3Index6, v)) +} + +// H3Index7EQ applies the EQ predicate on the "h3_index_7" field. +func H3Index7EQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldH3Index7, v)) +} + +// H3Index7NEQ applies the NEQ predicate on the "h3_index_7" field. +func H3Index7NEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldH3Index7, v)) +} + +// H3Index7In applies the In predicate on the "h3_index_7" field. +func H3Index7In(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldH3Index7, vs...)) +} + +// H3Index7NotIn applies the NotIn predicate on the "h3_index_7" field. +func H3Index7NotIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldH3Index7, vs...)) +} + +// H3Index7GT applies the GT predicate on the "h3_index_7" field. +func H3Index7GT(v string) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldH3Index7, v)) +} + +// H3Index7GTE applies the GTE predicate on the "h3_index_7" field. +func H3Index7GTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldH3Index7, v)) +} + +// H3Index7LT applies the LT predicate on the "h3_index_7" field. +func H3Index7LT(v string) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldH3Index7, v)) +} + +// H3Index7LTE applies the LTE predicate on the "h3_index_7" field. +func H3Index7LTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldH3Index7, v)) +} + +// H3Index7Contains applies the Contains predicate on the "h3_index_7" field. +func H3Index7Contains(v string) predicate.Mall { + return predicate.Mall(sql.FieldContains(FieldH3Index7, v)) +} + +// H3Index7HasPrefix applies the HasPrefix predicate on the "h3_index_7" field. +func H3Index7HasPrefix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasPrefix(FieldH3Index7, v)) +} + +// H3Index7HasSuffix applies the HasSuffix predicate on the "h3_index_7" field. +func H3Index7HasSuffix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasSuffix(FieldH3Index7, v)) +} + +// H3Index7EqualFold applies the EqualFold predicate on the "h3_index_7" field. +func H3Index7EqualFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldEqualFold(FieldH3Index7, v)) +} + +// H3Index7ContainsFold applies the ContainsFold predicate on the "h3_index_7" field. +func H3Index7ContainsFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldContainsFold(FieldH3Index7, v)) +} + +// H3Index8EQ applies the EQ predicate on the "h3_index_8" field. +func H3Index8EQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldH3Index8, v)) +} + +// H3Index8NEQ applies the NEQ predicate on the "h3_index_8" field. +func H3Index8NEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldH3Index8, v)) +} + +// H3Index8In applies the In predicate on the "h3_index_8" field. +func H3Index8In(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldH3Index8, vs...)) +} + +// H3Index8NotIn applies the NotIn predicate on the "h3_index_8" field. +func H3Index8NotIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldH3Index8, vs...)) +} + +// H3Index8GT applies the GT predicate on the "h3_index_8" field. +func H3Index8GT(v string) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldH3Index8, v)) +} + +// H3Index8GTE applies the GTE predicate on the "h3_index_8" field. +func H3Index8GTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldH3Index8, v)) +} + +// H3Index8LT applies the LT predicate on the "h3_index_8" field. +func H3Index8LT(v string) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldH3Index8, v)) +} + +// H3Index8LTE applies the LTE predicate on the "h3_index_8" field. +func H3Index8LTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldH3Index8, v)) +} + +// H3Index8Contains applies the Contains predicate on the "h3_index_8" field. +func H3Index8Contains(v string) predicate.Mall { + return predicate.Mall(sql.FieldContains(FieldH3Index8, v)) +} + +// H3Index8HasPrefix applies the HasPrefix predicate on the "h3_index_8" field. +func H3Index8HasPrefix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasPrefix(FieldH3Index8, v)) +} + +// H3Index8HasSuffix applies the HasSuffix predicate on the "h3_index_8" field. +func H3Index8HasSuffix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasSuffix(FieldH3Index8, v)) +} + +// H3Index8EqualFold applies the EqualFold predicate on the "h3_index_8" field. +func H3Index8EqualFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldEqualFold(FieldH3Index8, v)) +} + +// H3Index8ContainsFold applies the ContainsFold predicate on the "h3_index_8" field. +func H3Index8ContainsFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldContainsFold(FieldH3Index8, v)) +} + +// MemoEQ applies the EQ predicate on the "memo" field. +func MemoEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldMemo, v)) +} + +// MemoNEQ applies the NEQ predicate on the "memo" field. +func MemoNEQ(v string) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldMemo, v)) +} + +// MemoIn applies the In predicate on the "memo" field. +func MemoIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldMemo, vs...)) +} + +// MemoNotIn applies the NotIn predicate on the "memo" field. +func MemoNotIn(vs ...string) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldMemo, vs...)) +} + +// MemoGT applies the GT predicate on the "memo" field. +func MemoGT(v string) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldMemo, v)) +} + +// MemoGTE applies the GTE predicate on the "memo" field. +func MemoGTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldMemo, v)) +} + +// MemoLT applies the LT predicate on the "memo" field. +func MemoLT(v string) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldMemo, v)) +} + +// MemoLTE applies the LTE predicate on the "memo" field. +func MemoLTE(v string) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldMemo, v)) +} + +// MemoContains applies the Contains predicate on the "memo" field. +func MemoContains(v string) predicate.Mall { + return predicate.Mall(sql.FieldContains(FieldMemo, v)) +} + +// MemoHasPrefix applies the HasPrefix predicate on the "memo" field. +func MemoHasPrefix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasPrefix(FieldMemo, v)) +} + +// MemoHasSuffix applies the HasSuffix predicate on the "memo" field. +func MemoHasSuffix(v string) predicate.Mall { + return predicate.Mall(sql.FieldHasSuffix(FieldMemo, v)) +} + +// MemoEqualFold applies the EqualFold predicate on the "memo" field. +func MemoEqualFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldEqualFold(FieldMemo, v)) +} + +// MemoContainsFold applies the ContainsFold predicate on the "memo" field. +func MemoContainsFold(v string) predicate.Mall { + return predicate.Mall(sql.FieldContainsFold(FieldMemo, v)) +} + +// StartTimeEQ applies the EQ predicate on the "start_time" field. +func StartTimeEQ(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldStartTime, v)) +} + +// StartTimeNEQ applies the NEQ predicate on the "start_time" field. +func StartTimeNEQ(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldStartTime, v)) +} + +// StartTimeIn applies the In predicate on the "start_time" field. +func StartTimeIn(vs ...time.Time) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldStartTime, vs...)) +} + +// StartTimeNotIn applies the NotIn predicate on the "start_time" field. +func StartTimeNotIn(vs ...time.Time) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldStartTime, vs...)) +} + +// StartTimeGT applies the GT predicate on the "start_time" field. +func StartTimeGT(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldStartTime, v)) +} + +// StartTimeGTE applies the GTE predicate on the "start_time" field. +func StartTimeGTE(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldStartTime, v)) +} + +// StartTimeLT applies the LT predicate on the "start_time" field. +func StartTimeLT(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldStartTime, v)) +} + +// StartTimeLTE applies the LTE predicate on the "start_time" field. +func StartTimeLTE(v time.Time) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldStartTime, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v int) predicate.Mall { + return predicate.Mall(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v int) predicate.Mall { + return predicate.Mall(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...int) predicate.Mall { + return predicate.Mall(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...int) predicate.Mall { + return predicate.Mall(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v int) predicate.Mall { + return predicate.Mall(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v int) predicate.Mall { + return predicate.Mall(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v int) predicate.Mall { + return predicate.Mall(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v int) predicate.Mall { + return predicate.Mall(sql.FieldLTE(FieldStatus, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Mall) predicate.Mall { + return predicate.Mall(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Mall) predicate.Mall { + return predicate.Mall(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Mall) predicate.Mall { + return predicate.Mall(sql.NotPredicates(p)) +} diff --git a/adv/orm/ent/mall_create.go b/adv/orm/ent/mall_create.go new file mode 100644 index 0000000..53ee729 --- /dev/null +++ b/adv/orm/ent/mall_create.go @@ -0,0 +1,1018 @@ +// 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" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/mall" +) + +// MallCreate is the builder for creating a Mall entity. +type MallCreate struct { + config + mutation *MallMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetCreateTime sets the "create_time" field. +func (mc *MallCreate) SetCreateTime(t time.Time) *MallCreate { + mc.mutation.SetCreateTime(t) + return mc +} + +// SetNillableCreateTime sets the "create_time" field if the given value is not nil. +func (mc *MallCreate) SetNillableCreateTime(t *time.Time) *MallCreate { + if t != nil { + mc.SetCreateTime(*t) + } + return mc +} + +// SetUpdateTime sets the "update_time" field. +func (mc *MallCreate) SetUpdateTime(t time.Time) *MallCreate { + mc.mutation.SetUpdateTime(t) + return mc +} + +// SetNillableUpdateTime sets the "update_time" field if the given value is not nil. +func (mc *MallCreate) SetNillableUpdateTime(t *time.Time) *MallCreate { + if t != nil { + mc.SetUpdateTime(*t) + } + return mc +} + +// SetCode sets the "code" field. +func (mc *MallCreate) SetCode(s string) *MallCreate { + mc.mutation.SetCode(s) + return mc +} + +// SetNillableCode sets the "code" field if the given value is not nil. +func (mc *MallCreate) SetNillableCode(s *string) *MallCreate { + if s != nil { + mc.SetCode(*s) + } + return mc +} + +// SetMallCode sets the "mall_code" field. +func (mc *MallCreate) SetMallCode(s string) *MallCreate { + mc.mutation.SetMallCode(s) + return mc +} + +// SetMallName sets the "mall_name" field. +func (mc *MallCreate) SetMallName(s string) *MallCreate { + mc.mutation.SetMallName(s) + return mc +} + +// SetH3Index6 sets the "h3_index_6" field. +func (mc *MallCreate) SetH3Index6(s string) *MallCreate { + mc.mutation.SetH3Index6(s) + return mc +} + +// SetH3Index7 sets the "h3_index_7" field. +func (mc *MallCreate) SetH3Index7(s string) *MallCreate { + mc.mutation.SetH3Index7(s) + return mc +} + +// SetH3Index8 sets the "h3_index_8" field. +func (mc *MallCreate) SetH3Index8(s string) *MallCreate { + mc.mutation.SetH3Index8(s) + return mc +} + +// SetMemo sets the "memo" field. +func (mc *MallCreate) SetMemo(s string) *MallCreate { + mc.mutation.SetMemo(s) + return mc +} + +// SetStartTime sets the "start_time" field. +func (mc *MallCreate) SetStartTime(t time.Time) *MallCreate { + mc.mutation.SetStartTime(t) + return mc +} + +// SetNillableStartTime sets the "start_time" field if the given value is not nil. +func (mc *MallCreate) SetNillableStartTime(t *time.Time) *MallCreate { + if t != nil { + mc.SetStartTime(*t) + } + return mc +} + +// SetStatus sets the "status" field. +func (mc *MallCreate) SetStatus(i int) *MallCreate { + mc.mutation.SetStatus(i) + return mc +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (mc *MallCreate) SetNillableStatus(i *int) *MallCreate { + if i != nil { + mc.SetStatus(*i) + } + return mc +} + +// SetID sets the "id" field. +func (mc *MallCreate) SetID(u uuid.UUID) *MallCreate { + mc.mutation.SetID(u) + return mc +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (mc *MallCreate) SetNillableID(u *uuid.UUID) *MallCreate { + if u != nil { + mc.SetID(*u) + } + return mc +} + +// Mutation returns the MallMutation object of the builder. +func (mc *MallCreate) Mutation() *MallMutation { + return mc.mutation +} + +// Save creates the Mall in the database. +func (mc *MallCreate) Save(ctx context.Context) (*Mall, error) { + mc.defaults() + return withHooks(ctx, mc.sqlSave, mc.mutation, mc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (mc *MallCreate) SaveX(ctx context.Context) *Mall { + v, err := mc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mc *MallCreate) Exec(ctx context.Context) error { + _, err := mc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mc *MallCreate) ExecX(ctx context.Context) { + if err := mc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (mc *MallCreate) defaults() { + if _, ok := mc.mutation.CreateTime(); !ok { + v := mall.DefaultCreateTime() + mc.mutation.SetCreateTime(v) + } + if _, ok := mc.mutation.UpdateTime(); !ok { + v := mall.DefaultUpdateTime() + mc.mutation.SetUpdateTime(v) + } + if _, ok := mc.mutation.Code(); !ok { + v := mall.DefaultCode() + mc.mutation.SetCode(v) + } + if _, ok := mc.mutation.StartTime(); !ok { + v := mall.DefaultStartTime() + mc.mutation.SetStartTime(v) + } + if _, ok := mc.mutation.Status(); !ok { + v := mall.DefaultStatus + mc.mutation.SetStatus(v) + } + if _, ok := mc.mutation.ID(); !ok { + v := mall.DefaultID() + mc.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (mc *MallCreate) check() error { + if _, ok := mc.mutation.CreateTime(); !ok { + return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "Mall.create_time"`)} + } + if _, ok := mc.mutation.UpdateTime(); !ok { + return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "Mall.update_time"`)} + } + if _, ok := mc.mutation.Code(); !ok { + return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "Mall.code"`)} + } + if v, ok := mc.mutation.Code(); ok { + if err := mall.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Mall.code": %w`, err)} + } + } + if _, ok := mc.mutation.MallCode(); !ok { + return &ValidationError{Name: "mall_code", err: errors.New(`ent: missing required field "Mall.mall_code"`)} + } + if v, ok := mc.mutation.MallCode(); ok { + if err := mall.MallCodeValidator(v); err != nil { + return &ValidationError{Name: "mall_code", err: fmt.Errorf(`ent: validator failed for field "Mall.mall_code": %w`, err)} + } + } + if _, ok := mc.mutation.MallName(); !ok { + return &ValidationError{Name: "mall_name", err: errors.New(`ent: missing required field "Mall.mall_name"`)} + } + if v, ok := mc.mutation.MallName(); ok { + if err := mall.MallNameValidator(v); err != nil { + return &ValidationError{Name: "mall_name", err: fmt.Errorf(`ent: validator failed for field "Mall.mall_name": %w`, err)} + } + } + if _, ok := mc.mutation.H3Index6(); !ok { + return &ValidationError{Name: "h3_index_6", err: errors.New(`ent: missing required field "Mall.h3_index_6"`)} + } + if v, ok := mc.mutation.H3Index6(); ok { + if err := mall.H3Index6Validator(v); err != nil { + return &ValidationError{Name: "h3_index_6", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_6": %w`, err)} + } + } + if _, ok := mc.mutation.H3Index7(); !ok { + return &ValidationError{Name: "h3_index_7", err: errors.New(`ent: missing required field "Mall.h3_index_7"`)} + } + if v, ok := mc.mutation.H3Index7(); ok { + if err := mall.H3Index7Validator(v); err != nil { + return &ValidationError{Name: "h3_index_7", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_7": %w`, err)} + } + } + if _, ok := mc.mutation.H3Index8(); !ok { + return &ValidationError{Name: "h3_index_8", err: errors.New(`ent: missing required field "Mall.h3_index_8"`)} + } + if v, ok := mc.mutation.H3Index8(); ok { + if err := mall.H3Index8Validator(v); err != nil { + return &ValidationError{Name: "h3_index_8", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_8": %w`, err)} + } + } + if _, ok := mc.mutation.Memo(); !ok { + return &ValidationError{Name: "memo", err: errors.New(`ent: missing required field "Mall.memo"`)} + } + if v, ok := mc.mutation.Memo(); ok { + if err := mall.MemoValidator(v); err != nil { + return &ValidationError{Name: "memo", err: fmt.Errorf(`ent: validator failed for field "Mall.memo": %w`, err)} + } + } + if _, ok := mc.mutation.StartTime(); !ok { + return &ValidationError{Name: "start_time", err: errors.New(`ent: missing required field "Mall.start_time"`)} + } + if _, ok := mc.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Mall.status"`)} + } + return nil +} + +func (mc *MallCreate) sqlSave(ctx context.Context) (*Mall, error) { + if err := mc.check(); err != nil { + return nil, err + } + _node, _spec := mc.createSpec() + if err := sqlgraph.CreateNode(ctx, mc.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 + } + } + mc.mutation.id = &_node.ID + mc.mutation.done = true + return _node, nil +} + +func (mc *MallCreate) createSpec() (*Mall, *sqlgraph.CreateSpec) { + var ( + _node = &Mall{config: mc.config} + _spec = sqlgraph.NewCreateSpec(mall.Table, sqlgraph.NewFieldSpec(mall.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = mc.conflict + if id, ok := mc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := mc.mutation.CreateTime(); ok { + _spec.SetField(mall.FieldCreateTime, field.TypeTime, value) + _node.CreateTime = value + } + if value, ok := mc.mutation.UpdateTime(); ok { + _spec.SetField(mall.FieldUpdateTime, field.TypeTime, value) + _node.UpdateTime = value + } + if value, ok := mc.mutation.Code(); ok { + _spec.SetField(mall.FieldCode, field.TypeString, value) + _node.Code = value + } + if value, ok := mc.mutation.MallCode(); ok { + _spec.SetField(mall.FieldMallCode, field.TypeString, value) + _node.MallCode = value + } + if value, ok := mc.mutation.MallName(); ok { + _spec.SetField(mall.FieldMallName, field.TypeString, value) + _node.MallName = value + } + if value, ok := mc.mutation.H3Index6(); ok { + _spec.SetField(mall.FieldH3Index6, field.TypeString, value) + _node.H3Index6 = value + } + if value, ok := mc.mutation.H3Index7(); ok { + _spec.SetField(mall.FieldH3Index7, field.TypeString, value) + _node.H3Index7 = value + } + if value, ok := mc.mutation.H3Index8(); ok { + _spec.SetField(mall.FieldH3Index8, field.TypeString, value) + _node.H3Index8 = value + } + if value, ok := mc.mutation.Memo(); ok { + _spec.SetField(mall.FieldMemo, field.TypeString, value) + _node.Memo = value + } + if value, ok := mc.mutation.StartTime(); ok { + _spec.SetField(mall.FieldStartTime, field.TypeTime, value) + _node.StartTime = value + } + if value, ok := mc.mutation.Status(); ok { + _spec.SetField(mall.FieldStatus, field.TypeInt, value) + _node.Status = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Mall.Create(). +// SetCreateTime(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.MallUpsert) { +// SetCreateTime(v+v). +// }). +// Exec(ctx) +func (mc *MallCreate) OnConflict(opts ...sql.ConflictOption) *MallUpsertOne { + mc.conflict = opts + return &MallUpsertOne{ + create: mc, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Mall.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (mc *MallCreate) OnConflictColumns(columns ...string) *MallUpsertOne { + mc.conflict = append(mc.conflict, sql.ConflictColumns(columns...)) + return &MallUpsertOne{ + create: mc, + } +} + +type ( + // MallUpsertOne is the builder for "upsert"-ing + // one Mall node. + MallUpsertOne struct { + create *MallCreate + } + + // MallUpsert is the "OnConflict" setter. + MallUpsert struct { + *sql.UpdateSet + } +) + +// SetUpdateTime sets the "update_time" field. +func (u *MallUpsert) SetUpdateTime(v time.Time) *MallUpsert { + u.Set(mall.FieldUpdateTime, v) + return u +} + +// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. +func (u *MallUpsert) UpdateUpdateTime() *MallUpsert { + u.SetExcluded(mall.FieldUpdateTime) + return u +} + +// SetMallName sets the "mall_name" field. +func (u *MallUpsert) SetMallName(v string) *MallUpsert { + u.Set(mall.FieldMallName, v) + return u +} + +// UpdateMallName sets the "mall_name" field to the value that was provided on create. +func (u *MallUpsert) UpdateMallName() *MallUpsert { + u.SetExcluded(mall.FieldMallName) + return u +} + +// SetH3Index6 sets the "h3_index_6" field. +func (u *MallUpsert) SetH3Index6(v string) *MallUpsert { + u.Set(mall.FieldH3Index6, v) + return u +} + +// UpdateH3Index6 sets the "h3_index_6" field to the value that was provided on create. +func (u *MallUpsert) UpdateH3Index6() *MallUpsert { + u.SetExcluded(mall.FieldH3Index6) + return u +} + +// SetH3Index7 sets the "h3_index_7" field. +func (u *MallUpsert) SetH3Index7(v string) *MallUpsert { + u.Set(mall.FieldH3Index7, v) + return u +} + +// UpdateH3Index7 sets the "h3_index_7" field to the value that was provided on create. +func (u *MallUpsert) UpdateH3Index7() *MallUpsert { + u.SetExcluded(mall.FieldH3Index7) + return u +} + +// SetH3Index8 sets the "h3_index_8" field. +func (u *MallUpsert) SetH3Index8(v string) *MallUpsert { + u.Set(mall.FieldH3Index8, v) + return u +} + +// UpdateH3Index8 sets the "h3_index_8" field to the value that was provided on create. +func (u *MallUpsert) UpdateH3Index8() *MallUpsert { + u.SetExcluded(mall.FieldH3Index8) + return u +} + +// SetMemo sets the "memo" field. +func (u *MallUpsert) SetMemo(v string) *MallUpsert { + u.Set(mall.FieldMemo, v) + return u +} + +// UpdateMemo sets the "memo" field to the value that was provided on create. +func (u *MallUpsert) UpdateMemo() *MallUpsert { + u.SetExcluded(mall.FieldMemo) + return u +} + +// SetStatus sets the "status" field. +func (u *MallUpsert) SetStatus(v int) *MallUpsert { + u.Set(mall.FieldStatus, v) + return u +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *MallUpsert) UpdateStatus() *MallUpsert { + u.SetExcluded(mall.FieldStatus) + return u +} + +// AddStatus adds v to the "status" field. +func (u *MallUpsert) AddStatus(v int) *MallUpsert { + u.Add(mall.FieldStatus, v) + 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.Mall.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(mall.FieldID) +// }), +// ). +// Exec(ctx) +func (u *MallUpsertOne) UpdateNewValues() *MallUpsertOne { + 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(mall.FieldID) + } + if _, exists := u.create.mutation.CreateTime(); exists { + s.SetIgnore(mall.FieldCreateTime) + } + if _, exists := u.create.mutation.Code(); exists { + s.SetIgnore(mall.FieldCode) + } + if _, exists := u.create.mutation.MallCode(); exists { + s.SetIgnore(mall.FieldMallCode) + } + if _, exists := u.create.mutation.StartTime(); exists { + s.SetIgnore(mall.FieldStartTime) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Mall.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *MallUpsertOne) Ignore() *MallUpsertOne { + 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 *MallUpsertOne) DoNothing() *MallUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the MallCreate.OnConflict +// documentation for more info. +func (u *MallUpsertOne) Update(set func(*MallUpsert)) *MallUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&MallUpsert{UpdateSet: update}) + })) + return u +} + +// SetUpdateTime sets the "update_time" field. +func (u *MallUpsertOne) SetUpdateTime(v time.Time) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.SetUpdateTime(v) + }) +} + +// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. +func (u *MallUpsertOne) UpdateUpdateTime() *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.UpdateUpdateTime() + }) +} + +// SetMallName sets the "mall_name" field. +func (u *MallUpsertOne) SetMallName(v string) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.SetMallName(v) + }) +} + +// UpdateMallName sets the "mall_name" field to the value that was provided on create. +func (u *MallUpsertOne) UpdateMallName() *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.UpdateMallName() + }) +} + +// SetH3Index6 sets the "h3_index_6" field. +func (u *MallUpsertOne) SetH3Index6(v string) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.SetH3Index6(v) + }) +} + +// UpdateH3Index6 sets the "h3_index_6" field to the value that was provided on create. +func (u *MallUpsertOne) UpdateH3Index6() *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.UpdateH3Index6() + }) +} + +// SetH3Index7 sets the "h3_index_7" field. +func (u *MallUpsertOne) SetH3Index7(v string) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.SetH3Index7(v) + }) +} + +// UpdateH3Index7 sets the "h3_index_7" field to the value that was provided on create. +func (u *MallUpsertOne) UpdateH3Index7() *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.UpdateH3Index7() + }) +} + +// SetH3Index8 sets the "h3_index_8" field. +func (u *MallUpsertOne) SetH3Index8(v string) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.SetH3Index8(v) + }) +} + +// UpdateH3Index8 sets the "h3_index_8" field to the value that was provided on create. +func (u *MallUpsertOne) UpdateH3Index8() *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.UpdateH3Index8() + }) +} + +// SetMemo sets the "memo" field. +func (u *MallUpsertOne) SetMemo(v string) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.SetMemo(v) + }) +} + +// UpdateMemo sets the "memo" field to the value that was provided on create. +func (u *MallUpsertOne) UpdateMemo() *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.UpdateMemo() + }) +} + +// SetStatus sets the "status" field. +func (u *MallUpsertOne) SetStatus(v int) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.SetStatus(v) + }) +} + +// AddStatus adds v to the "status" field. +func (u *MallUpsertOne) AddStatus(v int) *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.AddStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *MallUpsertOne) UpdateStatus() *MallUpsertOne { + return u.Update(func(s *MallUpsert) { + s.UpdateStatus() + }) +} + +// Exec executes the query. +func (u *MallUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for MallCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *MallUpsertOne) 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 *MallUpsertOne) 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: MallUpsertOne.ID is not supported by MySQL driver. Use MallUpsertOne.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 *MallUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// MallCreateBulk is the builder for creating many Mall entities in bulk. +type MallCreateBulk struct { + config + err error + builders []*MallCreate + conflict []sql.ConflictOption +} + +// Save creates the Mall entities in the database. +func (mcb *MallCreateBulk) Save(ctx context.Context) ([]*Mall, error) { + if mcb.err != nil { + return nil, mcb.err + } + specs := make([]*sqlgraph.CreateSpec, len(mcb.builders)) + nodes := make([]*Mall, len(mcb.builders)) + mutators := make([]Mutator, len(mcb.builders)) + for i := range mcb.builders { + func(i int, root context.Context) { + builder := mcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MallMutation) + 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, mcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = mcb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, mcb.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, mcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (mcb *MallCreateBulk) SaveX(ctx context.Context) []*Mall { + v, err := mcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mcb *MallCreateBulk) Exec(ctx context.Context) error { + _, err := mcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mcb *MallCreateBulk) ExecX(ctx context.Context) { + if err := mcb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Mall.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.MallUpsert) { +// SetCreateTime(v+v). +// }). +// Exec(ctx) +func (mcb *MallCreateBulk) OnConflict(opts ...sql.ConflictOption) *MallUpsertBulk { + mcb.conflict = opts + return &MallUpsertBulk{ + create: mcb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Mall.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (mcb *MallCreateBulk) OnConflictColumns(columns ...string) *MallUpsertBulk { + mcb.conflict = append(mcb.conflict, sql.ConflictColumns(columns...)) + return &MallUpsertBulk{ + create: mcb, + } +} + +// MallUpsertBulk is the builder for "upsert"-ing +// a bulk of Mall nodes. +type MallUpsertBulk struct { + create *MallCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.Mall.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(mall.FieldID) +// }), +// ). +// Exec(ctx) +func (u *MallUpsertBulk) UpdateNewValues() *MallUpsertBulk { + 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(mall.FieldID) + } + if _, exists := b.mutation.CreateTime(); exists { + s.SetIgnore(mall.FieldCreateTime) + } + if _, exists := b.mutation.Code(); exists { + s.SetIgnore(mall.FieldCode) + } + if _, exists := b.mutation.MallCode(); exists { + s.SetIgnore(mall.FieldMallCode) + } + if _, exists := b.mutation.StartTime(); exists { + s.SetIgnore(mall.FieldStartTime) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Mall.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *MallUpsertBulk) Ignore() *MallUpsertBulk { + 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 *MallUpsertBulk) DoNothing() *MallUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the MallCreateBulk.OnConflict +// documentation for more info. +func (u *MallUpsertBulk) Update(set func(*MallUpsert)) *MallUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&MallUpsert{UpdateSet: update}) + })) + return u +} + +// SetUpdateTime sets the "update_time" field. +func (u *MallUpsertBulk) SetUpdateTime(v time.Time) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.SetUpdateTime(v) + }) +} + +// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. +func (u *MallUpsertBulk) UpdateUpdateTime() *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.UpdateUpdateTime() + }) +} + +// SetMallName sets the "mall_name" field. +func (u *MallUpsertBulk) SetMallName(v string) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.SetMallName(v) + }) +} + +// UpdateMallName sets the "mall_name" field to the value that was provided on create. +func (u *MallUpsertBulk) UpdateMallName() *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.UpdateMallName() + }) +} + +// SetH3Index6 sets the "h3_index_6" field. +func (u *MallUpsertBulk) SetH3Index6(v string) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.SetH3Index6(v) + }) +} + +// UpdateH3Index6 sets the "h3_index_6" field to the value that was provided on create. +func (u *MallUpsertBulk) UpdateH3Index6() *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.UpdateH3Index6() + }) +} + +// SetH3Index7 sets the "h3_index_7" field. +func (u *MallUpsertBulk) SetH3Index7(v string) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.SetH3Index7(v) + }) +} + +// UpdateH3Index7 sets the "h3_index_7" field to the value that was provided on create. +func (u *MallUpsertBulk) UpdateH3Index7() *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.UpdateH3Index7() + }) +} + +// SetH3Index8 sets the "h3_index_8" field. +func (u *MallUpsertBulk) SetH3Index8(v string) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.SetH3Index8(v) + }) +} + +// UpdateH3Index8 sets the "h3_index_8" field to the value that was provided on create. +func (u *MallUpsertBulk) UpdateH3Index8() *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.UpdateH3Index8() + }) +} + +// SetMemo sets the "memo" field. +func (u *MallUpsertBulk) SetMemo(v string) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.SetMemo(v) + }) +} + +// UpdateMemo sets the "memo" field to the value that was provided on create. +func (u *MallUpsertBulk) UpdateMemo() *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.UpdateMemo() + }) +} + +// SetStatus sets the "status" field. +func (u *MallUpsertBulk) SetStatus(v int) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.SetStatus(v) + }) +} + +// AddStatus adds v to the "status" field. +func (u *MallUpsertBulk) AddStatus(v int) *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.AddStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *MallUpsertBulk) UpdateStatus() *MallUpsertBulk { + return u.Update(func(s *MallUpsert) { + s.UpdateStatus() + }) +} + +// Exec executes the query. +func (u *MallUpsertBulk) 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 MallCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for MallCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *MallUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/adv/orm/ent/mall_delete.go b/adv/orm/ent/mall_delete.go new file mode 100644 index 0000000..0aff516 --- /dev/null +++ b/adv/orm/ent/mall_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/twiglab/crm/adv/orm/ent/mall" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// MallDelete is the builder for deleting a Mall entity. +type MallDelete struct { + config + hooks []Hook + mutation *MallMutation +} + +// Where appends a list predicates to the MallDelete builder. +func (md *MallDelete) Where(ps ...predicate.Mall) *MallDelete { + md.mutation.Where(ps...) + return md +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (md *MallDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, md.sqlExec, md.mutation, md.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (md *MallDelete) ExecX(ctx context.Context) int { + n, err := md.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (md *MallDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(mall.Table, sqlgraph.NewFieldSpec(mall.FieldID, field.TypeUUID)) + if ps := md.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, md.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + md.mutation.done = true + return affected, err +} + +// MallDeleteOne is the builder for deleting a single Mall entity. +type MallDeleteOne struct { + md *MallDelete +} + +// Where appends a list predicates to the MallDelete builder. +func (mdo *MallDeleteOne) Where(ps ...predicate.Mall) *MallDeleteOne { + mdo.md.mutation.Where(ps...) + return mdo +} + +// Exec executes the deletion query. +func (mdo *MallDeleteOne) Exec(ctx context.Context) error { + n, err := mdo.md.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{mall.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (mdo *MallDeleteOne) ExecX(ctx context.Context) { + if err := mdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/adv/orm/ent/mall_query.go b/adv/orm/ent/mall_query.go new file mode 100644 index 0000000..b8eec5c --- /dev/null +++ b/adv/orm/ent/mall_query.go @@ -0,0 +1,528 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/mall" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// MallQuery is the builder for querying Mall entities. +type MallQuery struct { + config + ctx *QueryContext + order []mall.OrderOption + inters []Interceptor + predicates []predicate.Mall + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the MallQuery builder. +func (mq *MallQuery) Where(ps ...predicate.Mall) *MallQuery { + mq.predicates = append(mq.predicates, ps...) + return mq +} + +// Limit the number of records to be returned by this query. +func (mq *MallQuery) Limit(limit int) *MallQuery { + mq.ctx.Limit = &limit + return mq +} + +// Offset to start from. +func (mq *MallQuery) Offset(offset int) *MallQuery { + mq.ctx.Offset = &offset + return mq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (mq *MallQuery) Unique(unique bool) *MallQuery { + mq.ctx.Unique = &unique + return mq +} + +// Order specifies how the records should be ordered. +func (mq *MallQuery) Order(o ...mall.OrderOption) *MallQuery { + mq.order = append(mq.order, o...) + return mq +} + +// First returns the first Mall entity from the query. +// Returns a *NotFoundError when no Mall was found. +func (mq *MallQuery) First(ctx context.Context) (*Mall, error) { + nodes, err := mq.Limit(1).All(setContextOp(ctx, mq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{mall.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (mq *MallQuery) FirstX(ctx context.Context) *Mall { + node, err := mq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Mall ID from the query. +// Returns a *NotFoundError when no Mall ID was found. +func (mq *MallQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = mq.Limit(1).IDs(setContextOp(ctx, mq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{mall.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (mq *MallQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := mq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Mall entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Mall entity is found. +// Returns a *NotFoundError when no Mall entities are found. +func (mq *MallQuery) Only(ctx context.Context) (*Mall, error) { + nodes, err := mq.Limit(2).All(setContextOp(ctx, mq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{mall.Label} + default: + return nil, &NotSingularError{mall.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (mq *MallQuery) OnlyX(ctx context.Context) *Mall { + node, err := mq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Mall ID in the query. +// Returns a *NotSingularError when more than one Mall ID is found. +// Returns a *NotFoundError when no entities are found. +func (mq *MallQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = mq.Limit(2).IDs(setContextOp(ctx, mq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{mall.Label} + default: + err = &NotSingularError{mall.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (mq *MallQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := mq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Malls. +func (mq *MallQuery) All(ctx context.Context) ([]*Mall, error) { + ctx = setContextOp(ctx, mq.ctx, ent.OpQueryAll) + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Mall, *MallQuery]() + return withInterceptors[[]*Mall](ctx, mq, qr, mq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (mq *MallQuery) AllX(ctx context.Context) []*Mall { + nodes, err := mq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Mall IDs. +func (mq *MallQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if mq.ctx.Unique == nil && mq.path != nil { + mq.Unique(true) + } + ctx = setContextOp(ctx, mq.ctx, ent.OpQueryIDs) + if err = mq.Select(mall.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (mq *MallQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := mq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (mq *MallQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, mq.ctx, ent.OpQueryCount) + if err := mq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, mq, querierCount[*MallQuery](), mq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (mq *MallQuery) CountX(ctx context.Context) int { + count, err := mq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (mq *MallQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, mq.ctx, ent.OpQueryExist) + switch _, err := mq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (mq *MallQuery) ExistX(ctx context.Context) bool { + exist, err := mq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the MallQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (mq *MallQuery) Clone() *MallQuery { + if mq == nil { + return nil + } + return &MallQuery{ + config: mq.config, + ctx: mq.ctx.Clone(), + order: append([]mall.OrderOption{}, mq.order...), + inters: append([]Interceptor{}, mq.inters...), + predicates: append([]predicate.Mall{}, mq.predicates...), + // clone intermediate query. + sql: mq.sql.Clone(), + path: mq.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// CreateTime time.Time `json:"create_time,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Mall.Query(). +// GroupBy(mall.FieldCreateTime). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (mq *MallQuery) GroupBy(field string, fields ...string) *MallGroupBy { + mq.ctx.Fields = append([]string{field}, fields...) + grbuild := &MallGroupBy{build: mq} + grbuild.flds = &mq.ctx.Fields + grbuild.label = mall.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// CreateTime time.Time `json:"create_time,omitempty"` +// } +// +// client.Mall.Query(). +// Select(mall.FieldCreateTime). +// Scan(ctx, &v) +func (mq *MallQuery) Select(fields ...string) *MallSelect { + mq.ctx.Fields = append(mq.ctx.Fields, fields...) + sbuild := &MallSelect{MallQuery: mq} + sbuild.label = mall.Label + sbuild.flds, sbuild.scan = &mq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a MallSelect configured with the given aggregations. +func (mq *MallQuery) Aggregate(fns ...AggregateFunc) *MallSelect { + return mq.Select().Aggregate(fns...) +} + +func (mq *MallQuery) prepareQuery(ctx context.Context) error { + for _, inter := range mq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, mq); err != nil { + return err + } + } + } + for _, f := range mq.ctx.Fields { + if !mall.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if mq.path != nil { + prev, err := mq.path(ctx) + if err != nil { + return err + } + mq.sql = prev + } + return nil +} + +func (mq *MallQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Mall, error) { + var ( + nodes = []*Mall{} + _spec = mq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Mall).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Mall{config: mq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (mq *MallQuery) sqlCount(ctx context.Context) (int, error) { + _spec := mq.querySpec() + _spec.Node.Columns = mq.ctx.Fields + if len(mq.ctx.Fields) > 0 { + _spec.Unique = mq.ctx.Unique != nil && *mq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, mq.driver, _spec) +} + +func (mq *MallQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(mall.Table, mall.Columns, sqlgraph.NewFieldSpec(mall.FieldID, field.TypeUUID)) + _spec.From = mq.sql + if unique := mq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if mq.path != nil { + _spec.Unique = true + } + if fields := mq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, mall.FieldID) + for i := range fields { + if fields[i] != mall.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := mq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := mq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := mq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := mq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (mq *MallQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(mq.driver.Dialect()) + t1 := builder.Table(mall.Table) + columns := mq.ctx.Fields + if len(columns) == 0 { + columns = mall.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if mq.sql != nil { + selector = mq.sql + selector.Select(selector.Columns(columns...)...) + } + if mq.ctx.Unique != nil && *mq.ctx.Unique { + selector.Distinct() + } + for _, p := range mq.predicates { + p(selector) + } + for _, p := range mq.order { + p(selector) + } + if offset := mq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := mq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// MallGroupBy is the group-by builder for Mall entities. +type MallGroupBy struct { + selector + build *MallQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (mgb *MallGroupBy) Aggregate(fns ...AggregateFunc) *MallGroupBy { + mgb.fns = append(mgb.fns, fns...) + return mgb +} + +// Scan applies the selector query and scans the result into the given value. +func (mgb *MallGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, mgb.build.ctx, ent.OpQueryGroupBy) + if err := mgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*MallQuery, *MallGroupBy](ctx, mgb.build, mgb, mgb.build.inters, v) +} + +func (mgb *MallGroupBy) sqlScan(ctx context.Context, root *MallQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(mgb.fns)) + for _, fn := range mgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*mgb.flds)+len(mgb.fns)) + for _, f := range *mgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*mgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := mgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// MallSelect is the builder for selecting fields of Mall entities. +type MallSelect struct { + *MallQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ms *MallSelect) Aggregate(fns ...AggregateFunc) *MallSelect { + ms.fns = append(ms.fns, fns...) + return ms +} + +// Scan applies the selector query and scans the result into the given value. +func (ms *MallSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ms.ctx, ent.OpQuerySelect) + if err := ms.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*MallQuery, *MallSelect](ctx, ms.MallQuery, ms, ms.inters, v) +} + +func (ms *MallSelect) sqlScan(ctx context.Context, root *MallQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ms.fns)) + for _, fn := range ms.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ms.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := ms.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/adv/orm/ent/mall_update.go b/adv/orm/ent/mall_update.go new file mode 100644 index 0000000..f326bcd --- /dev/null +++ b/adv/orm/ent/mall_update.go @@ -0,0 +1,502 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/twiglab/crm/adv/orm/ent/mall" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +// MallUpdate is the builder for updating Mall entities. +type MallUpdate struct { + config + hooks []Hook + mutation *MallMutation +} + +// Where appends a list predicates to the MallUpdate builder. +func (mu *MallUpdate) Where(ps ...predicate.Mall) *MallUpdate { + mu.mutation.Where(ps...) + return mu +} + +// SetUpdateTime sets the "update_time" field. +func (mu *MallUpdate) SetUpdateTime(t time.Time) *MallUpdate { + mu.mutation.SetUpdateTime(t) + return mu +} + +// SetMallName sets the "mall_name" field. +func (mu *MallUpdate) SetMallName(s string) *MallUpdate { + mu.mutation.SetMallName(s) + return mu +} + +// SetNillableMallName sets the "mall_name" field if the given value is not nil. +func (mu *MallUpdate) SetNillableMallName(s *string) *MallUpdate { + if s != nil { + mu.SetMallName(*s) + } + return mu +} + +// SetH3Index6 sets the "h3_index_6" field. +func (mu *MallUpdate) SetH3Index6(s string) *MallUpdate { + mu.mutation.SetH3Index6(s) + return mu +} + +// SetNillableH3Index6 sets the "h3_index_6" field if the given value is not nil. +func (mu *MallUpdate) SetNillableH3Index6(s *string) *MallUpdate { + if s != nil { + mu.SetH3Index6(*s) + } + return mu +} + +// SetH3Index7 sets the "h3_index_7" field. +func (mu *MallUpdate) SetH3Index7(s string) *MallUpdate { + mu.mutation.SetH3Index7(s) + return mu +} + +// SetNillableH3Index7 sets the "h3_index_7" field if the given value is not nil. +func (mu *MallUpdate) SetNillableH3Index7(s *string) *MallUpdate { + if s != nil { + mu.SetH3Index7(*s) + } + return mu +} + +// SetH3Index8 sets the "h3_index_8" field. +func (mu *MallUpdate) SetH3Index8(s string) *MallUpdate { + mu.mutation.SetH3Index8(s) + return mu +} + +// SetNillableH3Index8 sets the "h3_index_8" field if the given value is not nil. +func (mu *MallUpdate) SetNillableH3Index8(s *string) *MallUpdate { + if s != nil { + mu.SetH3Index8(*s) + } + return mu +} + +// SetMemo sets the "memo" field. +func (mu *MallUpdate) SetMemo(s string) *MallUpdate { + mu.mutation.SetMemo(s) + return mu +} + +// SetNillableMemo sets the "memo" field if the given value is not nil. +func (mu *MallUpdate) SetNillableMemo(s *string) *MallUpdate { + if s != nil { + mu.SetMemo(*s) + } + return mu +} + +// SetStatus sets the "status" field. +func (mu *MallUpdate) SetStatus(i int) *MallUpdate { + mu.mutation.ResetStatus() + mu.mutation.SetStatus(i) + return mu +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (mu *MallUpdate) SetNillableStatus(i *int) *MallUpdate { + if i != nil { + mu.SetStatus(*i) + } + return mu +} + +// AddStatus adds i to the "status" field. +func (mu *MallUpdate) AddStatus(i int) *MallUpdate { + mu.mutation.AddStatus(i) + return mu +} + +// Mutation returns the MallMutation object of the builder. +func (mu *MallUpdate) Mutation() *MallMutation { + return mu.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (mu *MallUpdate) Save(ctx context.Context) (int, error) { + mu.defaults() + return withHooks(ctx, mu.sqlSave, mu.mutation, mu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (mu *MallUpdate) SaveX(ctx context.Context) int { + affected, err := mu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (mu *MallUpdate) Exec(ctx context.Context) error { + _, err := mu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mu *MallUpdate) ExecX(ctx context.Context) { + if err := mu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (mu *MallUpdate) defaults() { + if _, ok := mu.mutation.UpdateTime(); !ok { + v := mall.UpdateDefaultUpdateTime() + mu.mutation.SetUpdateTime(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (mu *MallUpdate) check() error { + if v, ok := mu.mutation.MallName(); ok { + if err := mall.MallNameValidator(v); err != nil { + return &ValidationError{Name: "mall_name", err: fmt.Errorf(`ent: validator failed for field "Mall.mall_name": %w`, err)} + } + } + if v, ok := mu.mutation.H3Index6(); ok { + if err := mall.H3Index6Validator(v); err != nil { + return &ValidationError{Name: "h3_index_6", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_6": %w`, err)} + } + } + if v, ok := mu.mutation.H3Index7(); ok { + if err := mall.H3Index7Validator(v); err != nil { + return &ValidationError{Name: "h3_index_7", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_7": %w`, err)} + } + } + if v, ok := mu.mutation.H3Index8(); ok { + if err := mall.H3Index8Validator(v); err != nil { + return &ValidationError{Name: "h3_index_8", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_8": %w`, err)} + } + } + if v, ok := mu.mutation.Memo(); ok { + if err := mall.MemoValidator(v); err != nil { + return &ValidationError{Name: "memo", err: fmt.Errorf(`ent: validator failed for field "Mall.memo": %w`, err)} + } + } + return nil +} + +func (mu *MallUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := mu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(mall.Table, mall.Columns, sqlgraph.NewFieldSpec(mall.FieldID, field.TypeUUID)) + if ps := mu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := mu.mutation.UpdateTime(); ok { + _spec.SetField(mall.FieldUpdateTime, field.TypeTime, value) + } + if value, ok := mu.mutation.MallName(); ok { + _spec.SetField(mall.FieldMallName, field.TypeString, value) + } + if value, ok := mu.mutation.H3Index6(); ok { + _spec.SetField(mall.FieldH3Index6, field.TypeString, value) + } + if value, ok := mu.mutation.H3Index7(); ok { + _spec.SetField(mall.FieldH3Index7, field.TypeString, value) + } + if value, ok := mu.mutation.H3Index8(); ok { + _spec.SetField(mall.FieldH3Index8, field.TypeString, value) + } + if value, ok := mu.mutation.Memo(); ok { + _spec.SetField(mall.FieldMemo, field.TypeString, value) + } + if value, ok := mu.mutation.Status(); ok { + _spec.SetField(mall.FieldStatus, field.TypeInt, value) + } + if value, ok := mu.mutation.AddedStatus(); ok { + _spec.AddField(mall.FieldStatus, field.TypeInt, value) + } + if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{mall.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + mu.mutation.done = true + return n, nil +} + +// MallUpdateOne is the builder for updating a single Mall entity. +type MallUpdateOne struct { + config + fields []string + hooks []Hook + mutation *MallMutation +} + +// SetUpdateTime sets the "update_time" field. +func (muo *MallUpdateOne) SetUpdateTime(t time.Time) *MallUpdateOne { + muo.mutation.SetUpdateTime(t) + return muo +} + +// SetMallName sets the "mall_name" field. +func (muo *MallUpdateOne) SetMallName(s string) *MallUpdateOne { + muo.mutation.SetMallName(s) + return muo +} + +// SetNillableMallName sets the "mall_name" field if the given value is not nil. +func (muo *MallUpdateOne) SetNillableMallName(s *string) *MallUpdateOne { + if s != nil { + muo.SetMallName(*s) + } + return muo +} + +// SetH3Index6 sets the "h3_index_6" field. +func (muo *MallUpdateOne) SetH3Index6(s string) *MallUpdateOne { + muo.mutation.SetH3Index6(s) + return muo +} + +// SetNillableH3Index6 sets the "h3_index_6" field if the given value is not nil. +func (muo *MallUpdateOne) SetNillableH3Index6(s *string) *MallUpdateOne { + if s != nil { + muo.SetH3Index6(*s) + } + return muo +} + +// SetH3Index7 sets the "h3_index_7" field. +func (muo *MallUpdateOne) SetH3Index7(s string) *MallUpdateOne { + muo.mutation.SetH3Index7(s) + return muo +} + +// SetNillableH3Index7 sets the "h3_index_7" field if the given value is not nil. +func (muo *MallUpdateOne) SetNillableH3Index7(s *string) *MallUpdateOne { + if s != nil { + muo.SetH3Index7(*s) + } + return muo +} + +// SetH3Index8 sets the "h3_index_8" field. +func (muo *MallUpdateOne) SetH3Index8(s string) *MallUpdateOne { + muo.mutation.SetH3Index8(s) + return muo +} + +// SetNillableH3Index8 sets the "h3_index_8" field if the given value is not nil. +func (muo *MallUpdateOne) SetNillableH3Index8(s *string) *MallUpdateOne { + if s != nil { + muo.SetH3Index8(*s) + } + return muo +} + +// SetMemo sets the "memo" field. +func (muo *MallUpdateOne) SetMemo(s string) *MallUpdateOne { + muo.mutation.SetMemo(s) + return muo +} + +// SetNillableMemo sets the "memo" field if the given value is not nil. +func (muo *MallUpdateOne) SetNillableMemo(s *string) *MallUpdateOne { + if s != nil { + muo.SetMemo(*s) + } + return muo +} + +// SetStatus sets the "status" field. +func (muo *MallUpdateOne) SetStatus(i int) *MallUpdateOne { + muo.mutation.ResetStatus() + muo.mutation.SetStatus(i) + return muo +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (muo *MallUpdateOne) SetNillableStatus(i *int) *MallUpdateOne { + if i != nil { + muo.SetStatus(*i) + } + return muo +} + +// AddStatus adds i to the "status" field. +func (muo *MallUpdateOne) AddStatus(i int) *MallUpdateOne { + muo.mutation.AddStatus(i) + return muo +} + +// Mutation returns the MallMutation object of the builder. +func (muo *MallUpdateOne) Mutation() *MallMutation { + return muo.mutation +} + +// Where appends a list predicates to the MallUpdate builder. +func (muo *MallUpdateOne) Where(ps ...predicate.Mall) *MallUpdateOne { + muo.mutation.Where(ps...) + return muo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (muo *MallUpdateOne) Select(field string, fields ...string) *MallUpdateOne { + muo.fields = append([]string{field}, fields...) + return muo +} + +// Save executes the query and returns the updated Mall entity. +func (muo *MallUpdateOne) Save(ctx context.Context) (*Mall, error) { + muo.defaults() + return withHooks(ctx, muo.sqlSave, muo.mutation, muo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (muo *MallUpdateOne) SaveX(ctx context.Context) *Mall { + node, err := muo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (muo *MallUpdateOne) Exec(ctx context.Context) error { + _, err := muo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (muo *MallUpdateOne) ExecX(ctx context.Context) { + if err := muo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (muo *MallUpdateOne) defaults() { + if _, ok := muo.mutation.UpdateTime(); !ok { + v := mall.UpdateDefaultUpdateTime() + muo.mutation.SetUpdateTime(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (muo *MallUpdateOne) check() error { + if v, ok := muo.mutation.MallName(); ok { + if err := mall.MallNameValidator(v); err != nil { + return &ValidationError{Name: "mall_name", err: fmt.Errorf(`ent: validator failed for field "Mall.mall_name": %w`, err)} + } + } + if v, ok := muo.mutation.H3Index6(); ok { + if err := mall.H3Index6Validator(v); err != nil { + return &ValidationError{Name: "h3_index_6", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_6": %w`, err)} + } + } + if v, ok := muo.mutation.H3Index7(); ok { + if err := mall.H3Index7Validator(v); err != nil { + return &ValidationError{Name: "h3_index_7", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_7": %w`, err)} + } + } + if v, ok := muo.mutation.H3Index8(); ok { + if err := mall.H3Index8Validator(v); err != nil { + return &ValidationError{Name: "h3_index_8", err: fmt.Errorf(`ent: validator failed for field "Mall.h3_index_8": %w`, err)} + } + } + if v, ok := muo.mutation.Memo(); ok { + if err := mall.MemoValidator(v); err != nil { + return &ValidationError{Name: "memo", err: fmt.Errorf(`ent: validator failed for field "Mall.memo": %w`, err)} + } + } + return nil +} + +func (muo *MallUpdateOne) sqlSave(ctx context.Context) (_node *Mall, err error) { + if err := muo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(mall.Table, mall.Columns, sqlgraph.NewFieldSpec(mall.FieldID, field.TypeUUID)) + id, ok := muo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Mall.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := muo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, mall.FieldID) + for _, f := range fields { + if !mall.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != mall.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := muo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := muo.mutation.UpdateTime(); ok { + _spec.SetField(mall.FieldUpdateTime, field.TypeTime, value) + } + if value, ok := muo.mutation.MallName(); ok { + _spec.SetField(mall.FieldMallName, field.TypeString, value) + } + if value, ok := muo.mutation.H3Index6(); ok { + _spec.SetField(mall.FieldH3Index6, field.TypeString, value) + } + if value, ok := muo.mutation.H3Index7(); ok { + _spec.SetField(mall.FieldH3Index7, field.TypeString, value) + } + if value, ok := muo.mutation.H3Index8(); ok { + _spec.SetField(mall.FieldH3Index8, field.TypeString, value) + } + if value, ok := muo.mutation.Memo(); ok { + _spec.SetField(mall.FieldMemo, field.TypeString, value) + } + if value, ok := muo.mutation.Status(); ok { + _spec.SetField(mall.FieldStatus, field.TypeInt, value) + } + if value, ok := muo.mutation.AddedStatus(); ok { + _spec.AddField(mall.FieldStatus, field.TypeInt, value) + } + _node = &Mall{config: muo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{mall.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + muo.mutation.done = true + return _node, nil +} diff --git a/adv/orm/ent/migrate/migrate.go b/adv/orm/ent/migrate/migrate.go new file mode 100644 index 0000000..1956a6b --- /dev/null +++ b/adv/orm/ent/migrate/migrate.go @@ -0,0 +1,64 @@ +// Code generated by ent, DO NOT EDIT. + +package migrate + +import ( + "context" + "fmt" + "io" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql/schema" +) + +var ( + // WithGlobalUniqueID sets the universal ids options to the migration. + // If this option is enabled, ent migration will allocate a 1<<32 range + // for the ids of each entity (table). + // Note that this option cannot be applied on tables that already exist. + WithGlobalUniqueID = schema.WithGlobalUniqueID + // WithDropColumn sets the drop column option to the migration. + // If this option is enabled, ent migration will drop old columns + // that were used for both fields and edges. This defaults to false. + WithDropColumn = schema.WithDropColumn + // WithDropIndex sets the drop index option to the migration. + // If this option is enabled, ent migration will drop old indexes + // that were defined in the schema. This defaults to false. + // Note that unique constraints are defined using `UNIQUE INDEX`, + // and therefore, it's recommended to enable this option to get more + // flexibility in the schema changes. + WithDropIndex = schema.WithDropIndex + // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. + WithForeignKeys = schema.WithForeignKeys +) + +// Schema is the API for creating, migrating and dropping a schema. +type Schema struct { + drv dialect.Driver +} + +// NewSchema creates a new schema client. +func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } + +// Create creates all schema resources. +func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { + return Create(ctx, s, Tables, opts...) +} + +// Create creates all table resources using the given schema driver. +func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error { + migrate, err := schema.NewMigrate(s.drv, opts...) + if err != nil { + return fmt.Errorf("ent/migrate: %w", err) + } + return migrate.Create(ctx, tables...) +} + +// WriteTo writes the schema changes to w instead of running them against the database. +// +// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { +// log.Fatal(err) +// } +func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { + return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...) +} diff --git a/adv/orm/ent/migrate/schema.go b/adv/orm/ent/migrate/schema.go new file mode 100644 index 0000000..90dcf29 --- /dev/null +++ b/adv/orm/ent/migrate/schema.go @@ -0,0 +1,112 @@ +// Code generated by ent, DO NOT EDIT. + +package migrate + +import ( + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/dialect/sql/schema" + "entgo.io/ent/schema/field" +) + +var ( + // TAdvColumns holds the columns for the "t_adv" table. + TAdvColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "create_time", Type: field.TypeTime}, + {Name: "update_time", Type: field.TypeTime}, + {Name: "code", Type: field.TypeString, Unique: true, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "mall_code", Type: field.TypeString, Unique: true, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "mall_name", Type: field.TypeString, Unique: true, Size: 64, SchemaType: map[string]string{"mysql": "char(64)", "postgres": "char(64)", "sqlite3": "char(64)"}}, + {Name: "h3_index_6", Type: field.TypeString, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "h3_index_7", Type: field.TypeString, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "h3_index_8", Type: field.TypeString, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "img_path", Type: field.TypeString, Unique: true, Size: 64, SchemaType: map[string]string{"mysql": "char(64)", "postgres": "char(64)", "sqlite3": "char(64)"}}, + {Name: "url", Type: field.TypeString, Unique: true, Size: 64, SchemaType: map[string]string{"mysql": "char(64)", "postgres": "char(64)", "sqlite3": "char(64)"}}, + {Name: "ruler", Type: field.TypeString, Size: 256, SchemaType: map[string]string{"mysql": "char(256)", "postgres": "char(256)", "sqlite3": "char(256)"}}, + {Name: "ord", Type: field.TypeInt, Default: 0}, + {Name: "memo", Type: field.TypeString, Size: 64, SchemaType: map[string]string{"mysql": "varchar(64)", "postgres": "varchar(64)", "sqlite3": "varchar(64)"}}, + {Name: "start_time", Type: field.TypeTime}, + {Name: "end_time", Type: field.TypeTime}, + {Name: "status", Type: field.TypeInt, Default: 1}, + } + // TAdvTable holds the schema information for the "t_adv" table. + TAdvTable = &schema.Table{ + Name: "t_adv", + Columns: TAdvColumns, + PrimaryKey: []*schema.Column{TAdvColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "adv_code", + Unique: false, + Columns: []*schema.Column{TAdvColumns[3]}, + }, + { + Name: "adv_status", + Unique: false, + Columns: []*schema.Column{TAdvColumns[16]}, + }, + { + Name: "adv_ord", + Unique: false, + Columns: []*schema.Column{TAdvColumns[12]}, + }, + { + Name: "adv_start_time", + Unique: false, + Columns: []*schema.Column{TAdvColumns[14]}, + }, + { + Name: "adv_end_time", + Unique: false, + Columns: []*schema.Column{TAdvColumns[15]}, + }, + }, + } + // TMallColumns holds the columns for the "t_mall" table. + TMallColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "create_time", Type: field.TypeTime}, + {Name: "update_time", Type: field.TypeTime}, + {Name: "code", Type: field.TypeString, Unique: true, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "mall_code", Type: field.TypeString, Unique: true, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "mall_name", Type: field.TypeString, Unique: true, Size: 64, SchemaType: map[string]string{"mysql": "char(64)", "postgres": "char(64)", "sqlite3": "char(64)"}}, + {Name: "h3_index_6", Type: field.TypeString, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "h3_index_7", Type: field.TypeString, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "h3_index_8", Type: field.TypeString, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, + {Name: "memo", Type: field.TypeString, Size: 64, SchemaType: map[string]string{"mysql": "varchar(64)", "postgres": "varchar(64)", "sqlite3": "varchar(64)"}}, + {Name: "start_time", Type: field.TypeTime}, + {Name: "status", Type: field.TypeInt, Default: 1}, + } + // TMallTable holds the schema information for the "t_mall" table. + TMallTable = &schema.Table{ + Name: "t_mall", + Columns: TMallColumns, + PrimaryKey: []*schema.Column{TMallColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "mall_code", + Unique: false, + Columns: []*schema.Column{TMallColumns[3]}, + }, + { + Name: "mall_status", + Unique: false, + Columns: []*schema.Column{TMallColumns[11]}, + }, + }, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + TAdvTable, + TMallTable, + } +) + +func init() { + TAdvTable.Annotation = &entsql.Annotation{ + Table: "t_adv", + } + TMallTable.Annotation = &entsql.Annotation{ + Table: "t_mall", + } +} diff --git a/adv/orm/ent/mutation.go b/adv/orm/ent/mutation.go new file mode 100644 index 0000000..f7558c6 --- /dev/null +++ b/adv/orm/ent/mutation.go @@ -0,0 +1,2150 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "sync" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/mall" + "github.com/twiglab/crm/adv/orm/ent/predicate" +) + +const ( + // Operation types. + OpCreate = ent.OpCreate + OpDelete = ent.OpDelete + OpDeleteOne = ent.OpDeleteOne + OpUpdate = ent.OpUpdate + OpUpdateOne = ent.OpUpdateOne + + // Node types. + TypeAdv = "Adv" + TypeMall = "Mall" +) + +// AdvMutation represents an operation that mutates the Adv nodes in the graph. +type AdvMutation struct { + config + op Op + typ string + id *uuid.UUID + create_time *time.Time + update_time *time.Time + code *string + mall_code *string + mall_name *string + h3_index_6 *string + h3_index_7 *string + h3_index_8 *string + img_path *string + url *string + ruler *string + ord *int + addord *int + memo *string + start_time *time.Time + end_time *time.Time + status *int + addstatus *int + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*Adv, error) + predicates []predicate.Adv +} + +var _ ent.Mutation = (*AdvMutation)(nil) + +// advOption allows management of the mutation configuration using functional options. +type advOption func(*AdvMutation) + +// newAdvMutation creates new mutation for the Adv entity. +func newAdvMutation(c config, op Op, opts ...advOption) *AdvMutation { + m := &AdvMutation{ + config: c, + op: op, + typ: TypeAdv, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withAdvID sets the ID field of the mutation. +func withAdvID(id uuid.UUID) advOption { + return func(m *AdvMutation) { + var ( + err error + once sync.Once + value *Adv + ) + m.oldValue = func(ctx context.Context) (*Adv, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Adv.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withAdv sets the old Adv of the mutation. +func withAdv(node *Adv) advOption { + return func(m *AdvMutation) { + m.oldValue = func(context.Context) (*Adv, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m AdvMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m AdvMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Adv entities. +func (m *AdvMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *AdvMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *AdvMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Adv.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreateTime sets the "create_time" field. +func (m *AdvMutation) SetCreateTime(t time.Time) { + m.create_time = &t +} + +// CreateTime returns the value of the "create_time" field in the mutation. +func (m *AdvMutation) CreateTime() (r time.Time, exists bool) { + v := m.create_time + if v == nil { + return + } + return *v, true +} + +// OldCreateTime returns the old "create_time" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldCreateTime(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreateTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreateTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreateTime: %w", err) + } + return oldValue.CreateTime, nil +} + +// ResetCreateTime resets all changes to the "create_time" field. +func (m *AdvMutation) ResetCreateTime() { + m.create_time = nil +} + +// SetUpdateTime sets the "update_time" field. +func (m *AdvMutation) SetUpdateTime(t time.Time) { + m.update_time = &t +} + +// UpdateTime returns the value of the "update_time" field in the mutation. +func (m *AdvMutation) UpdateTime() (r time.Time, exists bool) { + v := m.update_time + if v == nil { + return + } + return *v, true +} + +// OldUpdateTime returns the old "update_time" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldUpdateTime(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdateTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err) + } + return oldValue.UpdateTime, nil +} + +// ResetUpdateTime resets all changes to the "update_time" field. +func (m *AdvMutation) ResetUpdateTime() { + m.update_time = nil +} + +// SetCode sets the "code" field. +func (m *AdvMutation) SetCode(s string) { + m.code = &s +} + +// Code returns the value of the "code" field in the mutation. +func (m *AdvMutation) Code() (r string, exists bool) { + v := m.code + if v == nil { + return + } + return *v, true +} + +// OldCode returns the old "code" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldCode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCode: %w", err) + } + return oldValue.Code, nil +} + +// ResetCode resets all changes to the "code" field. +func (m *AdvMutation) ResetCode() { + m.code = nil +} + +// SetMallCode sets the "mall_code" field. +func (m *AdvMutation) SetMallCode(s string) { + m.mall_code = &s +} + +// MallCode returns the value of the "mall_code" field in the mutation. +func (m *AdvMutation) MallCode() (r string, exists bool) { + v := m.mall_code + if v == nil { + return + } + return *v, true +} + +// OldMallCode returns the old "mall_code" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldMallCode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMallCode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMallCode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMallCode: %w", err) + } + return oldValue.MallCode, nil +} + +// ResetMallCode resets all changes to the "mall_code" field. +func (m *AdvMutation) ResetMallCode() { + m.mall_code = nil +} + +// SetMallName sets the "mall_name" field. +func (m *AdvMutation) SetMallName(s string) { + m.mall_name = &s +} + +// MallName returns the value of the "mall_name" field in the mutation. +func (m *AdvMutation) MallName() (r string, exists bool) { + v := m.mall_name + if v == nil { + return + } + return *v, true +} + +// OldMallName returns the old "mall_name" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldMallName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMallName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMallName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMallName: %w", err) + } + return oldValue.MallName, nil +} + +// ResetMallName resets all changes to the "mall_name" field. +func (m *AdvMutation) ResetMallName() { + m.mall_name = nil +} + +// SetH3Index6 sets the "h3_index_6" field. +func (m *AdvMutation) SetH3Index6(s string) { + m.h3_index_6 = &s +} + +// H3Index6 returns the value of the "h3_index_6" field in the mutation. +func (m *AdvMutation) H3Index6() (r string, exists bool) { + v := m.h3_index_6 + if v == nil { + return + } + return *v, true +} + +// OldH3Index6 returns the old "h3_index_6" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldH3Index6(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldH3Index6 is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldH3Index6 requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldH3Index6: %w", err) + } + return oldValue.H3Index6, nil +} + +// ResetH3Index6 resets all changes to the "h3_index_6" field. +func (m *AdvMutation) ResetH3Index6() { + m.h3_index_6 = nil +} + +// SetH3Index7 sets the "h3_index_7" field. +func (m *AdvMutation) SetH3Index7(s string) { + m.h3_index_7 = &s +} + +// H3Index7 returns the value of the "h3_index_7" field in the mutation. +func (m *AdvMutation) H3Index7() (r string, exists bool) { + v := m.h3_index_7 + if v == nil { + return + } + return *v, true +} + +// OldH3Index7 returns the old "h3_index_7" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldH3Index7(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldH3Index7 is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldH3Index7 requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldH3Index7: %w", err) + } + return oldValue.H3Index7, nil +} + +// ResetH3Index7 resets all changes to the "h3_index_7" field. +func (m *AdvMutation) ResetH3Index7() { + m.h3_index_7 = nil +} + +// SetH3Index8 sets the "h3_index_8" field. +func (m *AdvMutation) SetH3Index8(s string) { + m.h3_index_8 = &s +} + +// H3Index8 returns the value of the "h3_index_8" field in the mutation. +func (m *AdvMutation) H3Index8() (r string, exists bool) { + v := m.h3_index_8 + if v == nil { + return + } + return *v, true +} + +// OldH3Index8 returns the old "h3_index_8" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldH3Index8(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldH3Index8 is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldH3Index8 requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldH3Index8: %w", err) + } + return oldValue.H3Index8, nil +} + +// ResetH3Index8 resets all changes to the "h3_index_8" field. +func (m *AdvMutation) ResetH3Index8() { + m.h3_index_8 = nil +} + +// SetImgPath sets the "img_path" field. +func (m *AdvMutation) SetImgPath(s string) { + m.img_path = &s +} + +// ImgPath returns the value of the "img_path" field in the mutation. +func (m *AdvMutation) ImgPath() (r string, exists bool) { + v := m.img_path + if v == nil { + return + } + return *v, true +} + +// OldImgPath returns the old "img_path" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldImgPath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldImgPath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldImgPath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldImgPath: %w", err) + } + return oldValue.ImgPath, nil +} + +// ResetImgPath resets all changes to the "img_path" field. +func (m *AdvMutation) ResetImgPath() { + m.img_path = nil +} + +// SetURL sets the "url" field. +func (m *AdvMutation) SetURL(s string) { + m.url = &s +} + +// URL returns the value of the "url" field in the mutation. +func (m *AdvMutation) URL() (r string, exists bool) { + v := m.url + if v == nil { + return + } + return *v, true +} + +// OldURL returns the old "url" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldURL: %w", err) + } + return oldValue.URL, nil +} + +// ResetURL resets all changes to the "url" field. +func (m *AdvMutation) ResetURL() { + m.url = nil +} + +// SetRuler sets the "ruler" field. +func (m *AdvMutation) SetRuler(s string) { + m.ruler = &s +} + +// Ruler returns the value of the "ruler" field in the mutation. +func (m *AdvMutation) Ruler() (r string, exists bool) { + v := m.ruler + if v == nil { + return + } + return *v, true +} + +// OldRuler returns the old "ruler" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldRuler(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRuler is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRuler requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRuler: %w", err) + } + return oldValue.Ruler, nil +} + +// ResetRuler resets all changes to the "ruler" field. +func (m *AdvMutation) ResetRuler() { + m.ruler = nil +} + +// SetOrd sets the "ord" field. +func (m *AdvMutation) SetOrd(i int) { + m.ord = &i + m.addord = nil +} + +// Ord returns the value of the "ord" field in the mutation. +func (m *AdvMutation) Ord() (r int, exists bool) { + v := m.ord + if v == nil { + return + } + return *v, true +} + +// OldOrd returns the old "ord" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldOrd(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldOrd is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldOrd requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldOrd: %w", err) + } + return oldValue.Ord, nil +} + +// AddOrd adds i to the "ord" field. +func (m *AdvMutation) AddOrd(i int) { + if m.addord != nil { + *m.addord += i + } else { + m.addord = &i + } +} + +// AddedOrd returns the value that was added to the "ord" field in this mutation. +func (m *AdvMutation) AddedOrd() (r int, exists bool) { + v := m.addord + if v == nil { + return + } + return *v, true +} + +// ResetOrd resets all changes to the "ord" field. +func (m *AdvMutation) ResetOrd() { + m.ord = nil + m.addord = nil +} + +// SetMemo sets the "memo" field. +func (m *AdvMutation) SetMemo(s string) { + m.memo = &s +} + +// Memo returns the value of the "memo" field in the mutation. +func (m *AdvMutation) Memo() (r string, exists bool) { + v := m.memo + if v == nil { + return + } + return *v, true +} + +// OldMemo returns the old "memo" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldMemo(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMemo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMemo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMemo: %w", err) + } + return oldValue.Memo, nil +} + +// ResetMemo resets all changes to the "memo" field. +func (m *AdvMutation) ResetMemo() { + m.memo = nil +} + +// SetStartTime sets the "start_time" field. +func (m *AdvMutation) SetStartTime(t time.Time) { + m.start_time = &t +} + +// StartTime returns the value of the "start_time" field in the mutation. +func (m *AdvMutation) StartTime() (r time.Time, exists bool) { + v := m.start_time + if v == nil { + return + } + return *v, true +} + +// OldStartTime returns the old "start_time" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldStartTime(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStartTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStartTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStartTime: %w", err) + } + return oldValue.StartTime, nil +} + +// ResetStartTime resets all changes to the "start_time" field. +func (m *AdvMutation) ResetStartTime() { + m.start_time = nil +} + +// SetEndTime sets the "end_time" field. +func (m *AdvMutation) SetEndTime(t time.Time) { + m.end_time = &t +} + +// EndTime returns the value of the "end_time" field in the mutation. +func (m *AdvMutation) EndTime() (r time.Time, exists bool) { + v := m.end_time + if v == nil { + return + } + return *v, true +} + +// OldEndTime returns the old "end_time" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldEndTime(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEndTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEndTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEndTime: %w", err) + } + return oldValue.EndTime, nil +} + +// ResetEndTime resets all changes to the "end_time" field. +func (m *AdvMutation) ResetEndTime() { + m.end_time = nil +} + +// SetStatus sets the "status" field. +func (m *AdvMutation) SetStatus(i int) { + m.status = &i + m.addstatus = nil +} + +// Status returns the value of the "status" field in the mutation. +func (m *AdvMutation) Status() (r int, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the Adv entity. +// If the Adv object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AdvMutation) OldStatus(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// AddStatus adds i to the "status" field. +func (m *AdvMutation) AddStatus(i int) { + if m.addstatus != nil { + *m.addstatus += i + } else { + m.addstatus = &i + } +} + +// AddedStatus returns the value that was added to the "status" field in this mutation. +func (m *AdvMutation) AddedStatus() (r int, exists bool) { + v := m.addstatus + if v == nil { + return + } + return *v, true +} + +// ResetStatus resets all changes to the "status" field. +func (m *AdvMutation) ResetStatus() { + m.status = nil + m.addstatus = nil +} + +// Where appends a list predicates to the AdvMutation builder. +func (m *AdvMutation) Where(ps ...predicate.Adv) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the AdvMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AdvMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Adv, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *AdvMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *AdvMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Adv). +func (m *AdvMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *AdvMutation) Fields() []string { + fields := make([]string, 0, 16) + if m.create_time != nil { + fields = append(fields, adv.FieldCreateTime) + } + if m.update_time != nil { + fields = append(fields, adv.FieldUpdateTime) + } + if m.code != nil { + fields = append(fields, adv.FieldCode) + } + if m.mall_code != nil { + fields = append(fields, adv.FieldMallCode) + } + if m.mall_name != nil { + fields = append(fields, adv.FieldMallName) + } + if m.h3_index_6 != nil { + fields = append(fields, adv.FieldH3Index6) + } + if m.h3_index_7 != nil { + fields = append(fields, adv.FieldH3Index7) + } + if m.h3_index_8 != nil { + fields = append(fields, adv.FieldH3Index8) + } + if m.img_path != nil { + fields = append(fields, adv.FieldImgPath) + } + if m.url != nil { + fields = append(fields, adv.FieldURL) + } + if m.ruler != nil { + fields = append(fields, adv.FieldRuler) + } + if m.ord != nil { + fields = append(fields, adv.FieldOrd) + } + if m.memo != nil { + fields = append(fields, adv.FieldMemo) + } + if m.start_time != nil { + fields = append(fields, adv.FieldStartTime) + } + if m.end_time != nil { + fields = append(fields, adv.FieldEndTime) + } + if m.status != nil { + fields = append(fields, adv.FieldStatus) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *AdvMutation) Field(name string) (ent.Value, bool) { + switch name { + case adv.FieldCreateTime: + return m.CreateTime() + case adv.FieldUpdateTime: + return m.UpdateTime() + case adv.FieldCode: + return m.Code() + case adv.FieldMallCode: + return m.MallCode() + case adv.FieldMallName: + return m.MallName() + case adv.FieldH3Index6: + return m.H3Index6() + case adv.FieldH3Index7: + return m.H3Index7() + case adv.FieldH3Index8: + return m.H3Index8() + case adv.FieldImgPath: + return m.ImgPath() + case adv.FieldURL: + return m.URL() + case adv.FieldRuler: + return m.Ruler() + case adv.FieldOrd: + return m.Ord() + case adv.FieldMemo: + return m.Memo() + case adv.FieldStartTime: + return m.StartTime() + case adv.FieldEndTime: + return m.EndTime() + case adv.FieldStatus: + return m.Status() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *AdvMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case adv.FieldCreateTime: + return m.OldCreateTime(ctx) + case adv.FieldUpdateTime: + return m.OldUpdateTime(ctx) + case adv.FieldCode: + return m.OldCode(ctx) + case adv.FieldMallCode: + return m.OldMallCode(ctx) + case adv.FieldMallName: + return m.OldMallName(ctx) + case adv.FieldH3Index6: + return m.OldH3Index6(ctx) + case adv.FieldH3Index7: + return m.OldH3Index7(ctx) + case adv.FieldH3Index8: + return m.OldH3Index8(ctx) + case adv.FieldImgPath: + return m.OldImgPath(ctx) + case adv.FieldURL: + return m.OldURL(ctx) + case adv.FieldRuler: + return m.OldRuler(ctx) + case adv.FieldOrd: + return m.OldOrd(ctx) + case adv.FieldMemo: + return m.OldMemo(ctx) + case adv.FieldStartTime: + return m.OldStartTime(ctx) + case adv.FieldEndTime: + return m.OldEndTime(ctx) + case adv.FieldStatus: + return m.OldStatus(ctx) + } + return nil, fmt.Errorf("unknown Adv field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AdvMutation) SetField(name string, value ent.Value) error { + switch name { + case adv.FieldCreateTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreateTime(v) + return nil + case adv.FieldUpdateTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdateTime(v) + return nil + case adv.FieldCode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCode(v) + return nil + case adv.FieldMallCode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMallCode(v) + return nil + case adv.FieldMallName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMallName(v) + return nil + case adv.FieldH3Index6: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetH3Index6(v) + return nil + case adv.FieldH3Index7: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetH3Index7(v) + return nil + case adv.FieldH3Index8: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetH3Index8(v) + return nil + case adv.FieldImgPath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetImgPath(v) + return nil + case adv.FieldURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetURL(v) + return nil + case adv.FieldRuler: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRuler(v) + return nil + case adv.FieldOrd: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOrd(v) + return nil + case adv.FieldMemo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMemo(v) + return nil + case adv.FieldStartTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStartTime(v) + return nil + case adv.FieldEndTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEndTime(v) + return nil + case adv.FieldStatus: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + } + return fmt.Errorf("unknown Adv field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *AdvMutation) AddedFields() []string { + var fields []string + if m.addord != nil { + fields = append(fields, adv.FieldOrd) + } + if m.addstatus != nil { + fields = append(fields, adv.FieldStatus) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *AdvMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case adv.FieldOrd: + return m.AddedOrd() + case adv.FieldStatus: + return m.AddedStatus() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AdvMutation) AddField(name string, value ent.Value) error { + switch name { + case adv.FieldOrd: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddOrd(v) + return nil + case adv.FieldStatus: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddStatus(v) + return nil + } + return fmt.Errorf("unknown Adv numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *AdvMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *AdvMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *AdvMutation) ClearField(name string) error { + return fmt.Errorf("unknown Adv nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *AdvMutation) ResetField(name string) error { + switch name { + case adv.FieldCreateTime: + m.ResetCreateTime() + return nil + case adv.FieldUpdateTime: + m.ResetUpdateTime() + return nil + case adv.FieldCode: + m.ResetCode() + return nil + case adv.FieldMallCode: + m.ResetMallCode() + return nil + case adv.FieldMallName: + m.ResetMallName() + return nil + case adv.FieldH3Index6: + m.ResetH3Index6() + return nil + case adv.FieldH3Index7: + m.ResetH3Index7() + return nil + case adv.FieldH3Index8: + m.ResetH3Index8() + return nil + case adv.FieldImgPath: + m.ResetImgPath() + return nil + case adv.FieldURL: + m.ResetURL() + return nil + case adv.FieldRuler: + m.ResetRuler() + return nil + case adv.FieldOrd: + m.ResetOrd() + return nil + case adv.FieldMemo: + m.ResetMemo() + return nil + case adv.FieldStartTime: + m.ResetStartTime() + return nil + case adv.FieldEndTime: + m.ResetEndTime() + return nil + case adv.FieldStatus: + m.ResetStatus() + return nil + } + return fmt.Errorf("unknown Adv field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *AdvMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *AdvMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *AdvMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *AdvMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *AdvMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *AdvMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *AdvMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown Adv unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *AdvMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown Adv edge %s", name) +} + +// MallMutation represents an operation that mutates the Mall nodes in the graph. +type MallMutation struct { + config + op Op + typ string + id *uuid.UUID + create_time *time.Time + update_time *time.Time + code *string + mall_code *string + mall_name *string + h3_index_6 *string + h3_index_7 *string + h3_index_8 *string + memo *string + start_time *time.Time + status *int + addstatus *int + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*Mall, error) + predicates []predicate.Mall +} + +var _ ent.Mutation = (*MallMutation)(nil) + +// mallOption allows management of the mutation configuration using functional options. +type mallOption func(*MallMutation) + +// newMallMutation creates new mutation for the Mall entity. +func newMallMutation(c config, op Op, opts ...mallOption) *MallMutation { + m := &MallMutation{ + config: c, + op: op, + typ: TypeMall, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withMallID sets the ID field of the mutation. +func withMallID(id uuid.UUID) mallOption { + return func(m *MallMutation) { + var ( + err error + once sync.Once + value *Mall + ) + m.oldValue = func(ctx context.Context) (*Mall, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Mall.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withMall sets the old Mall of the mutation. +func withMall(node *Mall) mallOption { + return func(m *MallMutation) { + m.oldValue = func(context.Context) (*Mall, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m MallMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m MallMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Mall entities. +func (m *MallMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *MallMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *MallMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Mall.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreateTime sets the "create_time" field. +func (m *MallMutation) SetCreateTime(t time.Time) { + m.create_time = &t +} + +// CreateTime returns the value of the "create_time" field in the mutation. +func (m *MallMutation) CreateTime() (r time.Time, exists bool) { + v := m.create_time + if v == nil { + return + } + return *v, true +} + +// OldCreateTime returns the old "create_time" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldCreateTime(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreateTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreateTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreateTime: %w", err) + } + return oldValue.CreateTime, nil +} + +// ResetCreateTime resets all changes to the "create_time" field. +func (m *MallMutation) ResetCreateTime() { + m.create_time = nil +} + +// SetUpdateTime sets the "update_time" field. +func (m *MallMutation) SetUpdateTime(t time.Time) { + m.update_time = &t +} + +// UpdateTime returns the value of the "update_time" field in the mutation. +func (m *MallMutation) UpdateTime() (r time.Time, exists bool) { + v := m.update_time + if v == nil { + return + } + return *v, true +} + +// OldUpdateTime returns the old "update_time" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldUpdateTime(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdateTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err) + } + return oldValue.UpdateTime, nil +} + +// ResetUpdateTime resets all changes to the "update_time" field. +func (m *MallMutation) ResetUpdateTime() { + m.update_time = nil +} + +// SetCode sets the "code" field. +func (m *MallMutation) SetCode(s string) { + m.code = &s +} + +// Code returns the value of the "code" field in the mutation. +func (m *MallMutation) Code() (r string, exists bool) { + v := m.code + if v == nil { + return + } + return *v, true +} + +// OldCode returns the old "code" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldCode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCode: %w", err) + } + return oldValue.Code, nil +} + +// ResetCode resets all changes to the "code" field. +func (m *MallMutation) ResetCode() { + m.code = nil +} + +// SetMallCode sets the "mall_code" field. +func (m *MallMutation) SetMallCode(s string) { + m.mall_code = &s +} + +// MallCode returns the value of the "mall_code" field in the mutation. +func (m *MallMutation) MallCode() (r string, exists bool) { + v := m.mall_code + if v == nil { + return + } + return *v, true +} + +// OldMallCode returns the old "mall_code" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldMallCode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMallCode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMallCode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMallCode: %w", err) + } + return oldValue.MallCode, nil +} + +// ResetMallCode resets all changes to the "mall_code" field. +func (m *MallMutation) ResetMallCode() { + m.mall_code = nil +} + +// SetMallName sets the "mall_name" field. +func (m *MallMutation) SetMallName(s string) { + m.mall_name = &s +} + +// MallName returns the value of the "mall_name" field in the mutation. +func (m *MallMutation) MallName() (r string, exists bool) { + v := m.mall_name + if v == nil { + return + } + return *v, true +} + +// OldMallName returns the old "mall_name" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldMallName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMallName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMallName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMallName: %w", err) + } + return oldValue.MallName, nil +} + +// ResetMallName resets all changes to the "mall_name" field. +func (m *MallMutation) ResetMallName() { + m.mall_name = nil +} + +// SetH3Index6 sets the "h3_index_6" field. +func (m *MallMutation) SetH3Index6(s string) { + m.h3_index_6 = &s +} + +// H3Index6 returns the value of the "h3_index_6" field in the mutation. +func (m *MallMutation) H3Index6() (r string, exists bool) { + v := m.h3_index_6 + if v == nil { + return + } + return *v, true +} + +// OldH3Index6 returns the old "h3_index_6" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldH3Index6(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldH3Index6 is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldH3Index6 requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldH3Index6: %w", err) + } + return oldValue.H3Index6, nil +} + +// ResetH3Index6 resets all changes to the "h3_index_6" field. +func (m *MallMutation) ResetH3Index6() { + m.h3_index_6 = nil +} + +// SetH3Index7 sets the "h3_index_7" field. +func (m *MallMutation) SetH3Index7(s string) { + m.h3_index_7 = &s +} + +// H3Index7 returns the value of the "h3_index_7" field in the mutation. +func (m *MallMutation) H3Index7() (r string, exists bool) { + v := m.h3_index_7 + if v == nil { + return + } + return *v, true +} + +// OldH3Index7 returns the old "h3_index_7" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldH3Index7(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldH3Index7 is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldH3Index7 requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldH3Index7: %w", err) + } + return oldValue.H3Index7, nil +} + +// ResetH3Index7 resets all changes to the "h3_index_7" field. +func (m *MallMutation) ResetH3Index7() { + m.h3_index_7 = nil +} + +// SetH3Index8 sets the "h3_index_8" field. +func (m *MallMutation) SetH3Index8(s string) { + m.h3_index_8 = &s +} + +// H3Index8 returns the value of the "h3_index_8" field in the mutation. +func (m *MallMutation) H3Index8() (r string, exists bool) { + v := m.h3_index_8 + if v == nil { + return + } + return *v, true +} + +// OldH3Index8 returns the old "h3_index_8" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldH3Index8(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldH3Index8 is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldH3Index8 requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldH3Index8: %w", err) + } + return oldValue.H3Index8, nil +} + +// ResetH3Index8 resets all changes to the "h3_index_8" field. +func (m *MallMutation) ResetH3Index8() { + m.h3_index_8 = nil +} + +// SetMemo sets the "memo" field. +func (m *MallMutation) SetMemo(s string) { + m.memo = &s +} + +// Memo returns the value of the "memo" field in the mutation. +func (m *MallMutation) Memo() (r string, exists bool) { + v := m.memo + if v == nil { + return + } + return *v, true +} + +// OldMemo returns the old "memo" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldMemo(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMemo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMemo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMemo: %w", err) + } + return oldValue.Memo, nil +} + +// ResetMemo resets all changes to the "memo" field. +func (m *MallMutation) ResetMemo() { + m.memo = nil +} + +// SetStartTime sets the "start_time" field. +func (m *MallMutation) SetStartTime(t time.Time) { + m.start_time = &t +} + +// StartTime returns the value of the "start_time" field in the mutation. +func (m *MallMutation) StartTime() (r time.Time, exists bool) { + v := m.start_time + if v == nil { + return + } + return *v, true +} + +// OldStartTime returns the old "start_time" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldStartTime(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStartTime is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStartTime requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStartTime: %w", err) + } + return oldValue.StartTime, nil +} + +// ResetStartTime resets all changes to the "start_time" field. +func (m *MallMutation) ResetStartTime() { + m.start_time = nil +} + +// SetStatus sets the "status" field. +func (m *MallMutation) SetStatus(i int) { + m.status = &i + m.addstatus = nil +} + +// Status returns the value of the "status" field in the mutation. +func (m *MallMutation) Status() (r int, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the Mall entity. +// If the Mall object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MallMutation) OldStatus(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// AddStatus adds i to the "status" field. +func (m *MallMutation) AddStatus(i int) { + if m.addstatus != nil { + *m.addstatus += i + } else { + m.addstatus = &i + } +} + +// AddedStatus returns the value that was added to the "status" field in this mutation. +func (m *MallMutation) AddedStatus() (r int, exists bool) { + v := m.addstatus + if v == nil { + return + } + return *v, true +} + +// ResetStatus resets all changes to the "status" field. +func (m *MallMutation) ResetStatus() { + m.status = nil + m.addstatus = nil +} + +// Where appends a list predicates to the MallMutation builder. +func (m *MallMutation) Where(ps ...predicate.Mall) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the MallMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *MallMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Mall, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *MallMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *MallMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Mall). +func (m *MallMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *MallMutation) Fields() []string { + fields := make([]string, 0, 11) + if m.create_time != nil { + fields = append(fields, mall.FieldCreateTime) + } + if m.update_time != nil { + fields = append(fields, mall.FieldUpdateTime) + } + if m.code != nil { + fields = append(fields, mall.FieldCode) + } + if m.mall_code != nil { + fields = append(fields, mall.FieldMallCode) + } + if m.mall_name != nil { + fields = append(fields, mall.FieldMallName) + } + if m.h3_index_6 != nil { + fields = append(fields, mall.FieldH3Index6) + } + if m.h3_index_7 != nil { + fields = append(fields, mall.FieldH3Index7) + } + if m.h3_index_8 != nil { + fields = append(fields, mall.FieldH3Index8) + } + if m.memo != nil { + fields = append(fields, mall.FieldMemo) + } + if m.start_time != nil { + fields = append(fields, mall.FieldStartTime) + } + if m.status != nil { + fields = append(fields, mall.FieldStatus) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *MallMutation) Field(name string) (ent.Value, bool) { + switch name { + case mall.FieldCreateTime: + return m.CreateTime() + case mall.FieldUpdateTime: + return m.UpdateTime() + case mall.FieldCode: + return m.Code() + case mall.FieldMallCode: + return m.MallCode() + case mall.FieldMallName: + return m.MallName() + case mall.FieldH3Index6: + return m.H3Index6() + case mall.FieldH3Index7: + return m.H3Index7() + case mall.FieldH3Index8: + return m.H3Index8() + case mall.FieldMemo: + return m.Memo() + case mall.FieldStartTime: + return m.StartTime() + case mall.FieldStatus: + return m.Status() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *MallMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case mall.FieldCreateTime: + return m.OldCreateTime(ctx) + case mall.FieldUpdateTime: + return m.OldUpdateTime(ctx) + case mall.FieldCode: + return m.OldCode(ctx) + case mall.FieldMallCode: + return m.OldMallCode(ctx) + case mall.FieldMallName: + return m.OldMallName(ctx) + case mall.FieldH3Index6: + return m.OldH3Index6(ctx) + case mall.FieldH3Index7: + return m.OldH3Index7(ctx) + case mall.FieldH3Index8: + return m.OldH3Index8(ctx) + case mall.FieldMemo: + return m.OldMemo(ctx) + case mall.FieldStartTime: + return m.OldStartTime(ctx) + case mall.FieldStatus: + return m.OldStatus(ctx) + } + return nil, fmt.Errorf("unknown Mall field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MallMutation) SetField(name string, value ent.Value) error { + switch name { + case mall.FieldCreateTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreateTime(v) + return nil + case mall.FieldUpdateTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdateTime(v) + return nil + case mall.FieldCode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCode(v) + return nil + case mall.FieldMallCode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMallCode(v) + return nil + case mall.FieldMallName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMallName(v) + return nil + case mall.FieldH3Index6: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetH3Index6(v) + return nil + case mall.FieldH3Index7: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetH3Index7(v) + return nil + case mall.FieldH3Index8: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetH3Index8(v) + return nil + case mall.FieldMemo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMemo(v) + return nil + case mall.FieldStartTime: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStartTime(v) + return nil + case mall.FieldStatus: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + } + return fmt.Errorf("unknown Mall field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *MallMutation) AddedFields() []string { + var fields []string + if m.addstatus != nil { + fields = append(fields, mall.FieldStatus) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *MallMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case mall.FieldStatus: + return m.AddedStatus() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MallMutation) AddField(name string, value ent.Value) error { + switch name { + case mall.FieldStatus: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddStatus(v) + return nil + } + return fmt.Errorf("unknown Mall numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *MallMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *MallMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *MallMutation) ClearField(name string) error { + return fmt.Errorf("unknown Mall nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *MallMutation) ResetField(name string) error { + switch name { + case mall.FieldCreateTime: + m.ResetCreateTime() + return nil + case mall.FieldUpdateTime: + m.ResetUpdateTime() + return nil + case mall.FieldCode: + m.ResetCode() + return nil + case mall.FieldMallCode: + m.ResetMallCode() + return nil + case mall.FieldMallName: + m.ResetMallName() + return nil + case mall.FieldH3Index6: + m.ResetH3Index6() + return nil + case mall.FieldH3Index7: + m.ResetH3Index7() + return nil + case mall.FieldH3Index8: + m.ResetH3Index8() + return nil + case mall.FieldMemo: + m.ResetMemo() + return nil + case mall.FieldStartTime: + m.ResetStartTime() + return nil + case mall.FieldStatus: + m.ResetStatus() + return nil + } + return fmt.Errorf("unknown Mall field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *MallMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *MallMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *MallMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *MallMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *MallMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *MallMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *MallMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown Mall unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *MallMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown Mall edge %s", name) +} diff --git a/adv/orm/ent/predicate/predicate.go b/adv/orm/ent/predicate/predicate.go new file mode 100644 index 0000000..5d014d4 --- /dev/null +++ b/adv/orm/ent/predicate/predicate.go @@ -0,0 +1,13 @@ +// Code generated by ent, DO NOT EDIT. + +package predicate + +import ( + "entgo.io/ent/dialect/sql" +) + +// Adv is the predicate function for adv builders. +type Adv func(*sql.Selector) + +// Mall is the predicate function for mall builders. +type Mall func(*sql.Selector) diff --git a/adv/orm/ent/privacy/privacy.go b/adv/orm/ent/privacy/privacy.go new file mode 100644 index 0000000..731e05e --- /dev/null +++ b/adv/orm/ent/privacy/privacy.go @@ -0,0 +1,215 @@ +// Code generated by ent, DO NOT EDIT. + +package privacy + +import ( + "context" + + "github.com/twiglab/crm/adv/orm/ent" + + "entgo.io/ent/entql" + "entgo.io/ent/privacy" +) + +var ( + // Allow may be returned by rules to indicate that the policy + // evaluation should terminate with allow decision. + Allow = privacy.Allow + + // Deny may be returned by rules to indicate that the policy + // evaluation should terminate with deny decision. + Deny = privacy.Deny + + // Skip may be returned by rules to indicate that the policy + // evaluation should continue to the next rule. + Skip = privacy.Skip +) + +// Allowf returns a formatted wrapped Allow decision. +func Allowf(format string, a ...any) error { + return privacy.Allowf(format, a...) +} + +// Denyf returns a formatted wrapped Deny decision. +func Denyf(format string, a ...any) error { + return privacy.Denyf(format, a...) +} + +// Skipf returns a formatted wrapped Skip decision. +func Skipf(format string, a ...any) error { + return privacy.Skipf(format, a...) +} + +// DecisionContext creates a new context from the given parent context with +// a policy decision attach to it. +func DecisionContext(parent context.Context, decision error) context.Context { + return privacy.DecisionContext(parent, decision) +} + +// DecisionFromContext retrieves the policy decision from the context. +func DecisionFromContext(ctx context.Context) (error, bool) { + return privacy.DecisionFromContext(ctx) +} + +type ( + // Policy groups query and mutation policies. + Policy = privacy.Policy + + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule = privacy.QueryRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy = privacy.QueryPolicy + + // MutationRule defines the interface which decides whether a + // mutation is allowed and optionally modifies it. + MutationRule = privacy.MutationRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy = privacy.MutationPolicy + // MutationRuleFunc type is an adapter which allows the use of + // ordinary functions as mutation rules. + MutationRuleFunc = privacy.MutationRuleFunc + + // QueryMutationRule is an interface which groups query and mutation rules. + QueryMutationRule = privacy.QueryMutationRule +) + +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error + +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) +} + +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { + return privacy.AlwaysAllowRule() +} + +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { + return privacy.AlwaysDenyRule() +} + +// ContextQueryMutationRule creates a query/mutation rule from a context eval func. +func ContextQueryMutationRule(eval func(context.Context) error) QueryMutationRule { + return privacy.ContextQueryMutationRule(eval) +} + +// OnMutationOperation evaluates the given rule only on a given mutation operation. +func OnMutationOperation(rule MutationRule, op ent.Op) MutationRule { + return privacy.OnMutationOperation(rule, op) +} + +// DenyMutationOperationRule returns a rule denying specified mutation operation. +func DenyMutationOperationRule(op ent.Op) MutationRule { + rule := MutationRuleFunc(func(_ context.Context, m ent.Mutation) error { + return Denyf("ent/privacy: operation %s is not allowed", m.Op()) + }) + return OnMutationOperation(rule, op) +} + +// The AdvQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type AdvQueryRuleFunc func(context.Context, *ent.AdvQuery) error + +// EvalQuery return f(ctx, q). +func (f AdvQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.AdvQuery); ok { + return f(ctx, q) + } + return Denyf("ent/privacy: unexpected query type %T, expect *ent.AdvQuery", q) +} + +// The AdvMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type AdvMutationRuleFunc func(context.Context, *ent.AdvMutation) error + +// EvalMutation calls f(ctx, m). +func (f AdvMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { + if m, ok := m.(*ent.AdvMutation); ok { + return f(ctx, m) + } + return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.AdvMutation", m) +} + +// The MallQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type MallQueryRuleFunc func(context.Context, *ent.MallQuery) error + +// EvalQuery return f(ctx, q). +func (f MallQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.MallQuery); ok { + return f(ctx, q) + } + return Denyf("ent/privacy: unexpected query type %T, expect *ent.MallQuery", q) +} + +// The MallMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type MallMutationRuleFunc func(context.Context, *ent.MallMutation) error + +// EvalMutation calls f(ctx, m). +func (f MallMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { + if m, ok := m.(*ent.MallMutation); ok { + return f(ctx, m) + } + return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.MallMutation", m) +} + +type ( + // Filter is the interface that wraps the Where function + // for filtering nodes in queries and mutations. + Filter interface { + // Where applies a filter on the executed query/mutation. + Where(entql.P) + } + + // The FilterFunc type is an adapter that allows the use of ordinary + // functions as filters for query and mutation types. + FilterFunc func(context.Context, Filter) error +) + +// EvalQuery calls f(ctx, q) if the query implements the Filter interface, otherwise it is denied. +func (f FilterFunc) EvalQuery(ctx context.Context, q ent.Query) error { + fr, err := queryFilter(q) + if err != nil { + return err + } + return f(ctx, fr) +} + +// EvalMutation calls f(ctx, q) if the mutation implements the Filter interface, otherwise it is denied. +func (f FilterFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { + fr, err := mutationFilter(m) + if err != nil { + return err + } + return f(ctx, fr) +} + +var _ QueryMutationRule = FilterFunc(nil) + +func queryFilter(q ent.Query) (Filter, error) { + switch q := q.(type) { + case *ent.AdvQuery: + return q.Filter(), nil + case *ent.MallQuery: + return q.Filter(), nil + default: + return nil, Denyf("ent/privacy: unexpected query type %T for query filter", q) + } +} + +func mutationFilter(m ent.Mutation) (Filter, error) { + switch m := m.(type) { + case *ent.AdvMutation: + return m.Filter(), nil + case *ent.MallMutation: + return m.Filter(), nil + default: + return nil, Denyf("ent/privacy: unexpected mutation type %T for mutation filter", m) + } +} diff --git a/adv/orm/ent/runtime.go b/adv/orm/ent/runtime.go new file mode 100644 index 0000000..939ca3e --- /dev/null +++ b/adv/orm/ent/runtime.go @@ -0,0 +1,264 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "time" + + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/ent/adv" + "github.com/twiglab/crm/adv/orm/ent/mall" + "github.com/twiglab/crm/adv/orm/schema" +) + +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it +// to their package variables. +func init() { + advMixin := schema.Adv{}.Mixin() + advMixinFields0 := advMixin[0].Fields() + _ = advMixinFields0 + advFields := schema.Adv{}.Fields() + _ = advFields + // advDescCreateTime is the schema descriptor for create_time field. + advDescCreateTime := advMixinFields0[0].Descriptor() + // adv.DefaultCreateTime holds the default value on creation for the create_time field. + adv.DefaultCreateTime = advDescCreateTime.Default.(func() time.Time) + // advDescUpdateTime is the schema descriptor for update_time field. + advDescUpdateTime := advMixinFields0[1].Descriptor() + // adv.DefaultUpdateTime holds the default value on creation for the update_time field. + adv.DefaultUpdateTime = advDescUpdateTime.Default.(func() time.Time) + // adv.UpdateDefaultUpdateTime holds the default value on update for the update_time field. + adv.UpdateDefaultUpdateTime = advDescUpdateTime.UpdateDefault.(func() time.Time) + // advDescCode is the schema descriptor for code field. + advDescCode := advFields[1].Descriptor() + // adv.DefaultCode holds the default value on creation for the code field. + adv.DefaultCode = advDescCode.Default.(func() string) + // adv.CodeValidator is a validator for the "code" field. It is called by the builders before save. + adv.CodeValidator = func() func(string) error { + validators := advDescCode.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(code string) error { + for _, fn := range fns { + if err := fn(code); err != nil { + return err + } + } + return nil + } + }() + // advDescMallCode is the schema descriptor for mall_code field. + advDescMallCode := advFields[2].Descriptor() + // adv.MallCodeValidator is a validator for the "mall_code" field. It is called by the builders before save. + adv.MallCodeValidator = func() func(string) error { + validators := advDescMallCode.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(mall_code string) error { + for _, fn := range fns { + if err := fn(mall_code); err != nil { + return err + } + } + return nil + } + }() + // advDescMallName is the schema descriptor for mall_name field. + advDescMallName := advFields[3].Descriptor() + // adv.MallNameValidator is a validator for the "mall_name" field. It is called by the builders before save. + adv.MallNameValidator = func() func(string) error { + validators := advDescMallName.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(mall_name string) error { + for _, fn := range fns { + if err := fn(mall_name); err != nil { + return err + } + } + return nil + } + }() + // advDescH3Index6 is the schema descriptor for h3_index_6 field. + advDescH3Index6 := advFields[4].Descriptor() + // adv.H3Index6Validator is a validator for the "h3_index_6" field. It is called by the builders before save. + adv.H3Index6Validator = advDescH3Index6.Validators[0].(func(string) error) + // advDescH3Index7 is the schema descriptor for h3_index_7 field. + advDescH3Index7 := advFields[5].Descriptor() + // adv.H3Index7Validator is a validator for the "h3_index_7" field. It is called by the builders before save. + adv.H3Index7Validator = advDescH3Index7.Validators[0].(func(string) error) + // advDescH3Index8 is the schema descriptor for h3_index_8 field. + advDescH3Index8 := advFields[6].Descriptor() + // adv.H3Index8Validator is a validator for the "h3_index_8" field. It is called by the builders before save. + adv.H3Index8Validator = advDescH3Index8.Validators[0].(func(string) error) + // advDescImgPath is the schema descriptor for img_path field. + advDescImgPath := advFields[7].Descriptor() + // adv.ImgPathValidator is a validator for the "img_path" field. It is called by the builders before save. + adv.ImgPathValidator = func() func(string) error { + validators := advDescImgPath.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(img_path string) error { + for _, fn := range fns { + if err := fn(img_path); err != nil { + return err + } + } + return nil + } + }() + // advDescURL is the schema descriptor for url field. + advDescURL := advFields[8].Descriptor() + // adv.URLValidator is a validator for the "url" field. It is called by the builders before save. + adv.URLValidator = func() func(string) error { + validators := advDescURL.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(url string) error { + for _, fn := range fns { + if err := fn(url); err != nil { + return err + } + } + return nil + } + }() + // advDescRuler is the schema descriptor for ruler field. + advDescRuler := advFields[9].Descriptor() + // adv.RulerValidator is a validator for the "ruler" field. It is called by the builders before save. + adv.RulerValidator = advDescRuler.Validators[0].(func(string) error) + // advDescOrd is the schema descriptor for ord field. + advDescOrd := advFields[10].Descriptor() + // adv.DefaultOrd holds the default value on creation for the ord field. + adv.DefaultOrd = advDescOrd.Default.(int) + // advDescMemo is the schema descriptor for memo field. + advDescMemo := advFields[11].Descriptor() + // adv.MemoValidator is a validator for the "memo" field. It is called by the builders before save. + adv.MemoValidator = advDescMemo.Validators[0].(func(string) error) + // advDescStartTime is the schema descriptor for start_time field. + advDescStartTime := advFields[12].Descriptor() + // adv.DefaultStartTime holds the default value on creation for the start_time field. + adv.DefaultStartTime = advDescStartTime.Default.(func() time.Time) + // advDescEndTime is the schema descriptor for end_time field. + advDescEndTime := advFields[13].Descriptor() + // adv.DefaultEndTime holds the default value on creation for the end_time field. + adv.DefaultEndTime = advDescEndTime.Default.(func() time.Time) + // advDescStatus is the schema descriptor for status field. + advDescStatus := advFields[14].Descriptor() + // adv.DefaultStatus holds the default value on creation for the status field. + adv.DefaultStatus = advDescStatus.Default.(int) + // advDescID is the schema descriptor for id field. + advDescID := advFields[0].Descriptor() + // adv.DefaultID holds the default value on creation for the id field. + adv.DefaultID = advDescID.Default.(func() uuid.UUID) + mallMixin := schema.Mall{}.Mixin() + mallMixinFields0 := mallMixin[0].Fields() + _ = mallMixinFields0 + mallFields := schema.Mall{}.Fields() + _ = mallFields + // mallDescCreateTime is the schema descriptor for create_time field. + mallDescCreateTime := mallMixinFields0[0].Descriptor() + // mall.DefaultCreateTime holds the default value on creation for the create_time field. + mall.DefaultCreateTime = mallDescCreateTime.Default.(func() time.Time) + // mallDescUpdateTime is the schema descriptor for update_time field. + mallDescUpdateTime := mallMixinFields0[1].Descriptor() + // mall.DefaultUpdateTime holds the default value on creation for the update_time field. + mall.DefaultUpdateTime = mallDescUpdateTime.Default.(func() time.Time) + // mall.UpdateDefaultUpdateTime holds the default value on update for the update_time field. + mall.UpdateDefaultUpdateTime = mallDescUpdateTime.UpdateDefault.(func() time.Time) + // mallDescCode is the schema descriptor for code field. + mallDescCode := mallFields[1].Descriptor() + // mall.DefaultCode holds the default value on creation for the code field. + mall.DefaultCode = mallDescCode.Default.(func() string) + // mall.CodeValidator is a validator for the "code" field. It is called by the builders before save. + mall.CodeValidator = func() func(string) error { + validators := mallDescCode.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(code string) error { + for _, fn := range fns { + if err := fn(code); err != nil { + return err + } + } + return nil + } + }() + // mallDescMallCode is the schema descriptor for mall_code field. + mallDescMallCode := mallFields[2].Descriptor() + // mall.MallCodeValidator is a validator for the "mall_code" field. It is called by the builders before save. + mall.MallCodeValidator = func() func(string) error { + validators := mallDescMallCode.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(mall_code string) error { + for _, fn := range fns { + if err := fn(mall_code); err != nil { + return err + } + } + return nil + } + }() + // mallDescMallName is the schema descriptor for mall_name field. + mallDescMallName := mallFields[3].Descriptor() + // mall.MallNameValidator is a validator for the "mall_name" field. It is called by the builders before save. + mall.MallNameValidator = func() func(string) error { + validators := mallDescMallName.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(mall_name string) error { + for _, fn := range fns { + if err := fn(mall_name); err != nil { + return err + } + } + return nil + } + }() + // mallDescH3Index6 is the schema descriptor for h3_index_6 field. + mallDescH3Index6 := mallFields[4].Descriptor() + // mall.H3Index6Validator is a validator for the "h3_index_6" field. It is called by the builders before save. + mall.H3Index6Validator = mallDescH3Index6.Validators[0].(func(string) error) + // mallDescH3Index7 is the schema descriptor for h3_index_7 field. + mallDescH3Index7 := mallFields[5].Descriptor() + // mall.H3Index7Validator is a validator for the "h3_index_7" field. It is called by the builders before save. + mall.H3Index7Validator = mallDescH3Index7.Validators[0].(func(string) error) + // mallDescH3Index8 is the schema descriptor for h3_index_8 field. + mallDescH3Index8 := mallFields[6].Descriptor() + // mall.H3Index8Validator is a validator for the "h3_index_8" field. It is called by the builders before save. + mall.H3Index8Validator = mallDescH3Index8.Validators[0].(func(string) error) + // mallDescMemo is the schema descriptor for memo field. + mallDescMemo := mallFields[7].Descriptor() + // mall.MemoValidator is a validator for the "memo" field. It is called by the builders before save. + mall.MemoValidator = mallDescMemo.Validators[0].(func(string) error) + // mallDescStartTime is the schema descriptor for start_time field. + mallDescStartTime := mallFields[8].Descriptor() + // mall.DefaultStartTime holds the default value on creation for the start_time field. + mall.DefaultStartTime = mallDescStartTime.Default.(func() time.Time) + // mallDescStatus is the schema descriptor for status field. + mallDescStatus := mallFields[9].Descriptor() + // mall.DefaultStatus holds the default value on creation for the status field. + mall.DefaultStatus = mallDescStatus.Default.(int) + // mallDescID is the schema descriptor for id field. + mallDescID := mallFields[0].Descriptor() + // mall.DefaultID holds the default value on creation for the id field. + mall.DefaultID = mallDescID.Default.(func() uuid.UUID) +} diff --git a/adv/orm/ent/runtime/runtime.go b/adv/orm/ent/runtime/runtime.go new file mode 100644 index 0000000..d1def08 --- /dev/null +++ b/adv/orm/ent/runtime/runtime.go @@ -0,0 +1,10 @@ +// Code generated by ent, DO NOT EDIT. + +package runtime + +// The schema-stitching logic is generated in github.com/twiglab/crm/adv/orm/ent/runtime.go + +const ( + Version = "v0.14.1" // Version of ent codegen. + Sum = "h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=" // Sum of ent codegen. +) diff --git a/adv/orm/ent/tx.go b/adv/orm/ent/tx.go new file mode 100644 index 0000000..476ba8e --- /dev/null +++ b/adv/orm/ent/tx.go @@ -0,0 +1,239 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + stdsql "database/sql" + "fmt" + "sync" + + "entgo.io/ent/dialect" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // Adv is the client for interacting with the Adv builders. + Adv *AdvClient + // Mall is the client for interacting with the Mall builders. + Mall *MallClient + + // lazily loaded. + client *Client + clientOnce sync.Once + // ctx lives for the life of the transaction. It is + // the same context used by the underlying connection. + ctx context.Context +} + +type ( + // Committer is the interface that wraps the Commit method. + Committer interface { + Commit(context.Context, *Tx) error + } + + // The CommitFunc type is an adapter to allow the use of ordinary + // function as a Committer. If f is a function with the appropriate + // signature, CommitFunc(f) is a Committer that calls f. + CommitFunc func(context.Context, *Tx) error + + // CommitHook defines the "commit middleware". A function that gets a Committer + // and returns a Committer. For example: + // + // hook := func(next ent.Committer) ent.Committer { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Commit(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + CommitHook func(Committer) Committer +) + +// Commit calls f(ctx, m). +func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + txDriver := tx.config.driver.(*txDriver) + var fn Committer = CommitFunc(func(context.Context, *Tx) error { + return txDriver.tx.Commit() + }) + txDriver.mu.Lock() + hooks := append([]CommitHook(nil), txDriver.onCommit...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Commit(tx.ctx, tx) +} + +// OnCommit adds a hook to call on commit. +func (tx *Tx) OnCommit(f CommitHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onCommit = append(txDriver.onCommit, f) + txDriver.mu.Unlock() +} + +type ( + // Rollbacker is the interface that wraps the Rollback method. + Rollbacker interface { + Rollback(context.Context, *Tx) error + } + + // The RollbackFunc type is an adapter to allow the use of ordinary + // function as a Rollbacker. If f is a function with the appropriate + // signature, RollbackFunc(f) is a Rollbacker that calls f. + RollbackFunc func(context.Context, *Tx) error + + // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker + // and returns a Rollbacker. For example: + // + // hook := func(next ent.Rollbacker) ent.Rollbacker { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Rollback(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + RollbackHook func(Rollbacker) Rollbacker +) + +// Rollback calls f(ctx, m). +func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + txDriver := tx.config.driver.(*txDriver) + var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { + return txDriver.tx.Rollback() + }) + txDriver.mu.Lock() + hooks := append([]RollbackHook(nil), txDriver.onRollback...) + txDriver.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Rollback(tx.ctx, tx) +} + +// OnRollback adds a hook to call on rollback. +func (tx *Tx) OnRollback(f RollbackHook) { + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onRollback = append(txDriver.onRollback, f) + txDriver.mu.Unlock() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + tx.clientOnce.Do(func() { + tx.client = &Client{config: tx.config} + tx.client.init() + }) + return tx.client +} + +func (tx *Tx) init() { + tx.Adv = NewAdvClient(tx.config) + tx.Mall = NewMallClient(tx.config) +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: Adv.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that txDriver is not goroutine safe. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // tx is the underlying transaction. + tx dialect.Tx + // completion hooks. + mu sync.Mutex + onCommit []CommitHook + onRollback []RollbackHook +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) + +// ExecContext allows calling the underlying ExecContext method of the transaction if it is supported by it. +// See, database/sql#Tx.ExecContext for more information. +func (tx *txDriver) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { + ex, ok := tx.tx.(interface { + ExecContext(context.Context, string, ...any) (stdsql.Result, error) + }) + if !ok { + return nil, fmt.Errorf("Tx.ExecContext is not supported") + } + return ex.ExecContext(ctx, query, args...) +} + +// QueryContext allows calling the underlying QueryContext method of the transaction if it is supported by it. +// See, database/sql#Tx.QueryContext for more information. +func (tx *txDriver) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { + q, ok := tx.tx.(interface { + QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) + }) + if !ok { + return nil, fmt.Errorf("Tx.QueryContext is not supported") + } + return q.QueryContext(ctx, query, args...) +} diff --git a/adv/orm/generate.go b/adv/orm/generate.go new file mode 100644 index 0000000..fecd97b --- /dev/null +++ b/adv/orm/generate.go @@ -0,0 +1,3 @@ +package orm + +//go:generate go run entgo.io/ent/cmd/ent generate --feature sql/upsert,sql/execquery,privacy,entql ./schema --target ./ent diff --git a/adv/orm/pg.go b/adv/orm/pg.go new file mode 100644 index 0000000..e276ae8 --- /dev/null +++ b/adv/orm/pg.go @@ -0,0 +1,28 @@ +package orm + +import ( + "context" + "database/sql" + + _ "github.com/twiglab/crm/adv/orm/ent/runtime" + + "entgo.io/ent/dialect" + entsql "entgo.io/ent/dialect/sql" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/jackc/pgx/v5/stdlib" + + "github.com/twiglab/crm/adv/orm/ent" +) + +func OpenClient(in *sql.DB) *ent.Client { + drv := entsql.OpenDB(dialect.Postgres, in) + return ent.NewClient(ent.Driver(drv)) +} + +func FromURL(ctx context.Context, url string, ops ...stdlib.OptionOpenDB) (*sql.DB, error) { + pool, err := pgxpool.New(ctx, url) + if err != nil { + return nil, err + } + return stdlib.OpenDBFromPool(pool, ops...), nil +} diff --git a/adv/orm/schema/adv.go b/adv/orm/schema/adv.go new file mode 100644 index 0000000..c851bd0 --- /dev/null +++ b/adv/orm/schema/adv.go @@ -0,0 +1,152 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "entgo.io/ent/schema/mixin" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/schema/x" +) + +type Adv struct { + ent.Schema +} + +func (Adv) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.Nil). + Default(x.ID). + Unique(). + Immutable(), + + field.String("code"). + MaxLen(36). + NotEmpty(). + Unique(). + Immutable(). + DefaultFunc(x.Code36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("mall_code"). + MaxLen(36). + NotEmpty(). + Unique(). + Immutable(). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("mall_name"). + MaxLen(64). + NotEmpty(). + Unique(). + SchemaType(map[string]string{ + dialect.MySQL: "char(64)", // Override MySQL. + dialect.Postgres: "char(64)", // Override Postgres. + dialect.SQLite: "char(64)", // Override Postgres. + }), + + field.String("h3_index_6"). + MaxLen(36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("h3_index_7"). + MaxLen(36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("h3_index_8"). + MaxLen(36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("img_path"). + MaxLen(64). + NotEmpty(). + Unique(). + Immutable(). + SchemaType(map[string]string{ + dialect.MySQL: "char(64)", // Override MySQL. + dialect.Postgres: "char(64)", // Override Postgres. + dialect.SQLite: "char(64)", // Override Postgres. + }), + + field.String("url"). + MaxLen(64). + NotEmpty(). + Unique(). + Immutable(). + SchemaType(map[string]string{ + dialect.MySQL: "char(64)", // Override MySQL. + dialect.Postgres: "char(64)", // Override Postgres. + dialect.SQLite: "char(64)", // Override Postgres. + }), + + field.String("ruler"). + MaxLen(256). + SchemaType(map[string]string{ + dialect.MySQL: "char(256)", // Override MySQL. + dialect.Postgres: "char(256)", // Override Postgres. + dialect.SQLite: "char(256)", // Override Postgres. + }), + + field.Int("ord").Default(0), + + field.String("memo"). + MaxLen(64). + SchemaType(map[string]string{ + dialect.MySQL: "varchar(64)", // Override MySQL. + dialect.Postgres: "varchar(64)", // Override Postgres. + dialect.SQLite: "varchar(64)", // Override Postgres. + }), + + field.Time("start_time").Immutable().Default(time.Now), + field.Time("end_time").Immutable().Default(x.AddDay(1)), + + field.Int("status").Default(1), + } +} + +func (Adv) Mixin() []ent.Mixin { + return []ent.Mixin{ + mixin.Time{}, + } +} + +func (Adv) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("code"), + index.Fields("status"), + index.Fields("ord"), + index.Fields("start_time"), + index.Fields("end_time"), + } +} + +func (Adv) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "t_adv"}, + } +} diff --git a/adv/orm/schema/mall.go b/adv/orm/schema/mall.go new file mode 100644 index 0000000..c6f7682 --- /dev/null +++ b/adv/orm/schema/mall.go @@ -0,0 +1,115 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "entgo.io/ent/schema/mixin" + "github.com/google/uuid" + "github.com/twiglab/crm/adv/orm/schema/x" +) + +type Mall struct { + ent.Schema +} + +func (Mall) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.Nil). + Default(x.ID). + Unique(). + Immutable(), + + field.String("code"). + MaxLen(36). + NotEmpty(). + Unique(). + Immutable(). + DefaultFunc(x.Code36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("mall_code"). + MaxLen(36). + NotEmpty(). + Unique(). + Immutable(). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("mall_name"). + MaxLen(64). + NotEmpty(). + Unique(). + SchemaType(map[string]string{ + dialect.MySQL: "char(64)", // Override MySQL. + dialect.Postgres: "char(64)", // Override Postgres. + dialect.SQLite: "char(64)", // Override Postgres. + }), + + field.String("h3_index_6"). + MaxLen(36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("h3_index_7"). + MaxLen(36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("h3_index_8"). + MaxLen(36). + SchemaType(map[string]string{ + dialect.MySQL: "char(36)", // Override MySQL. + dialect.Postgres: "char(36)", // Override Postgres. + dialect.SQLite: "char(36)", // Override Postgres. + }), + + field.String("memo"). + MaxLen(64). + SchemaType(map[string]string{ + dialect.MySQL: "varchar(64)", // Override MySQL. + dialect.Postgres: "varchar(64)", // Override Postgres. + dialect.SQLite: "varchar(64)", // Override Postgres. + }), + + field.Time("start_time").Immutable().Default(time.Now), + field.Int("status").Default(1), + } +} + +func (Mall) Mixin() []ent.Mixin { + return []ent.Mixin{ + mixin.Time{}, + } +} + +func (Mall) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("code"), + index.Fields("status"), + } +} + +func (Mall) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "t_mall"}, + } +} diff --git a/adv/orm/schema/x/util.go b/adv/orm/schema/x/util.go new file mode 100644 index 0000000..9d75965 --- /dev/null +++ b/adv/orm/schema/x/util.go @@ -0,0 +1,44 @@ +package x + +import ( + "errors" + "regexp" + "time" + + "github.com/google/uuid" +) + +func ID() uuid.UUID { + return uuid.Must(uuid.NewV7()) +} + +func Code36() string { + return uuid.Must(uuid.NewV7()).String() +} + +// CheckMobile 检验手机号 +func CheckMobile(phone string) error { + // 匹配规则 + // ^1第一位为一 + // [345789]{1} 后接一位345789 的数字 + // \\d \d的转义 表示数字 {9} 接9位 + // $ 结束符 + regRuler := "^1[345789]{1}\\d{9}$" + + // 正则调用规则 + reg := regexp.MustCompile(regRuler) + + // 返回 MatchString 是否匹配 + if !reg.MatchString(phone) { + return errors.New("dadas") + } + + return nil +} + +func AddDay(i int) func() time.Time { + return func() time.Time { + now := time.Now() + return now.AddDate(0, 0, i) + } +}