1
0

update migrate

This commit is contained in:
2023-04-05 15:05:14 +09:00
parent 9573dc895f
commit 1d5cb2ad9f
87 changed files with 65302 additions and 622 deletions

12
.gitignore vendored
View File

@@ -1 +1,13 @@
t
.env
*.json
*.sqlite
tmp/card_limit.zsh
tmp/card_day.zsh
tmp/card_delete.zsh
memo.md
api
**.DS_Store
node_modules
*.lock
target

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "scpt"]
path = scpt
url = git@git.syui.ai:ai/api_scpt

14
Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM syui/aios
RUN pacman -Syu --noconfirm go
WORKDIR /app
RUN git clone https://git.syui.ai/ai/api tmp
WORKDIR /app/tmp
RUN go build
RUN mv api /app/api
#ADD ./app /app
WORKDIR /app
ENTRYPOINT ["/app/api"]

View File

@@ -1 +1 @@
web: bin/t
web: bin/api

0
app/data/keep Normal file
View File

24
build.zsh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/zsh
d=${0:a:h}
cd $d
su=5000
go1.21.8 generate ./...
#go generate ./...
cp -rf $d/ent/openapi.json $d/tmp/
case $OSTYPE in
darwin*)
sed -i '' "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go
sed -i '' "s/255/$su/g" $d/ent/openapi.json
;;
linux*)
sed -i "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go
sed -i "s/255/$su/g" $d/ent/openapi.json
;;
esac
cp -rf $d/tmp/ogent ent/
#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go build
#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go run -mod=mod main.go

11
compose.yml Normal file
View File

@@ -0,0 +1,11 @@
services:
api:
ports:
- 8080:8080
build:
context: .
restart: always
env_file:
- .env
volumes:
- ./app/data:/app/data

133
docs/wiki.md Normal file
View File

@@ -0,0 +1,133 @@
### build
```sh
$ vim ent/entc.go
$ vim ent/schema/users.go
$ go generate ./...
$ go build
$ ./card
$ go generate ./...
$ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go
$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards
$ curl localhost:8080/users
$ curl localhost:8080/cards
$ curl localhost:8080/users/1
$ curl localhost:8080/users/1/card
```
### use
```sh
$ curl -X POST -H "Content-Type: application/json" -d '{"username":"syui",\"password\":\"$pass\"}' https://api.syui.ai/users
# onconflict
$ !!
$ curl -sL https://api.syui.ai/users/1
```
```sh
# item select
$ curl -sL "https://api.syui.ai/users?itemsPerPage=255"
$ curl -sL "https://api.syui.ai/cards?itemsPerPage=255"
$ curl -sL "https://api.syui.ai/users/1/card?itemsPerPage=255"
```
### ref
```sh
$ vim ./ent/ogent/ogent.go
// 新規登録の停止
// CreateUsers handles POST /users-slice requests.
func (h *OgentHandler) CreateUsers(ctx context.Context, req CreateUsersReq) (CreateUsersRes, error) {
b := h.client.Users.Create()
//b.SetUser(req.User)
b.SetUser("syui")
}
// 削除の無効
// DeleteUsers handles DELETE /users-slice/{id} requests.
func (h *OgentHandler) DeleteUsers(ctx context.Context, params DeleteUsersParams) (DeleteUsersRes, error) {
if params.ID != 1 {
err := h.client.Users.DeleteOneID(params.ID).Exec(ctx)
}
return new(DeleteUsersNoContent), nil
}
// 要素の書き換えの禁止
// UpdateUsers handles PATCH /users-slice/{id} requests.
func (h *OgentHandler) UpdateUsers(ctx context.Context, req UpdateUsersReq, params UpdateUsersParams) (UpdateUsersRes, error) {
b := h.client.Users.UpdateOneID(params.ID)
// Add all fields.
//if v, ok := req.Hp.Get(); ok {
// b.SetHp(v)
//}
```
### link
- https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/
- https://github.com/ariga/ogent/blob/main/example/todo/ent/entc.go
- https://github.com/ent/ent/blob/master/dialect/sql/schema/postgres_test.go
- https://github.com/go-kratos/beer-shop/tree/main/app/catalog/service/internal/data/ent
### update
```sh
$ curl --dump-header - 'https://api.syui.ai/users' -H 'Origin: https://card.syui.ai'|less
```
> ent/ogent/oas_response_encoders_gen.go
```go
func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
switch response := response.(type) {
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
```
### northflank
#### backup sqlite
- `cron`, `repo(private)`, `pass(token)`
```sh
#!/bin/zsh
pass=password
/usr/bin/northflank exec service --project $project --service $service --cmd "/app/data/api/backup.sh $pass"
function f(){
rm /app/data/api/backup.sh
echo '#!/bin/bash
pass=$1
git config --global user.email syui@syui.ai
git config --global user.name syui
cp -rf /app/data/new.sqlite /app/data/api/latest.sqlite
cp -rf /app/data/new.sqlite /app/data/api/`date '+%w'`.sqlite
cd /app/data/api
git remote add origin https://$pass@github.com/ai/api
git add .
git commit -m backup
git push origin main
git remote rm origin
' >> /app/data/api/backup.sh
chmod +x /app/data/api/backup.sh
}
```
#### setting
- ports : http, 8080, dns=api.syui.ai
- env : PASS=xxx, TOKEN=xxx
- cmd-override : /bin/api
- volumes : /app/data

View File

@@ -3,12 +3,13 @@
package ent
import (
"api/ent/card"
"api/ent/user"
"fmt"
"strings"
"t/ent/card"
"t/ent/user"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
@@ -17,20 +18,31 @@ type Card struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"-"`
// Card holds the value of the "card" field.
Card int `json:"card,omitempty"`
// Skill holds the value of the "skill" field.
Skill string `json:"skill,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// Token holds the value of the "token" field.
Token string `json:"-"`
// Cp holds the value of the "cp" field.
Cp int `json:"cp,omitempty"`
// URL holds the value of the "url" field.
URL string `json:"url,omitempty"`
// Count holds the value of the "count" field.
Count int `json:"count,omitempty"`
// Author holds the value of the "author" field.
Author string `json:"author,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the CardQuery when eager-loading is set.
Edges CardEdges `json:"edges"`
user_card *int
Edges CardEdges `json:"edges"`
user_card *int
selectValues sql.SelectValues
}
// CardEdges holds the relations/edges for other nodes in the graph.
@@ -60,16 +72,16 @@ func (*Card) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case card.FieldID, card.FieldCard, card.FieldCp:
case card.FieldID, card.FieldCard, card.FieldCp, card.FieldCount:
values[i] = new(sql.NullInt64)
case card.FieldStatus, card.FieldURL:
case card.FieldPassword, card.FieldSkill, card.FieldStatus, card.FieldToken, card.FieldURL, card.FieldAuthor:
values[i] = new(sql.NullString)
case card.FieldCreatedAt:
values[i] = new(sql.NullTime)
case card.ForeignKeys[0]: // user_card
values[i] = new(sql.NullInt64)
default:
return nil, fmt.Errorf("unexpected column %q for type Card", columns[i])
values[i] = new(sql.UnknownType)
}
}
return values, nil
@@ -89,18 +101,36 @@ func (c *Card) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value)
}
c.ID = int(value.Int64)
case card.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
c.Password = value.String
}
case card.FieldCard:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field card", values[i])
} else if value.Valid {
c.Card = int(value.Int64)
}
case card.FieldSkill:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field skill", values[i])
} else if value.Valid {
c.Skill = value.String
}
case card.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
c.Status = value.String
}
case card.FieldToken:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field token", values[i])
} else if value.Valid {
c.Token = value.String
}
case card.FieldCp:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field cp", values[i])
@@ -113,6 +143,18 @@ func (c *Card) assignValues(columns []string, values []any) error {
} else if value.Valid {
c.URL = value.String
}
case card.FieldCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field count", values[i])
} else if value.Valid {
c.Count = int(value.Int64)
}
case card.FieldAuthor:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field author", values[i])
} else if value.Valid {
c.Author = value.String
}
case card.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
@@ -126,11 +168,19 @@ func (c *Card) assignValues(columns []string, values []any) error {
c.user_card = new(int)
*c.user_card = int(value.Int64)
}
default:
c.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Card.
// This includes values selected through modifiers, order, etc.
func (c *Card) Value(name string) (ent.Value, error) {
return c.selectValues.Get(name)
}
// QueryOwner queries the "owner" edge of the Card entity.
func (c *Card) QueryOwner() *UserQuery {
return NewCardClient(c.config).QueryOwner(c)
@@ -159,18 +209,31 @@ func (c *Card) String() string {
var builder strings.Builder
builder.WriteString("Card(")
builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
builder.WriteString("password=<sensitive>")
builder.WriteString(", ")
builder.WriteString("card=")
builder.WriteString(fmt.Sprintf("%v", c.Card))
builder.WriteString(", ")
builder.WriteString("skill=")
builder.WriteString(c.Skill)
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(c.Status)
builder.WriteString(", ")
builder.WriteString("token=<sensitive>")
builder.WriteString(", ")
builder.WriteString("cp=")
builder.WriteString(fmt.Sprintf("%v", c.Cp))
builder.WriteString(", ")
builder.WriteString("url=")
builder.WriteString(c.URL)
builder.WriteString(", ")
builder.WriteString("count=")
builder.WriteString(fmt.Sprintf("%v", c.Count))
builder.WriteString(", ")
builder.WriteString("author=")
builder.WriteString(c.Author)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(c.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')

View File

@@ -4,6 +4,9 @@ package card
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
@@ -11,14 +14,24 @@ const (
Label = "card"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// FieldCard holds the string denoting the card field in the database.
FieldCard = "card"
// FieldSkill holds the string denoting the skill field in the database.
FieldSkill = "skill"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldToken holds the string denoting the token field in the database.
FieldToken = "token"
// FieldCp holds the string denoting the cp field in the database.
FieldCp = "cp"
// FieldURL holds the string denoting the url field in the database.
FieldURL = "url"
// FieldCount holds the string denoting the count field in the database.
FieldCount = "count"
// FieldAuthor holds the string denoting the author field in the database.
FieldAuthor = "author"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// EdgeOwner holds the string denoting the owner edge name in mutations.
@@ -37,10 +50,15 @@ const (
// Columns holds all SQL columns for card fields.
var Columns = []string{
FieldID,
FieldPassword,
FieldCard,
FieldSkill,
FieldStatus,
FieldToken,
FieldCp,
FieldURL,
FieldCount,
FieldAuthor,
FieldCreatedAt,
}
@@ -66,8 +84,12 @@ func ValidColumn(column string) bool {
}
var (
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
PasswordValidator func(string) error
// DefaultCard holds the default value on creation for the "card" field.
DefaultCard func() int
// DefaultSkill holds the default value on creation for the "skill" field.
DefaultSkill func() string
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus func() string
// DefaultCp holds the default value on creation for the "cp" field.
@@ -77,3 +99,75 @@ var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
// OrderOption defines the ordering options for the Card 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()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByCard orders the results by the card field.
func ByCard(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCard, opts...).ToFunc()
}
// BySkill orders the results by the skill field.
func BySkill(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSkill, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByToken orders the results by the token field.
func ByToken(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldToken, opts...).ToFunc()
}
// ByCp orders the results by the cp field.
func ByCp(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCp, opts...).ToFunc()
}
// ByURL orders the results by the url field.
func ByURL(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldURL, opts...).ToFunc()
}
// ByCount orders the results by the count field.
func ByCount(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCount, opts...).ToFunc()
}
// ByAuthor orders the results by the author field.
func ByAuthor(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAuthor, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByOwnerField orders the results by owner field.
func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...))
}
}
func newOwnerStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(OwnerInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn),
)
}

View File

@@ -3,7 +3,7 @@
package card
import (
"t/ent/predicate"
"api/ent/predicate"
"time"
"entgo.io/ent/dialect/sql"
@@ -55,16 +55,31 @@ func IDLTE(id int) predicate.Card {
return predicate.Card(sql.FieldLTE(FieldID, id))
}
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
func Password(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldPassword, v))
}
// Card applies equality check predicate on the "card" field. It's identical to CardEQ.
func Card(v int) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCard, v))
}
// Skill applies equality check predicate on the "skill" field. It's identical to SkillEQ.
func Skill(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldSkill, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldStatus, v))
}
// Token applies equality check predicate on the "token" field. It's identical to TokenEQ.
func Token(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldToken, v))
}
// Cp applies equality check predicate on the "cp" field. It's identical to CpEQ.
func Cp(v int) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCp, v))
@@ -75,11 +90,86 @@ func URL(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldURL, v))
}
// Count applies equality check predicate on the "count" field. It's identical to CountEQ.
func Count(v int) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCount, v))
}
// Author applies equality check predicate on the "author" field. It's identical to AuthorEQ.
func Author(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldAuthor, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCreatedAt, v))
}
// PasswordEQ applies the EQ predicate on the "password" field.
func PasswordEQ(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldPassword, v))
}
// PasswordNEQ applies the NEQ predicate on the "password" field.
func PasswordNEQ(v string) predicate.Card {
return predicate.Card(sql.FieldNEQ(FieldPassword, v))
}
// PasswordIn applies the In predicate on the "password" field.
func PasswordIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldIn(FieldPassword, vs...))
}
// PasswordNotIn applies the NotIn predicate on the "password" field.
func PasswordNotIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldNotIn(FieldPassword, vs...))
}
// PasswordGT applies the GT predicate on the "password" field.
func PasswordGT(v string) predicate.Card {
return predicate.Card(sql.FieldGT(FieldPassword, v))
}
// PasswordGTE applies the GTE predicate on the "password" field.
func PasswordGTE(v string) predicate.Card {
return predicate.Card(sql.FieldGTE(FieldPassword, v))
}
// PasswordLT applies the LT predicate on the "password" field.
func PasswordLT(v string) predicate.Card {
return predicate.Card(sql.FieldLT(FieldPassword, v))
}
// PasswordLTE applies the LTE predicate on the "password" field.
func PasswordLTE(v string) predicate.Card {
return predicate.Card(sql.FieldLTE(FieldPassword, v))
}
// PasswordContains applies the Contains predicate on the "password" field.
func PasswordContains(v string) predicate.Card {
return predicate.Card(sql.FieldContains(FieldPassword, v))
}
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
func PasswordHasPrefix(v string) predicate.Card {
return predicate.Card(sql.FieldHasPrefix(FieldPassword, v))
}
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
func PasswordHasSuffix(v string) predicate.Card {
return predicate.Card(sql.FieldHasSuffix(FieldPassword, v))
}
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
func PasswordEqualFold(v string) predicate.Card {
return predicate.Card(sql.FieldEqualFold(FieldPassword, v))
}
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
func PasswordContainsFold(v string) predicate.Card {
return predicate.Card(sql.FieldContainsFold(FieldPassword, v))
}
// CardEQ applies the EQ predicate on the "card" field.
func CardEQ(v int) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCard, v))
@@ -130,6 +220,81 @@ func CardNotNil() predicate.Card {
return predicate.Card(sql.FieldNotNull(FieldCard))
}
// SkillEQ applies the EQ predicate on the "skill" field.
func SkillEQ(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldSkill, v))
}
// SkillNEQ applies the NEQ predicate on the "skill" field.
func SkillNEQ(v string) predicate.Card {
return predicate.Card(sql.FieldNEQ(FieldSkill, v))
}
// SkillIn applies the In predicate on the "skill" field.
func SkillIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldIn(FieldSkill, vs...))
}
// SkillNotIn applies the NotIn predicate on the "skill" field.
func SkillNotIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldNotIn(FieldSkill, vs...))
}
// SkillGT applies the GT predicate on the "skill" field.
func SkillGT(v string) predicate.Card {
return predicate.Card(sql.FieldGT(FieldSkill, v))
}
// SkillGTE applies the GTE predicate on the "skill" field.
func SkillGTE(v string) predicate.Card {
return predicate.Card(sql.FieldGTE(FieldSkill, v))
}
// SkillLT applies the LT predicate on the "skill" field.
func SkillLT(v string) predicate.Card {
return predicate.Card(sql.FieldLT(FieldSkill, v))
}
// SkillLTE applies the LTE predicate on the "skill" field.
func SkillLTE(v string) predicate.Card {
return predicate.Card(sql.FieldLTE(FieldSkill, v))
}
// SkillContains applies the Contains predicate on the "skill" field.
func SkillContains(v string) predicate.Card {
return predicate.Card(sql.FieldContains(FieldSkill, v))
}
// SkillHasPrefix applies the HasPrefix predicate on the "skill" field.
func SkillHasPrefix(v string) predicate.Card {
return predicate.Card(sql.FieldHasPrefix(FieldSkill, v))
}
// SkillHasSuffix applies the HasSuffix predicate on the "skill" field.
func SkillHasSuffix(v string) predicate.Card {
return predicate.Card(sql.FieldHasSuffix(FieldSkill, v))
}
// SkillIsNil applies the IsNil predicate on the "skill" field.
func SkillIsNil() predicate.Card {
return predicate.Card(sql.FieldIsNull(FieldSkill))
}
// SkillNotNil applies the NotNil predicate on the "skill" field.
func SkillNotNil() predicate.Card {
return predicate.Card(sql.FieldNotNull(FieldSkill))
}
// SkillEqualFold applies the EqualFold predicate on the "skill" field.
func SkillEqualFold(v string) predicate.Card {
return predicate.Card(sql.FieldEqualFold(FieldSkill, v))
}
// SkillContainsFold applies the ContainsFold predicate on the "skill" field.
func SkillContainsFold(v string) predicate.Card {
return predicate.Card(sql.FieldContainsFold(FieldSkill, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldStatus, v))
@@ -205,6 +370,81 @@ func StatusContainsFold(v string) predicate.Card {
return predicate.Card(sql.FieldContainsFold(FieldStatus, v))
}
// TokenEQ applies the EQ predicate on the "token" field.
func TokenEQ(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldToken, v))
}
// TokenNEQ applies the NEQ predicate on the "token" field.
func TokenNEQ(v string) predicate.Card {
return predicate.Card(sql.FieldNEQ(FieldToken, v))
}
// TokenIn applies the In predicate on the "token" field.
func TokenIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldIn(FieldToken, vs...))
}
// TokenNotIn applies the NotIn predicate on the "token" field.
func TokenNotIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldNotIn(FieldToken, vs...))
}
// TokenGT applies the GT predicate on the "token" field.
func TokenGT(v string) predicate.Card {
return predicate.Card(sql.FieldGT(FieldToken, v))
}
// TokenGTE applies the GTE predicate on the "token" field.
func TokenGTE(v string) predicate.Card {
return predicate.Card(sql.FieldGTE(FieldToken, v))
}
// TokenLT applies the LT predicate on the "token" field.
func TokenLT(v string) predicate.Card {
return predicate.Card(sql.FieldLT(FieldToken, v))
}
// TokenLTE applies the LTE predicate on the "token" field.
func TokenLTE(v string) predicate.Card {
return predicate.Card(sql.FieldLTE(FieldToken, v))
}
// TokenContains applies the Contains predicate on the "token" field.
func TokenContains(v string) predicate.Card {
return predicate.Card(sql.FieldContains(FieldToken, v))
}
// TokenHasPrefix applies the HasPrefix predicate on the "token" field.
func TokenHasPrefix(v string) predicate.Card {
return predicate.Card(sql.FieldHasPrefix(FieldToken, v))
}
// TokenHasSuffix applies the HasSuffix predicate on the "token" field.
func TokenHasSuffix(v string) predicate.Card {
return predicate.Card(sql.FieldHasSuffix(FieldToken, v))
}
// TokenIsNil applies the IsNil predicate on the "token" field.
func TokenIsNil() predicate.Card {
return predicate.Card(sql.FieldIsNull(FieldToken))
}
// TokenNotNil applies the NotNil predicate on the "token" field.
func TokenNotNil() predicate.Card {
return predicate.Card(sql.FieldNotNull(FieldToken))
}
// TokenEqualFold applies the EqualFold predicate on the "token" field.
func TokenEqualFold(v string) predicate.Card {
return predicate.Card(sql.FieldEqualFold(FieldToken, v))
}
// TokenContainsFold applies the ContainsFold predicate on the "token" field.
func TokenContainsFold(v string) predicate.Card {
return predicate.Card(sql.FieldContainsFold(FieldToken, v))
}
// CpEQ applies the EQ predicate on the "cp" field.
func CpEQ(v int) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCp, v))
@@ -330,6 +570,131 @@ func URLContainsFold(v string) predicate.Card {
return predicate.Card(sql.FieldContainsFold(FieldURL, v))
}
// CountEQ applies the EQ predicate on the "count" field.
func CountEQ(v int) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCount, v))
}
// CountNEQ applies the NEQ predicate on the "count" field.
func CountNEQ(v int) predicate.Card {
return predicate.Card(sql.FieldNEQ(FieldCount, v))
}
// CountIn applies the In predicate on the "count" field.
func CountIn(vs ...int) predicate.Card {
return predicate.Card(sql.FieldIn(FieldCount, vs...))
}
// CountNotIn applies the NotIn predicate on the "count" field.
func CountNotIn(vs ...int) predicate.Card {
return predicate.Card(sql.FieldNotIn(FieldCount, vs...))
}
// CountGT applies the GT predicate on the "count" field.
func CountGT(v int) predicate.Card {
return predicate.Card(sql.FieldGT(FieldCount, v))
}
// CountGTE applies the GTE predicate on the "count" field.
func CountGTE(v int) predicate.Card {
return predicate.Card(sql.FieldGTE(FieldCount, v))
}
// CountLT applies the LT predicate on the "count" field.
func CountLT(v int) predicate.Card {
return predicate.Card(sql.FieldLT(FieldCount, v))
}
// CountLTE applies the LTE predicate on the "count" field.
func CountLTE(v int) predicate.Card {
return predicate.Card(sql.FieldLTE(FieldCount, v))
}
// CountIsNil applies the IsNil predicate on the "count" field.
func CountIsNil() predicate.Card {
return predicate.Card(sql.FieldIsNull(FieldCount))
}
// CountNotNil applies the NotNil predicate on the "count" field.
func CountNotNil() predicate.Card {
return predicate.Card(sql.FieldNotNull(FieldCount))
}
// AuthorEQ applies the EQ predicate on the "author" field.
func AuthorEQ(v string) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldAuthor, v))
}
// AuthorNEQ applies the NEQ predicate on the "author" field.
func AuthorNEQ(v string) predicate.Card {
return predicate.Card(sql.FieldNEQ(FieldAuthor, v))
}
// AuthorIn applies the In predicate on the "author" field.
func AuthorIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldIn(FieldAuthor, vs...))
}
// AuthorNotIn applies the NotIn predicate on the "author" field.
func AuthorNotIn(vs ...string) predicate.Card {
return predicate.Card(sql.FieldNotIn(FieldAuthor, vs...))
}
// AuthorGT applies the GT predicate on the "author" field.
func AuthorGT(v string) predicate.Card {
return predicate.Card(sql.FieldGT(FieldAuthor, v))
}
// AuthorGTE applies the GTE predicate on the "author" field.
func AuthorGTE(v string) predicate.Card {
return predicate.Card(sql.FieldGTE(FieldAuthor, v))
}
// AuthorLT applies the LT predicate on the "author" field.
func AuthorLT(v string) predicate.Card {
return predicate.Card(sql.FieldLT(FieldAuthor, v))
}
// AuthorLTE applies the LTE predicate on the "author" field.
func AuthorLTE(v string) predicate.Card {
return predicate.Card(sql.FieldLTE(FieldAuthor, v))
}
// AuthorContains applies the Contains predicate on the "author" field.
func AuthorContains(v string) predicate.Card {
return predicate.Card(sql.FieldContains(FieldAuthor, v))
}
// AuthorHasPrefix applies the HasPrefix predicate on the "author" field.
func AuthorHasPrefix(v string) predicate.Card {
return predicate.Card(sql.FieldHasPrefix(FieldAuthor, v))
}
// AuthorHasSuffix applies the HasSuffix predicate on the "author" field.
func AuthorHasSuffix(v string) predicate.Card {
return predicate.Card(sql.FieldHasSuffix(FieldAuthor, v))
}
// AuthorIsNil applies the IsNil predicate on the "author" field.
func AuthorIsNil() predicate.Card {
return predicate.Card(sql.FieldIsNull(FieldAuthor))
}
// AuthorNotNil applies the NotNil predicate on the "author" field.
func AuthorNotNil() predicate.Card {
return predicate.Card(sql.FieldNotNull(FieldAuthor))
}
// AuthorEqualFold applies the EqualFold predicate on the "author" field.
func AuthorEqualFold(v string) predicate.Card {
return predicate.Card(sql.FieldEqualFold(FieldAuthor, v))
}
// AuthorContainsFold applies the ContainsFold predicate on the "author" field.
func AuthorContainsFold(v string) predicate.Card {
return predicate.Card(sql.FieldContainsFold(FieldAuthor, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Card {
return predicate.Card(sql.FieldEQ(FieldCreatedAt, v))
@@ -394,11 +759,7 @@ func HasOwner() predicate.Card {
// HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates).
func HasOwnerWith(preds ...predicate.User) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(OwnerInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn),
)
step := newOwnerStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)

View File

@@ -3,11 +3,11 @@
package ent
import (
"api/ent/card"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/card"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -21,6 +21,12 @@ type CardCreate struct {
hooks []Hook
}
// SetPassword sets the "password" field.
func (cc *CardCreate) SetPassword(s string) *CardCreate {
cc.mutation.SetPassword(s)
return cc
}
// SetCard sets the "card" field.
func (cc *CardCreate) SetCard(i int) *CardCreate {
cc.mutation.SetCard(i)
@@ -35,6 +41,20 @@ func (cc *CardCreate) SetNillableCard(i *int) *CardCreate {
return cc
}
// SetSkill sets the "skill" field.
func (cc *CardCreate) SetSkill(s string) *CardCreate {
cc.mutation.SetSkill(s)
return cc
}
// SetNillableSkill sets the "skill" field if the given value is not nil.
func (cc *CardCreate) SetNillableSkill(s *string) *CardCreate {
if s != nil {
cc.SetSkill(*s)
}
return cc
}
// SetStatus sets the "status" field.
func (cc *CardCreate) SetStatus(s string) *CardCreate {
cc.mutation.SetStatus(s)
@@ -49,6 +69,20 @@ func (cc *CardCreate) SetNillableStatus(s *string) *CardCreate {
return cc
}
// SetToken sets the "token" field.
func (cc *CardCreate) SetToken(s string) *CardCreate {
cc.mutation.SetToken(s)
return cc
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (cc *CardCreate) SetNillableToken(s *string) *CardCreate {
if s != nil {
cc.SetToken(*s)
}
return cc
}
// SetCp sets the "cp" field.
func (cc *CardCreate) SetCp(i int) *CardCreate {
cc.mutation.SetCp(i)
@@ -77,6 +111,34 @@ func (cc *CardCreate) SetNillableURL(s *string) *CardCreate {
return cc
}
// SetCount sets the "count" field.
func (cc *CardCreate) SetCount(i int) *CardCreate {
cc.mutation.SetCount(i)
return cc
}
// SetNillableCount sets the "count" field if the given value is not nil.
func (cc *CardCreate) SetNillableCount(i *int) *CardCreate {
if i != nil {
cc.SetCount(*i)
}
return cc
}
// SetAuthor sets the "author" field.
func (cc *CardCreate) SetAuthor(s string) *CardCreate {
cc.mutation.SetAuthor(s)
return cc
}
// SetNillableAuthor sets the "author" field if the given value is not nil.
func (cc *CardCreate) SetNillableAuthor(s *string) *CardCreate {
if s != nil {
cc.SetAuthor(*s)
}
return cc
}
// SetCreatedAt sets the "created_at" field.
func (cc *CardCreate) SetCreatedAt(t time.Time) *CardCreate {
cc.mutation.SetCreatedAt(t)
@@ -141,6 +203,10 @@ func (cc *CardCreate) defaults() {
v := card.DefaultCard()
cc.mutation.SetCard(v)
}
if _, ok := cc.mutation.Skill(); !ok {
v := card.DefaultSkill()
cc.mutation.SetSkill(v)
}
if _, ok := cc.mutation.Status(); !ok {
v := card.DefaultStatus()
cc.mutation.SetStatus(v)
@@ -161,6 +227,14 @@ func (cc *CardCreate) defaults() {
// check runs all checks and user-defined validators on the builder.
func (cc *CardCreate) check() error {
if _, ok := cc.mutation.Password(); !ok {
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Card.password"`)}
}
if v, ok := cc.mutation.Password(); ok {
if err := card.PasswordValidator(v); err != nil {
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Card.password": %w`, err)}
}
}
if _, ok := cc.mutation.OwnerID(); !ok {
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required edge "Card.owner"`)}
}
@@ -190,14 +264,26 @@ func (cc *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) {
_node = &Card{config: cc.config}
_spec = sqlgraph.NewCreateSpec(card.Table, sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt))
)
if value, ok := cc.mutation.Password(); ok {
_spec.SetField(card.FieldPassword, field.TypeString, value)
_node.Password = value
}
if value, ok := cc.mutation.Card(); ok {
_spec.SetField(card.FieldCard, field.TypeInt, value)
_node.Card = value
}
if value, ok := cc.mutation.Skill(); ok {
_spec.SetField(card.FieldSkill, field.TypeString, value)
_node.Skill = value
}
if value, ok := cc.mutation.Status(); ok {
_spec.SetField(card.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := cc.mutation.Token(); ok {
_spec.SetField(card.FieldToken, field.TypeString, value)
_node.Token = value
}
if value, ok := cc.mutation.Cp(); ok {
_spec.SetField(card.FieldCp, field.TypeInt, value)
_node.Cp = value
@@ -206,6 +292,14 @@ func (cc *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) {
_spec.SetField(card.FieldURL, field.TypeString, value)
_node.URL = value
}
if value, ok := cc.mutation.Count(); ok {
_spec.SetField(card.FieldCount, field.TypeInt, value)
_node.Count = value
}
if value, ok := cc.mutation.Author(); ok {
_spec.SetField(card.FieldAuthor, field.TypeString, value)
_node.Author = value
}
if value, ok := cc.mutation.CreatedAt(); ok {
_spec.SetField(card.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
@@ -218,10 +312,7 @@ func (cc *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) {
Columns: []string{card.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
@@ -257,8 +348,8 @@ func (ccb *CardCreateBulk) Save(ctx context.Context) ([]*Card, error) {
return nil, err
}
builder.mutation = mutation
nodes[i], specs[i] = builder.createSpec()
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation)
} else {

View File

@@ -3,9 +3,9 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"context"
"t/ent/card"
"t/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@@ -3,12 +3,12 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"api/ent/user"
"context"
"fmt"
"math"
"t/ent/card"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -19,7 +19,7 @@ import (
type CardQuery struct {
config
ctx *QueryContext
order []OrderFunc
order []card.OrderOption
inters []Interceptor
predicates []predicate.Card
withOwner *UserQuery
@@ -55,7 +55,7 @@ func (cq *CardQuery) Unique(unique bool) *CardQuery {
}
// Order specifies how the records should be ordered.
func (cq *CardQuery) Order(o ...OrderFunc) *CardQuery {
func (cq *CardQuery) Order(o ...card.OrderOption) *CardQuery {
cq.order = append(cq.order, o...)
return cq
}
@@ -271,7 +271,7 @@ func (cq *CardQuery) Clone() *CardQuery {
return &CardQuery{
config: cq.config,
ctx: cq.ctx.Clone(),
order: append([]OrderFunc{}, cq.order...),
order: append([]card.OrderOption{}, cq.order...),
inters: append([]Interceptor{}, cq.inters...),
predicates: append([]predicate.Card{}, cq.predicates...),
withOwner: cq.withOwner.Clone(),
@@ -298,12 +298,12 @@ func (cq *CardQuery) WithOwner(opts ...func(*UserQuery)) *CardQuery {
// Example:
//
// var v []struct {
// Card int `json:"card,omitempty"`
// Password string `json:"password,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Card.Query().
// GroupBy(card.FieldCard).
// GroupBy(card.FieldPassword).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (cq *CardQuery) GroupBy(field string, fields ...string) *CardGroupBy {
@@ -321,11 +321,11 @@ func (cq *CardQuery) GroupBy(field string, fields ...string) *CardGroupBy {
// Example:
//
// var v []struct {
// Card int `json:"card,omitempty"`
// Password string `json:"password,omitempty"`
// }
//
// client.Card.Query().
// Select(card.FieldCard).
// Select(card.FieldPassword).
// Scan(ctx, &v)
func (cq *CardQuery) Select(fields ...string) *CardSelect {
cq.ctx.Fields = append(cq.ctx.Fields, fields...)

View File

@@ -3,12 +3,12 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/card"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -28,6 +28,187 @@ func (cu *CardUpdate) Where(ps ...predicate.Card) *CardUpdate {
return cu
}
// SetCard sets the "card" field.
func (cu *CardUpdate) SetCard(i int) *CardUpdate {
cu.mutation.ResetCard()
cu.mutation.SetCard(i)
return cu
}
// SetNillableCard sets the "card" field if the given value is not nil.
func (cu *CardUpdate) SetNillableCard(i *int) *CardUpdate {
if i != nil {
cu.SetCard(*i)
}
return cu
}
// AddCard adds i to the "card" field.
func (cu *CardUpdate) AddCard(i int) *CardUpdate {
cu.mutation.AddCard(i)
return cu
}
// ClearCard clears the value of the "card" field.
func (cu *CardUpdate) ClearCard() *CardUpdate {
cu.mutation.ClearCard()
return cu
}
// SetSkill sets the "skill" field.
func (cu *CardUpdate) SetSkill(s string) *CardUpdate {
cu.mutation.SetSkill(s)
return cu
}
// SetNillableSkill sets the "skill" field if the given value is not nil.
func (cu *CardUpdate) SetNillableSkill(s *string) *CardUpdate {
if s != nil {
cu.SetSkill(*s)
}
return cu
}
// ClearSkill clears the value of the "skill" field.
func (cu *CardUpdate) ClearSkill() *CardUpdate {
cu.mutation.ClearSkill()
return cu
}
// SetStatus sets the "status" field.
func (cu *CardUpdate) SetStatus(s string) *CardUpdate {
cu.mutation.SetStatus(s)
return cu
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (cu *CardUpdate) SetNillableStatus(s *string) *CardUpdate {
if s != nil {
cu.SetStatus(*s)
}
return cu
}
// ClearStatus clears the value of the "status" field.
func (cu *CardUpdate) ClearStatus() *CardUpdate {
cu.mutation.ClearStatus()
return cu
}
// SetToken sets the "token" field.
func (cu *CardUpdate) SetToken(s string) *CardUpdate {
cu.mutation.SetToken(s)
return cu
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (cu *CardUpdate) SetNillableToken(s *string) *CardUpdate {
if s != nil {
cu.SetToken(*s)
}
return cu
}
// ClearToken clears the value of the "token" field.
func (cu *CardUpdate) ClearToken() *CardUpdate {
cu.mutation.ClearToken()
return cu
}
// SetCp sets the "cp" field.
func (cu *CardUpdate) SetCp(i int) *CardUpdate {
cu.mutation.ResetCp()
cu.mutation.SetCp(i)
return cu
}
// SetNillableCp sets the "cp" field if the given value is not nil.
func (cu *CardUpdate) SetNillableCp(i *int) *CardUpdate {
if i != nil {
cu.SetCp(*i)
}
return cu
}
// AddCp adds i to the "cp" field.
func (cu *CardUpdate) AddCp(i int) *CardUpdate {
cu.mutation.AddCp(i)
return cu
}
// ClearCp clears the value of the "cp" field.
func (cu *CardUpdate) ClearCp() *CardUpdate {
cu.mutation.ClearCp()
return cu
}
// SetURL sets the "url" field.
func (cu *CardUpdate) SetURL(s string) *CardUpdate {
cu.mutation.SetURL(s)
return cu
}
// SetNillableURL sets the "url" field if the given value is not nil.
func (cu *CardUpdate) SetNillableURL(s *string) *CardUpdate {
if s != nil {
cu.SetURL(*s)
}
return cu
}
// ClearURL clears the value of the "url" field.
func (cu *CardUpdate) ClearURL() *CardUpdate {
cu.mutation.ClearURL()
return cu
}
// SetCount sets the "count" field.
func (cu *CardUpdate) SetCount(i int) *CardUpdate {
cu.mutation.ResetCount()
cu.mutation.SetCount(i)
return cu
}
// SetNillableCount sets the "count" field if the given value is not nil.
func (cu *CardUpdate) SetNillableCount(i *int) *CardUpdate {
if i != nil {
cu.SetCount(*i)
}
return cu
}
// AddCount adds i to the "count" field.
func (cu *CardUpdate) AddCount(i int) *CardUpdate {
cu.mutation.AddCount(i)
return cu
}
// ClearCount clears the value of the "count" field.
func (cu *CardUpdate) ClearCount() *CardUpdate {
cu.mutation.ClearCount()
return cu
}
// SetAuthor sets the "author" field.
func (cu *CardUpdate) SetAuthor(s string) *CardUpdate {
cu.mutation.SetAuthor(s)
return cu
}
// SetNillableAuthor sets the "author" field if the given value is not nil.
func (cu *CardUpdate) SetNillableAuthor(s *string) *CardUpdate {
if s != nil {
cu.SetAuthor(*s)
}
return cu
}
// ClearAuthor clears the value of the "author" field.
func (cu *CardUpdate) ClearAuthor() *CardUpdate {
cu.mutation.ClearAuthor()
return cu
}
// SetOwnerID sets the "owner" edge to the User entity by ID.
func (cu *CardUpdate) SetOwnerID(id int) *CardUpdate {
cu.mutation.SetOwnerID(id)
@@ -97,18 +278,63 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) {
}
}
}
if value, ok := cu.mutation.Card(); ok {
_spec.SetField(card.FieldCard, field.TypeInt, value)
}
if value, ok := cu.mutation.AddedCard(); ok {
_spec.AddField(card.FieldCard, field.TypeInt, value)
}
if cu.mutation.CardCleared() {
_spec.ClearField(card.FieldCard, field.TypeInt)
}
if value, ok := cu.mutation.Skill(); ok {
_spec.SetField(card.FieldSkill, field.TypeString, value)
}
if cu.mutation.SkillCleared() {
_spec.ClearField(card.FieldSkill, field.TypeString)
}
if value, ok := cu.mutation.Status(); ok {
_spec.SetField(card.FieldStatus, field.TypeString, value)
}
if cu.mutation.StatusCleared() {
_spec.ClearField(card.FieldStatus, field.TypeString)
}
if value, ok := cu.mutation.Token(); ok {
_spec.SetField(card.FieldToken, field.TypeString, value)
}
if cu.mutation.TokenCleared() {
_spec.ClearField(card.FieldToken, field.TypeString)
}
if value, ok := cu.mutation.Cp(); ok {
_spec.SetField(card.FieldCp, field.TypeInt, value)
}
if value, ok := cu.mutation.AddedCp(); ok {
_spec.AddField(card.FieldCp, field.TypeInt, value)
}
if cu.mutation.CpCleared() {
_spec.ClearField(card.FieldCp, field.TypeInt)
}
if value, ok := cu.mutation.URL(); ok {
_spec.SetField(card.FieldURL, field.TypeString, value)
}
if cu.mutation.URLCleared() {
_spec.ClearField(card.FieldURL, field.TypeString)
}
if value, ok := cu.mutation.Count(); ok {
_spec.SetField(card.FieldCount, field.TypeInt, value)
}
if value, ok := cu.mutation.AddedCount(); ok {
_spec.AddField(card.FieldCount, field.TypeInt, value)
}
if cu.mutation.CountCleared() {
_spec.ClearField(card.FieldCount, field.TypeInt)
}
if value, ok := cu.mutation.Author(); ok {
_spec.SetField(card.FieldAuthor, field.TypeString, value)
}
if cu.mutation.AuthorCleared() {
_spec.ClearField(card.FieldAuthor, field.TypeString)
}
if cu.mutation.CreatedAtCleared() {
_spec.ClearField(card.FieldCreatedAt, field.TypeTime)
}
@@ -120,10 +346,7 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) {
Columns: []string{card.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
@@ -136,10 +359,7 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) {
Columns: []string{card.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
@@ -167,6 +387,187 @@ type CardUpdateOne struct {
mutation *CardMutation
}
// SetCard sets the "card" field.
func (cuo *CardUpdateOne) SetCard(i int) *CardUpdateOne {
cuo.mutation.ResetCard()
cuo.mutation.SetCard(i)
return cuo
}
// SetNillableCard sets the "card" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableCard(i *int) *CardUpdateOne {
if i != nil {
cuo.SetCard(*i)
}
return cuo
}
// AddCard adds i to the "card" field.
func (cuo *CardUpdateOne) AddCard(i int) *CardUpdateOne {
cuo.mutation.AddCard(i)
return cuo
}
// ClearCard clears the value of the "card" field.
func (cuo *CardUpdateOne) ClearCard() *CardUpdateOne {
cuo.mutation.ClearCard()
return cuo
}
// SetSkill sets the "skill" field.
func (cuo *CardUpdateOne) SetSkill(s string) *CardUpdateOne {
cuo.mutation.SetSkill(s)
return cuo
}
// SetNillableSkill sets the "skill" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableSkill(s *string) *CardUpdateOne {
if s != nil {
cuo.SetSkill(*s)
}
return cuo
}
// ClearSkill clears the value of the "skill" field.
func (cuo *CardUpdateOne) ClearSkill() *CardUpdateOne {
cuo.mutation.ClearSkill()
return cuo
}
// SetStatus sets the "status" field.
func (cuo *CardUpdateOne) SetStatus(s string) *CardUpdateOne {
cuo.mutation.SetStatus(s)
return cuo
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableStatus(s *string) *CardUpdateOne {
if s != nil {
cuo.SetStatus(*s)
}
return cuo
}
// ClearStatus clears the value of the "status" field.
func (cuo *CardUpdateOne) ClearStatus() *CardUpdateOne {
cuo.mutation.ClearStatus()
return cuo
}
// SetToken sets the "token" field.
func (cuo *CardUpdateOne) SetToken(s string) *CardUpdateOne {
cuo.mutation.SetToken(s)
return cuo
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableToken(s *string) *CardUpdateOne {
if s != nil {
cuo.SetToken(*s)
}
return cuo
}
// ClearToken clears the value of the "token" field.
func (cuo *CardUpdateOne) ClearToken() *CardUpdateOne {
cuo.mutation.ClearToken()
return cuo
}
// SetCp sets the "cp" field.
func (cuo *CardUpdateOne) SetCp(i int) *CardUpdateOne {
cuo.mutation.ResetCp()
cuo.mutation.SetCp(i)
return cuo
}
// SetNillableCp sets the "cp" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableCp(i *int) *CardUpdateOne {
if i != nil {
cuo.SetCp(*i)
}
return cuo
}
// AddCp adds i to the "cp" field.
func (cuo *CardUpdateOne) AddCp(i int) *CardUpdateOne {
cuo.mutation.AddCp(i)
return cuo
}
// ClearCp clears the value of the "cp" field.
func (cuo *CardUpdateOne) ClearCp() *CardUpdateOne {
cuo.mutation.ClearCp()
return cuo
}
// SetURL sets the "url" field.
func (cuo *CardUpdateOne) SetURL(s string) *CardUpdateOne {
cuo.mutation.SetURL(s)
return cuo
}
// SetNillableURL sets the "url" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableURL(s *string) *CardUpdateOne {
if s != nil {
cuo.SetURL(*s)
}
return cuo
}
// ClearURL clears the value of the "url" field.
func (cuo *CardUpdateOne) ClearURL() *CardUpdateOne {
cuo.mutation.ClearURL()
return cuo
}
// SetCount sets the "count" field.
func (cuo *CardUpdateOne) SetCount(i int) *CardUpdateOne {
cuo.mutation.ResetCount()
cuo.mutation.SetCount(i)
return cuo
}
// SetNillableCount sets the "count" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableCount(i *int) *CardUpdateOne {
if i != nil {
cuo.SetCount(*i)
}
return cuo
}
// AddCount adds i to the "count" field.
func (cuo *CardUpdateOne) AddCount(i int) *CardUpdateOne {
cuo.mutation.AddCount(i)
return cuo
}
// ClearCount clears the value of the "count" field.
func (cuo *CardUpdateOne) ClearCount() *CardUpdateOne {
cuo.mutation.ClearCount()
return cuo
}
// SetAuthor sets the "author" field.
func (cuo *CardUpdateOne) SetAuthor(s string) *CardUpdateOne {
cuo.mutation.SetAuthor(s)
return cuo
}
// SetNillableAuthor sets the "author" field if the given value is not nil.
func (cuo *CardUpdateOne) SetNillableAuthor(s *string) *CardUpdateOne {
if s != nil {
cuo.SetAuthor(*s)
}
return cuo
}
// ClearAuthor clears the value of the "author" field.
func (cuo *CardUpdateOne) ClearAuthor() *CardUpdateOne {
cuo.mutation.ClearAuthor()
return cuo
}
// SetOwnerID sets the "owner" edge to the User entity by ID.
func (cuo *CardUpdateOne) SetOwnerID(id int) *CardUpdateOne {
cuo.mutation.SetOwnerID(id)
@@ -266,18 +667,63 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (_node *Card, err error)
}
}
}
if value, ok := cuo.mutation.Card(); ok {
_spec.SetField(card.FieldCard, field.TypeInt, value)
}
if value, ok := cuo.mutation.AddedCard(); ok {
_spec.AddField(card.FieldCard, field.TypeInt, value)
}
if cuo.mutation.CardCleared() {
_spec.ClearField(card.FieldCard, field.TypeInt)
}
if value, ok := cuo.mutation.Skill(); ok {
_spec.SetField(card.FieldSkill, field.TypeString, value)
}
if cuo.mutation.SkillCleared() {
_spec.ClearField(card.FieldSkill, field.TypeString)
}
if value, ok := cuo.mutation.Status(); ok {
_spec.SetField(card.FieldStatus, field.TypeString, value)
}
if cuo.mutation.StatusCleared() {
_spec.ClearField(card.FieldStatus, field.TypeString)
}
if value, ok := cuo.mutation.Token(); ok {
_spec.SetField(card.FieldToken, field.TypeString, value)
}
if cuo.mutation.TokenCleared() {
_spec.ClearField(card.FieldToken, field.TypeString)
}
if value, ok := cuo.mutation.Cp(); ok {
_spec.SetField(card.FieldCp, field.TypeInt, value)
}
if value, ok := cuo.mutation.AddedCp(); ok {
_spec.AddField(card.FieldCp, field.TypeInt, value)
}
if cuo.mutation.CpCleared() {
_spec.ClearField(card.FieldCp, field.TypeInt)
}
if value, ok := cuo.mutation.URL(); ok {
_spec.SetField(card.FieldURL, field.TypeString, value)
}
if cuo.mutation.URLCleared() {
_spec.ClearField(card.FieldURL, field.TypeString)
}
if value, ok := cuo.mutation.Count(); ok {
_spec.SetField(card.FieldCount, field.TypeInt, value)
}
if value, ok := cuo.mutation.AddedCount(); ok {
_spec.AddField(card.FieldCount, field.TypeInt, value)
}
if cuo.mutation.CountCleared() {
_spec.ClearField(card.FieldCount, field.TypeInt)
}
if value, ok := cuo.mutation.Author(); ok {
_spec.SetField(card.FieldAuthor, field.TypeString, value)
}
if cuo.mutation.AuthorCleared() {
_spec.ClearField(card.FieldAuthor, field.TypeString)
}
if cuo.mutation.CreatedAtCleared() {
_spec.ClearField(card.FieldCreatedAt, field.TypeTime)
}
@@ -289,10 +735,7 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (_node *Card, err error)
Columns: []string{card.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
@@ -305,10 +748,7 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (_node *Card, err error)
Columns: []string{card.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {

View File

@@ -8,11 +8,13 @@ import (
"fmt"
"log"
"t/ent/migrate"
"api/ent/migrate"
"t/ent/card"
"t/ent/group"
"t/ent/user"
"api/ent/card"
"api/ent/group"
"api/ent/ma"
"api/ent/ue"
"api/ent/user"
"entgo.io/ent"
"entgo.io/ent/dialect"
@@ -29,6 +31,10 @@ type Client struct {
Card *CardClient
// Group is the client for interacting with the Group builders.
Group *GroupClient
// Ma is the client for interacting with the Ma builders.
Ma *MaClient
// Ue is the client for interacting with the Ue builders.
Ue *UeClient
// User is the client for interacting with the User builders.
User *UserClient
}
@@ -46,6 +52,8 @@ func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.Card = NewCardClient(c.config)
c.Group = NewGroupClient(c.config)
c.Ma = NewMaClient(c.config)
c.Ue = NewUeClient(c.config)
c.User = NewUserClient(c.config)
}
@@ -131,6 +139,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
config: cfg,
Card: NewCardClient(cfg),
Group: NewGroupClient(cfg),
Ma: NewMaClient(cfg),
Ue: NewUeClient(cfg),
User: NewUserClient(cfg),
}, nil
}
@@ -153,6 +163,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
config: cfg,
Card: NewCardClient(cfg),
Group: NewGroupClient(cfg),
Ma: NewMaClient(cfg),
Ue: NewUeClient(cfg),
User: NewUserClient(cfg),
}, nil
}
@@ -184,6 +196,8 @@ func (c *Client) Close() error {
func (c *Client) Use(hooks ...Hook) {
c.Card.Use(hooks...)
c.Group.Use(hooks...)
c.Ma.Use(hooks...)
c.Ue.Use(hooks...)
c.User.Use(hooks...)
}
@@ -192,6 +206,8 @@ func (c *Client) Use(hooks ...Hook) {
func (c *Client) Intercept(interceptors ...Interceptor) {
c.Card.Intercept(interceptors...)
c.Group.Intercept(interceptors...)
c.Ma.Intercept(interceptors...)
c.Ue.Intercept(interceptors...)
c.User.Intercept(interceptors...)
}
@@ -202,6 +218,10 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.Card.mutate(ctx, m)
case *GroupMutation:
return c.Group.mutate(ctx, m)
case *MaMutation:
return c.Ma.mutate(ctx, m)
case *UeMutation:
return c.Ue.mutate(ctx, m)
case *UserMutation:
return c.User.mutate(ctx, m)
default:
@@ -477,6 +497,274 @@ func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, erro
}
}
// MaClient is a client for the Ma schema.
type MaClient struct {
config
}
// NewMaClient returns a client for the Ma from the given config.
func NewMaClient(c config) *MaClient {
return &MaClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `ma.Hooks(f(g(h())))`.
func (c *MaClient) Use(hooks ...Hook) {
c.hooks.Ma = append(c.hooks.Ma, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `ma.Intercept(f(g(h())))`.
func (c *MaClient) Intercept(interceptors ...Interceptor) {
c.inters.Ma = append(c.inters.Ma, interceptors...)
}
// Create returns a builder for creating a Ma entity.
func (c *MaClient) Create() *MaCreate {
mutation := newMaMutation(c.config, OpCreate)
return &MaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Ma entities.
func (c *MaClient) CreateBulk(builders ...*MaCreate) *MaCreateBulk {
return &MaCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Ma.
func (c *MaClient) Update() *MaUpdate {
mutation := newMaMutation(c.config, OpUpdate)
return &MaUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *MaClient) UpdateOne(m *Ma) *MaUpdateOne {
mutation := newMaMutation(c.config, OpUpdateOne, withMa(m))
return &MaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *MaClient) UpdateOneID(id int) *MaUpdateOne {
mutation := newMaMutation(c.config, OpUpdateOne, withMaID(id))
return &MaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Ma.
func (c *MaClient) Delete() *MaDelete {
mutation := newMaMutation(c.config, OpDelete)
return &MaDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *MaClient) DeleteOne(m *Ma) *MaDeleteOne {
return c.DeleteOneID(m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *MaClient) DeleteOneID(id int) *MaDeleteOne {
builder := c.Delete().Where(ma.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &MaDeleteOne{builder}
}
// Query returns a query builder for Ma.
func (c *MaClient) Query() *MaQuery {
return &MaQuery{
config: c.config,
ctx: &QueryContext{Type: TypeMa},
inters: c.Interceptors(),
}
}
// Get returns a Ma entity by its id.
func (c *MaClient) Get(ctx context.Context, id int) (*Ma, error) {
return c.Query().Where(ma.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *MaClient) GetX(ctx context.Context, id int) *Ma {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryOwner queries the owner edge of a Ma.
func (c *MaClient) QueryOwner(m *Ma) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := m.ID
step := sqlgraph.NewStep(
sqlgraph.From(ma.Table, ma.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, ma.OwnerTable, ma.OwnerColumn),
)
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *MaClient) Hooks() []Hook {
return c.hooks.Ma
}
// Interceptors returns the client interceptors.
func (c *MaClient) Interceptors() []Interceptor {
return c.inters.Ma
}
func (c *MaClient) mutate(ctx context.Context, m *MaMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&MaCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&MaUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&MaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&MaDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Ma mutation op: %q", m.Op())
}
}
// UeClient is a client for the Ue schema.
type UeClient struct {
config
}
// NewUeClient returns a client for the Ue from the given config.
func NewUeClient(c config) *UeClient {
return &UeClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `ue.Hooks(f(g(h())))`.
func (c *UeClient) Use(hooks ...Hook) {
c.hooks.Ue = append(c.hooks.Ue, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `ue.Intercept(f(g(h())))`.
func (c *UeClient) Intercept(interceptors ...Interceptor) {
c.inters.Ue = append(c.inters.Ue, interceptors...)
}
// Create returns a builder for creating a Ue entity.
func (c *UeClient) Create() *UeCreate {
mutation := newUeMutation(c.config, OpCreate)
return &UeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Ue entities.
func (c *UeClient) CreateBulk(builders ...*UeCreate) *UeCreateBulk {
return &UeCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Ue.
func (c *UeClient) Update() *UeUpdate {
mutation := newUeMutation(c.config, OpUpdate)
return &UeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *UeClient) UpdateOne(u *Ue) *UeUpdateOne {
mutation := newUeMutation(c.config, OpUpdateOne, withUe(u))
return &UeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *UeClient) UpdateOneID(id int) *UeUpdateOne {
mutation := newUeMutation(c.config, OpUpdateOne, withUeID(id))
return &UeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Ue.
func (c *UeClient) Delete() *UeDelete {
mutation := newUeMutation(c.config, OpDelete)
return &UeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *UeClient) DeleteOne(u *Ue) *UeDeleteOne {
return c.DeleteOneID(u.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *UeClient) DeleteOneID(id int) *UeDeleteOne {
builder := c.Delete().Where(ue.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &UeDeleteOne{builder}
}
// Query returns a query builder for Ue.
func (c *UeClient) Query() *UeQuery {
return &UeQuery{
config: c.config,
ctx: &QueryContext{Type: TypeUe},
inters: c.Interceptors(),
}
}
// Get returns a Ue entity by its id.
func (c *UeClient) Get(ctx context.Context, id int) (*Ue, error) {
return c.Query().Where(ue.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *UeClient) GetX(ctx context.Context, id int) *Ue {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryOwner queries the owner edge of a Ue.
func (c *UeClient) QueryOwner(u *Ue) *UserQuery {
query := (&UserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := u.ID
step := sqlgraph.NewStep(
sqlgraph.From(ue.Table, ue.FieldID, id),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, ue.OwnerTable, ue.OwnerColumn),
)
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *UeClient) Hooks() []Hook {
return c.hooks.Ue
}
// Interceptors returns the client interceptors.
func (c *UeClient) Interceptors() []Interceptor {
return c.inters.Ue
}
func (c *UeClient) mutate(ctx context.Context, m *UeMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&UeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&UeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&UeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&UeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Ue mutation op: %q", m.Op())
}
}
// UserClient is a client for the User schema.
type UserClient struct {
config
@@ -586,6 +874,38 @@ func (c *UserClient) QueryCard(u *User) *CardQuery {
return query
}
// QueryUe queries the ue edge of a User.
func (c *UserClient) QueryUe(u *User) *UeQuery {
query := (&UeClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := u.ID
step := sqlgraph.NewStep(
sqlgraph.From(user.Table, user.FieldID, id),
sqlgraph.To(ue.Table, ue.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, user.UeTable, user.UeColumn),
)
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryMa queries the ma edge of a User.
func (c *UserClient) QueryMa(u *User) *MaQuery {
query := (&MaClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := u.ID
step := sqlgraph.NewStep(
sqlgraph.From(user.Table, user.FieldID, id),
sqlgraph.To(ma.Table, ma.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, user.MaTable, user.MaColumn),
)
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *UserClient) Hooks() []Hook {
return c.hooks.User
@@ -614,9 +934,9 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error)
// hooks and interceptors per client, for fast access.
type (
hooks struct {
Card, Group, User []ent.Hook
Card, Group, Ma, Ue, User []ent.Hook
}
inters struct {
Card, Group, User []ent.Interceptor
Card, Group, Ma, Ue, User []ent.Interceptor
}
)

View File

@@ -3,13 +3,16 @@
package ent
import (
"api/ent/card"
"api/ent/group"
"api/ent/ma"
"api/ent/ue"
"api/ent/user"
"context"
"errors"
"fmt"
"reflect"
"t/ent/card"
"t/ent/group"
"t/ent/user"
"sync"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
@@ -62,35 +65,33 @@ func NewTxContext(parent context.Context, tx *Tx) context.Context {
}
// OrderFunc applies an ordering on the sql selector.
// Deprecated: Use Asc/Desc functions or the package builders instead.
type OrderFunc func(*sql.Selector)
// columnChecker returns a function indicates if the column exists in the given column.
func columnChecker(table string) func(string) error {
checks := map[string]func(string) bool{
card.Table: card.ValidColumn,
group.Table: group.ValidColumn,
user.Table: user.ValidColumn,
}
check, ok := checks[table]
if !ok {
return func(string) error {
return fmt.Errorf("unknown table %q", table)
}
}
return func(column string) error {
if !check(column) {
return fmt.Errorf("unknown column %q for table %q", column, table)
}
return nil
}
var (
initCheck sync.Once
columnCheck sql.ColumnCheck
)
// columnChecker 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{
card.Table: card.ValidColumn,
group.Table: group.ValidColumn,
ma.Table: ma.ValidColumn,
ue.Table: ue.ValidColumn,
user.Table: user.ValidColumn,
})
})
return columnCheck(table, column)
}
// Asc applies the given fields in ASC order.
func Asc(fields ...string) OrderFunc {
func Asc(fields ...string) func(*sql.Selector) {
return func(s *sql.Selector) {
check := columnChecker(s.TableName())
for _, f := range fields {
if err := check(f); err != nil {
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)))
@@ -99,11 +100,10 @@ func Asc(fields ...string) OrderFunc {
}
// Desc applies the given fields in DESC order.
func Desc(fields ...string) OrderFunc {
func Desc(fields ...string) func(*sql.Selector) {
return func(s *sql.Selector) {
check := columnChecker(s.TableName())
for _, f := range fields {
if err := check(f); err != nil {
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)))
@@ -135,8 +135,7 @@ func Count() AggregateFunc {
// Max applies the "max" aggregation function on the given field of each group.
func Max(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
@@ -147,8 +146,7 @@ func Max(field string) AggregateFunc {
// Mean applies the "mean" aggregation function on the given field of each group.
func Mean(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
@@ -159,8 +157,7 @@ func Mean(field string) AggregateFunc {
// Min applies the "min" aggregation function on the given field of each group.
func Min(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
@@ -171,8 +168,7 @@ func Min(field string) AggregateFunc {
// Sum applies the "sum" aggregation function on the given field of each group.
func Sum(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
@@ -509,7 +505,7 @@ func withHooks[V Value, M any, PM interface {
return exec(ctx)
}
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutationT, ok := m.(PM)
mutationT, ok := any(m).(PM)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}

View File

@@ -3,12 +3,12 @@
package enttest
import (
"api/ent"
"context"
"t/ent"
// required by schema hooks.
_ "t/ent/runtime"
_ "api/ent/runtime"
"t/ent/migrate"
"api/ent/migrate"
"entgo.io/ent/dialect/sql/schema"
)

View File

@@ -3,10 +3,11 @@
package ent
import (
"api/ent/group"
"fmt"
"strings"
"t/ent/group"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
@@ -17,9 +18,12 @@ type Group struct {
ID int `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"-"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the GroupQuery when eager-loading is set.
Edges GroupEdges `json:"edges"`
Edges GroupEdges `json:"edges"`
selectValues sql.SelectValues
}
// GroupEdges holds the relations/edges for other nodes in the graph.
@@ -47,10 +51,10 @@ func (*Group) scanValues(columns []string) ([]any, error) {
switch columns[i] {
case group.FieldID:
values[i] = new(sql.NullInt64)
case group.FieldName:
case group.FieldName, group.FieldPassword:
values[i] = new(sql.NullString)
default:
return nil, fmt.Errorf("unexpected column %q for type Group", columns[i])
values[i] = new(sql.UnknownType)
}
}
return values, nil
@@ -76,11 +80,25 @@ func (gr *Group) assignValues(columns []string, values []any) error {
} else if value.Valid {
gr.Name = value.String
}
case group.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
gr.Password = value.String
}
default:
gr.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Group.
// This includes values selected through modifiers, order, etc.
func (gr *Group) Value(name string) (ent.Value, error) {
return gr.selectValues.Get(name)
}
// QueryUsers queries the "users" edge of the Group entity.
func (gr *Group) QueryUsers() *UserQuery {
return NewGroupClient(gr.config).QueryUsers(gr)
@@ -111,6 +129,8 @@ func (gr *Group) String() string {
builder.WriteString(fmt.Sprintf("id=%v, ", gr.ID))
builder.WriteString("name=")
builder.WriteString(gr.Name)
builder.WriteString(", ")
builder.WriteString("password=<sensitive>")
builder.WriteByte(')')
return builder.String()
}

View File

@@ -2,6 +2,11 @@
package group
import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the group type in the database.
Label = "group"
@@ -9,6 +14,8 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// EdgeUsers holds the string denoting the users edge name in mutations.
EdgeUsers = "users"
// Table holds the table name of the group in the database.
@@ -26,6 +33,7 @@ const (
var Columns = []string{
FieldID,
FieldName,
FieldPassword,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -37,3 +45,47 @@ func ValidColumn(column string) bool {
}
return false
}
var (
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
PasswordValidator func(string) error
)
// OrderOption defines the ordering options for the Group 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()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByUsersCount orders the results by users count.
func ByUsersCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newUsersStep(), opts...)
}
}
// ByUsers orders the results by users terms.
func ByUsers(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newUsersStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newUsersStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UsersInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, UsersTable, UsersColumn),
)
}

View File

@@ -3,7 +3,7 @@
package group
import (
"t/ent/predicate"
"api/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -59,6 +59,11 @@ func Name(v string) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldName, v))
}
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
func Password(v string) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldPassword, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldName, v))
@@ -124,6 +129,71 @@ func NameContainsFold(v string) predicate.Group {
return predicate.Group(sql.FieldContainsFold(FieldName, v))
}
// PasswordEQ applies the EQ predicate on the "password" field.
func PasswordEQ(v string) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldPassword, v))
}
// PasswordNEQ applies the NEQ predicate on the "password" field.
func PasswordNEQ(v string) predicate.Group {
return predicate.Group(sql.FieldNEQ(FieldPassword, v))
}
// PasswordIn applies the In predicate on the "password" field.
func PasswordIn(vs ...string) predicate.Group {
return predicate.Group(sql.FieldIn(FieldPassword, vs...))
}
// PasswordNotIn applies the NotIn predicate on the "password" field.
func PasswordNotIn(vs ...string) predicate.Group {
return predicate.Group(sql.FieldNotIn(FieldPassword, vs...))
}
// PasswordGT applies the GT predicate on the "password" field.
func PasswordGT(v string) predicate.Group {
return predicate.Group(sql.FieldGT(FieldPassword, v))
}
// PasswordGTE applies the GTE predicate on the "password" field.
func PasswordGTE(v string) predicate.Group {
return predicate.Group(sql.FieldGTE(FieldPassword, v))
}
// PasswordLT applies the LT predicate on the "password" field.
func PasswordLT(v string) predicate.Group {
return predicate.Group(sql.FieldLT(FieldPassword, v))
}
// PasswordLTE applies the LTE predicate on the "password" field.
func PasswordLTE(v string) predicate.Group {
return predicate.Group(sql.FieldLTE(FieldPassword, v))
}
// PasswordContains applies the Contains predicate on the "password" field.
func PasswordContains(v string) predicate.Group {
return predicate.Group(sql.FieldContains(FieldPassword, v))
}
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
func PasswordHasPrefix(v string) predicate.Group {
return predicate.Group(sql.FieldHasPrefix(FieldPassword, v))
}
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
func PasswordHasSuffix(v string) predicate.Group {
return predicate.Group(sql.FieldHasSuffix(FieldPassword, v))
}
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
func PasswordEqualFold(v string) predicate.Group {
return predicate.Group(sql.FieldEqualFold(FieldPassword, v))
}
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
func PasswordContainsFold(v string) predicate.Group {
return predicate.Group(sql.FieldContainsFold(FieldPassword, v))
}
// HasUsers applies the HasEdge predicate on the "users" edge.
func HasUsers() predicate.Group {
return predicate.Group(func(s *sql.Selector) {
@@ -138,11 +208,7 @@ func HasUsers() predicate.Group {
// HasUsersWith applies the HasEdge predicate on the "users" edge with a given conditions (other predicates).
func HasUsersWith(preds ...predicate.User) predicate.Group {
return predicate.Group(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UsersInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, UsersTable, UsersColumn),
)
step := newUsersStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)

View File

@@ -3,11 +3,11 @@
package ent
import (
"api/ent/group"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/group"
"t/ent/user"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
@@ -26,6 +26,12 @@ func (gc *GroupCreate) SetName(s string) *GroupCreate {
return gc
}
// SetPassword sets the "password" field.
func (gc *GroupCreate) SetPassword(s string) *GroupCreate {
gc.mutation.SetPassword(s)
return gc
}
// AddUserIDs adds the "users" edge to the User entity by IDs.
func (gc *GroupCreate) AddUserIDs(ids ...int) *GroupCreate {
gc.mutation.AddUserIDs(ids...)
@@ -78,6 +84,14 @@ func (gc *GroupCreate) check() error {
if _, ok := gc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Group.name"`)}
}
if _, ok := gc.mutation.Password(); !ok {
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Group.password"`)}
}
if v, ok := gc.mutation.Password(); ok {
if err := group.PasswordValidator(v); err != nil {
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Group.password": %w`, err)}
}
}
return nil
}
@@ -108,6 +122,10 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec.SetField(group.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := gc.mutation.Password(); ok {
_spec.SetField(group.FieldPassword, field.TypeString, value)
_node.Password = value
}
if nodes := gc.mutation.UsersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -116,10 +134,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
Columns: []string{group.UsersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
@@ -153,8 +168,8 @@ func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) {
return nil, err
}
builder.mutation = mutation
nodes[i], specs[i] = builder.createSpec()
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, gcb.builders[i+1].mutation)
} else {

View File

@@ -3,9 +3,9 @@
package ent
import (
"api/ent/group"
"api/ent/predicate"
"context"
"t/ent/group"
"t/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@@ -3,13 +3,13 @@
package ent
import (
"api/ent/group"
"api/ent/predicate"
"api/ent/user"
"context"
"database/sql/driver"
"fmt"
"math"
"t/ent/group"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -20,7 +20,7 @@ import (
type GroupQuery struct {
config
ctx *QueryContext
order []OrderFunc
order []group.OrderOption
inters []Interceptor
predicates []predicate.Group
withUsers *UserQuery
@@ -55,7 +55,7 @@ func (gq *GroupQuery) Unique(unique bool) *GroupQuery {
}
// Order specifies how the records should be ordered.
func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery {
func (gq *GroupQuery) Order(o ...group.OrderOption) *GroupQuery {
gq.order = append(gq.order, o...)
return gq
}
@@ -271,7 +271,7 @@ func (gq *GroupQuery) Clone() *GroupQuery {
return &GroupQuery{
config: gq.config,
ctx: gq.ctx.Clone(),
order: append([]OrderFunc{}, gq.order...),
order: append([]group.OrderOption{}, gq.order...),
inters: append([]Interceptor{}, gq.inters...),
predicates: append([]predicate.Group{}, gq.predicates...),
withUsers: gq.withUsers.Clone(),
@@ -414,7 +414,7 @@ func (gq *GroupQuery) loadUsers(ctx context.Context, query *UserQuery, nodes []*
}
query.withFKs = true
query.Where(predicate.User(func(s *sql.Selector) {
s.Where(sql.InValues(group.UsersColumn, fks...))
s.Where(sql.InValues(s.C(group.UsersColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
@@ -427,7 +427,7 @@ func (gq *GroupQuery) loadUsers(ctx context.Context, query *UserQuery, nodes []*
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected foreign-key "group_users" returned %v for node %v`, *fk, n.ID)
return fmt.Errorf(`unexpected referenced foreign-key "group_users" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}

View File

@@ -3,12 +3,12 @@
package ent
import (
"api/ent/group"
"api/ent/predicate"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/group"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -122,10 +122,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
Columns: []string{group.UsersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
@@ -138,10 +135,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
Columns: []string{group.UsersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
@@ -157,10 +151,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
Columns: []string{group.UsersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
@@ -312,10 +303,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error
Columns: []string{group.UsersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
@@ -328,10 +316,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error
Columns: []string{group.UsersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
@@ -347,10 +332,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error
Columns: []string{group.UsersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {

View File

@@ -3,9 +3,9 @@
package hook
import (
"api/ent"
"context"
"fmt"
"t/ent"
)
// The CardFunc type is an adapter to allow the use of ordinary
@@ -32,6 +32,30 @@ func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m)
}
// The MaFunc type is an adapter to allow the use of ordinary
// function as Ma mutator.
type MaFunc func(context.Context, *ent.MaMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f MaFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.MaMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MaMutation", m)
}
// The UeFunc type is an adapter to allow the use of ordinary
// function as Ue mutator.
type UeFunc func(context.Context, *ent.UeMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f UeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.UeMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UeMutation", m)
}
// The UserFunc type is an adapter to allow the use of ordinary
// function as User mutator.
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)

290
ent/ma.go Normal file
View File

@@ -0,0 +1,290 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"api/ent/ma"
"api/ent/user"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Ma is the model entity for the Ma schema.
type Ma struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"-"`
// Token holds the value of the "token" field.
Token string `json:"-"`
// Limit holds the value of the "limit" field.
Limit bool `json:"limit,omitempty"`
// Count holds the value of the "count" field.
Count int `json:"count,omitempty"`
// Handle holds the value of the "handle" field.
Handle string `json:"handle,omitempty"`
// Text holds the value of the "text" field.
Text string `json:"text,omitempty"`
// Did holds the value of the "did" field.
Did string `json:"did,omitempty"`
// Avatar holds the value of the "avatar" field.
Avatar string `json:"avatar,omitempty"`
// Cid holds the value of the "cid" field.
Cid string `json:"cid,omitempty"`
// URI holds the value of the "uri" field.
URI string `json:"uri,omitempty"`
// Rkey holds the value of the "rkey" field.
Rkey string `json:"rkey,omitempty"`
// BskyURL holds the value of the "bsky_url" field.
BskyURL string `json:"bsky_url,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the MaQuery when eager-loading is set.
Edges MaEdges `json:"edges"`
user_ma *int
selectValues sql.SelectValues
}
// MaEdges holds the relations/edges for other nodes in the graph.
type MaEdges struct {
// Owner holds the value of the owner edge.
Owner *User `json:"owner,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e MaEdges) OwnerOrErr() (*User, error) {
if e.loadedTypes[0] {
if e.Owner == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: user.Label}
}
return e.Owner, nil
}
return nil, &NotLoadedError{edge: "owner"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Ma) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case ma.FieldLimit:
values[i] = new(sql.NullBool)
case ma.FieldID, ma.FieldCount:
values[i] = new(sql.NullInt64)
case ma.FieldPassword, ma.FieldToken, ma.FieldHandle, ma.FieldText, ma.FieldDid, ma.FieldAvatar, ma.FieldCid, ma.FieldURI, ma.FieldRkey, ma.FieldBskyURL:
values[i] = new(sql.NullString)
case ma.FieldUpdatedAt, ma.FieldCreatedAt:
values[i] = new(sql.NullTime)
case ma.ForeignKeys[0]: // user_ma
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Ma fields.
func (m *Ma) 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 ma.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
m.ID = int(value.Int64)
case ma.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
m.Password = value.String
}
case ma.FieldToken:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field token", values[i])
} else if value.Valid {
m.Token = value.String
}
case ma.FieldLimit:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field limit", values[i])
} else if value.Valid {
m.Limit = value.Bool
}
case ma.FieldCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field count", values[i])
} else if value.Valid {
m.Count = int(value.Int64)
}
case ma.FieldHandle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field handle", values[i])
} else if value.Valid {
m.Handle = value.String
}
case ma.FieldText:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field text", values[i])
} else if value.Valid {
m.Text = value.String
}
case ma.FieldDid:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field did", values[i])
} else if value.Valid {
m.Did = value.String
}
case ma.FieldAvatar:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field avatar", values[i])
} else if value.Valid {
m.Avatar = value.String
}
case ma.FieldCid:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field cid", values[i])
} else if value.Valid {
m.Cid = value.String
}
case ma.FieldURI:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field uri", values[i])
} else if value.Valid {
m.URI = value.String
}
case ma.FieldRkey:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field rkey", values[i])
} else if value.Valid {
m.Rkey = value.String
}
case ma.FieldBskyURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field bsky_url", values[i])
} else if value.Valid {
m.BskyURL = value.String
}
case ma.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
m.UpdatedAt = value.Time
}
case ma.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
m.CreatedAt = value.Time
}
case ma.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field user_ma", value)
} else if value.Valid {
m.user_ma = new(int)
*m.user_ma = 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 Ma.
// This includes values selected through modifiers, order, etc.
func (m *Ma) Value(name string) (ent.Value, error) {
return m.selectValues.Get(name)
}
// QueryOwner queries the "owner" edge of the Ma entity.
func (m *Ma) QueryOwner() *UserQuery {
return NewMaClient(m.config).QueryOwner(m)
}
// Update returns a builder for updating this Ma.
// Note that you need to call Ma.Unwrap() before calling this method if this Ma
// was returned from a transaction, and the transaction was committed or rolled back.
func (m *Ma) Update() *MaUpdateOne {
return NewMaClient(m.config).UpdateOne(m)
}
// Unwrap unwraps the Ma 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 *Ma) Unwrap() *Ma {
_tx, ok := m.config.driver.(*txDriver)
if !ok {
panic("ent: Ma is not a transactional entity")
}
m.config.driver = _tx.drv
return m
}
// String implements the fmt.Stringer.
func (m *Ma) String() string {
var builder strings.Builder
builder.WriteString("Ma(")
builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
builder.WriteString("password=<sensitive>")
builder.WriteString(", ")
builder.WriteString("token=<sensitive>")
builder.WriteString(", ")
builder.WriteString("limit=")
builder.WriteString(fmt.Sprintf("%v", m.Limit))
builder.WriteString(", ")
builder.WriteString("count=")
builder.WriteString(fmt.Sprintf("%v", m.Count))
builder.WriteString(", ")
builder.WriteString("handle=")
builder.WriteString(m.Handle)
builder.WriteString(", ")
builder.WriteString("text=")
builder.WriteString(m.Text)
builder.WriteString(", ")
builder.WriteString("did=")
builder.WriteString(m.Did)
builder.WriteString(", ")
builder.WriteString("avatar=")
builder.WriteString(m.Avatar)
builder.WriteString(", ")
builder.WriteString("cid=")
builder.WriteString(m.Cid)
builder.WriteString(", ")
builder.WriteString("uri=")
builder.WriteString(m.URI)
builder.WriteString(", ")
builder.WriteString("rkey=")
builder.WriteString(m.Rkey)
builder.WriteString(", ")
builder.WriteString("bsky_url=")
builder.WriteString(m.BskyURL)
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(m.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Mas is a parsable slice of Ma.
type Mas []*Ma

197
ent/ma/ma.go Normal file
View File

@@ -0,0 +1,197 @@
// Code generated by ent, DO NOT EDIT.
package ma
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the ma type in the database.
Label = "ma"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// FieldToken holds the string denoting the token field in the database.
FieldToken = "token"
// FieldLimit holds the string denoting the limit field in the database.
FieldLimit = "limit"
// FieldCount holds the string denoting the count field in the database.
FieldCount = "count"
// FieldHandle holds the string denoting the handle field in the database.
FieldHandle = "handle"
// FieldText holds the string denoting the text field in the database.
FieldText = "text"
// FieldDid holds the string denoting the did field in the database.
FieldDid = "did"
// FieldAvatar holds the string denoting the avatar field in the database.
FieldAvatar = "avatar"
// FieldCid holds the string denoting the cid field in the database.
FieldCid = "cid"
// FieldURI holds the string denoting the uri field in the database.
FieldURI = "uri"
// FieldRkey holds the string denoting the rkey field in the database.
FieldRkey = "rkey"
// FieldBskyURL holds the string denoting the bsky_url field in the database.
FieldBskyURL = "bsky_url"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// EdgeOwner holds the string denoting the owner edge name in mutations.
EdgeOwner = "owner"
// Table holds the table name of the ma in the database.
Table = "mas"
// OwnerTable is the table that holds the owner relation/edge.
OwnerTable = "mas"
// OwnerInverseTable is the table name for the User entity.
// It exists in this package in order to avoid circular dependency with the "user" package.
OwnerInverseTable = "users"
// OwnerColumn is the table column denoting the owner relation/edge.
OwnerColumn = "user_ma"
)
// Columns holds all SQL columns for ma fields.
var Columns = []string{
FieldID,
FieldPassword,
FieldToken,
FieldLimit,
FieldCount,
FieldHandle,
FieldText,
FieldDid,
FieldAvatar,
FieldCid,
FieldURI,
FieldRkey,
FieldBskyURL,
FieldUpdatedAt,
FieldCreatedAt,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "mas"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"user_ma",
}
// 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
}
}
for i := range ForeignKeys {
if column == ForeignKeys[i] {
return true
}
}
return false
}
var (
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
PasswordValidator func(string) error
// DefaultLimit holds the default value on creation for the "limit" field.
DefaultLimit bool
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
// OrderOption defines the ordering options for the Ma 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()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByToken orders the results by the token field.
func ByToken(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldToken, opts...).ToFunc()
}
// ByLimit orders the results by the limit field.
func ByLimit(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLimit, opts...).ToFunc()
}
// ByCount orders the results by the count field.
func ByCount(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCount, opts...).ToFunc()
}
// ByHandle orders the results by the handle field.
func ByHandle(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldHandle, opts...).ToFunc()
}
// ByText orders the results by the text field.
func ByText(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldText, opts...).ToFunc()
}
// ByDid orders the results by the did field.
func ByDid(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDid, opts...).ToFunc()
}
// ByAvatar orders the results by the avatar field.
func ByAvatar(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAvatar, opts...).ToFunc()
}
// ByCid orders the results by the cid field.
func ByCid(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCid, opts...).ToFunc()
}
// ByURI orders the results by the uri field.
func ByURI(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldURI, opts...).ToFunc()
}
// ByRkey orders the results by the rkey field.
func ByRkey(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRkey, opts...).ToFunc()
}
// ByBskyURL orders the results by the bsky_url field.
func ByBskyURL(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldBskyURL, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByOwnerField orders the results by owner field.
func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...))
}
}
func newOwnerStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(OwnerInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn),
)
}

1091
ent/ma/where.go Normal file

File diff suppressed because it is too large Load Diff

465
ent/ma_create.go Normal file
View File

@@ -0,0 +1,465 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"api/ent/ma"
"api/ent/user"
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// MaCreate is the builder for creating a Ma entity.
type MaCreate struct {
config
mutation *MaMutation
hooks []Hook
}
// SetPassword sets the "password" field.
func (mc *MaCreate) SetPassword(s string) *MaCreate {
mc.mutation.SetPassword(s)
return mc
}
// SetToken sets the "token" field.
func (mc *MaCreate) SetToken(s string) *MaCreate {
mc.mutation.SetToken(s)
return mc
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (mc *MaCreate) SetNillableToken(s *string) *MaCreate {
if s != nil {
mc.SetToken(*s)
}
return mc
}
// SetLimit sets the "limit" field.
func (mc *MaCreate) SetLimit(b bool) *MaCreate {
mc.mutation.SetLimit(b)
return mc
}
// SetNillableLimit sets the "limit" field if the given value is not nil.
func (mc *MaCreate) SetNillableLimit(b *bool) *MaCreate {
if b != nil {
mc.SetLimit(*b)
}
return mc
}
// SetCount sets the "count" field.
func (mc *MaCreate) SetCount(i int) *MaCreate {
mc.mutation.SetCount(i)
return mc
}
// SetNillableCount sets the "count" field if the given value is not nil.
func (mc *MaCreate) SetNillableCount(i *int) *MaCreate {
if i != nil {
mc.SetCount(*i)
}
return mc
}
// SetHandle sets the "handle" field.
func (mc *MaCreate) SetHandle(s string) *MaCreate {
mc.mutation.SetHandle(s)
return mc
}
// SetNillableHandle sets the "handle" field if the given value is not nil.
func (mc *MaCreate) SetNillableHandle(s *string) *MaCreate {
if s != nil {
mc.SetHandle(*s)
}
return mc
}
// SetText sets the "text" field.
func (mc *MaCreate) SetText(s string) *MaCreate {
mc.mutation.SetText(s)
return mc
}
// SetNillableText sets the "text" field if the given value is not nil.
func (mc *MaCreate) SetNillableText(s *string) *MaCreate {
if s != nil {
mc.SetText(*s)
}
return mc
}
// SetDid sets the "did" field.
func (mc *MaCreate) SetDid(s string) *MaCreate {
mc.mutation.SetDid(s)
return mc
}
// SetNillableDid sets the "did" field if the given value is not nil.
func (mc *MaCreate) SetNillableDid(s *string) *MaCreate {
if s != nil {
mc.SetDid(*s)
}
return mc
}
// SetAvatar sets the "avatar" field.
func (mc *MaCreate) SetAvatar(s string) *MaCreate {
mc.mutation.SetAvatar(s)
return mc
}
// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (mc *MaCreate) SetNillableAvatar(s *string) *MaCreate {
if s != nil {
mc.SetAvatar(*s)
}
return mc
}
// SetCid sets the "cid" field.
func (mc *MaCreate) SetCid(s string) *MaCreate {
mc.mutation.SetCid(s)
return mc
}
// SetNillableCid sets the "cid" field if the given value is not nil.
func (mc *MaCreate) SetNillableCid(s *string) *MaCreate {
if s != nil {
mc.SetCid(*s)
}
return mc
}
// SetURI sets the "uri" field.
func (mc *MaCreate) SetURI(s string) *MaCreate {
mc.mutation.SetURI(s)
return mc
}
// SetNillableURI sets the "uri" field if the given value is not nil.
func (mc *MaCreate) SetNillableURI(s *string) *MaCreate {
if s != nil {
mc.SetURI(*s)
}
return mc
}
// SetRkey sets the "rkey" field.
func (mc *MaCreate) SetRkey(s string) *MaCreate {
mc.mutation.SetRkey(s)
return mc
}
// SetNillableRkey sets the "rkey" field if the given value is not nil.
func (mc *MaCreate) SetNillableRkey(s *string) *MaCreate {
if s != nil {
mc.SetRkey(*s)
}
return mc
}
// SetBskyURL sets the "bsky_url" field.
func (mc *MaCreate) SetBskyURL(s string) *MaCreate {
mc.mutation.SetBskyURL(s)
return mc
}
// SetNillableBskyURL sets the "bsky_url" field if the given value is not nil.
func (mc *MaCreate) SetNillableBskyURL(s *string) *MaCreate {
if s != nil {
mc.SetBskyURL(*s)
}
return mc
}
// SetUpdatedAt sets the "updated_at" field.
func (mc *MaCreate) SetUpdatedAt(t time.Time) *MaCreate {
mc.mutation.SetUpdatedAt(t)
return mc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (mc *MaCreate) SetNillableUpdatedAt(t *time.Time) *MaCreate {
if t != nil {
mc.SetUpdatedAt(*t)
}
return mc
}
// SetCreatedAt sets the "created_at" field.
func (mc *MaCreate) SetCreatedAt(t time.Time) *MaCreate {
mc.mutation.SetCreatedAt(t)
return mc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (mc *MaCreate) SetNillableCreatedAt(t *time.Time) *MaCreate {
if t != nil {
mc.SetCreatedAt(*t)
}
return mc
}
// SetOwnerID sets the "owner" edge to the User entity by ID.
func (mc *MaCreate) SetOwnerID(id int) *MaCreate {
mc.mutation.SetOwnerID(id)
return mc
}
// SetOwner sets the "owner" edge to the User entity.
func (mc *MaCreate) SetOwner(u *User) *MaCreate {
return mc.SetOwnerID(u.ID)
}
// Mutation returns the MaMutation object of the builder.
func (mc *MaCreate) Mutation() *MaMutation {
return mc.mutation
}
// Save creates the Ma in the database.
func (mc *MaCreate) Save(ctx context.Context) (*Ma, error) {
mc.defaults()
return withHooks[*Ma, MaMutation](ctx, mc.sqlSave, mc.mutation, mc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (mc *MaCreate) SaveX(ctx context.Context) *Ma {
v, err := mc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (mc *MaCreate) Exec(ctx context.Context) error {
_, err := mc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (mc *MaCreate) 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 *MaCreate) defaults() {
if _, ok := mc.mutation.Limit(); !ok {
v := ma.DefaultLimit
mc.mutation.SetLimit(v)
}
if _, ok := mc.mutation.CreatedAt(); !ok {
v := ma.DefaultCreatedAt()
mc.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (mc *MaCreate) check() error {
if _, ok := mc.mutation.Password(); !ok {
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Ma.password"`)}
}
if v, ok := mc.mutation.Password(); ok {
if err := ma.PasswordValidator(v); err != nil {
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Ma.password": %w`, err)}
}
}
if _, ok := mc.mutation.OwnerID(); !ok {
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required edge "Ma.owner"`)}
}
return nil
}
func (mc *MaCreate) sqlSave(ctx context.Context) (*Ma, 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
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
mc.mutation.id = &_node.ID
mc.mutation.done = true
return _node, nil
}
func (mc *MaCreate) createSpec() (*Ma, *sqlgraph.CreateSpec) {
var (
_node = &Ma{config: mc.config}
_spec = sqlgraph.NewCreateSpec(ma.Table, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt))
)
if value, ok := mc.mutation.Password(); ok {
_spec.SetField(ma.FieldPassword, field.TypeString, value)
_node.Password = value
}
if value, ok := mc.mutation.Token(); ok {
_spec.SetField(ma.FieldToken, field.TypeString, value)
_node.Token = value
}
if value, ok := mc.mutation.Limit(); ok {
_spec.SetField(ma.FieldLimit, field.TypeBool, value)
_node.Limit = value
}
if value, ok := mc.mutation.Count(); ok {
_spec.SetField(ma.FieldCount, field.TypeInt, value)
_node.Count = value
}
if value, ok := mc.mutation.Handle(); ok {
_spec.SetField(ma.FieldHandle, field.TypeString, value)
_node.Handle = value
}
if value, ok := mc.mutation.Text(); ok {
_spec.SetField(ma.FieldText, field.TypeString, value)
_node.Text = value
}
if value, ok := mc.mutation.Did(); ok {
_spec.SetField(ma.FieldDid, field.TypeString, value)
_node.Did = value
}
if value, ok := mc.mutation.Avatar(); ok {
_spec.SetField(ma.FieldAvatar, field.TypeString, value)
_node.Avatar = value
}
if value, ok := mc.mutation.Cid(); ok {
_spec.SetField(ma.FieldCid, field.TypeString, value)
_node.Cid = value
}
if value, ok := mc.mutation.URI(); ok {
_spec.SetField(ma.FieldURI, field.TypeString, value)
_node.URI = value
}
if value, ok := mc.mutation.Rkey(); ok {
_spec.SetField(ma.FieldRkey, field.TypeString, value)
_node.Rkey = value
}
if value, ok := mc.mutation.BskyURL(); ok {
_spec.SetField(ma.FieldBskyURL, field.TypeString, value)
_node.BskyURL = value
}
if value, ok := mc.mutation.UpdatedAt(); ok {
_spec.SetField(ma.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := mc.mutation.CreatedAt(); ok {
_spec.SetField(ma.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if nodes := mc.mutation.OwnerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: ma.OwnerTable,
Columns: []string{ma.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.user_ma = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// MaCreateBulk is the builder for creating many Ma entities in bulk.
type MaCreateBulk struct {
config
builders []*MaCreate
}
// Save creates the Ma entities in the database.
func (mcb *MaCreateBulk) Save(ctx context.Context) ([]*Ma, error) {
specs := make([]*sqlgraph.CreateSpec, len(mcb.builders))
nodes := make([]*Ma, 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.(*MaMutation)
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}
// 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
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(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 *MaCreateBulk) SaveX(ctx context.Context) []*Ma {
v, err := mcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (mcb *MaCreateBulk) Exec(ctx context.Context) error {
_, err := mcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (mcb *MaCreateBulk) ExecX(ctx context.Context) {
if err := mcb.Exec(ctx); err != nil {
panic(err)
}
}

88
ent/ma_delete.go Normal file
View File

@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"api/ent/ma"
"api/ent/predicate"
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// MaDelete is the builder for deleting a Ma entity.
type MaDelete struct {
config
hooks []Hook
mutation *MaMutation
}
// Where appends a list predicates to the MaDelete builder.
func (md *MaDelete) Where(ps ...predicate.Ma) *MaDelete {
md.mutation.Where(ps...)
return md
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (md *MaDelete) Exec(ctx context.Context) (int, error) {
return withHooks[int, MaMutation](ctx, md.sqlExec, md.mutation, md.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (md *MaDelete) ExecX(ctx context.Context) int {
n, err := md.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (md *MaDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(ma.Table, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt))
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
}
// MaDeleteOne is the builder for deleting a single Ma entity.
type MaDeleteOne struct {
md *MaDelete
}
// Where appends a list predicates to the MaDelete builder.
func (mdo *MaDeleteOne) Where(ps ...predicate.Ma) *MaDeleteOne {
mdo.md.mutation.Where(ps...)
return mdo
}
// Exec executes the deletion query.
func (mdo *MaDeleteOne) Exec(ctx context.Context) error {
n, err := mdo.md.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{ma.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (mdo *MaDeleteOne) ExecX(ctx context.Context) {
if err := mdo.Exec(ctx); err != nil {
panic(err)
}
}

613
ent/ma_query.go Normal file
View File

@@ -0,0 +1,613 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"api/ent/ma"
"api/ent/predicate"
"api/ent/user"
"context"
"fmt"
"math"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// MaQuery is the builder for querying Ma entities.
type MaQuery struct {
config
ctx *QueryContext
order []ma.OrderOption
inters []Interceptor
predicates []predicate.Ma
withOwner *UserQuery
withFKs bool
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the MaQuery builder.
func (mq *MaQuery) Where(ps ...predicate.Ma) *MaQuery {
mq.predicates = append(mq.predicates, ps...)
return mq
}
// Limit the number of records to be returned by this query.
func (mq *MaQuery) Limit(limit int) *MaQuery {
mq.ctx.Limit = &limit
return mq
}
// Offset to start from.
func (mq *MaQuery) Offset(offset int) *MaQuery {
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 *MaQuery) Unique(unique bool) *MaQuery {
mq.ctx.Unique = &unique
return mq
}
// Order specifies how the records should be ordered.
func (mq *MaQuery) Order(o ...ma.OrderOption) *MaQuery {
mq.order = append(mq.order, o...)
return mq
}
// QueryOwner chains the current query on the "owner" edge.
func (mq *MaQuery) QueryOwner() *UserQuery {
query := (&UserClient{config: mq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := mq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := mq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(ma.Table, ma.FieldID, selector),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, ma.OwnerTable, ma.OwnerColumn),
)
fromU = sqlgraph.SetNeighbors(mq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first Ma entity from the query.
// Returns a *NotFoundError when no Ma was found.
func (mq *MaQuery) First(ctx context.Context) (*Ma, error) {
nodes, err := mq.Limit(1).All(setContextOp(ctx, mq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{ma.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (mq *MaQuery) FirstX(ctx context.Context) *Ma {
node, err := mq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first Ma ID from the query.
// Returns a *NotFoundError when no Ma ID was found.
func (mq *MaQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = mq.Limit(1).IDs(setContextOp(ctx, mq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{ma.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (mq *MaQuery) FirstIDX(ctx context.Context) int {
id, err := mq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single Ma entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Ma entity is found.
// Returns a *NotFoundError when no Ma entities are found.
func (mq *MaQuery) Only(ctx context.Context) (*Ma, error) {
nodes, err := mq.Limit(2).All(setContextOp(ctx, mq.ctx, "Only"))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{ma.Label}
default:
return nil, &NotSingularError{ma.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (mq *MaQuery) OnlyX(ctx context.Context) *Ma {
node, err := mq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only Ma ID in the query.
// Returns a *NotSingularError when more than one Ma ID is found.
// Returns a *NotFoundError when no entities are found.
func (mq *MaQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = mq.Limit(2).IDs(setContextOp(ctx, mq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{ma.Label}
default:
err = &NotSingularError{ma.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (mq *MaQuery) OnlyIDX(ctx context.Context) int {
id, err := mq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of Mas.
func (mq *MaQuery) All(ctx context.Context) ([]*Ma, error) {
ctx = setContextOp(ctx, mq.ctx, "All")
if err := mq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Ma, *MaQuery]()
return withInterceptors[[]*Ma](ctx, mq, qr, mq.inters)
}
// AllX is like All, but panics if an error occurs.
func (mq *MaQuery) AllX(ctx context.Context) []*Ma {
nodes, err := mq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of Ma IDs.
func (mq *MaQuery) IDs(ctx context.Context) (ids []int, err error) {
if mq.ctx.Unique == nil && mq.path != nil {
mq.Unique(true)
}
ctx = setContextOp(ctx, mq.ctx, "IDs")
if err = mq.Select(ma.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (mq *MaQuery) IDsX(ctx context.Context) []int {
ids, err := mq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (mq *MaQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, mq.ctx, "Count")
if err := mq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, mq, querierCount[*MaQuery](), mq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (mq *MaQuery) 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 *MaQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, mq.ctx, "Exist")
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 *MaQuery) ExistX(ctx context.Context) bool {
exist, err := mq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the MaQuery 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 *MaQuery) Clone() *MaQuery {
if mq == nil {
return nil
}
return &MaQuery{
config: mq.config,
ctx: mq.ctx.Clone(),
order: append([]ma.OrderOption{}, mq.order...),
inters: append([]Interceptor{}, mq.inters...),
predicates: append([]predicate.Ma{}, mq.predicates...),
withOwner: mq.withOwner.Clone(),
// clone intermediate query.
sql: mq.sql.Clone(),
path: mq.path,
}
}
// WithOwner tells the query-builder to eager-load the nodes that are connected to
// the "owner" edge. The optional arguments are used to configure the query builder of the edge.
func (mq *MaQuery) WithOwner(opts ...func(*UserQuery)) *MaQuery {
query := (&UserClient{config: mq.config}).Query()
for _, opt := range opts {
opt(query)
}
mq.withOwner = query
return mq
}
// 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 {
// Password string `json:"password,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Ma.Query().
// GroupBy(ma.FieldPassword).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (mq *MaQuery) GroupBy(field string, fields ...string) *MaGroupBy {
mq.ctx.Fields = append([]string{field}, fields...)
grbuild := &MaGroupBy{build: mq}
grbuild.flds = &mq.ctx.Fields
grbuild.label = ma.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 {
// Password string `json:"password,omitempty"`
// }
//
// client.Ma.Query().
// Select(ma.FieldPassword).
// Scan(ctx, &v)
func (mq *MaQuery) Select(fields ...string) *MaSelect {
mq.ctx.Fields = append(mq.ctx.Fields, fields...)
sbuild := &MaSelect{MaQuery: mq}
sbuild.label = ma.Label
sbuild.flds, sbuild.scan = &mq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a MaSelect configured with the given aggregations.
func (mq *MaQuery) Aggregate(fns ...AggregateFunc) *MaSelect {
return mq.Select().Aggregate(fns...)
}
func (mq *MaQuery) 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 !ma.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 *MaQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Ma, error) {
var (
nodes = []*Ma{}
withFKs = mq.withFKs
_spec = mq.querySpec()
loadedTypes = [1]bool{
mq.withOwner != nil,
}
)
if mq.withOwner != nil {
withFKs = true
}
if withFKs {
_spec.Node.Columns = append(_spec.Node.Columns, ma.ForeignKeys...)
}
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Ma).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Ma{config: mq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
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
}
if query := mq.withOwner; query != nil {
if err := mq.loadOwner(ctx, query, nodes, nil,
func(n *Ma, e *User) { n.Edges.Owner = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (mq *MaQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*Ma, init func(*Ma), assign func(*Ma, *User)) error {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*Ma)
for i := range nodes {
if nodes[i].user_ma == nil {
continue
}
fk := *nodes[i].user_ma
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(user.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "user_ma" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (mq *MaQuery) 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 *MaQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(ma.Table, ma.Columns, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt))
_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, ma.FieldID)
for i := range fields {
if fields[i] != ma.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 *MaQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(mq.driver.Dialect())
t1 := builder.Table(ma.Table)
columns := mq.ctx.Fields
if len(columns) == 0 {
columns = ma.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
}
// MaGroupBy is the group-by builder for Ma entities.
type MaGroupBy struct {
selector
build *MaQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (mgb *MaGroupBy) Aggregate(fns ...AggregateFunc) *MaGroupBy {
mgb.fns = append(mgb.fns, fns...)
return mgb
}
// Scan applies the selector query and scans the result into the given value.
func (mgb *MaGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, mgb.build.ctx, "GroupBy")
if err := mgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*MaQuery, *MaGroupBy](ctx, mgb.build, mgb, mgb.build.inters, v)
}
func (mgb *MaGroupBy) sqlScan(ctx context.Context, root *MaQuery, 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)
}
// MaSelect is the builder for selecting fields of Ma entities.
type MaSelect struct {
*MaQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (ms *MaSelect) Aggregate(fns ...AggregateFunc) *MaSelect {
ms.fns = append(ms.fns, fns...)
return ms
}
// Scan applies the selector query and scans the result into the given value.
func (ms *MaSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ms.ctx, "Select")
if err := ms.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*MaQuery, *MaSelect](ctx, ms.MaQuery, ms, ms.inters, v)
}
func (ms *MaSelect) sqlScan(ctx context.Context, root *MaQuery, 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)
}

941
ent/ma_update.go Normal file
View File

@@ -0,0 +1,941 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"api/ent/ma"
"api/ent/predicate"
"api/ent/user"
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// MaUpdate is the builder for updating Ma entities.
type MaUpdate struct {
config
hooks []Hook
mutation *MaMutation
}
// Where appends a list predicates to the MaUpdate builder.
func (mu *MaUpdate) Where(ps ...predicate.Ma) *MaUpdate {
mu.mutation.Where(ps...)
return mu
}
// SetToken sets the "token" field.
func (mu *MaUpdate) SetToken(s string) *MaUpdate {
mu.mutation.SetToken(s)
return mu
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (mu *MaUpdate) SetNillableToken(s *string) *MaUpdate {
if s != nil {
mu.SetToken(*s)
}
return mu
}
// ClearToken clears the value of the "token" field.
func (mu *MaUpdate) ClearToken() *MaUpdate {
mu.mutation.ClearToken()
return mu
}
// SetLimit sets the "limit" field.
func (mu *MaUpdate) SetLimit(b bool) *MaUpdate {
mu.mutation.SetLimit(b)
return mu
}
// SetNillableLimit sets the "limit" field if the given value is not nil.
func (mu *MaUpdate) SetNillableLimit(b *bool) *MaUpdate {
if b != nil {
mu.SetLimit(*b)
}
return mu
}
// ClearLimit clears the value of the "limit" field.
func (mu *MaUpdate) ClearLimit() *MaUpdate {
mu.mutation.ClearLimit()
return mu
}
// SetCount sets the "count" field.
func (mu *MaUpdate) SetCount(i int) *MaUpdate {
mu.mutation.ResetCount()
mu.mutation.SetCount(i)
return mu
}
// SetNillableCount sets the "count" field if the given value is not nil.
func (mu *MaUpdate) SetNillableCount(i *int) *MaUpdate {
if i != nil {
mu.SetCount(*i)
}
return mu
}
// AddCount adds i to the "count" field.
func (mu *MaUpdate) AddCount(i int) *MaUpdate {
mu.mutation.AddCount(i)
return mu
}
// ClearCount clears the value of the "count" field.
func (mu *MaUpdate) ClearCount() *MaUpdate {
mu.mutation.ClearCount()
return mu
}
// SetHandle sets the "handle" field.
func (mu *MaUpdate) SetHandle(s string) *MaUpdate {
mu.mutation.SetHandle(s)
return mu
}
// SetNillableHandle sets the "handle" field if the given value is not nil.
func (mu *MaUpdate) SetNillableHandle(s *string) *MaUpdate {
if s != nil {
mu.SetHandle(*s)
}
return mu
}
// ClearHandle clears the value of the "handle" field.
func (mu *MaUpdate) ClearHandle() *MaUpdate {
mu.mutation.ClearHandle()
return mu
}
// SetText sets the "text" field.
func (mu *MaUpdate) SetText(s string) *MaUpdate {
mu.mutation.SetText(s)
return mu
}
// SetNillableText sets the "text" field if the given value is not nil.
func (mu *MaUpdate) SetNillableText(s *string) *MaUpdate {
if s != nil {
mu.SetText(*s)
}
return mu
}
// ClearText clears the value of the "text" field.
func (mu *MaUpdate) ClearText() *MaUpdate {
mu.mutation.ClearText()
return mu
}
// SetDid sets the "did" field.
func (mu *MaUpdate) SetDid(s string) *MaUpdate {
mu.mutation.SetDid(s)
return mu
}
// SetNillableDid sets the "did" field if the given value is not nil.
func (mu *MaUpdate) SetNillableDid(s *string) *MaUpdate {
if s != nil {
mu.SetDid(*s)
}
return mu
}
// ClearDid clears the value of the "did" field.
func (mu *MaUpdate) ClearDid() *MaUpdate {
mu.mutation.ClearDid()
return mu
}
// SetAvatar sets the "avatar" field.
func (mu *MaUpdate) SetAvatar(s string) *MaUpdate {
mu.mutation.SetAvatar(s)
return mu
}
// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (mu *MaUpdate) SetNillableAvatar(s *string) *MaUpdate {
if s != nil {
mu.SetAvatar(*s)
}
return mu
}
// ClearAvatar clears the value of the "avatar" field.
func (mu *MaUpdate) ClearAvatar() *MaUpdate {
mu.mutation.ClearAvatar()
return mu
}
// SetCid sets the "cid" field.
func (mu *MaUpdate) SetCid(s string) *MaUpdate {
mu.mutation.SetCid(s)
return mu
}
// SetNillableCid sets the "cid" field if the given value is not nil.
func (mu *MaUpdate) SetNillableCid(s *string) *MaUpdate {
if s != nil {
mu.SetCid(*s)
}
return mu
}
// ClearCid clears the value of the "cid" field.
func (mu *MaUpdate) ClearCid() *MaUpdate {
mu.mutation.ClearCid()
return mu
}
// SetURI sets the "uri" field.
func (mu *MaUpdate) SetURI(s string) *MaUpdate {
mu.mutation.SetURI(s)
return mu
}
// SetNillableURI sets the "uri" field if the given value is not nil.
func (mu *MaUpdate) SetNillableURI(s *string) *MaUpdate {
if s != nil {
mu.SetURI(*s)
}
return mu
}
// ClearURI clears the value of the "uri" field.
func (mu *MaUpdate) ClearURI() *MaUpdate {
mu.mutation.ClearURI()
return mu
}
// SetRkey sets the "rkey" field.
func (mu *MaUpdate) SetRkey(s string) *MaUpdate {
mu.mutation.SetRkey(s)
return mu
}
// SetNillableRkey sets the "rkey" field if the given value is not nil.
func (mu *MaUpdate) SetNillableRkey(s *string) *MaUpdate {
if s != nil {
mu.SetRkey(*s)
}
return mu
}
// ClearRkey clears the value of the "rkey" field.
func (mu *MaUpdate) ClearRkey() *MaUpdate {
mu.mutation.ClearRkey()
return mu
}
// SetBskyURL sets the "bsky_url" field.
func (mu *MaUpdate) SetBskyURL(s string) *MaUpdate {
mu.mutation.SetBskyURL(s)
return mu
}
// SetNillableBskyURL sets the "bsky_url" field if the given value is not nil.
func (mu *MaUpdate) SetNillableBskyURL(s *string) *MaUpdate {
if s != nil {
mu.SetBskyURL(*s)
}
return mu
}
// ClearBskyURL clears the value of the "bsky_url" field.
func (mu *MaUpdate) ClearBskyURL() *MaUpdate {
mu.mutation.ClearBskyURL()
return mu
}
// SetUpdatedAt sets the "updated_at" field.
func (mu *MaUpdate) SetUpdatedAt(t time.Time) *MaUpdate {
mu.mutation.SetUpdatedAt(t)
return mu
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (mu *MaUpdate) SetNillableUpdatedAt(t *time.Time) *MaUpdate {
if t != nil {
mu.SetUpdatedAt(*t)
}
return mu
}
// ClearUpdatedAt clears the value of the "updated_at" field.
func (mu *MaUpdate) ClearUpdatedAt() *MaUpdate {
mu.mutation.ClearUpdatedAt()
return mu
}
// SetOwnerID sets the "owner" edge to the User entity by ID.
func (mu *MaUpdate) SetOwnerID(id int) *MaUpdate {
mu.mutation.SetOwnerID(id)
return mu
}
// SetOwner sets the "owner" edge to the User entity.
func (mu *MaUpdate) SetOwner(u *User) *MaUpdate {
return mu.SetOwnerID(u.ID)
}
// Mutation returns the MaMutation object of the builder.
func (mu *MaUpdate) Mutation() *MaMutation {
return mu.mutation
}
// ClearOwner clears the "owner" edge to the User entity.
func (mu *MaUpdate) ClearOwner() *MaUpdate {
mu.mutation.ClearOwner()
return mu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (mu *MaUpdate) Save(ctx context.Context) (int, error) {
return withHooks[int, MaMutation](ctx, mu.sqlSave, mu.mutation, mu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (mu *MaUpdate) SaveX(ctx context.Context) int {
affected, err := mu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (mu *MaUpdate) Exec(ctx context.Context) error {
_, err := mu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (mu *MaUpdate) ExecX(ctx context.Context) {
if err := mu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (mu *MaUpdate) check() error {
if _, ok := mu.mutation.OwnerID(); mu.mutation.OwnerCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "Ma.owner"`)
}
return nil
}
func (mu *MaUpdate) sqlSave(ctx context.Context) (n int, err error) {
if err := mu.check(); err != nil {
return n, err
}
_spec := sqlgraph.NewUpdateSpec(ma.Table, ma.Columns, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt))
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.Token(); ok {
_spec.SetField(ma.FieldToken, field.TypeString, value)
}
if mu.mutation.TokenCleared() {
_spec.ClearField(ma.FieldToken, field.TypeString)
}
if value, ok := mu.mutation.Limit(); ok {
_spec.SetField(ma.FieldLimit, field.TypeBool, value)
}
if mu.mutation.LimitCleared() {
_spec.ClearField(ma.FieldLimit, field.TypeBool)
}
if value, ok := mu.mutation.Count(); ok {
_spec.SetField(ma.FieldCount, field.TypeInt, value)
}
if value, ok := mu.mutation.AddedCount(); ok {
_spec.AddField(ma.FieldCount, field.TypeInt, value)
}
if mu.mutation.CountCleared() {
_spec.ClearField(ma.FieldCount, field.TypeInt)
}
if value, ok := mu.mutation.Handle(); ok {
_spec.SetField(ma.FieldHandle, field.TypeString, value)
}
if mu.mutation.HandleCleared() {
_spec.ClearField(ma.FieldHandle, field.TypeString)
}
if value, ok := mu.mutation.Text(); ok {
_spec.SetField(ma.FieldText, field.TypeString, value)
}
if mu.mutation.TextCleared() {
_spec.ClearField(ma.FieldText, field.TypeString)
}
if value, ok := mu.mutation.Did(); ok {
_spec.SetField(ma.FieldDid, field.TypeString, value)
}
if mu.mutation.DidCleared() {
_spec.ClearField(ma.FieldDid, field.TypeString)
}
if value, ok := mu.mutation.Avatar(); ok {
_spec.SetField(ma.FieldAvatar, field.TypeString, value)
}
if mu.mutation.AvatarCleared() {
_spec.ClearField(ma.FieldAvatar, field.TypeString)
}
if value, ok := mu.mutation.Cid(); ok {
_spec.SetField(ma.FieldCid, field.TypeString, value)
}
if mu.mutation.CidCleared() {
_spec.ClearField(ma.FieldCid, field.TypeString)
}
if value, ok := mu.mutation.URI(); ok {
_spec.SetField(ma.FieldURI, field.TypeString, value)
}
if mu.mutation.URICleared() {
_spec.ClearField(ma.FieldURI, field.TypeString)
}
if value, ok := mu.mutation.Rkey(); ok {
_spec.SetField(ma.FieldRkey, field.TypeString, value)
}
if mu.mutation.RkeyCleared() {
_spec.ClearField(ma.FieldRkey, field.TypeString)
}
if value, ok := mu.mutation.BskyURL(); ok {
_spec.SetField(ma.FieldBskyURL, field.TypeString, value)
}
if mu.mutation.BskyURLCleared() {
_spec.ClearField(ma.FieldBskyURL, field.TypeString)
}
if value, ok := mu.mutation.UpdatedAt(); ok {
_spec.SetField(ma.FieldUpdatedAt, field.TypeTime, value)
}
if mu.mutation.UpdatedAtCleared() {
_spec.ClearField(ma.FieldUpdatedAt, field.TypeTime)
}
if mu.mutation.CreatedAtCleared() {
_spec.ClearField(ma.FieldCreatedAt, field.TypeTime)
}
if mu.mutation.OwnerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: ma.OwnerTable,
Columns: []string{ma.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := mu.mutation.OwnerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: ma.OwnerTable,
Columns: []string{ma.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{ma.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
mu.mutation.done = true
return n, nil
}
// MaUpdateOne is the builder for updating a single Ma entity.
type MaUpdateOne struct {
config
fields []string
hooks []Hook
mutation *MaMutation
}
// SetToken sets the "token" field.
func (muo *MaUpdateOne) SetToken(s string) *MaUpdateOne {
muo.mutation.SetToken(s)
return muo
}
// SetNillableToken sets the "token" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableToken(s *string) *MaUpdateOne {
if s != nil {
muo.SetToken(*s)
}
return muo
}
// ClearToken clears the value of the "token" field.
func (muo *MaUpdateOne) ClearToken() *MaUpdateOne {
muo.mutation.ClearToken()
return muo
}
// SetLimit sets the "limit" field.
func (muo *MaUpdateOne) SetLimit(b bool) *MaUpdateOne {
muo.mutation.SetLimit(b)
return muo
}
// SetNillableLimit sets the "limit" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableLimit(b *bool) *MaUpdateOne {
if b != nil {
muo.SetLimit(*b)
}
return muo
}
// ClearLimit clears the value of the "limit" field.
func (muo *MaUpdateOne) ClearLimit() *MaUpdateOne {
muo.mutation.ClearLimit()
return muo
}
// SetCount sets the "count" field.
func (muo *MaUpdateOne) SetCount(i int) *MaUpdateOne {
muo.mutation.ResetCount()
muo.mutation.SetCount(i)
return muo
}
// SetNillableCount sets the "count" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableCount(i *int) *MaUpdateOne {
if i != nil {
muo.SetCount(*i)
}
return muo
}
// AddCount adds i to the "count" field.
func (muo *MaUpdateOne) AddCount(i int) *MaUpdateOne {
muo.mutation.AddCount(i)
return muo
}
// ClearCount clears the value of the "count" field.
func (muo *MaUpdateOne) ClearCount() *MaUpdateOne {
muo.mutation.ClearCount()
return muo
}
// SetHandle sets the "handle" field.
func (muo *MaUpdateOne) SetHandle(s string) *MaUpdateOne {
muo.mutation.SetHandle(s)
return muo
}
// SetNillableHandle sets the "handle" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableHandle(s *string) *MaUpdateOne {
if s != nil {
muo.SetHandle(*s)
}
return muo
}
// ClearHandle clears the value of the "handle" field.
func (muo *MaUpdateOne) ClearHandle() *MaUpdateOne {
muo.mutation.ClearHandle()
return muo
}
// SetText sets the "text" field.
func (muo *MaUpdateOne) SetText(s string) *MaUpdateOne {
muo.mutation.SetText(s)
return muo
}
// SetNillableText sets the "text" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableText(s *string) *MaUpdateOne {
if s != nil {
muo.SetText(*s)
}
return muo
}
// ClearText clears the value of the "text" field.
func (muo *MaUpdateOne) ClearText() *MaUpdateOne {
muo.mutation.ClearText()
return muo
}
// SetDid sets the "did" field.
func (muo *MaUpdateOne) SetDid(s string) *MaUpdateOne {
muo.mutation.SetDid(s)
return muo
}
// SetNillableDid sets the "did" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableDid(s *string) *MaUpdateOne {
if s != nil {
muo.SetDid(*s)
}
return muo
}
// ClearDid clears the value of the "did" field.
func (muo *MaUpdateOne) ClearDid() *MaUpdateOne {
muo.mutation.ClearDid()
return muo
}
// SetAvatar sets the "avatar" field.
func (muo *MaUpdateOne) SetAvatar(s string) *MaUpdateOne {
muo.mutation.SetAvatar(s)
return muo
}
// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableAvatar(s *string) *MaUpdateOne {
if s != nil {
muo.SetAvatar(*s)
}
return muo
}
// ClearAvatar clears the value of the "avatar" field.
func (muo *MaUpdateOne) ClearAvatar() *MaUpdateOne {
muo.mutation.ClearAvatar()
return muo
}
// SetCid sets the "cid" field.
func (muo *MaUpdateOne) SetCid(s string) *MaUpdateOne {
muo.mutation.SetCid(s)
return muo
}
// SetNillableCid sets the "cid" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableCid(s *string) *MaUpdateOne {
if s != nil {
muo.SetCid(*s)
}
return muo
}
// ClearCid clears the value of the "cid" field.
func (muo *MaUpdateOne) ClearCid() *MaUpdateOne {
muo.mutation.ClearCid()
return muo
}
// SetURI sets the "uri" field.
func (muo *MaUpdateOne) SetURI(s string) *MaUpdateOne {
muo.mutation.SetURI(s)
return muo
}
// SetNillableURI sets the "uri" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableURI(s *string) *MaUpdateOne {
if s != nil {
muo.SetURI(*s)
}
return muo
}
// ClearURI clears the value of the "uri" field.
func (muo *MaUpdateOne) ClearURI() *MaUpdateOne {
muo.mutation.ClearURI()
return muo
}
// SetRkey sets the "rkey" field.
func (muo *MaUpdateOne) SetRkey(s string) *MaUpdateOne {
muo.mutation.SetRkey(s)
return muo
}
// SetNillableRkey sets the "rkey" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableRkey(s *string) *MaUpdateOne {
if s != nil {
muo.SetRkey(*s)
}
return muo
}
// ClearRkey clears the value of the "rkey" field.
func (muo *MaUpdateOne) ClearRkey() *MaUpdateOne {
muo.mutation.ClearRkey()
return muo
}
// SetBskyURL sets the "bsky_url" field.
func (muo *MaUpdateOne) SetBskyURL(s string) *MaUpdateOne {
muo.mutation.SetBskyURL(s)
return muo
}
// SetNillableBskyURL sets the "bsky_url" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableBskyURL(s *string) *MaUpdateOne {
if s != nil {
muo.SetBskyURL(*s)
}
return muo
}
// ClearBskyURL clears the value of the "bsky_url" field.
func (muo *MaUpdateOne) ClearBskyURL() *MaUpdateOne {
muo.mutation.ClearBskyURL()
return muo
}
// SetUpdatedAt sets the "updated_at" field.
func (muo *MaUpdateOne) SetUpdatedAt(t time.Time) *MaUpdateOne {
muo.mutation.SetUpdatedAt(t)
return muo
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (muo *MaUpdateOne) SetNillableUpdatedAt(t *time.Time) *MaUpdateOne {
if t != nil {
muo.SetUpdatedAt(*t)
}
return muo
}
// ClearUpdatedAt clears the value of the "updated_at" field.
func (muo *MaUpdateOne) ClearUpdatedAt() *MaUpdateOne {
muo.mutation.ClearUpdatedAt()
return muo
}
// SetOwnerID sets the "owner" edge to the User entity by ID.
func (muo *MaUpdateOne) SetOwnerID(id int) *MaUpdateOne {
muo.mutation.SetOwnerID(id)
return muo
}
// SetOwner sets the "owner" edge to the User entity.
func (muo *MaUpdateOne) SetOwner(u *User) *MaUpdateOne {
return muo.SetOwnerID(u.ID)
}
// Mutation returns the MaMutation object of the builder.
func (muo *MaUpdateOne) Mutation() *MaMutation {
return muo.mutation
}
// ClearOwner clears the "owner" edge to the User entity.
func (muo *MaUpdateOne) ClearOwner() *MaUpdateOne {
muo.mutation.ClearOwner()
return muo
}
// Where appends a list predicates to the MaUpdate builder.
func (muo *MaUpdateOne) Where(ps ...predicate.Ma) *MaUpdateOne {
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 *MaUpdateOne) Select(field string, fields ...string) *MaUpdateOne {
muo.fields = append([]string{field}, fields...)
return muo
}
// Save executes the query and returns the updated Ma entity.
func (muo *MaUpdateOne) Save(ctx context.Context) (*Ma, error) {
return withHooks[*Ma, MaMutation](ctx, muo.sqlSave, muo.mutation, muo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (muo *MaUpdateOne) SaveX(ctx context.Context) *Ma {
node, err := muo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (muo *MaUpdateOne) Exec(ctx context.Context) error {
_, err := muo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (muo *MaUpdateOne) ExecX(ctx context.Context) {
if err := muo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (muo *MaUpdateOne) check() error {
if _, ok := muo.mutation.OwnerID(); muo.mutation.OwnerCleared() && !ok {
return errors.New(`ent: clearing a required unique edge "Ma.owner"`)
}
return nil
}
func (muo *MaUpdateOne) sqlSave(ctx context.Context) (_node *Ma, err error) {
if err := muo.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(ma.Table, ma.Columns, sqlgraph.NewFieldSpec(ma.FieldID, field.TypeInt))
id, ok := muo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Ma.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, ma.FieldID)
for _, f := range fields {
if !ma.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != ma.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.Token(); ok {
_spec.SetField(ma.FieldToken, field.TypeString, value)
}
if muo.mutation.TokenCleared() {
_spec.ClearField(ma.FieldToken, field.TypeString)
}
if value, ok := muo.mutation.Limit(); ok {
_spec.SetField(ma.FieldLimit, field.TypeBool, value)
}
if muo.mutation.LimitCleared() {
_spec.ClearField(ma.FieldLimit, field.TypeBool)
}
if value, ok := muo.mutation.Count(); ok {
_spec.SetField(ma.FieldCount, field.TypeInt, value)
}
if value, ok := muo.mutation.AddedCount(); ok {
_spec.AddField(ma.FieldCount, field.TypeInt, value)
}
if muo.mutation.CountCleared() {
_spec.ClearField(ma.FieldCount, field.TypeInt)
}
if value, ok := muo.mutation.Handle(); ok {
_spec.SetField(ma.FieldHandle, field.TypeString, value)
}
if muo.mutation.HandleCleared() {
_spec.ClearField(ma.FieldHandle, field.TypeString)
}
if value, ok := muo.mutation.Text(); ok {
_spec.SetField(ma.FieldText, field.TypeString, value)
}
if muo.mutation.TextCleared() {
_spec.ClearField(ma.FieldText, field.TypeString)
}
if value, ok := muo.mutation.Did(); ok {
_spec.SetField(ma.FieldDid, field.TypeString, value)
}
if muo.mutation.DidCleared() {
_spec.ClearField(ma.FieldDid, field.TypeString)
}
if value, ok := muo.mutation.Avatar(); ok {
_spec.SetField(ma.FieldAvatar, field.TypeString, value)
}
if muo.mutation.AvatarCleared() {
_spec.ClearField(ma.FieldAvatar, field.TypeString)
}
if value, ok := muo.mutation.Cid(); ok {
_spec.SetField(ma.FieldCid, field.TypeString, value)
}
if muo.mutation.CidCleared() {
_spec.ClearField(ma.FieldCid, field.TypeString)
}
if value, ok := muo.mutation.URI(); ok {
_spec.SetField(ma.FieldURI, field.TypeString, value)
}
if muo.mutation.URICleared() {
_spec.ClearField(ma.FieldURI, field.TypeString)
}
if value, ok := muo.mutation.Rkey(); ok {
_spec.SetField(ma.FieldRkey, field.TypeString, value)
}
if muo.mutation.RkeyCleared() {
_spec.ClearField(ma.FieldRkey, field.TypeString)
}
if value, ok := muo.mutation.BskyURL(); ok {
_spec.SetField(ma.FieldBskyURL, field.TypeString, value)
}
if muo.mutation.BskyURLCleared() {
_spec.ClearField(ma.FieldBskyURL, field.TypeString)
}
if value, ok := muo.mutation.UpdatedAt(); ok {
_spec.SetField(ma.FieldUpdatedAt, field.TypeTime, value)
}
if muo.mutation.UpdatedAtCleared() {
_spec.ClearField(ma.FieldUpdatedAt, field.TypeTime)
}
if muo.mutation.CreatedAtCleared() {
_spec.ClearField(ma.FieldCreatedAt, field.TypeTime)
}
if muo.mutation.OwnerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: ma.OwnerTable,
Columns: []string{ma.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := muo.mutation.OwnerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: ma.OwnerTable,
Columns: []string{ma.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Ma{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{ma.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
muo.mutation.done = true
return _node, nil
}

View File

@@ -0,0 +1,12 @@
-- Create "cards" table
CREATE TABLE `cards` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `password` text NOT NULL, `card` integer NULL, `status` text NULL, `cp` integer NULL, `url` text NULL DEFAULT 'https://card.syui.ai', `created_at` datetime NULL, `user_card` integer NOT NULL, CONSTRAINT `cards_users_card` FOREIGN KEY (`user_card`) REFERENCES `users` (`id`) ON DELETE NO ACTION);
-- Create "groups" table
CREATE TABLE `groups` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `name` text NOT NULL, `password` text NOT NULL);
-- Create index "group_name" to table: "groups"
CREATE UNIQUE INDEX `group_name` ON `groups` (`name`);
-- Create "users" table
CREATE TABLE `users` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `username` text NOT NULL, `password` text NOT NULL, `created_at` datetime NULL, `updated_at` datetime NULL, `next` text NULL DEFAULT '20230405', `group_users` integer NULL, CONSTRAINT `users_groups_users` FOREIGN KEY (`group_users`) REFERENCES `groups` (`id`) ON DELETE SET NULL);
-- Create index "users_username_key" to table: "users"
CREATE UNIQUE INDEX `users_username_key` ON `users` (`username`);
-- Create index "user_username" to table: "users"
CREATE UNIQUE INDEX `user_username` ON `users` (`username`);

View File

@@ -0,0 +1,2 @@
h1:GU79ffcSbQHeq4BLGuuAdObBOt0WLTcsQx+AucxEqkA=
20230405104340_migration_name.sql h1:vlsZT8ob1qpLmBAGPqNBBG/iFact7wy1pb27tAavvRU=

View File

@@ -11,10 +11,15 @@ var (
// CardsColumns holds the columns for the "cards" table.
CardsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "password", Type: field.TypeString},
{Name: "card", Type: field.TypeInt, Nullable: true},
{Name: "skill", Type: field.TypeString, Nullable: true},
{Name: "status", Type: field.TypeString, Nullable: true},
{Name: "token", Type: field.TypeString, Nullable: true},
{Name: "cp", Type: field.TypeInt, Nullable: true},
{Name: "url", Type: field.TypeString, Nullable: true, Default: "https://card.syui.ai"},
{Name: "count", Type: field.TypeInt, Nullable: true},
{Name: "author", Type: field.TypeString, Nullable: true},
{Name: "created_at", Type: field.TypeTime, Nullable: true},
{Name: "user_card", Type: field.TypeInt},
}
@@ -26,7 +31,7 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "cards_users_card",
Columns: []*schema.Column{CardsColumns[6]},
Columns: []*schema.Column{CardsColumns[11]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
@@ -36,6 +41,7 @@ var (
GroupsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "name", Type: field.TypeString},
{Name: "password", Type: field.TypeString},
}
// GroupsTable holds the schema information for the "groups" table.
GroupsTable = &schema.Table{
@@ -50,13 +56,130 @@ var (
},
},
}
// MasColumns holds the columns for the "mas" table.
MasColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "password", Type: field.TypeString},
{Name: "token", Type: field.TypeString, Nullable: true},
{Name: "limit", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "count", Type: field.TypeInt, Nullable: true},
{Name: "handle", Type: field.TypeString, Nullable: true},
{Name: "text", Type: field.TypeString, Nullable: true},
{Name: "did", Type: field.TypeString, Nullable: true},
{Name: "avatar", Type: field.TypeString, Nullable: true},
{Name: "cid", Type: field.TypeString, Nullable: true},
{Name: "uri", Type: field.TypeString, Nullable: true},
{Name: "rkey", Type: field.TypeString, Nullable: true},
{Name: "bsky_url", Type: field.TypeString, Nullable: true},
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
{Name: "created_at", Type: field.TypeTime, Nullable: true},
{Name: "user_ma", Type: field.TypeInt},
}
// MasTable holds the schema information for the "mas" table.
MasTable = &schema.Table{
Name: "mas",
Columns: MasColumns,
PrimaryKey: []*schema.Column{MasColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "mas_users_ma",
Columns: []*schema.Column{MasColumns[15]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
},
}
// UesColumns holds the columns for the "ues" table.
UesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "limit", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "limit_boss", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "limit_item", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "password", Type: field.TypeString},
{Name: "lv", Type: field.TypeInt, Nullable: true},
{Name: "lv_point", Type: field.TypeInt, Nullable: true},
{Name: "model", Type: field.TypeInt, Nullable: true},
{Name: "sword", Type: field.TypeInt, Nullable: true},
{Name: "card", Type: field.TypeInt, Nullable: true},
{Name: "mode", Type: field.TypeString, Nullable: true},
{Name: "token", Type: field.TypeString, Nullable: true},
{Name: "cp", Type: field.TypeInt, Nullable: true},
{Name: "count", Type: field.TypeInt, Nullable: true},
{Name: "location_x", Type: field.TypeInt, Nullable: true},
{Name: "location_y", Type: field.TypeInt, Nullable: true},
{Name: "location_z", Type: field.TypeInt, Nullable: true},
{Name: "location_n", Type: field.TypeInt, Nullable: true},
{Name: "author", Type: field.TypeString, Nullable: true},
{Name: "created_at", Type: field.TypeTime, Nullable: true},
{Name: "user_ue", Type: field.TypeInt},
}
// UesTable holds the schema information for the "ues" table.
UesTable = &schema.Table{
Name: "ues",
Columns: UesColumns,
PrimaryKey: []*schema.Column{UesColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "ues_users_ue",
Columns: []*schema.Column{UesColumns[20]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
},
}
// UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "username", Type: field.TypeString, Unique: true, Size: 30},
{Name: "username", Type: field.TypeString, Unique: true, Size: 100},
{Name: "did", Type: field.TypeString, Nullable: true},
{Name: "member", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "book", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "manga", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "badge", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "bsky", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "mastodon", Type: field.TypeBool, Nullable: true, Default: true},
{Name: "delete", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "handle", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "token", Type: field.TypeString, Nullable: true},
{Name: "password", Type: field.TypeString},
{Name: "created_at", Type: field.TypeTime, Nullable: true},
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20230404"},
{Name: "raid_at", Type: field.TypeTime, Nullable: true},
{Name: "server_at", Type: field.TypeTime, Nullable: true},
{Name: "egg_at", Type: field.TypeTime, Nullable: true},
{Name: "luck", Type: field.TypeInt, Nullable: true},
{Name: "luck_at", Type: field.TypeTime, Nullable: true},
{Name: "like", Type: field.TypeInt, Nullable: true},
{Name: "like_rank", Type: field.TypeInt, Nullable: true},
{Name: "like_at", Type: field.TypeTime, Nullable: true},
{Name: "fav", Type: field.TypeInt, Nullable: true},
{Name: "ten", Type: field.TypeBool, Nullable: true},
{Name: "ten_su", Type: field.TypeInt, Nullable: true},
{Name: "ten_kai", Type: field.TypeInt, Nullable: true},
{Name: "aiten", Type: field.TypeInt, Nullable: true},
{Name: "ten_card", Type: field.TypeString, Nullable: true},
{Name: "ten_delete", Type: field.TypeString, Nullable: true},
{Name: "ten_post", Type: field.TypeString, Nullable: true},
{Name: "ten_get", Type: field.TypeString, Nullable: true},
{Name: "ten_at", Type: field.TypeTime, Nullable: true},
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20240401"},
{Name: "room", Type: field.TypeInt, Nullable: true},
{Name: "model", Type: field.TypeBool, Nullable: true},
{Name: "model_at", Type: field.TypeTime, Nullable: true},
{Name: "model_attack", Type: field.TypeInt, Nullable: true},
{Name: "model_limit", Type: field.TypeInt, Nullable: true},
{Name: "model_skill", Type: field.TypeInt, Nullable: true},
{Name: "model_mode", Type: field.TypeInt, Nullable: true},
{Name: "model_critical", Type: field.TypeInt, Nullable: true},
{Name: "model_critical_d", Type: field.TypeInt, Nullable: true},
{Name: "game", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "game_test", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "game_end", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "game_account", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "game_lv", Type: field.TypeInt, Nullable: true},
{Name: "coin", Type: field.TypeInt, Nullable: true},
{Name: "coin_open", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "coin_at", Type: field.TypeTime, Nullable: true},
{Name: "group_users", Type: field.TypeInt, Nullable: true},
}
// UsersTable holds the schema information for the "users" table.
@@ -67,7 +190,7 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "users_groups_users",
Columns: []*schema.Column{UsersColumns[5]},
Columns: []*schema.Column{UsersColumns[51]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.SetNull,
},
@@ -84,11 +207,15 @@ var (
Tables = []*schema.Table{
CardsTable,
GroupsTable,
MasTable,
UesTable,
UsersTable,
}
)
func init() {
CardsTable.ForeignKeys[0].RefTable = UsersTable
MasTable.ForeignKeys[0].RefTable = UsersTable
UesTable.ForeignKeys[0].RefTable = UsersTable
UsersTable.ForeignKeys[0].RefTable = GroupsTable
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,14 @@ type CreateGroupRes interface {
createGroupRes()
}
type CreateMaRes interface {
createMaRes()
}
type CreateUeRes interface {
createUeRes()
}
type CreateUserRes interface {
createUserRes()
}
@@ -21,6 +29,14 @@ type DeleteGroupRes interface {
deleteGroupRes()
}
type DeleteMaRes interface {
deleteMaRes()
}
type DeleteUeRes interface {
deleteUeRes()
}
type DeleteUserRes interface {
deleteUserRes()
}
@@ -37,14 +53,30 @@ type ListGroupUsersRes interface {
listGroupUsersRes()
}
type ListMaRes interface {
listMaRes()
}
type ListUeRes interface {
listUeRes()
}
type ListUserCardRes interface {
listUserCardRes()
}
type ListUserMaRes interface {
listUserMaRes()
}
type ListUserRes interface {
listUserRes()
}
type ListUserUeRes interface {
listUserUeRes()
}
type ReadCardOwnerRes interface {
readCardOwnerRes()
}
@@ -57,6 +89,22 @@ type ReadGroupRes interface {
readGroupRes()
}
type ReadMaOwnerRes interface {
readMaOwnerRes()
}
type ReadMaRes interface {
readMaRes()
}
type ReadUeOwnerRes interface {
readUeOwnerRes()
}
type ReadUeRes interface {
readUeRes()
}
type ReadUserRes interface {
readUserRes()
}
@@ -69,6 +117,14 @@ type UpdateGroupRes interface {
updateGroupRes()
}
type UpdateMaRes interface {
updateMaRes()
}
type UpdateUeRes interface {
updateUeRes()
}
type UpdateUserRes interface {
updateUserRes()
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -141,6 +141,132 @@ func (s *Server) decodeCreateGroupRequest(r *http.Request) (
}
}
func (s *Server) decodeCreateMaRequest(r *http.Request) (
req *CreateMaReq,
close func() error,
rerr error,
) {
var closers []func() error
close = func() error {
var merr error
// Close in reverse order, to match defer behavior.
for i := len(closers) - 1; i >= 0; i-- {
c := closers[i]
merr = multierr.Append(merr, c())
}
return merr
}
defer func() {
if rerr != nil {
rerr = multierr.Append(rerr, close())
}
}()
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return req, close, errors.Wrap(err, "parse media type")
}
switch {
case ct == "application/json":
if r.ContentLength == 0 {
return req, close, validate.ErrBodyRequired
}
buf, err := io.ReadAll(r.Body)
if err != nil {
return req, close, err
}
if len(buf) == 0 {
return req, close, validate.ErrBodyRequired
}
d := jx.DecodeBytes(buf)
var request CreateMaReq
if err := func() error {
if err := request.Decode(d); err != nil {
return err
}
if err := d.Skip(); err != io.EOF {
return errors.New("unexpected trailing data")
}
return nil
}(); err != nil {
err = &ogenerrors.DecodeBodyError{
ContentType: ct,
Body: buf,
Err: err,
}
return req, close, err
}
return &request, close, nil
default:
return req, close, validate.InvalidContentType(ct)
}
}
func (s *Server) decodeCreateUeRequest(r *http.Request) (
req *CreateUeReq,
close func() error,
rerr error,
) {
var closers []func() error
close = func() error {
var merr error
// Close in reverse order, to match defer behavior.
for i := len(closers) - 1; i >= 0; i-- {
c := closers[i]
merr = multierr.Append(merr, c())
}
return merr
}
defer func() {
if rerr != nil {
rerr = multierr.Append(rerr, close())
}
}()
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return req, close, errors.Wrap(err, "parse media type")
}
switch {
case ct == "application/json":
if r.ContentLength == 0 {
return req, close, validate.ErrBodyRequired
}
buf, err := io.ReadAll(r.Body)
if err != nil {
return req, close, err
}
if len(buf) == 0 {
return req, close, validate.ErrBodyRequired
}
d := jx.DecodeBytes(buf)
var request CreateUeReq
if err := func() error {
if err := request.Decode(d); err != nil {
return err
}
if err := d.Skip(); err != io.EOF {
return errors.New("unexpected trailing data")
}
return nil
}(); err != nil {
err = &ogenerrors.DecodeBodyError{
ContentType: ct,
Body: buf,
Err: err,
}
return req, close, err
}
return &request, close, nil
default:
return req, close, validate.InvalidContentType(ct)
}
}
func (s *Server) decodeCreateUserRequest(r *http.Request) (
req *CreateUserReq,
close func() error,
@@ -330,6 +456,132 @@ func (s *Server) decodeUpdateGroupRequest(r *http.Request) (
}
}
func (s *Server) decodeUpdateMaRequest(r *http.Request) (
req *UpdateMaReq,
close func() error,
rerr error,
) {
var closers []func() error
close = func() error {
var merr error
// Close in reverse order, to match defer behavior.
for i := len(closers) - 1; i >= 0; i-- {
c := closers[i]
merr = multierr.Append(merr, c())
}
return merr
}
defer func() {
if rerr != nil {
rerr = multierr.Append(rerr, close())
}
}()
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return req, close, errors.Wrap(err, "parse media type")
}
switch {
case ct == "application/json":
if r.ContentLength == 0 {
return req, close, validate.ErrBodyRequired
}
buf, err := io.ReadAll(r.Body)
if err != nil {
return req, close, err
}
if len(buf) == 0 {
return req, close, validate.ErrBodyRequired
}
d := jx.DecodeBytes(buf)
var request UpdateMaReq
if err := func() error {
if err := request.Decode(d); err != nil {
return err
}
if err := d.Skip(); err != io.EOF {
return errors.New("unexpected trailing data")
}
return nil
}(); err != nil {
err = &ogenerrors.DecodeBodyError{
ContentType: ct,
Body: buf,
Err: err,
}
return req, close, err
}
return &request, close, nil
default:
return req, close, validate.InvalidContentType(ct)
}
}
func (s *Server) decodeUpdateUeRequest(r *http.Request) (
req *UpdateUeReq,
close func() error,
rerr error,
) {
var closers []func() error
close = func() error {
var merr error
// Close in reverse order, to match defer behavior.
for i := len(closers) - 1; i >= 0; i-- {
c := closers[i]
merr = multierr.Append(merr, c())
}
return merr
}
defer func() {
if rerr != nil {
rerr = multierr.Append(rerr, close())
}
}()
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return req, close, errors.Wrap(err, "parse media type")
}
switch {
case ct == "application/json":
if r.ContentLength == 0 {
return req, close, validate.ErrBodyRequired
}
buf, err := io.ReadAll(r.Body)
if err != nil {
return req, close, err
}
if len(buf) == 0 {
return req, close, validate.ErrBodyRequired
}
d := jx.DecodeBytes(buf)
var request UpdateUeReq
if err := func() error {
if err := request.Decode(d); err != nil {
return err
}
if err := d.Skip(); err != io.EOF {
return errors.New("unexpected trailing data")
}
return nil
}(); err != nil {
err = &ogenerrors.DecodeBodyError{
ContentType: ct,
Body: buf,
Err: err,
}
return req, close, err
}
return &request, close, nil
default:
return req, close, validate.InvalidContentType(ct)
}
}
func (s *Server) decodeUpdateUserRequest(r *http.Request) (
req *UpdateUserReq,
close func() error,

View File

@@ -39,6 +39,34 @@ func encodeCreateGroupRequest(
return nil
}
func encodeCreateMaRequest(
req *CreateMaReq,
r *http.Request,
) error {
const contentType = "application/json"
e := jx.GetEncoder()
{
req.Encode(e)
}
encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil
}
func encodeCreateUeRequest(
req *CreateUeReq,
r *http.Request,
) error {
const contentType = "application/json"
e := jx.GetEncoder()
{
req.Encode(e)
}
encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil
}
func encodeCreateUserRequest(
req *CreateUserReq,
r *http.Request,
@@ -81,6 +109,34 @@ func encodeUpdateGroupRequest(
return nil
}
func encodeUpdateMaRequest(
req *UpdateMaReq,
r *http.Request,
) error {
const contentType = "application/json"
e := jx.GetEncoder()
{
req.Encode(e)
}
encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil
}
func encodeUpdateUeRequest(
req *UpdateUeReq,
r *http.Request,
) error {
const contentType = "application/json"
e := jx.GetEncoder()
{
req.Encode(e)
}
encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil
}
func encodeUpdateUserRequest(
req *UpdateUserReq,
r *http.Request,

File diff suppressed because it is too large Load Diff

View File

@@ -121,6 +121,116 @@ func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, s
}
}
func encodeCreateMaResponse(response CreateMaRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *MaCreate:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R400:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
span.SetStatus(codes.Error, http.StatusText(400))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R409:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(409)
span.SetStatus(codes.Error, http.StatusText(409))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R500:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(500)
span.SetStatus(codes.Error, http.StatusText(500))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
default:
return errors.Errorf("unexpected response type: %T", response)
}
}
func encodeCreateUeResponse(response CreateUeRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *UeCreate:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
span.SetStatus(codes.Ok, http.StatusText(200))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R400:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
span.SetStatus(codes.Error, http.StatusText(400))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R409:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(409)
span.SetStatus(codes.Error, http.StatusText(409))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R500:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(500)
span.SetStatus(codes.Error, http.StatusText(500))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
default:
return errors.Errorf("unexpected response type: %T", response)
}
}
func encodeCreateUserResponse(response CreateUserRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *UserCreate:
@@ -298,6 +408,128 @@ func encodeDeleteGroupResponse(response DeleteGroupRes, w http.ResponseWriter, s
}
}
func encodeDeleteMaResponse(response DeleteMaRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *DeleteMaNoContent:
w.WriteHeader(204)
span.SetStatus(codes.Ok, http.StatusText(204))
return nil
case *R400:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
span.SetStatus(codes.Error, http.StatusText(400))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R404:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(404)
span.SetStatus(codes.Error, http.StatusText(404))
e := jx.GetEncoder()
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *R409:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(409)
span.SetStatus(codes.Error, http.StatusText(409))
e := jx.GetEncoder()