mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-15 17:19:10 +00:00
re-init because of weird subtree shit
This commit is contained in:
commit
68254ddd13
85 changed files with 13501 additions and 0 deletions
14
src/common/version/BUILD.bazel
Normal file
14
src/common/version/BUILD.bazel
Normal file
|
@ -0,0 +1,14 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "version",
|
||||
srcs = ["version.go"],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/common/version",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "version_test",
|
||||
srcs = ["version_test.go"],
|
||||
embed = [":version"],
|
||||
)
|
21
src/common/version/version.go
Normal file
21
src/common/version/version.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
GitCommit = "unknown"
|
||||
GitBranch = "unknown"
|
||||
BuildDate = "unknown"
|
||||
)
|
||||
|
||||
func StartupInfo(serviceName string) string {
|
||||
return fmt.Sprintf(
|
||||
"Starting %s service.\n Build %s (%s) at %s",
|
||||
serviceName,
|
||||
GitCommit,
|
||||
GitBranch,
|
||||
BuildDate,
|
||||
)
|
||||
}
|
18
src/common/version/version_test.go
Normal file
18
src/common/version/version_test.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStartup(t *testing.T) {
|
||||
GitBranch = "test"
|
||||
GitCommit = "e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"
|
||||
BuildDate = time.Now().UTC().Format("2006-01-02T15:04:05.000Z")
|
||||
|
||||
expected := "Starting test service.\n Build e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e (test) at " + BuildDate
|
||||
value := StartupInfo("test")
|
||||
if value != expected {
|
||||
t.Error("Incorrect render, got `", value, "`")
|
||||
}
|
||||
}
|
1
src/db/.gitignore
vendored
Normal file
1
src/db/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.env
|
21
src/db/LICENSE
Normal file
21
src/db/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 roleypoly maintainers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
17
src/db/README.md
Normal file
17
src/db/README.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# DB
|
||||
|
||||
Roleypoly's DB schemas, connectors, and other useful database admin tools.
|
||||
|
||||
## Tools
|
||||
|
||||
### ent
|
||||
|
||||
ent schema and the files it generates.
|
||||
|
||||
Edit nothing outside of the `schemas` folder, as all others are generated.
|
||||
|
||||
When done editing, do `go generate ./ent` to update generation.
|
||||
|
||||
*Failing to generate files will make CI fail.*
|
||||
|
||||
All schemas must be backwards compatible with previous versions of this library, and be compatible with **CockroachDB**-based Postgres.
|
23
src/db/cmd/db-tool/BUILD.bazel
Normal file
23
src/db/cmd/db-tool/BUILD.bazel
Normal file
|
@ -0,0 +1,23 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "db-tool_lib",
|
||||
srcs = [
|
||||
"import.go",
|
||||
"migrate.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/cmd/db-tool",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"@com_github_lib_pq//:pq",
|
||||
"@com_github_roleypoly_db//ent",
|
||||
"@com_github_roleypoly_db//ent/migrate",
|
||||
"@com_github_roleypoly_db//ent/schema",
|
||||
],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "db-tool",
|
||||
embed = [":db-tool_lib"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
59
src/db/cmd/db-tool/Dockerfile
Normal file
59
src/db/cmd/db-tool/Dockerfile
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Accept the Go version for the image to be set as a build argument.
|
||||
# Default to Go 1.12
|
||||
ARG GO_VERSION=1.13
|
||||
|
||||
# First stage: build the executable.
|
||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS builder
|
||||
|
||||
ARG GOPROXY
|
||||
ARG BUILDPLATFORM
|
||||
ARG TARGETARCH
|
||||
ARG TARGETOS
|
||||
ENV GOPROXY ${GOPROXY}
|
||||
ENV GOOS ${TARGETOS}
|
||||
ENV GOARCH ${TARGETARCH}
|
||||
|
||||
# Create the user and group files that will be used in the running container to
|
||||
# run the process as an unprivileged user.
|
||||
RUN mkdir /user && \
|
||||
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
|
||||
echo 'nobody:x:65534:' > /user/group
|
||||
|
||||
# Install the Certificate-Authority certificates for the app to be able to make
|
||||
# calls to HTTPS endpoints.
|
||||
# Git is required for fetching the dependencies.
|
||||
RUN apk add --no-cache ca-certificates git
|
||||
|
||||
# Set the working directory outside $GOPATH to enable the support for modules.
|
||||
WORKDIR /src
|
||||
|
||||
# Fetch dependencies first; they are less susceptible to change on every build
|
||||
# and will therefore be cached for speeding up the next build
|
||||
COPY ./go.mod ./go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Import the code from the context.
|
||||
COPY ./ ./
|
||||
|
||||
# Build the executable to `/app`. Mark the build as statically linked.
|
||||
RUN CGO_ENABLED=0 go build \
|
||||
-installsuffix 'static' \
|
||||
-o /app ./cmd/db-tool
|
||||
|
||||
# Final stage: the running container.
|
||||
FROM scratch AS final
|
||||
|
||||
# Import the user and group files from the first stage.
|
||||
COPY --from=builder /user/group /user/passwd /etc/
|
||||
|
||||
# Import the Certificate-Authority certificates for enabling HTTPS.
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
# Import the compiled executable from the first stage.
|
||||
COPY --from=builder /app /app
|
||||
|
||||
# Perform any further action as an unprivileged user.
|
||||
USER nobody:nobody
|
||||
|
||||
# Run the compiled binary.
|
||||
ENTRYPOINT ["/app"]
|
14
src/db/cmd/db-tool/docker-compose.yaml
Normal file
14
src/db/cmd/db-tool/docker-compose.yaml
Normal file
|
@ -0,0 +1,14 @@
|
|||
version: '2'
|
||||
|
||||
services:
|
||||
pg:
|
||||
image: postgres:11-alpine
|
||||
ports:
|
||||
- 5432
|
||||
volumes:
|
||||
- './.data/pg:/var/lib/postgresql/data'
|
||||
environment:
|
||||
POSTGRES_PASSWORD: 19216801
|
||||
POSTGRES_DB: roleypoly
|
||||
POSTGRES_USER: roleypoly
|
||||
POSTGRES_INITDB_ARGS: -A trust
|
104
src/db/cmd/db-tool/import.go
Normal file
104
src/db/cmd/db-tool/import.go
Normal file
|
@ -0,0 +1,104 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
ent "github.com/roleypoly/db/ent"
|
||||
"github.com/roleypoly/db/ent/schema"
|
||||
)
|
||||
|
||||
type v1Category struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Roles []string `json:"roles"`
|
||||
Hidden bool `json:"hidden"`
|
||||
Type string `json:"type"`
|
||||
Position int `json:"position"`
|
||||
}
|
||||
|
||||
type v1Server struct {
|
||||
ID string `json:"id"`
|
||||
Categories []v1Category `json:"categories"`
|
||||
Message string `json:"message"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func fromCategories(cats []v1Category) []schema.Category {
|
||||
out := make([]schema.Category, len(cats))
|
||||
for i, cat := range cats {
|
||||
out[i] = schema.Category{
|
||||
ID: cat.ID,
|
||||
Name: cat.Name,
|
||||
Hidden: cat.Hidden,
|
||||
Type: cat.Type,
|
||||
Position: cat.Position,
|
||||
Roles: cat.Roles,
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func runImport(newDB *ent.Client, oldDB *sql.DB) {
|
||||
ctx := ent.NewContext(context.Background(), newDB)
|
||||
tx, err := newDB.Tx(ctx)
|
||||
|
||||
oldServers, err := oldDB.Query(`SELECT * FROM servers`)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
log.Fatalln("query error", err)
|
||||
}
|
||||
|
||||
defer oldServers.Close()
|
||||
|
||||
for oldServers.Next() == true {
|
||||
var data v1Server
|
||||
|
||||
log.Printf("importing %s\n", data.ID)
|
||||
|
||||
err = oldServers.Scan(&data)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
log.Fatalln("data scan error", err)
|
||||
}
|
||||
|
||||
guild := tx.Guild.Create()
|
||||
|
||||
guild.SetMessage(data.Message).
|
||||
SetSnowflake(data.ID).
|
||||
SetCategories(fromCategories(data.Categories)).
|
||||
SetCreateTime(data.CreatedAt)
|
||||
|
||||
ctx := ent.NewContext(context.Background(), newDB)
|
||||
guild.SaveX(ctx)
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Fatalln("tx commit error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func importFromV1() {
|
||||
log.Println("Import from V1 starting.")
|
||||
|
||||
client, err := ent.Open("postgres", os.Getenv("DB_URL"))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
oldClient, err := sql.Open("postgres", os.Getenv("OLD_DB_URL"))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer oldClient.Close()
|
||||
|
||||
runImport(client, oldClient)
|
||||
log.Println("Import from V1 finished.")
|
||||
}
|
58
src/db/cmd/db-tool/migrate.go
Normal file
58
src/db/cmd/db-tool/migrate.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
ent "github.com/roleypoly/db/ent"
|
||||
"github.com/roleypoly/db/ent/migrate"
|
||||
)
|
||||
|
||||
func retryMigrate(client *ent.Client) {
|
||||
for i := 0; i < 10; i++ {
|
||||
err := client.Schema.Create(context.Background(), migrate.WithGlobalUniqueID(true))
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Migration failed --", err)
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
||||
log.Fatalln("Migration failed after 20 seconds.")
|
||||
return
|
||||
}
|
||||
|
||||
func doMigrate() {
|
||||
log.Println("Migrations starting.")
|
||||
|
||||
client, err := ent.Open("postgres", os.Getenv("DB_URL"))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
defer client.Close()
|
||||
|
||||
retryMigrate(client)
|
||||
log.Println("Migrations finished.")
|
||||
}
|
||||
|
||||
func main() {
|
||||
tool := os.Args[1]
|
||||
if tool == "" {
|
||||
tool = "migrate"
|
||||
}
|
||||
|
||||
switch tool {
|
||||
case "migrate":
|
||||
doMigrate()
|
||||
case "import":
|
||||
importFromV1()
|
||||
default:
|
||||
log.Fatalln("supported tools: migrate, import")
|
||||
}
|
||||
|
||||
}
|
45
src/db/ent/BUILD.bazel
Normal file
45
src/db/ent/BUILD.bazel
Normal file
|
@ -0,0 +1,45 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "ent",
|
||||
srcs = [
|
||||
"challenge.go",
|
||||
"challenge_create.go",
|
||||
"challenge_delete.go",
|
||||
"challenge_query.go",
|
||||
"challenge_update.go",
|
||||
"client.go",
|
||||
"config.go",
|
||||
"context.go",
|
||||
"ent.go",
|
||||
"generate.go",
|
||||
"guild.go",
|
||||
"guild_create.go",
|
||||
"guild_delete.go",
|
||||
"guild_query.go",
|
||||
"guild_update.go",
|
||||
"mutation.go",
|
||||
"runtime.go",
|
||||
"session.go",
|
||||
"session_create.go",
|
||||
"session_delete.go",
|
||||
"session_query.go",
|
||||
"session_update.go",
|
||||
"tx.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//src/db/ent/challenge",
|
||||
"//src/db/ent/guild",
|
||||
"//src/db/ent/migrate",
|
||||
"//src/db/ent/predicate",
|
||||
"//src/db/ent/schema",
|
||||
"//src/db/ent/session",
|
||||
"@com_github_facebook_ent//:ent",
|
||||
"@com_github_facebook_ent//dialect",
|
||||
"@com_github_facebook_ent//dialect/sql",
|
||||
"@com_github_facebook_ent//dialect/sql/sqlgraph",
|
||||
"@com_github_facebook_ent//schema/field",
|
||||
],
|
||||
)
|
147
src/db/ent/challenge.go
Normal file
147
src/db/ent/challenge.go
Normal file
|
@ -0,0 +1,147 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/challenge"
|
||||
)
|
||||
|
||||
// Challenge is the model entity for the Challenge schema.
|
||||
type Challenge struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||
// ChallengeID holds the value of the "challenge_id" field.
|
||||
ChallengeID string `json:"challenge_id,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID string `json:"user_id,omitempty"`
|
||||
// Human holds the value of the "human" field.
|
||||
Human string `json:"human,omitempty"`
|
||||
// Magic holds the value of the "magic" field.
|
||||
Magic string `json:"magic,omitempty"`
|
||||
// ExpiresAt holds the value of the "expires_at" field.
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Challenge) scanValues() []interface{} {
|
||||
return []interface{}{
|
||||
&sql.NullInt64{}, // id
|
||||
&sql.NullTime{}, // create_time
|
||||
&sql.NullTime{}, // update_time
|
||||
&sql.NullString{}, // challenge_id
|
||||
&sql.NullString{}, // user_id
|
||||
&sql.NullString{}, // human
|
||||
&sql.NullString{}, // magic
|
||||
&sql.NullTime{}, // expires_at
|
||||
}
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Challenge fields.
|
||||
func (c *Challenge) assignValues(values ...interface{}) error {
|
||||
if m, n := len(values), len(challenge.Columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
value, ok := values[0].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
c.ID = int(value.Int64)
|
||||
values = values[1:]
|
||||
if value, ok := values[0].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[0])
|
||||
} else if value.Valid {
|
||||
c.CreateTime = value.Time
|
||||
}
|
||||
if value, ok := values[1].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field update_time", values[1])
|
||||
} else if value.Valid {
|
||||
c.UpdateTime = value.Time
|
||||
}
|
||||
if value, ok := values[2].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field challenge_id", values[2])
|
||||
} else if value.Valid {
|
||||
c.ChallengeID = value.String
|
||||
}
|
||||
if value, ok := values[3].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[3])
|
||||
} else if value.Valid {
|
||||
c.UserID = value.String
|
||||
}
|
||||
if value, ok := values[4].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field human", values[4])
|
||||
} else if value.Valid {
|
||||
c.Human = value.String
|
||||
}
|
||||
if value, ok := values[5].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field magic", values[5])
|
||||
} else if value.Valid {
|
||||
c.Magic = value.String
|
||||
}
|
||||
if value, ok := values[6].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field expires_at", values[6])
|
||||
} else if value.Valid {
|
||||
c.ExpiresAt = value.Time
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Challenge.
|
||||
// Note that, you need to call Challenge.Unwrap() before calling this method, if this Challenge
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (c *Challenge) Update() *ChallengeUpdateOne {
|
||||
return (&ChallengeClient{config: c.config}).UpdateOne(c)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
|
||||
// so that all next queries will be executed through the driver which created the transaction.
|
||||
func (c *Challenge) Unwrap() *Challenge {
|
||||
tx, ok := c.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Challenge is not a transactional entity")
|
||||
}
|
||||
c.config.driver = tx.drv
|
||||
return c
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (c *Challenge) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Challenge(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", c.ID))
|
||||
builder.WriteString(", create_time=")
|
||||
builder.WriteString(c.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", update_time=")
|
||||
builder.WriteString(c.UpdateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", challenge_id=")
|
||||
builder.WriteString(c.ChallengeID)
|
||||
builder.WriteString(", user_id=")
|
||||
builder.WriteString(c.UserID)
|
||||
builder.WriteString(", human=")
|
||||
builder.WriteString(c.Human)
|
||||
builder.WriteString(", magic=")
|
||||
builder.WriteString(c.Magic)
|
||||
builder.WriteString(", expires_at=")
|
||||
builder.WriteString(c.ExpiresAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Challenges is a parsable slice of Challenge.
|
||||
type Challenges []*Challenge
|
||||
|
||||
func (c Challenges) config(cfg config) {
|
||||
for _i := range c {
|
||||
c[_i].config = cfg
|
||||
}
|
||||
}
|
15
src/db/ent/challenge/BUILD.bazel
Normal file
15
src/db/ent/challenge/BUILD.bazel
Normal file
|
@ -0,0 +1,15 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "challenge",
|
||||
srcs = [
|
||||
"challenge.go",
|
||||
"where.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/challenge",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//src/db/ent/predicate",
|
||||
"@com_github_facebook_ent//dialect/sql",
|
||||
],
|
||||
)
|
54
src/db/ent/challenge/challenge.go
Normal file
54
src/db/ent/challenge/challenge.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package challenge
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the challenge type in the database.
|
||||
Label = "challenge"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||
FieldUpdateTime = "update_time"
|
||||
// FieldChallengeID holds the string denoting the challenge_id field in the database.
|
||||
FieldChallengeID = "challenge_id"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldHuman holds the string denoting the human field in the database.
|
||||
FieldHuman = "human"
|
||||
// FieldMagic holds the string denoting the magic field in the database.
|
||||
FieldMagic = "magic"
|
||||
// FieldExpiresAt holds the string denoting the expires_at field in the database.
|
||||
FieldExpiresAt = "expires_at"
|
||||
|
||||
// Table holds the table name of the challenge in the database.
|
||||
Table = "challenges"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for challenge fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldChallengeID,
|
||||
FieldUserID,
|
||||
FieldHuman,
|
||||
FieldMagic,
|
||||
FieldExpiresAt,
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
DefaultCreateTime func() time.Time
|
||||
// DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
DefaultUpdateTime func() time.Time
|
||||
// UpdateDefaultUpdateTime holds the default value on update for the update_time field.
|
||||
UpdateDefaultUpdateTime func() time.Time
|
||||
// DefaultExpiresAt holds the default value on creation for the expires_at field.
|
||||
DefaultExpiresAt func() time.Time
|
||||
)
|
846
src/db/ent/challenge/where.go
Normal file
846
src/db/ent/challenge/where.go
Normal file
|
@ -0,0 +1,846 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package challenge
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their identifier.
|
||||
func ID(id int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||
func UpdateTime(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeID applies equality check predicate on the "challenge_id" field. It's identical to ChallengeIDEQ.
|
||||
func ChallengeID(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Human applies equality check predicate on the "human" field. It's identical to HumanEQ.
|
||||
func Human(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Magic applies equality check predicate on the "magic" field. It's identical to MagicEQ.
|
||||
func Magic(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
|
||||
func ExpiresAt(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldCreateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldCreateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...time.Time) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldUpdateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...time.Time) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldUpdateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDEQ applies the EQ predicate on the "challenge_id" field.
|
||||
func ChallengeIDEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDNEQ applies the NEQ predicate on the "challenge_id" field.
|
||||
func ChallengeIDNEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDIn applies the In predicate on the "challenge_id" field.
|
||||
func ChallengeIDIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldChallengeID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDNotIn applies the NotIn predicate on the "challenge_id" field.
|
||||
func ChallengeIDNotIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldChallengeID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDGT applies the GT predicate on the "challenge_id" field.
|
||||
func ChallengeIDGT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDGTE applies the GTE predicate on the "challenge_id" field.
|
||||
func ChallengeIDGTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDLT applies the LT predicate on the "challenge_id" field.
|
||||
func ChallengeIDLT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDLTE applies the LTE predicate on the "challenge_id" field.
|
||||
func ChallengeIDLTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDContains applies the Contains predicate on the "challenge_id" field.
|
||||
func ChallengeIDContains(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDHasPrefix applies the HasPrefix predicate on the "challenge_id" field.
|
||||
func ChallengeIDHasPrefix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDHasSuffix applies the HasSuffix predicate on the "challenge_id" field.
|
||||
func ChallengeIDHasSuffix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDEqualFold applies the EqualFold predicate on the "challenge_id" field.
|
||||
func ChallengeIDEqualFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ChallengeIDContainsFold applies the ContainsFold predicate on the "challenge_id" field.
|
||||
func ChallengeIDContainsFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldChallengeID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldUserID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldUserID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDGT applies the GT predicate on the "user_id" field.
|
||||
func UserIDGT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDGTE applies the GTE predicate on the "user_id" field.
|
||||
func UserIDGTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDLT applies the LT predicate on the "user_id" field.
|
||||
func UserIDLT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDLTE applies the LTE predicate on the "user_id" field.
|
||||
func UserIDLTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDContains applies the Contains predicate on the "user_id" field.
|
||||
func UserIDContains(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field.
|
||||
func UserIDHasPrefix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field.
|
||||
func UserIDHasSuffix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDEqualFold applies the EqualFold predicate on the "user_id" field.
|
||||
func UserIDEqualFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field.
|
||||
func UserIDContainsFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanEQ applies the EQ predicate on the "human" field.
|
||||
func HumanEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanNEQ applies the NEQ predicate on the "human" field.
|
||||
func HumanNEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanIn applies the In predicate on the "human" field.
|
||||
func HumanIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldHuman), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanNotIn applies the NotIn predicate on the "human" field.
|
||||
func HumanNotIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldHuman), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanGT applies the GT predicate on the "human" field.
|
||||
func HumanGT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanGTE applies the GTE predicate on the "human" field.
|
||||
func HumanGTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanLT applies the LT predicate on the "human" field.
|
||||
func HumanLT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanLTE applies the LTE predicate on the "human" field.
|
||||
func HumanLTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanContains applies the Contains predicate on the "human" field.
|
||||
func HumanContains(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanHasPrefix applies the HasPrefix predicate on the "human" field.
|
||||
func HumanHasPrefix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanHasSuffix applies the HasSuffix predicate on the "human" field.
|
||||
func HumanHasSuffix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanEqualFold applies the EqualFold predicate on the "human" field.
|
||||
func HumanEqualFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// HumanContainsFold applies the ContainsFold predicate on the "human" field.
|
||||
func HumanContainsFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldHuman), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicEQ applies the EQ predicate on the "magic" field.
|
||||
func MagicEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicNEQ applies the NEQ predicate on the "magic" field.
|
||||
func MagicNEQ(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicIn applies the In predicate on the "magic" field.
|
||||
func MagicIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldMagic), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicNotIn applies the NotIn predicate on the "magic" field.
|
||||
func MagicNotIn(vs ...string) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldMagic), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicGT applies the GT predicate on the "magic" field.
|
||||
func MagicGT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicGTE applies the GTE predicate on the "magic" field.
|
||||
func MagicGTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicLT applies the LT predicate on the "magic" field.
|
||||
func MagicLT(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicLTE applies the LTE predicate on the "magic" field.
|
||||
func MagicLTE(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicContains applies the Contains predicate on the "magic" field.
|
||||
func MagicContains(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicHasPrefix applies the HasPrefix predicate on the "magic" field.
|
||||
func MagicHasPrefix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicHasSuffix applies the HasSuffix predicate on the "magic" field.
|
||||
func MagicHasSuffix(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicEqualFold applies the EqualFold predicate on the "magic" field.
|
||||
func MagicEqualFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MagicContainsFold applies the ContainsFold predicate on the "magic" field.
|
||||
func MagicContainsFold(v string) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldMagic), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
|
||||
func ExpiresAtEQ(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
|
||||
func ExpiresAtNEQ(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtIn applies the In predicate on the "expires_at" field.
|
||||
func ExpiresAtIn(vs ...time.Time) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldExpiresAt), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
|
||||
func ExpiresAtNotIn(vs ...time.Time) predicate.Challenge {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldExpiresAt), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
|
||||
func ExpiresAtGT(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
|
||||
func ExpiresAtGTE(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
|
||||
func ExpiresAtLT(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
|
||||
func ExpiresAtLTE(v time.Time) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Challenge) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups list of predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Challenge) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Challenge) predicate.Challenge {
|
||||
return predicate.Challenge(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
310
src/db/ent/challenge_create.go
Normal file
310
src/db/ent/challenge_create.go
Normal file
|
@ -0,0 +1,310 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/challenge"
|
||||
)
|
||||
|
||||
// ChallengeCreate is the builder for creating a Challenge entity.
|
||||
type ChallengeCreate struct {
|
||||
config
|
||||
mutation *ChallengeMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreateTime sets the create_time field.
|
||||
func (cc *ChallengeCreate) SetCreateTime(t time.Time) *ChallengeCreate {
|
||||
cc.mutation.SetCreateTime(t)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the create_time field if the given value is not nil.
|
||||
func (cc *ChallengeCreate) SetNillableCreateTime(t *time.Time) *ChallengeCreate {
|
||||
if t != nil {
|
||||
cc.SetCreateTime(*t)
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the update_time field.
|
||||
func (cc *ChallengeCreate) SetUpdateTime(t time.Time) *ChallengeCreate {
|
||||
cc.mutation.SetUpdateTime(t)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetNillableUpdateTime sets the update_time field if the given value is not nil.
|
||||
func (cc *ChallengeCreate) SetNillableUpdateTime(t *time.Time) *ChallengeCreate {
|
||||
if t != nil {
|
||||
cc.SetUpdateTime(*t)
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetChallengeID sets the challenge_id field.
|
||||
func (cc *ChallengeCreate) SetChallengeID(s string) *ChallengeCreate {
|
||||
cc.mutation.SetChallengeID(s)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetUserID sets the user_id field.
|
||||
func (cc *ChallengeCreate) SetUserID(s string) *ChallengeCreate {
|
||||
cc.mutation.SetUserID(s)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetHuman sets the human field.
|
||||
func (cc *ChallengeCreate) SetHuman(s string) *ChallengeCreate {
|
||||
cc.mutation.SetHuman(s)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetMagic sets the magic field.
|
||||
func (cc *ChallengeCreate) SetMagic(s string) *ChallengeCreate {
|
||||
cc.mutation.SetMagic(s)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetExpiresAt sets the expires_at field.
|
||||
func (cc *ChallengeCreate) SetExpiresAt(t time.Time) *ChallengeCreate {
|
||||
cc.mutation.SetExpiresAt(t)
|
||||
return cc
|
||||
}
|
||||
|
||||
// SetNillableExpiresAt sets the expires_at field if the given value is not nil.
|
||||
func (cc *ChallengeCreate) SetNillableExpiresAt(t *time.Time) *ChallengeCreate {
|
||||
if t != nil {
|
||||
cc.SetExpiresAt(*t)
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
// Mutation returns the ChallengeMutation object of the builder.
|
||||
func (cc *ChallengeCreate) Mutation() *ChallengeMutation {
|
||||
return cc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Challenge in the database.
|
||||
func (cc *ChallengeCreate) Save(ctx context.Context) (*Challenge, error) {
|
||||
if err := cc.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Challenge
|
||||
)
|
||||
if len(cc.hooks) == 0 {
|
||||
node, err = cc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ChallengeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
cc.mutation = mutation
|
||||
node, err = cc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(cc.hooks) - 1; i >= 0; i-- {
|
||||
mut = cc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (cc *ChallengeCreate) SaveX(ctx context.Context) *Challenge {
|
||||
v, err := cc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (cc *ChallengeCreate) preSave() error {
|
||||
if _, ok := cc.mutation.CreateTime(); !ok {
|
||||
v := challenge.DefaultCreateTime()
|
||||
cc.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := cc.mutation.UpdateTime(); !ok {
|
||||
v := challenge.DefaultUpdateTime()
|
||||
cc.mutation.SetUpdateTime(v)
|
||||
}
|
||||
if _, ok := cc.mutation.ChallengeID(); !ok {
|
||||
return &ValidationError{Name: "challenge_id", err: errors.New("ent: missing required field \"challenge_id\"")}
|
||||
}
|
||||
if _, ok := cc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New("ent: missing required field \"user_id\"")}
|
||||
}
|
||||
if _, ok := cc.mutation.Human(); !ok {
|
||||
return &ValidationError{Name: "human", err: errors.New("ent: missing required field \"human\"")}
|
||||
}
|
||||
if _, ok := cc.mutation.Magic(); !ok {
|
||||
return &ValidationError{Name: "magic", err: errors.New("ent: missing required field \"magic\"")}
|
||||
}
|
||||
if _, ok := cc.mutation.ExpiresAt(); !ok {
|
||||
v := challenge.DefaultExpiresAt()
|
||||
cc.mutation.SetExpiresAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cc *ChallengeCreate) sqlSave(ctx context.Context) (*Challenge, error) {
|
||||
c, _spec := cc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
c.ID = int(id)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (cc *ChallengeCreate) createSpec() (*Challenge, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
c = &Challenge{config: cc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: challenge.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: challenge.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := cc.mutation.CreateTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: challenge.FieldCreateTime,
|
||||
})
|
||||
c.CreateTime = value
|
||||
}
|
||||
if value, ok := cc.mutation.UpdateTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: challenge.FieldUpdateTime,
|
||||
})
|
||||
c.UpdateTime = value
|
||||
}
|
||||
if value, ok := cc.mutation.ChallengeID(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: challenge.FieldChallengeID,
|
||||
})
|
||||
c.ChallengeID = value
|
||||
}
|
||||
if value, ok := cc.mutation.UserID(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: challenge.FieldUserID,
|
||||
})
|
||||
c.UserID = value
|
||||
}
|
||||
if value, ok := cc.mutation.Human(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: challenge.FieldHuman,
|
||||
})
|
||||
c.Human = value
|
||||
}
|
||||
if value, ok := cc.mutation.Magic(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: challenge.FieldMagic,
|
||||
})
|
||||
c.Magic = value
|
||||
}
|
||||
if value, ok := cc.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: challenge.FieldExpiresAt,
|
||||
})
|
||||
c.ExpiresAt = value
|
||||
}
|
||||
return c, _spec
|
||||
}
|
||||
|
||||
// ChallengeCreateBulk is the builder for creating a bulk of Challenge entities.
|
||||
type ChallengeCreateBulk struct {
|
||||
config
|
||||
builders []*ChallengeCreate
|
||||
}
|
||||
|
||||
// Save creates the Challenge entities in the database.
|
||||
func (ccb *ChallengeCreateBulk) Save(ctx context.Context) ([]*Challenge, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
|
||||
nodes := make([]*Challenge, len(ccb.builders))
|
||||
mutators := make([]Mutator, len(ccb.builders))
|
||||
for i := range ccb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := ccb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
if err := builder.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation, ok := m.(*ChallengeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation)
|
||||
} else {
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ccb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
}
|
||||
}
|
||||
mutation.done = true
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
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, ccb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (ccb *ChallengeCreateBulk) SaveX(ctx context.Context) []*Challenge {
|
||||
v, err := ccb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
109
src/db/ent/challenge_delete.go
Normal file
109
src/db/ent/challenge_delete.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/challenge"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ChallengeDelete is the builder for deleting a Challenge entity.
|
||||
type ChallengeDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ChallengeMutation
|
||||
predicates []predicate.Challenge
|
||||
}
|
||||
|
||||
// Where adds a new predicate to the delete builder.
|
||||
func (cd *ChallengeDelete) Where(ps ...predicate.Challenge) *ChallengeDelete {
|
||||
cd.predicates = append(cd.predicates, ps...)
|
||||
return cd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (cd *ChallengeDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(cd.hooks) == 0 {
|
||||
affected, err = cd.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ChallengeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
cd.mutation = mutation
|
||||
affected, err = cd.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(cd.hooks) - 1; i >= 0; i-- {
|
||||
mut = cd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cd.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cd *ChallengeDelete) ExecX(ctx context.Context) int {
|
||||
n, err := cd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (cd *ChallengeDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: challenge.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: challenge.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := cd.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, cd.driver, _spec)
|
||||
}
|
||||
|
||||
// ChallengeDeleteOne is the builder for deleting a single Challenge entity.
|
||||
type ChallengeDeleteOne struct {
|
||||
cd *ChallengeDelete
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (cdo *ChallengeDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := cdo.cd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{challenge.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cdo *ChallengeDeleteOne) ExecX(ctx context.Context) {
|
||||
cdo.cd.ExecX(ctx)
|
||||
}
|
866
src/db/ent/challenge_query.go
Normal file
866
src/db/ent/challenge_query.go
Normal file
|
@ -0,0 +1,866 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/challenge"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ChallengeQuery is the builder for querying Challenge entities.
|
||||
type ChallengeQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.Challenge
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (cq *ChallengeQuery) Where(ps ...predicate.Challenge) *ChallengeQuery {
|
||||
cq.predicates = append(cq.predicates, ps...)
|
||||
return cq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (cq *ChallengeQuery) Limit(limit int) *ChallengeQuery {
|
||||
cq.limit = &limit
|
||||
return cq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (cq *ChallengeQuery) Offset(offset int) *ChallengeQuery {
|
||||
cq.offset = &offset
|
||||
return cq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (cq *ChallengeQuery) Order(o ...OrderFunc) *ChallengeQuery {
|
||||
cq.order = append(cq.order, o...)
|
||||
return cq
|
||||
}
|
||||
|
||||
// First returns the first Challenge entity in the query. Returns *NotFoundError when no challenge was found.
|
||||
func (cq *ChallengeQuery) First(ctx context.Context) (*Challenge, error) {
|
||||
cs, err := cq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(cs) == 0 {
|
||||
return nil, &NotFoundError{challenge.Label}
|
||||
}
|
||||
return cs[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) FirstX(ctx context.Context) *Challenge {
|
||||
c, err := cq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// FirstID returns the first Challenge id in the query. Returns *NotFoundError when no id was found.
|
||||
func (cq *ChallengeQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = cq.Limit(1).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{challenge.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstXID is like FirstID, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) FirstXID(ctx context.Context) int {
|
||||
id, err := cq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns the only Challenge entity in the query, returns an error if not exactly one entity was returned.
|
||||
func (cq *ChallengeQuery) Only(ctx context.Context) (*Challenge, error) {
|
||||
cs, err := cq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(cs) {
|
||||
case 1:
|
||||
return cs[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{challenge.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{challenge.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) OnlyX(ctx context.Context) *Challenge {
|
||||
c, err := cq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// OnlyID returns the only Challenge id in the query, returns an error if not exactly one id was returned.
|
||||
func (cq *ChallengeQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = cq.Limit(2).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = &NotSingularError{challenge.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := cq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Challenges.
|
||||
func (cq *ChallengeQuery) All(ctx context.Context) ([]*Challenge, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) AllX(ctx context.Context) []*Challenge {
|
||||
cs, err := cq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return cs
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Challenge ids.
|
||||
func (cq *ChallengeQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := cq.Select(challenge.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := cq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (cq *ChallengeQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return cq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) CountX(ctx context.Context) int {
|
||||
count, err := cq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (cq *ChallengeQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (cq *ChallengeQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := cq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the query builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (cq *ChallengeQuery) Clone() *ChallengeQuery {
|
||||
return &ChallengeQuery{
|
||||
config: cq.config,
|
||||
limit: cq.limit,
|
||||
offset: cq.offset,
|
||||
order: append([]OrderFunc{}, cq.order...),
|
||||
unique: append([]string{}, cq.unique...),
|
||||
predicates: append([]predicate.Challenge{}, cq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: cq.sql.Clone(),
|
||||
path: cq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Challenge.Query().
|
||||
// GroupBy(challenge.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (cq *ChallengeQuery) GroupBy(field string, fields ...string) *ChallengeGroupBy {
|
||||
group := &ChallengeGroupBy{config: cq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
// Select one or more fields from the given query.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Challenge.Query().
|
||||
// Select(challenge.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (cq *ChallengeQuery) Select(field string, fields ...string) *ChallengeSelect {
|
||||
selector := &ChallengeSelect{config: cq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (cq *ChallengeQuery) prepareQuery(ctx context.Context) error {
|
||||
if cq.path != nil {
|
||||
prev, err := cq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cq *ChallengeQuery) sqlAll(ctx context.Context) ([]*Challenge, error) {
|
||||
var (
|
||||
nodes = []*Challenge{}
|
||||
_spec = cq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func() []interface{} {
|
||||
node := &Challenge{config: cq.config}
|
||||
nodes = append(nodes, node)
|
||||
values := node.scanValues()
|
||||
return values
|
||||
}
|
||||
_spec.Assign = func(values ...interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
return node.assignValues(values...)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (cq *ChallengeQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := cq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, cq.driver, _spec)
|
||||
}
|
||||
|
||||
func (cq *ChallengeQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := cq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %v", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (cq *ChallengeQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: challenge.Table,
|
||||
Columns: challenge.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: challenge.FieldID,
|
||||
},
|
||||
},
|
||||
From: cq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if ps := cq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := cq.limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := cq.offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := cq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (cq *ChallengeQuery) sqlQuery() *sql.Selector {
|
||||
builder := sql.Dialect(cq.driver.Dialect())
|
||||
t1 := builder.Table(challenge.Table)
|
||||
selector := builder.Select(t1.Columns(challenge.Columns...)...).From(t1)
|
||||
if cq.sql != nil {
|
||||
selector = cq.sql
|
||||
selector.Select(selector.Columns(challenge.Columns...)...)
|
||||
}
|
||||
for _, p := range cq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range cq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := cq.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 := cq.limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ChallengeGroupBy is the builder for group-by Challenge entities.
|
||||
type ChallengeGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (cgb *ChallengeGroupBy) Aggregate(fns ...AggregateFunc) *ChallengeGroupBy {
|
||||
cgb.fns = append(cgb.fns, fns...)
|
||||
return cgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (cgb *ChallengeGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := cgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cgb.sql = query
|
||||
return cgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := cgb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(cgb.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := cgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := cgb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = cgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := cgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(cgb.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := cgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := cgb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = cgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := cgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(cgb.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := cgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := cgb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = cgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := cgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(cgb.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := cgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := cgb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (cgb *ChallengeGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = cgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (cgb *ChallengeGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := cgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (cgb *ChallengeGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := cgb.sqlQuery().Query()
|
||||
if err := cgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (cgb *ChallengeGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := cgb.sql
|
||||
columns := make([]string, 0, len(cgb.fields)+len(cgb.fns))
|
||||
columns = append(columns, cgb.fields...)
|
||||
for _, fn := range cgb.fns {
|
||||
columns = append(columns, fn(selector))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(cgb.fields...)
|
||||
}
|
||||
|
||||
// ChallengeSelect is the builder for select fields of Challenge entities.
|
||||
type ChallengeSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (cs *ChallengeSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := cs.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cs.sql = query
|
||||
return cs.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := cs.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(cs.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeSelect.Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := cs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := cs.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = cs.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) StringX(ctx context.Context) string {
|
||||
v, err := cs.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(cs.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := cs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := cs.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = cs.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) IntX(ctx context.Context) int {
|
||||
v, err := cs.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(cs.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := cs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := cs.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = cs.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := cs.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(cs.fields) > 1 {
|
||||
return nil, errors.New("ent: ChallengeSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := cs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := cs.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (cs *ChallengeSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = cs.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{challenge.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: ChallengeSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (cs *ChallengeSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := cs.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (cs *ChallengeSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := cs.sqlQuery().Query()
|
||||
if err := cs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (cs *ChallengeSelect) sqlQuery() sql.Querier {
|
||||
selector := cs.sql
|
||||
selector.Select(selector.Columns(cs.fields...)...)
|
||||
return selector
|
||||
}
|
228
src/db/ent/challenge_update.go
Normal file
228
src/db/ent/challenge_update.go
Normal file
|
@ -0,0 +1,228 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/challenge"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ChallengeUpdate is the builder for updating Challenge entities.
|
||||
type ChallengeUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ChallengeMutation
|
||||
predicates []predicate.Challenge
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (cu *ChallengeUpdate) Where(ps ...predicate.Challenge) *ChallengeUpdate {
|
||||
cu.predicates = append(cu.predicates, ps...)
|
||||
return cu
|
||||
}
|
||||
|
||||
// Mutation returns the ChallengeMutation object of the builder.
|
||||
func (cu *ChallengeUpdate) Mutation() *ChallengeMutation {
|
||||
return cu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (cu *ChallengeUpdate) Save(ctx context.Context) (int, error) {
|
||||
if _, ok := cu.mutation.UpdateTime(); !ok {
|
||||
v := challenge.UpdateDefaultUpdateTime()
|
||||
cu.mutation.SetUpdateTime(v)
|
||||
}
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(cu.hooks) == 0 {
|
||||
affected, err = cu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ChallengeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
cu.mutation = mutation
|
||||
affected, err = cu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(cu.hooks) - 1; i >= 0; i-- {
|
||||
mut = cu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cu *ChallengeUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := cu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (cu *ChallengeUpdate) Exec(ctx context.Context) error {
|
||||
_, err := cu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cu *ChallengeUpdate) ExecX(ctx context.Context) {
|
||||
if err := cu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (cu *ChallengeUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: challenge.Table,
|
||||
Columns: challenge.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: challenge.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := cu.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := cu.mutation.UpdateTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: challenge.FieldUpdateTime,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{challenge.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// ChallengeUpdateOne is the builder for updating a single Challenge entity.
|
||||
type ChallengeUpdateOne struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ChallengeMutation
|
||||
}
|
||||
|
||||
// Mutation returns the ChallengeMutation object of the builder.
|
||||
func (cuo *ChallengeUpdateOne) Mutation() *ChallengeMutation {
|
||||
return cuo.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (cuo *ChallengeUpdateOne) Save(ctx context.Context) (*Challenge, error) {
|
||||
if _, ok := cuo.mutation.UpdateTime(); !ok {
|
||||
v := challenge.UpdateDefaultUpdateTime()
|
||||
cuo.mutation.SetUpdateTime(v)
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Challenge
|
||||
)
|
||||
if len(cuo.hooks) == 0 {
|
||||
node, err = cuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ChallengeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
cuo.mutation = mutation
|
||||
node, err = cuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(cuo.hooks) - 1; i >= 0; i-- {
|
||||
mut = cuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, cuo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cuo *ChallengeUpdateOne) SaveX(ctx context.Context) *Challenge {
|
||||
c, err := cuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (cuo *ChallengeUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := cuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cuo *ChallengeUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := cuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (cuo *ChallengeUpdateOne) sqlSave(ctx context.Context) (c *Challenge, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: challenge.Table,
|
||||
Columns: challenge.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: challenge.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := cuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Challenge.ID for update")}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if value, ok := cuo.mutation.UpdateTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: challenge.FieldUpdateTime,
|
||||
})
|
||||
}
|
||||
c = &Challenge{config: cuo.config}
|
||||
_spec.Assign = c.assignValues
|
||||
_spec.ScanValues = c.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{challenge.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
395
src/db/ent/client.go
Normal file
395
src/db/ent/client.go
Normal file
|
@ -0,0 +1,395 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/migrate"
|
||||
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/challenge"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/guild"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/session"
|
||||
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Client is the client that holds all ent builders.
|
||||
type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// Challenge is the client for interacting with the Challenge builders.
|
||||
Challenge *ChallengeClient
|
||||
// Guild is the client for interacting with the Guild builders.
|
||||
Guild *GuildClient
|
||||
// Session is the client for interacting with the Session builders.
|
||||
Session *SessionClient
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client {
|
||||
cfg := config{log: log.Println, hooks: &hooks{}}
|
||||
cfg.options(opts...)
|
||||
client := &Client{config: cfg}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Challenge = NewChallengeClient(c.config)
|
||||
c.Guild = NewGuildClient(c.config)
|
||||
c.Session = NewSessionClient(c.config)
|
||||
}
|
||||
|
||||
// Open opens a database/sql.DB specified by the driver name and
|
||||
// the data source name, and returns a new client attached to it.
|
||||
// Optional parameters can be added for configuring the client.
|
||||
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||
switch driverName {
|
||||
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||
drv, err := sql.Open(driverName, dataSourceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewClient(append(options, Driver(drv))...), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||
}
|
||||
}
|
||||
|
||||
// Tx returns a new transactional client. The provided context
|
||||
// is used until the transaction is committed or rolled back.
|
||||
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
if _, ok := c.driver.(*txDriver); ok {
|
||||
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||
}
|
||||
tx, err := newTx(ctx, c.driver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ent: starting a transaction: %v", err)
|
||||
}
|
||||
cfg := config{driver: tx, log: c.log, debug: c.debug, hooks: c.hooks}
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Challenge: NewChallengeClient(cfg),
|
||||
Guild: NewGuildClient(cfg),
|
||||
Session: NewSessionClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BeginTx returns a transactional client with options.
|
||||
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||
if _, ok := c.driver.(*txDriver); ok {
|
||||
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||
}
|
||||
tx, err := c.driver.(*sql.Driver).BeginTx(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ent: starting a transaction: %v", err)
|
||||
}
|
||||
cfg := config{driver: &txDriver{tx: tx, drv: c.driver}, log: c.log, debug: c.debug, hooks: c.hooks}
|
||||
return &Tx{
|
||||
config: cfg,
|
||||
Challenge: NewChallengeClient(cfg),
|
||||
Guild: NewGuildClient(cfg),
|
||||
Session: NewSessionClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// Challenge.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
//
|
||||
func (c *Client) Debug() *Client {
|
||||
if c.debug {
|
||||
return c
|
||||
}
|
||||
cfg := config{driver: dialect.Debug(c.driver, c.log), log: c.log, debug: true, hooks: c.hooks}
|
||||
client := &Client{config: cfg}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Close closes the database connection and prevents new queries from starting.
|
||||
func (c *Client) Close() error {
|
||||
return c.driver.Close()
|
||||
}
|
||||
|
||||
// Use adds the mutation hooks to all the entity clients.
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
c.Challenge.Use(hooks...)
|
||||
c.Guild.Use(hooks...)
|
||||
c.Session.Use(hooks...)
|
||||
}
|
||||
|
||||
// ChallengeClient is a client for the Challenge schema.
|
||||
type ChallengeClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewChallengeClient returns a client for the Challenge from the given config.
|
||||
func NewChallengeClient(c config) *ChallengeClient {
|
||||
return &ChallengeClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `challenge.Hooks(f(g(h())))`.
|
||||
func (c *ChallengeClient) Use(hooks ...Hook) {
|
||||
c.hooks.Challenge = append(c.hooks.Challenge, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for Challenge.
|
||||
func (c *ChallengeClient) Create() *ChallengeCreate {
|
||||
mutation := newChallengeMutation(c.config, OpCreate)
|
||||
return &ChallengeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// BulkCreate returns a builder for creating a bulk of Challenge entities.
|
||||
func (c *ChallengeClient) CreateBulk(builders ...*ChallengeCreate) *ChallengeCreateBulk {
|
||||
return &ChallengeCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Challenge.
|
||||
func (c *ChallengeClient) Update() *ChallengeUpdate {
|
||||
mutation := newChallengeMutation(c.config, OpUpdate)
|
||||
return &ChallengeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *ChallengeClient) UpdateOne(ch *Challenge) *ChallengeUpdateOne {
|
||||
mutation := newChallengeMutation(c.config, OpUpdateOne, withChallenge(ch))
|
||||
return &ChallengeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *ChallengeClient) UpdateOneID(id int) *ChallengeUpdateOne {
|
||||
mutation := newChallengeMutation(c.config, OpUpdateOne, withChallengeID(id))
|
||||
return &ChallengeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Challenge.
|
||||
func (c *ChallengeClient) Delete() *ChallengeDelete {
|
||||
mutation := newChallengeMutation(c.config, OpDelete)
|
||||
return &ChallengeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *ChallengeClient) DeleteOne(ch *Challenge) *ChallengeDeleteOne {
|
||||
return c.DeleteOneID(ch.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *ChallengeClient) DeleteOneID(id int) *ChallengeDeleteOne {
|
||||
builder := c.Delete().Where(challenge.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &ChallengeDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Challenge.
|
||||
func (c *ChallengeClient) Query() *ChallengeQuery {
|
||||
return &ChallengeQuery{config: c.config}
|
||||
}
|
||||
|
||||
// Get returns a Challenge entity by its id.
|
||||
func (c *ChallengeClient) Get(ctx context.Context, id int) (*Challenge, error) {
|
||||
return c.Query().Where(challenge.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *ChallengeClient) GetX(ctx context.Context, id int) *Challenge {
|
||||
ch, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ch
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *ChallengeClient) Hooks() []Hook {
|
||||
return c.hooks.Challenge
|
||||
}
|
||||
|
||||
// GuildClient is a client for the Guild schema.
|
||||
type GuildClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewGuildClient returns a client for the Guild from the given config.
|
||||
func NewGuildClient(c config) *GuildClient {
|
||||
return &GuildClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `guild.Hooks(f(g(h())))`.
|
||||
func (c *GuildClient) Use(hooks ...Hook) {
|
||||
c.hooks.Guild = append(c.hooks.Guild, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for Guild.
|
||||
func (c *GuildClient) Create() *GuildCreate {
|
||||
mutation := newGuildMutation(c.config, OpCreate)
|
||||
return &GuildCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// BulkCreate returns a builder for creating a bulk of Guild entities.
|
||||
func (c *GuildClient) CreateBulk(builders ...*GuildCreate) *GuildCreateBulk {
|
||||
return &GuildCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Guild.
|
||||
func (c *GuildClient) Update() *GuildUpdate {
|
||||
mutation := newGuildMutation(c.config, OpUpdate)
|
||||
return &GuildUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *GuildClient) UpdateOne(gu *Guild) *GuildUpdateOne {
|
||||
mutation := newGuildMutation(c.config, OpUpdateOne, withGuild(gu))
|
||||
return &GuildUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *GuildClient) UpdateOneID(id int) *GuildUpdateOne {
|
||||
mutation := newGuildMutation(c.config, OpUpdateOne, withGuildID(id))
|
||||
return &GuildUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Guild.
|
||||
func (c *GuildClient) Delete() *GuildDelete {
|
||||
mutation := newGuildMutation(c.config, OpDelete)
|
||||
return &GuildDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *GuildClient) DeleteOne(gu *Guild) *GuildDeleteOne {
|
||||
return c.DeleteOneID(gu.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *GuildClient) DeleteOneID(id int) *GuildDeleteOne {
|
||||
builder := c.Delete().Where(guild.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &GuildDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Guild.
|
||||
func (c *GuildClient) Query() *GuildQuery {
|
||||
return &GuildQuery{config: c.config}
|
||||
}
|
||||
|
||||
// Get returns a Guild entity by its id.
|
||||
func (c *GuildClient) Get(ctx context.Context, id int) (*Guild, error) {
|
||||
return c.Query().Where(guild.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *GuildClient) GetX(ctx context.Context, id int) *Guild {
|
||||
gu, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return gu
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *GuildClient) Hooks() []Hook {
|
||||
return c.hooks.Guild
|
||||
}
|
||||
|
||||
// SessionClient is a client for the Session schema.
|
||||
type SessionClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSessionClient returns a client for the Session from the given config.
|
||||
func NewSessionClient(c config) *SessionClient {
|
||||
return &SessionClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `session.Hooks(f(g(h())))`.
|
||||
func (c *SessionClient) Use(hooks ...Hook) {
|
||||
c.hooks.Session = append(c.hooks.Session, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for Session.
|
||||
func (c *SessionClient) Create() *SessionCreate {
|
||||
mutation := newSessionMutation(c.config, OpCreate)
|
||||
return &SessionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// BulkCreate returns a builder for creating a bulk of Session entities.
|
||||
func (c *SessionClient) CreateBulk(builders ...*SessionCreate) *SessionCreateBulk {
|
||||
return &SessionCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Session.
|
||||
func (c *SessionClient) Update() *SessionUpdate {
|
||||
mutation := newSessionMutation(c.config, OpUpdate)
|
||||
return &SessionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SessionClient) UpdateOne(s *Session) *SessionUpdateOne {
|
||||
mutation := newSessionMutation(c.config, OpUpdateOne, withSession(s))
|
||||
return &SessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SessionClient) UpdateOneID(id int) *SessionUpdateOne {
|
||||
mutation := newSessionMutation(c.config, OpUpdateOne, withSessionID(id))
|
||||
return &SessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Session.
|
||||
func (c *SessionClient) Delete() *SessionDelete {
|
||||
mutation := newSessionMutation(c.config, OpDelete)
|
||||
return &SessionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *SessionClient) DeleteOne(s *Session) *SessionDeleteOne {
|
||||
return c.DeleteOneID(s.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *SessionClient) DeleteOneID(id int) *SessionDeleteOne {
|
||||
builder := c.Delete().Where(session.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SessionDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Session.
|
||||
func (c *SessionClient) Query() *SessionQuery {
|
||||
return &SessionQuery{config: c.config}
|
||||
}
|
||||
|
||||
// Get returns a Session entity by its id.
|
||||
func (c *SessionClient) Get(ctx context.Context, id int) (*Session, error) {
|
||||
return c.Query().Where(session.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SessionClient) GetX(ctx context.Context, id int) *Session {
|
||||
s, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SessionClient) Hooks() []Hook {
|
||||
return c.hooks.Session
|
||||
}
|
61
src/db/ent/config.go
Normal file
61
src/db/ent/config.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect"
|
||||
)
|
||||
|
||||
// Option function to configure the client.
|
||||
type Option func(*config)
|
||||
|
||||
// Config is the configuration for the client and its builder.
|
||||
type config struct {
|
||||
// driver used for executing database requests.
|
||||
driver dialect.Driver
|
||||
// debug enable a debug logging.
|
||||
debug bool
|
||||
// log used for logging on debug mode.
|
||||
log func(...interface{})
|
||||
// hooks to execute on mutations.
|
||||
hooks *hooks
|
||||
}
|
||||
|
||||
// hooks per client, for fast access.
|
||||
type hooks struct {
|
||||
Challenge []ent.Hook
|
||||
Guild []ent.Hook
|
||||
Session []ent.Hook
|
||||
}
|
||||
|
||||
// Options applies the options on the config object.
|
||||
func (c *config) options(opts ...Option) {
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
if c.debug {
|
||||
c.driver = dialect.Debug(c.driver, c.log)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug enables debug logging on the ent.Driver.
|
||||
func Debug() Option {
|
||||
return func(c *config) {
|
||||
c.debug = true
|
||||
}
|
||||
}
|
||||
|
||||
// Log sets the logging function for debug mode.
|
||||
func Log(fn func(...interface{})) Option {
|
||||
return func(c *config) {
|
||||
c.log = fn
|
||||
}
|
||||
}
|
||||
|
||||
// Driver configures the client driver.
|
||||
func Driver(driver dialect.Driver) Option {
|
||||
return func(c *config) {
|
||||
c.driver = driver
|
||||
}
|
||||
}
|
33
src/db/ent/context.go
Normal file
33
src/db/ent/context.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type clientCtxKey struct{}
|
||||
|
||||
// FromContext returns the Client stored in a context, or nil if there isn't one.
|
||||
func FromContext(ctx context.Context) *Client {
|
||||
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewContext returns a new context with the given Client attached.
|
||||
func NewContext(parent context.Context, c *Client) context.Context {
|
||||
return context.WithValue(parent, clientCtxKey{}, c)
|
||||
}
|
||||
|
||||
type txCtxKey struct{}
|
||||
|
||||
// TxFromContext returns the Tx stored in a context, or nil if there isn't one.
|
||||
func TxFromContext(ctx context.Context) *Tx {
|
||||
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||
return tx
|
||||
}
|
||||
|
||||
// NewTxContext returns a new context with the given Client attached.
|
||||
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||
return context.WithValue(parent, txCtxKey{}, tx)
|
||||
}
|
246
src/db/ent/ent.go
Normal file
246
src/db/ent/ent.go
Normal file
|
@ -0,0 +1,246 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflict in user's code.
|
||||
type (
|
||||
Op = ent.Op
|
||||
Hook = ent.Hook
|
||||
Value = ent.Value
|
||||
Query = ent.Query
|
||||
Policy = ent.Policy
|
||||
Mutator = ent.Mutator
|
||||
Mutation = ent.Mutation
|
||||
MutateFunc = ent.MutateFunc
|
||||
)
|
||||
|
||||
// OrderFunc applies an ordering on either graph traversal or sql selector.
|
||||
type OrderFunc func(*sql.Selector)
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) OrderFunc {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Asc(f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) OrderFunc {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Desc(f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||
type AggregateFunc func(*sql.Selector) string
|
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
// GroupBy(field1, field2).
|
||||
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.As(fn(s), end)
|
||||
}
|
||||
}
|
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Count("*")
|
||||
}
|
||||
}
|
||||
|
||||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Max(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Avg(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Min(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Sum(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// ValidationError returns when validating a field fails.
|
||||
type ValidationError struct {
|
||||
Name string // Field or edge name.
|
||||
err error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *ValidationError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ValidationError) Unwrap() error {
|
||||
return errors.Unwrap(e.err)
|
||||
}
|
||||
|
||||
// IsValidationError returns a boolean indicating whether the error is a validaton error.
|
||||
func IsValidationError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ValidationError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||
type NotFoundError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotFoundError) Error() string {
|
||||
return "ent: " + e.label + " not found"
|
||||
}
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// MaskNotFound masks nor found error.
|
||||
func MaskNotFound(err error) error {
|
||||
if IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||
type NotSingularError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotSingularError) Error() string {
|
||||
return "ent: " + e.label + " not singular"
|
||||
}
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
type NotLoadedError struct {
|
||||
edge string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotLoadedError) Error() string {
|
||||
return "ent: " + e.edge + " edge was not loaded"
|
||||
}
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ConstraintError) Error() string {
|
||||
return "ent: constraint failed: " + e.msg
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
errors = [...]string{
|
||||
"Error 1062", // MySQL 1062 error (ER_DUP_ENTRY).
|
||||
"UNIQUE constraint failed", // SQLite.
|
||||
"duplicate key value violates unique constraint", // PostgreSQL.
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// rollback calls to tx.Rollback and wraps the given error with the rollback error if occurred.
|
||||
func rollback(tx dialect.Tx, err error) error {
|
||||
if rerr := tx.Rollback(); rerr != nil {
|
||||
err = fmt.Errorf("%s: %v", err.Error(), rerr)
|
||||
}
|
||||
if err, ok := isSQLConstraintError(err); ok {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
13
src/db/ent/enttest/BUILD.bazel
Normal file
13
src/db/ent/enttest/BUILD.bazel
Normal file
|
@ -0,0 +1,13 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "enttest",
|
||||
srcs = ["enttest.go"],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/enttest",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//src/db/ent",
|
||||
"//src/db/ent/runtime",
|
||||
"@com_github_facebook_ent//dialect/sql/schema",
|
||||
],
|
||||
)
|
78
src/db/ent/enttest/enttest.go
Normal file
78
src/db/ent/enttest/enttest.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package enttest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/roleypoly/roleypoly/src/db/ent"
|
||||
// required by schema hooks.
|
||||
_ "github.com/roleypoly/roleypoly/src/db/ent/runtime"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
type (
|
||||
// TestingT is the interface that is shared between
|
||||
// testing.T and testing.B and used by enttest.
|
||||
TestingT interface {
|
||||
FailNow()
|
||||
Error(...interface{})
|
||||
}
|
||||
|
||||
// Option configures client creation.
|
||||
Option func(*options)
|
||||
|
||||
options struct {
|
||||
opts []ent.Option
|
||||
migrateOpts []schema.MigrateOption
|
||||
}
|
||||
)
|
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...ent.Option) Option {
|
||||
return func(o *options) {
|
||||
o.opts = append(o.opts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigrateOptions forwards options to auto migration.
|
||||
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||
return func(o *options) {
|
||||
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func newOptions(opts []Option) *options {
|
||||
o := &options{}
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// Open calls ent.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c, err := ent.Open(driverName, dataSourceName, o.opts...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// NewClient calls ent.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c := ent.NewClient(o.opts...)
|
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
return c
|
||||
}
|
3
src/db/ent/generate.go
Normal file
3
src/db/ent/generate.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package ent
|
||||
|
||||
//go:generate go run github.com/facebook/ent/cmd/entc generate ./schema
|
145
src/db/ent/guild.go
Normal file
145
src/db/ent/guild.go
Normal file
|
@ -0,0 +1,145 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/guild"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/schema"
|
||||
)
|
||||
|
||||
// Guild is the model entity for the Guild schema.
|
||||
type Guild struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||
// Snowflake holds the value of the "snowflake" field.
|
||||
Snowflake string `json:"snowflake,omitempty"`
|
||||
// Message holds the value of the "message" field.
|
||||
Message string `json:"message,omitempty"`
|
||||
// Categories holds the value of the "categories" field.
|
||||
Categories []schema.Category `json:"categories,omitempty"`
|
||||
// Entitlements holds the value of the "entitlements" field.
|
||||
Entitlements []string `json:"entitlements,omitempty"`
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Guild) scanValues() []interface{} {
|
||||
return []interface{}{
|
||||
&sql.NullInt64{}, // id
|
||||
&sql.NullTime{}, // create_time
|
||||
&sql.NullTime{}, // update_time
|
||||
&sql.NullString{}, // snowflake
|
||||
&sql.NullString{}, // message
|
||||
&[]byte{}, // categories
|
||||
&[]byte{}, // entitlements
|
||||
}
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Guild fields.
|
||||
func (gu *Guild) assignValues(values ...interface{}) error {
|
||||
if m, n := len(values), len(guild.Columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
value, ok := values[0].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
gu.ID = int(value.Int64)
|
||||
values = values[1:]
|
||||
if value, ok := values[0].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[0])
|
||||
} else if value.Valid {
|
||||
gu.CreateTime = value.Time
|
||||
}
|
||||
if value, ok := values[1].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field update_time", values[1])
|
||||
} else if value.Valid {
|
||||
gu.UpdateTime = value.Time
|
||||
}
|
||||
if value, ok := values[2].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field snowflake", values[2])
|
||||
} else if value.Valid {
|
||||
gu.Snowflake = value.String
|
||||
}
|
||||
if value, ok := values[3].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field message", values[3])
|
||||
} else if value.Valid {
|
||||
gu.Message = value.String
|
||||
}
|
||||
|
||||
if value, ok := values[4].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field categories", values[4])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &gu.Categories); err != nil {
|
||||
return fmt.Errorf("unmarshal field categories: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if value, ok := values[5].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field entitlements", values[5])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &gu.Entitlements); err != nil {
|
||||
return fmt.Errorf("unmarshal field entitlements: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Guild.
|
||||
// Note that, you need to call Guild.Unwrap() before calling this method, if this Guild
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (gu *Guild) Update() *GuildUpdateOne {
|
||||
return (&GuildClient{config: gu.config}).UpdateOne(gu)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
|
||||
// so that all next queries will be executed through the driver which created the transaction.
|
||||
func (gu *Guild) Unwrap() *Guild {
|
||||
tx, ok := gu.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Guild is not a transactional entity")
|
||||
}
|
||||
gu.config.driver = tx.drv
|
||||
return gu
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (gu *Guild) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Guild(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", gu.ID))
|
||||
builder.WriteString(", create_time=")
|
||||
builder.WriteString(gu.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", update_time=")
|
||||
builder.WriteString(gu.UpdateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", snowflake=")
|
||||
builder.WriteString(gu.Snowflake)
|
||||
builder.WriteString(", message=")
|
||||
builder.WriteString(gu.Message)
|
||||
builder.WriteString(", categories=")
|
||||
builder.WriteString(fmt.Sprintf("%v", gu.Categories))
|
||||
builder.WriteString(", entitlements=")
|
||||
builder.WriteString(fmt.Sprintf("%v", gu.Entitlements))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Guilds is a parsable slice of Guild.
|
||||
type Guilds []*Guild
|
||||
|
||||
func (gu Guilds) config(cfg config) {
|
||||
for _i := range gu {
|
||||
gu[_i].config = cfg
|
||||
}
|
||||
}
|
15
src/db/ent/guild/BUILD.bazel
Normal file
15
src/db/ent/guild/BUILD.bazel
Normal file
|
@ -0,0 +1,15 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "guild",
|
||||
srcs = [
|
||||
"guild.go",
|
||||
"where.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/guild",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//src/db/ent/predicate",
|
||||
"@com_github_facebook_ent//dialect/sql",
|
||||
],
|
||||
)
|
49
src/db/ent/guild/guild.go
Normal file
49
src/db/ent/guild/guild.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package guild
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the guild type in the database.
|
||||
Label = "guild"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||
FieldUpdateTime = "update_time"
|
||||
// FieldSnowflake holds the string denoting the snowflake field in the database.
|
||||
FieldSnowflake = "snowflake"
|
||||
// FieldMessage holds the string denoting the message field in the database.
|
||||
FieldMessage = "message"
|
||||
// FieldCategories holds the string denoting the categories field in the database.
|
||||
FieldCategories = "categories"
|
||||
// FieldEntitlements holds the string denoting the entitlements field in the database.
|
||||
FieldEntitlements = "entitlements"
|
||||
|
||||
// Table holds the table name of the guild in the database.
|
||||
Table = "guilds"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for guild fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldSnowflake,
|
||||
FieldMessage,
|
||||
FieldCategories,
|
||||
FieldEntitlements,
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
DefaultCreateTime func() time.Time
|
||||
// DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
DefaultUpdateTime func() time.Time
|
||||
// UpdateDefaultUpdateTime holds the default value on update for the update_time field.
|
||||
UpdateDefaultUpdateTime func() time.Time
|
||||
)
|
527
src/db/ent/guild/where.go
Normal file
527
src/db/ent/guild/where.go
Normal file
|
@ -0,0 +1,527 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package guild
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their identifier.
|
||||
func ID(id int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||
func UpdateTime(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Snowflake applies equality check predicate on the "snowflake" field. It's identical to SnowflakeEQ.
|
||||
func Snowflake(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Message applies equality check predicate on the "message" field. It's identical to MessageEQ.
|
||||
func Message(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldCreateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldCreateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...time.Time) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldUpdateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...time.Time) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldUpdateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v time.Time) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeEQ applies the EQ predicate on the "snowflake" field.
|
||||
func SnowflakeEQ(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeNEQ applies the NEQ predicate on the "snowflake" field.
|
||||
func SnowflakeNEQ(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeIn applies the In predicate on the "snowflake" field.
|
||||
func SnowflakeIn(vs ...string) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldSnowflake), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeNotIn applies the NotIn predicate on the "snowflake" field.
|
||||
func SnowflakeNotIn(vs ...string) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldSnowflake), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeGT applies the GT predicate on the "snowflake" field.
|
||||
func SnowflakeGT(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeGTE applies the GTE predicate on the "snowflake" field.
|
||||
func SnowflakeGTE(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeLT applies the LT predicate on the "snowflake" field.
|
||||
func SnowflakeLT(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeLTE applies the LTE predicate on the "snowflake" field.
|
||||
func SnowflakeLTE(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeContains applies the Contains predicate on the "snowflake" field.
|
||||
func SnowflakeContains(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeHasPrefix applies the HasPrefix predicate on the "snowflake" field.
|
||||
func SnowflakeHasPrefix(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeHasSuffix applies the HasSuffix predicate on the "snowflake" field.
|
||||
func SnowflakeHasSuffix(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeEqualFold applies the EqualFold predicate on the "snowflake" field.
|
||||
func SnowflakeEqualFold(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SnowflakeContainsFold applies the ContainsFold predicate on the "snowflake" field.
|
||||
func SnowflakeContainsFold(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldSnowflake), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageEQ applies the EQ predicate on the "message" field.
|
||||
func MessageEQ(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageNEQ applies the NEQ predicate on the "message" field.
|
||||
func MessageNEQ(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageIn applies the In predicate on the "message" field.
|
||||
func MessageIn(vs ...string) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldMessage), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageNotIn applies the NotIn predicate on the "message" field.
|
||||
func MessageNotIn(vs ...string) predicate.Guild {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldMessage), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageGT applies the GT predicate on the "message" field.
|
||||
func MessageGT(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageGTE applies the GTE predicate on the "message" field.
|
||||
func MessageGTE(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageLT applies the LT predicate on the "message" field.
|
||||
func MessageLT(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageLTE applies the LTE predicate on the "message" field.
|
||||
func MessageLTE(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageContains applies the Contains predicate on the "message" field.
|
||||
func MessageContains(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageHasPrefix applies the HasPrefix predicate on the "message" field.
|
||||
func MessageHasPrefix(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageHasSuffix applies the HasSuffix predicate on the "message" field.
|
||||
func MessageHasSuffix(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageEqualFold applies the EqualFold predicate on the "message" field.
|
||||
func MessageEqualFold(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// MessageContainsFold applies the ContainsFold predicate on the "message" field.
|
||||
func MessageContainsFold(v string) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldMessage), v))
|
||||
})
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Guild) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups list of predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Guild) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Guild) predicate.Guild {
|
||||
return predicate.Guild(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
285
src/db/ent/guild_create.go
Normal file
285
src/db/ent/guild_create.go
Normal file
|
@ -0,0 +1,285 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/guild"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/schema"
|
||||
)
|
||||
|
||||
// GuildCreate is the builder for creating a Guild entity.
|
||||
type GuildCreate struct {
|
||||
config
|
||||
mutation *GuildMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreateTime sets the create_time field.
|
||||
func (gc *GuildCreate) SetCreateTime(t time.Time) *GuildCreate {
|
||||
gc.mutation.SetCreateTime(t)
|
||||
return gc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the create_time field if the given value is not nil.
|
||||
func (gc *GuildCreate) SetNillableCreateTime(t *time.Time) *GuildCreate {
|
||||
if t != nil {
|
||||
gc.SetCreateTime(*t)
|
||||
}
|
||||
return gc
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the update_time field.
|
||||
func (gc *GuildCreate) SetUpdateTime(t time.Time) *GuildCreate {
|
||||
gc.mutation.SetUpdateTime(t)
|
||||
return gc
|
||||
}
|
||||
|
||||
// SetNillableUpdateTime sets the update_time field if the given value is not nil.
|
||||
func (gc *GuildCreate) SetNillableUpdateTime(t *time.Time) *GuildCreate {
|
||||
if t != nil {
|
||||
gc.SetUpdateTime(*t)
|
||||
}
|
||||
return gc
|
||||
}
|
||||
|
||||
// SetSnowflake sets the snowflake field.
|
||||
func (gc *GuildCreate) SetSnowflake(s string) *GuildCreate {
|
||||
gc.mutation.SetSnowflake(s)
|
||||
return gc
|
||||
}
|
||||
|
||||
// SetMessage sets the message field.
|
||||
func (gc *GuildCreate) SetMessage(s string) *GuildCreate {
|
||||
gc.mutation.SetMessage(s)
|
||||
return gc
|
||||
}
|
||||
|
||||
// SetCategories sets the categories field.
|
||||
func (gc *GuildCreate) SetCategories(s []schema.Category) *GuildCreate {
|
||||
gc.mutation.SetCategories(s)
|
||||
return gc
|
||||
}
|
||||
|
||||
// SetEntitlements sets the entitlements field.
|
||||
func (gc *GuildCreate) SetEntitlements(s []string) *GuildCreate {
|
||||
gc.mutation.SetEntitlements(s)
|
||||
return gc
|
||||
}
|
||||
|
||||
// Mutation returns the GuildMutation object of the builder.
|
||||
func (gc *GuildCreate) Mutation() *GuildMutation {
|
||||
return gc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Guild in the database.
|
||||
func (gc *GuildCreate) Save(ctx context.Context) (*Guild, error) {
|
||||
if err := gc.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Guild
|
||||
)
|
||||
if len(gc.hooks) == 0 {
|
||||
node, err = gc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*GuildMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
gc.mutation = mutation
|
||||
node, err = gc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(gc.hooks) - 1; i >= 0; i-- {
|
||||
mut = gc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, gc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (gc *GuildCreate) SaveX(ctx context.Context) *Guild {
|
||||
v, err := gc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (gc *GuildCreate) preSave() error {
|
||||
if _, ok := gc.mutation.CreateTime(); !ok {
|
||||
v := guild.DefaultCreateTime()
|
||||
gc.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := gc.mutation.UpdateTime(); !ok {
|
||||
v := guild.DefaultUpdateTime()
|
||||
gc.mutation.SetUpdateTime(v)
|
||||
}
|
||||
if _, ok := gc.mutation.Snowflake(); !ok {
|
||||
return &ValidationError{Name: "snowflake", err: errors.New("ent: missing required field \"snowflake\"")}
|
||||
}
|
||||
if _, ok := gc.mutation.Message(); !ok {
|
||||
return &ValidationError{Name: "message", err: errors.New("ent: missing required field \"message\"")}
|
||||
}
|
||||
if _, ok := gc.mutation.Categories(); !ok {
|
||||
return &ValidationError{Name: "categories", err: errors.New("ent: missing required field \"categories\"")}
|
||||
}
|
||||
if _, ok := gc.mutation.Entitlements(); !ok {
|
||||
return &ValidationError{Name: "entitlements", err: errors.New("ent: missing required field \"entitlements\"")}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gc *GuildCreate) sqlSave(ctx context.Context) (*Guild, error) {
|
||||
gu, _spec := gc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, gc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
gu.ID = int(id)
|
||||
return gu, nil
|
||||
}
|
||||
|
||||
func (gc *GuildCreate) createSpec() (*Guild, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
gu = &Guild{config: gc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: guild.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: guild.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := gc.mutation.CreateTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: guild.FieldCreateTime,
|
||||
})
|
||||
gu.CreateTime = value
|
||||
}
|
||||
if value, ok := gc.mutation.UpdateTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: guild.FieldUpdateTime,
|
||||
})
|
||||
gu.UpdateTime = value
|
||||
}
|
||||
if value, ok := gc.mutation.Snowflake(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: guild.FieldSnowflake,
|
||||
})
|
||||
gu.Snowflake = value
|
||||
}
|
||||
if value, ok := gc.mutation.Message(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: guild.FieldMessage,
|
||||
})
|
||||
gu.Message = value
|
||||
}
|
||||
if value, ok := gc.mutation.Categories(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: guild.FieldCategories,
|
||||
})
|
||||
gu.Categories = value
|
||||
}
|
||||
if value, ok := gc.mutation.Entitlements(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: guild.FieldEntitlements,
|
||||
})
|
||||
gu.Entitlements = value
|
||||
}
|
||||
return gu, _spec
|
||||
}
|
||||
|
||||
// GuildCreateBulk is the builder for creating a bulk of Guild entities.
|
||||
type GuildCreateBulk struct {
|
||||
config
|
||||
builders []*GuildCreate
|
||||
}
|
||||
|
||||
// Save creates the Guild entities in the database.
|
||||
func (gcb *GuildCreateBulk) Save(ctx context.Context) ([]*Guild, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(gcb.builders))
|
||||
nodes := make([]*Guild, len(gcb.builders))
|
||||
mutators := make([]Mutator, len(gcb.builders))
|
||||
for i := range gcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := gcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
if err := builder.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation, ok := m.(*GuildMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, gcb.builders[i+1].mutation)
|
||||
} else {
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, gcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
}
|
||||
}
|
||||
mutation.done = true
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
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, gcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (gcb *GuildCreateBulk) SaveX(ctx context.Context) []*Guild {
|
||||
v, err := gcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
109
src/db/ent/guild_delete.go
Normal file
109
src/db/ent/guild_delete.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/guild"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// GuildDelete is the builder for deleting a Guild entity.
|
||||
type GuildDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GuildMutation
|
||||
predicates []predicate.Guild
|
||||
}
|
||||
|
||||
// Where adds a new predicate to the delete builder.
|
||||
func (gd *GuildDelete) Where(ps ...predicate.Guild) *GuildDelete {
|
||||
gd.predicates = append(gd.predicates, ps...)
|
||||
return gd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (gd *GuildDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(gd.hooks) == 0 {
|
||||
affected, err = gd.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*GuildMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
gd.mutation = mutation
|
||||
affected, err = gd.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(gd.hooks) - 1; i >= 0; i-- {
|
||||
mut = gd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, gd.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (gd *GuildDelete) ExecX(ctx context.Context) int {
|
||||
n, err := gd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (gd *GuildDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: guild.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: guild.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := gd.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, gd.driver, _spec)
|
||||
}
|
||||
|
||||
// GuildDeleteOne is the builder for deleting a single Guild entity.
|
||||
type GuildDeleteOne struct {
|
||||
gd *GuildDelete
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (gdo *GuildDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := gdo.gd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{guild.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (gdo *GuildDeleteOne) ExecX(ctx context.Context) {
|
||||
gdo.gd.ExecX(ctx)
|
||||
}
|
866
src/db/ent/guild_query.go
Normal file
866
src/db/ent/guild_query.go
Normal file
|
@ -0,0 +1,866 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/guild"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// GuildQuery is the builder for querying Guild entities.
|
||||
type GuildQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.Guild
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (gq *GuildQuery) Where(ps ...predicate.Guild) *GuildQuery {
|
||||
gq.predicates = append(gq.predicates, ps...)
|
||||
return gq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (gq *GuildQuery) Limit(limit int) *GuildQuery {
|
||||
gq.limit = &limit
|
||||
return gq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (gq *GuildQuery) Offset(offset int) *GuildQuery {
|
||||
gq.offset = &offset
|
||||
return gq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (gq *GuildQuery) Order(o ...OrderFunc) *GuildQuery {
|
||||
gq.order = append(gq.order, o...)
|
||||
return gq
|
||||
}
|
||||
|
||||
// First returns the first Guild entity in the query. Returns *NotFoundError when no guild was found.
|
||||
func (gq *GuildQuery) First(ctx context.Context) (*Guild, error) {
|
||||
gus, err := gq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(gus) == 0 {
|
||||
return nil, &NotFoundError{guild.Label}
|
||||
}
|
||||
return gus[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (gq *GuildQuery) FirstX(ctx context.Context) *Guild {
|
||||
gu, err := gq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return gu
|
||||
}
|
||||
|
||||
// FirstID returns the first Guild id in the query. Returns *NotFoundError when no id was found.
|
||||
func (gq *GuildQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = gq.Limit(1).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{guild.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstXID is like FirstID, but panics if an error occurs.
|
||||
func (gq *GuildQuery) FirstXID(ctx context.Context) int {
|
||||
id, err := gq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns the only Guild entity in the query, returns an error if not exactly one entity was returned.
|
||||
func (gq *GuildQuery) Only(ctx context.Context) (*Guild, error) {
|
||||
gus, err := gq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(gus) {
|
||||
case 1:
|
||||
return gus[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{guild.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{guild.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (gq *GuildQuery) OnlyX(ctx context.Context) *Guild {
|
||||
gu, err := gq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return gu
|
||||
}
|
||||
|
||||
// OnlyID returns the only Guild id in the query, returns an error if not exactly one id was returned.
|
||||
func (gq *GuildQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = gq.Limit(2).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = &NotSingularError{guild.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (gq *GuildQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := gq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Guilds.
|
||||
func (gq *GuildQuery) All(ctx context.Context) ([]*Guild, error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (gq *GuildQuery) AllX(ctx context.Context) []*Guild {
|
||||
gus, err := gq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return gus
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Guild ids.
|
||||
func (gq *GuildQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := gq.Select(guild.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (gq *GuildQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := gq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (gq *GuildQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return gq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (gq *GuildQuery) CountX(ctx context.Context) int {
|
||||
count, err := gq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (gq *GuildQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return gq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (gq *GuildQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := gq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the query builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (gq *GuildQuery) Clone() *GuildQuery {
|
||||
return &GuildQuery{
|
||||
config: gq.config,
|
||||
limit: gq.limit,
|
||||
offset: gq.offset,
|
||||
order: append([]OrderFunc{}, gq.order...),
|
||||
unique: append([]string{}, gq.unique...),
|
||||
predicates: append([]predicate.Guild{}, gq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: gq.sql.Clone(),
|
||||
path: gq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Guild.Query().
|
||||
// GroupBy(guild.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (gq *GuildQuery) GroupBy(field string, fields ...string) *GuildGroupBy {
|
||||
group := &GuildGroupBy{config: gq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
// Select one or more fields from the given query.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Guild.Query().
|
||||
// Select(guild.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (gq *GuildQuery) Select(field string, fields ...string) *GuildSelect {
|
||||
selector := &GuildSelect{config: gq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := gq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (gq *GuildQuery) prepareQuery(ctx context.Context) error {
|
||||
if gq.path != nil {
|
||||
prev, err := gq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gq *GuildQuery) sqlAll(ctx context.Context) ([]*Guild, error) {
|
||||
var (
|
||||
nodes = []*Guild{}
|
||||
_spec = gq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func() []interface{} {
|
||||
node := &Guild{config: gq.config}
|
||||
nodes = append(nodes, node)
|
||||
values := node.scanValues()
|
||||
return values
|
||||
}
|
||||
_spec.Assign = func(values ...interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
return node.assignValues(values...)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, gq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (gq *GuildQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := gq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, gq.driver, _spec)
|
||||
}
|
||||
|
||||
func (gq *GuildQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := gq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %v", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (gq *GuildQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: guild.Table,
|
||||
Columns: guild.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: guild.FieldID,
|
||||
},
|
||||
},
|
||||
From: gq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if ps := gq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := gq.limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := gq.offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := gq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (gq *GuildQuery) sqlQuery() *sql.Selector {
|
||||
builder := sql.Dialect(gq.driver.Dialect())
|
||||
t1 := builder.Table(guild.Table)
|
||||
selector := builder.Select(t1.Columns(guild.Columns...)...).From(t1)
|
||||
if gq.sql != nil {
|
||||
selector = gq.sql
|
||||
selector.Select(selector.Columns(guild.Columns...)...)
|
||||
}
|
||||
for _, p := range gq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range gq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := gq.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 := gq.limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// GuildGroupBy is the builder for group-by Guild entities.
|
||||
type GuildGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ggb *GuildGroupBy) Aggregate(fns ...AggregateFunc) *GuildGroupBy {
|
||||
ggb.fns = append(ggb.fns, fns...)
|
||||
return ggb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (ggb *GuildGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ggb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ggb.sql = query
|
||||
return ggb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := ggb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(ggb.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := ggb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := ggb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ggb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := ggb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ggb.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := ggb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := ggb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ggb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := ggb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ggb.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := ggb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := ggb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ggb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := ggb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ggb.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := ggb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := ggb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GuildGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ggb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ggb *GuildGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := ggb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ggb *GuildGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := ggb.sqlQuery().Query()
|
||||
if err := ggb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (ggb *GuildGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := ggb.sql
|
||||
columns := make([]string, 0, len(ggb.fields)+len(ggb.fns))
|
||||
columns = append(columns, ggb.fields...)
|
||||
for _, fn := range ggb.fns {
|
||||
columns = append(columns, fn(selector))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(ggb.fields...)
|
||||
}
|
||||
|
||||
// GuildSelect is the builder for select fields of Guild entities.
|
||||
type GuildSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (gs *GuildSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := gs.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gs.sql = query
|
||||
return gs.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (gs *GuildSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := gs.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(gs.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildSelect.Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := gs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (gs *GuildSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := gs.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = gs.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (gs *GuildSelect) StringX(ctx context.Context) string {
|
||||
v, err := gs.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(gs.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := gs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (gs *GuildSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := gs.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = gs.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (gs *GuildSelect) IntX(ctx context.Context) int {
|
||||
v, err := gs.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(gs.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := gs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (gs *GuildSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := gs.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = gs.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (gs *GuildSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := gs.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(gs.fields) > 1 {
|
||||
return nil, errors.New("ent: GuildSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := gs.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (gs *GuildSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := gs.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (gs *GuildSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = gs.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{guild.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GuildSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (gs *GuildSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := gs.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (gs *GuildSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := gs.sqlQuery().Query()
|
||||
if err := gs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (gs *GuildSelect) sqlQuery() sql.Querier {
|
||||
selector := gs.sql
|
||||
selector.Select(selector.Columns(gs.fields...)...)
|
||||
return selector
|
||||
}
|
307
src/db/ent/guild_update.go
Normal file
307
src/db/ent/guild_update.go
Normal file
|
@ -0,0 +1,307 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/guild"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/schema"
|
||||
)
|
||||
|
||||
// GuildUpdate is the builder for updating Guild entities.
|
||||
type GuildUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GuildMutation
|
||||
predicates []predicate.Guild
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (gu *GuildUpdate) Where(ps ...predicate.Guild) *GuildUpdate {
|
||||
gu.predicates = append(gu.predicates, ps...)
|
||||
return gu
|
||||
}
|
||||
|
||||
// SetMessage sets the message field.
|
||||
func (gu *GuildUpdate) SetMessage(s string) *GuildUpdate {
|
||||
gu.mutation.SetMessage(s)
|
||||
return gu
|
||||
}
|
||||
|
||||
// SetCategories sets the categories field.
|
||||
func (gu *GuildUpdate) SetCategories(s []schema.Category) *GuildUpdate {
|
||||
gu.mutation.SetCategories(s)
|
||||
return gu
|
||||
}
|
||||
|
||||
// SetEntitlements sets the entitlements field.
|
||||
func (gu *GuildUpdate) SetEntitlements(s []string) *GuildUpdate {
|
||||
gu.mutation.SetEntitlements(s)
|
||||
return gu
|
||||
}
|
||||
|
||||
// Mutation returns the GuildMutation object of the builder.
|
||||
func (gu *GuildUpdate) Mutation() *GuildMutation {
|
||||
return gu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (gu *GuildUpdate) Save(ctx context.Context) (int, error) {
|
||||
if _, ok := gu.mutation.UpdateTime(); !ok {
|
||||
v := guild.UpdateDefaultUpdateTime()
|
||||
gu.mutation.SetUpdateTime(v)
|
||||
}
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(gu.hooks) == 0 {
|
||||
affected, err = gu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*GuildMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
gu.mutation = mutation
|
||||
affected, err = gu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(gu.hooks) - 1; i >= 0; i-- {
|
||||
mut = gu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, gu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (gu *GuildUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := gu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (gu *GuildUpdate) Exec(ctx context.Context) error {
|
||||
_, err := gu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (gu *GuildUpdate) ExecX(ctx context.Context) {
|
||||
if err := gu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (gu *GuildUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: guild.Table,
|
||||
Columns: guild.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: guild.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := gu.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := gu.mutation.UpdateTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: guild.FieldUpdateTime,
|
||||
})
|
||||
}
|
||||
if value, ok := gu.mutation.Message(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: guild.FieldMessage,
|
||||
})
|
||||
}
|
||||
if value, ok := gu.mutation.Categories(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: guild.FieldCategories,
|
||||
})
|
||||
}
|
||||
if value, ok := gu.mutation.Entitlements(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: guild.FieldEntitlements,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, gu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{guild.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// GuildUpdateOne is the builder for updating a single Guild entity.
|
||||
type GuildUpdateOne struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GuildMutation
|
||||
}
|
||||
|
||||
// SetMessage sets the message field.
|
||||
func (guo *GuildUpdateOne) SetMessage(s string) *GuildUpdateOne {
|
||||
guo.mutation.SetMessage(s)
|
||||
return guo
|
||||
}
|
||||
|
||||
// SetCategories sets the categories field.
|
||||
func (guo *GuildUpdateOne) SetCategories(s []schema.Category) *GuildUpdateOne {
|
||||
guo.mutation.SetCategories(s)
|
||||
return guo
|
||||
}
|
||||
|
||||
// SetEntitlements sets the entitlements field.
|
||||
func (guo *GuildUpdateOne) SetEntitlements(s []string) *GuildUpdateOne {
|
||||
guo.mutation.SetEntitlements(s)
|
||||
return guo
|
||||
}
|
||||
|
||||
// Mutation returns the GuildMutation object of the builder.
|
||||
func (guo *GuildUpdateOne) Mutation() *GuildMutation {
|
||||
return guo.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (guo *GuildUpdateOne) Save(ctx context.Context) (*Guild, error) {
|
||||
if _, ok := guo.mutation.UpdateTime(); !ok {
|
||||
v := guild.UpdateDefaultUpdateTime()
|
||||
guo.mutation.SetUpdateTime(v)
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Guild
|
||||
)
|
||||
if len(guo.hooks) == 0 {
|
||||
node, err = guo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*GuildMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
guo.mutation = mutation
|
||||
node, err = guo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(guo.hooks) - 1; i >= 0; i-- {
|
||||
mut = guo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, guo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (guo *GuildUpdateOne) SaveX(ctx context.Context) *Guild {
|
||||
gu, err := guo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return gu
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (guo *GuildUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := guo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (guo *GuildUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := guo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (guo *GuildUpdateOne) sqlSave(ctx context.Context) (gu *Guild, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: guild.Table,
|
||||
Columns: guild.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: guild.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := guo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Guild.ID for update")}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if value, ok := guo.mutation.UpdateTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: guild.FieldUpdateTime,
|
||||
})
|
||||
}
|
||||
if value, ok := guo.mutation.Message(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: guild.FieldMessage,
|
||||
})
|
||||
}
|
||||
if value, ok := guo.mutation.Categories(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: guild.FieldCategories,
|
||||
})
|
||||
}
|
||||
if value, ok := guo.mutation.Entitlements(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeJSON,
|
||||
Value: value,
|
||||
Column: guild.FieldEntitlements,
|
||||
})
|
||||
}
|
||||
gu = &Guild{config: guo.config}
|
||||
_spec.Assign = gu.assignValues
|
||||
_spec.ScanValues = gu.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, guo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{guild.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return gu, nil
|
||||
}
|
9
src/db/ent/hook/BUILD.bazel
Normal file
9
src/db/ent/hook/BUILD.bazel
Normal file
|
@ -0,0 +1,9 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "hook",
|
||||
srcs = ["hook.go"],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/hook",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//src/db/ent"],
|
||||
)
|
225
src/db/ent/hook/hook.go
Normal file
225
src/db/ent/hook/hook.go
Normal file
|
@ -0,0 +1,225 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/roleypoly/roleypoly/src/db/ent"
|
||||
)
|
||||
|
||||
// The ChallengeFunc type is an adapter to allow the use of ordinary
|
||||
// function as Challenge mutator.
|
||||
type ChallengeFunc func(context.Context, *ent.ChallengeMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ChallengeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.ChallengeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChallengeMutation", m)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// The GuildFunc type is an adapter to allow the use of ordinary
|
||||
// function as Guild mutator.
|
||||
type GuildFunc func(context.Context, *ent.GuildMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f GuildFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.GuildMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GuildMutation", m)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// The SessionFunc type is an adapter to allow the use of ordinary
|
||||
// function as Session mutator.
|
||||
type SessionFunc func(context.Context, *ent.SessionMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SessionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.SessionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SessionMutation", m)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, ent.Mutation) bool
|
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
if !first(ctx, m) || !second(ctx, m) {
|
||||
return false
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if !cond(ctx, m) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Or groups conditions with the OR operator.
|
||||
func Or(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
if first(ctx, m) || second(ctx, m) {
|
||||
return true
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if cond(ctx, m) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Not negates a given condition.
|
||||
func Not(cond Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
return !cond(ctx, m)
|
||||
}
|
||||
}
|
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op ent.Op) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
return m.Op().Is(op)
|
||||
}
|
||||
}
|
||||
|
||||
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||
func HasAddedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||
func HasClearedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasFields is a condition validating `.Field` on fields.
|
||||
func HasFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// If executes the given hook under condition.
|
||||
//
|
||||
// Hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||
//
|
||||
func If(hk ent.Hook, cond Condition) ent.Hook {
|
||||
return func(next ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if cond(ctx, m) {
|
||||
return hk(next).Mutate(ctx, m)
|
||||
}
|
||||
return next.Mutate(ctx, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// On executes the given hook only for the given operation.
|
||||
//
|
||||
// hook.On(Log, ent.Delete|ent.Create)
|
||||
//
|
||||
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||
//
|
||||
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
// return []ent.Hook{
|
||||
// Reject(ent.Delete|ent.Update),
|
||||
// }
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(_ context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("%s operation is not allowed", m.Op())
|
||||
})
|
||||
}
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
// Chain acts as a list of hooks and is effectively immutable.
|
||||
// Once created, it will always hold the same set of hooks in the same order.
|
||||
type Chain struct {
|
||||
hooks []ent.Hook
|
||||
}
|
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...ent.Hook) Chain {
|
||||
return Chain{append([]ent.Hook(nil), hooks...)}
|
||||
}
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() ent.Hook {
|
||||
return func(mutator ent.Mutator) ent.Mutator {
|
||||
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||
mutator = c.hooks[i](mutator)
|
||||
}
|
||||
return mutator
|
||||
}
|
||||
}
|
||||
|
||||
// Append extends a chain, adding the specified hook
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Append(hooks ...ent.Hook) Chain {
|
||||
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
|
||||
newHooks = append(newHooks, c.hooks...)
|
||||
newHooks = append(newHooks, hooks...)
|
||||
return Chain{newHooks}
|
||||
}
|
||||
|
||||
// Extend extends a chain, adding the specified chain
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Extend(chain Chain) Chain {
|
||||
return c.Append(chain.hooks...)
|
||||
}
|
16
src/db/ent/migrate/BUILD.bazel
Normal file
16
src/db/ent/migrate/BUILD.bazel
Normal file
|
@ -0,0 +1,16 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "migrate",
|
||||
srcs = [
|
||||
"migrate.go",
|
||||
"schema.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/migrate",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@com_github_facebook_ent//dialect",
|
||||
"@com_github_facebook_ent//dialect/sql/schema",
|
||||
"@com_github_facebook_ent//schema/field",
|
||||
],
|
||||
)
|
70
src/db/ent/migrate/migrate.go
Normal file
70
src/db/ent/migrate/migrate.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||
// for the ids of each entity (table).
|
||||
// Note that this option cannot be applied on tables that already exist.
|
||||
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||
// WithDropColumn sets the drop column option to the migration.
|
||||
// If this option is enabled, ent migration will drop old columns
|
||||
// that were used for both fields and edges. This defaults to false.
|
||||
WithDropColumn = schema.WithDropColumn
|
||||
// WithDropIndex sets the drop index option to the migration.
|
||||
// If this option is enabled, ent migration will drop old indexes
|
||||
// that were defined in the schema. This defaults to false.
|
||||
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex
|
||||
// WithFixture sets the foreign-key renaming option to the migration when upgrading
|
||||
// ent from v0.1.0 (issue-#285). Defaults to true.
|
||||
WithFixture = schema.WithFixture
|
||||
)
|
||||
|
||||
// Schema is the API for creating, migrating and dropping a schema.
|
||||
type Schema struct {
|
||||
drv dialect.Driver
|
||||
universalID bool
|
||||
}
|
||||
|
||||
// NewSchema creates a new schema client.
|
||||
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %v", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
}
|
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
//
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||
drv := &schema.WriteDriver{
|
||||
Writer: w,
|
||||
Driver: s.drv,
|
||||
}
|
||||
migrate, err := schema.NewMigrate(drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %v", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
}
|
72
src/db/ent/migrate/schema.go
Normal file
72
src/db/ent/migrate/schema.go
Normal file
|
@ -0,0 +1,72 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent/dialect/sql/schema"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// ChallengesColumns holds the columns for the "challenges" table.
|
||||
ChallengesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "create_time", Type: field.TypeTime},
|
||||
{Name: "update_time", Type: field.TypeTime},
|
||||
{Name: "challenge_id", Type: field.TypeString, Unique: true, Size: 2147483647},
|
||||
{Name: "user_id", Type: field.TypeString, Unique: true, Size: 2147483647},
|
||||
{Name: "human", Type: field.TypeString, Unique: true},
|
||||
{Name: "magic", Type: field.TypeString, Unique: true},
|
||||
{Name: "expires_at", Type: field.TypeTime},
|
||||
}
|
||||
// ChallengesTable holds the schema information for the "challenges" table.
|
||||
ChallengesTable = &schema.Table{
|
||||
Name: "challenges",
|
||||
Columns: ChallengesColumns,
|
||||
PrimaryKey: []*schema.Column{ChallengesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{},
|
||||
}
|
||||
// GuildsColumns holds the columns for the "guilds" table.
|
||||
GuildsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "create_time", Type: field.TypeTime},
|
||||
{Name: "update_time", Type: field.TypeTime},
|
||||
{Name: "snowflake", Type: field.TypeString, Unique: true, Size: 2147483647},
|
||||
{Name: "message", Type: field.TypeString, Size: 2147483647},
|
||||
{Name: "categories", Type: field.TypeJSON},
|
||||
{Name: "entitlements", Type: field.TypeJSON},
|
||||
}
|
||||
// GuildsTable holds the schema information for the "guilds" table.
|
||||
GuildsTable = &schema.Table{
|
||||
Name: "guilds",
|
||||
Columns: GuildsColumns,
|
||||
PrimaryKey: []*schema.Column{GuildsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{},
|
||||
}
|
||||
// SessionsColumns holds the columns for the "sessions" table.
|
||||
SessionsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "create_time", Type: field.TypeTime},
|
||||
{Name: "update_time", Type: field.TypeTime},
|
||||
{Name: "session_id", Type: field.TypeString, Unique: true, Size: 2147483647},
|
||||
{Name: "user_id", Type: field.TypeString, Unique: true, Size: 2147483647},
|
||||
{Name: "source", Type: field.TypeEnum, Enums: []string{"oauth", "dm"}},
|
||||
{Name: "expires_at", Type: field.TypeTime},
|
||||
}
|
||||
// SessionsTable holds the schema information for the "sessions" table.
|
||||
SessionsTable = &schema.Table{
|
||||
Name: "sessions",
|
||||
Columns: SessionsColumns,
|
||||
PrimaryKey: []*schema.Column{SessionsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
ChallengesTable,
|
||||
GuildsTable,
|
||||
SessionsTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
1790
src/db/ent/mutation.go
Normal file
1790
src/db/ent/mutation.go
Normal file
File diff suppressed because it is too large
Load diff
9
src/db/ent/predicate/BUILD.bazel
Normal file
9
src/db/ent/predicate/BUILD.bazel
Normal file
|
@ -0,0 +1,9 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "predicate",
|
||||
srcs = ["predicate.go"],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/predicate",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_facebook_ent//dialect/sql"],
|
||||
)
|
16
src/db/ent/predicate/predicate.go
Normal file
16
src/db/ent/predicate/predicate.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Challenge is the predicate function for challenge builders.
|
||||
type Challenge func(*sql.Selector)
|
||||
|
||||
// Guild is the predicate function for guild builders.
|
||||
type Guild func(*sql.Selector)
|
||||
|
||||
// Session is the predicate function for session builders.
|
||||
type Session func(*sql.Selector)
|
9
src/db/ent/privacy/BUILD.bazel
Normal file
9
src/db/ent/privacy/BUILD.bazel
Normal file
|
@ -0,0 +1,9 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "privacy",
|
||||
srcs = ["privacy.go"],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/privacy",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//src/db/ent"],
|
||||
)
|
283
src/db/ent/privacy/privacy.go
Normal file
283
src/db/ent/privacy/privacy.go
Normal file
|
@ -0,0 +1,283 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package privacy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/roleypoly/roleypoly/src/db/ent"
|
||||
)
|
||||
|
||||
var (
|
||||
// Allow may be returned by rules to indicate that the policy
|
||||
// evaluation should terminate with an allow decision.
|
||||
Allow = errors.New("ent/privacy: allow rule")
|
||||
|
||||
// Deny may be returned by rules to indicate that the policy
|
||||
// evaluation should terminate with an deny decision.
|
||||
Deny = errors.New("ent/privacy: deny rule")
|
||||
|
||||
// Skip may be returned by rules to indicate that the policy
|
||||
// evaluation should continue to the next rule.
|
||||
Skip = errors.New("ent/privacy: skip rule")
|
||||
)
|
||||
|
||||
// Allowf returns an formatted wrapped Allow decision.
|
||||
func Allowf(format string, a ...interface{}) error {
|
||||
return fmt.Errorf(format+": %w", append(a, Allow)...)
|
||||
}
|
||||
|
||||
// Denyf returns an formatted wrapped Deny decision.
|
||||
func Denyf(format string, a ...interface{}) error {
|
||||
return fmt.Errorf(format+": %w", append(a, Deny)...)
|
||||
}
|
||||
|
||||
// Skipf returns an formatted wrapped Skip decision.
|
||||
func Skipf(format string, a ...interface{}) error {
|
||||
return fmt.Errorf(format+": %w", append(a, Skip)...)
|
||||
}
|
||||
|
||||
type decisionCtxKey struct{}
|
||||
|
||||
// DecisionContext creates a decision context.
|
||||
func DecisionContext(parent context.Context, decision error) context.Context {
|
||||
if decision == nil || errors.Is(decision, Skip) {
|
||||
return parent
|
||||
}
|
||||
return context.WithValue(parent, decisionCtxKey{}, decision)
|
||||
}
|
||||
|
||||
func decisionFromContext(ctx context.Context) (error, bool) {
|
||||
decision, ok := ctx.Value(decisionCtxKey{}).(error)
|
||||
if ok && errors.Is(decision, Allow) {
|
||||
decision = nil
|
||||
}
|
||||
return decision, ok
|
||||
}
|
||||
|
||||
type (
|
||||
// QueryPolicy combines multiple query rules into a single policy.
|
||||
QueryPolicy []QueryRule
|
||||
|
||||
// QueryRule defines the interface deciding whether a
|
||||
// query is allowed and optionally modify it.
|
||||
QueryRule interface {
|
||||
EvalQuery(context.Context, ent.Query) error
|
||||
}
|
||||
)
|
||||
|
||||
// EvalQuery evaluates a query against a query policy.
|
||||
func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if decision, ok := decisionFromContext(ctx); ok {
|
||||
return decision
|
||||
}
|
||||
for _, rule := range policy {
|
||||
switch decision := rule.EvalQuery(ctx, q); {
|
||||
case decision == nil || errors.Is(decision, Skip):
|
||||
case errors.Is(decision, Allow):
|
||||
return nil
|
||||
default:
|
||||
return decision
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryRuleFunc type is an adapter to allow the use of
|
||||
// ordinary functions as query rules.
|
||||
type QueryRuleFunc func(context.Context, ent.Query) error
|
||||
|
||||
// Eval returns f(ctx, q).
|
||||
func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
return f(ctx, q)
|
||||
}
|
||||
|
||||
type (
|
||||
// MutationPolicy combines multiple mutation rules into a single policy.
|
||||
MutationPolicy []MutationRule
|
||||
|
||||
// MutationRule defines the interface deciding whether a
|
||||
// mutation is allowed and optionally modify it.
|
||||
MutationRule interface {
|
||||
EvalMutation(context.Context, ent.Mutation) error
|
||||
}
|
||||
)
|
||||
|
||||
// EvalMutation evaluates a mutation against a mutation policy.
|
||||
func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if decision, ok := decisionFromContext(ctx); ok {
|
||||
return decision
|
||||
}
|
||||
for _, rule := range policy {
|
||||
switch decision := rule.EvalMutation(ctx, m); {
|
||||
case decision == nil || errors.Is(decision, Skip):
|
||||
case errors.Is(decision, Allow):
|
||||
return nil
|
||||
default:
|
||||
return decision
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MutationRuleFunc type is an adapter to allow the use of
|
||||
// ordinary functions as mutation rules.
|
||||
type MutationRuleFunc func(context.Context, ent.Mutation) error
|
||||
|
||||
// EvalMutation returns f(ctx, m).
|
||||
func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
return f(ctx, m)
|
||||
}
|
||||
|
||||
// Policy groups query and mutation policies.
|
||||
type Policy struct {
|
||||
Query QueryPolicy
|
||||
Mutation MutationPolicy
|
||||
}
|
||||
|
||||
// EvalQuery forwards evaluation to query policy.
|
||||
func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
return policy.Query.EvalQuery(ctx, q)
|
||||
}
|
||||
|
||||
// EvalMutation forwards evaluation to mutation policy.
|
||||
func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
return policy.Mutation.EvalMutation(ctx, m)
|
||||
}
|
||||
|
||||
// QueryMutationRule is the interface that groups query and mutation rules.
|
||||
type QueryMutationRule interface {
|
||||
QueryRule
|
||||
MutationRule
|
||||
}
|
||||
|
||||
// AlwaysAllowRule returns a rule that returns an allow decision.
|
||||
func AlwaysAllowRule() QueryMutationRule {
|
||||
return fixedDecision{Allow}
|
||||
}
|
||||
|
||||
// AlwaysDenyRule returns a rule that returns a deny decision.
|
||||
func AlwaysDenyRule() QueryMutationRule {
|
||||
return fixedDecision{Deny}
|
||||
}
|
||||
|
||||
type fixedDecision struct {
|
||||
decision error
|
||||
}
|
||||
|
||||
func (f fixedDecision) EvalQuery(context.Context, ent.Query) error {
|
||||
return f.decision
|
||||
}
|
||||
|
||||
func (f fixedDecision) EvalMutation(context.Context, ent.Mutation) error {
|
||||
return f.decision
|
||||
}
|
||||
|
||||
type contextDecision struct {
|
||||
eval func(context.Context) error
|
||||
}
|
||||
|
||||
// ContextQueryMutationRule creates a query/mutation rule from a context eval func.
|
||||
func ContextQueryMutationRule(eval func(context.Context) error) QueryMutationRule {
|
||||
return contextDecision{eval}
|
||||
}
|
||||
|
||||
func (c contextDecision) EvalQuery(ctx context.Context, _ ent.Query) error {
|
||||
return c.eval(ctx)
|
||||
}
|
||||
|
||||
func (c contextDecision) EvalMutation(ctx context.Context, _ ent.Mutation) error {
|
||||
return c.eval(ctx)
|
||||
}
|
||||
|
||||
// OnMutationOperation evaluates the given rule only on a given mutation operation.
|
||||
func OnMutationOperation(rule MutationRule, op ent.Op) MutationRule {
|
||||
return MutationRuleFunc(func(ctx context.Context, m ent.Mutation) error {
|
||||
if m.Op().Is(op) {
|
||||
return rule.EvalMutation(ctx, m)
|
||||
}
|
||||
return Skip
|
||||
})
|
||||
}
|
||||
|
||||
// DenyMutationOperationRule returns a rule denying specified mutation operation.
|
||||
func DenyMutationOperationRule(op ent.Op) MutationRule {
|
||||
rule := MutationRuleFunc(func(_ context.Context, m ent.Mutation) error {
|
||||
return Denyf("ent/privacy: operation %s is not allowed", m.Op())
|
||||
})
|
||||
return OnMutationOperation(rule, op)
|
||||
}
|
||||
|
||||
// The ChallengeQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type ChallengeQueryRuleFunc func(context.Context, *ent.ChallengeQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f ChallengeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.ChallengeQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.ChallengeQuery", q)
|
||||
}
|
||||
|
||||
// The ChallengeMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type ChallengeMutationRuleFunc func(context.Context, *ent.ChallengeMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f ChallengeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.ChallengeMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ChallengeMutation", m)
|
||||
}
|
||||
|
||||
// The GuildQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type GuildQueryRuleFunc func(context.Context, *ent.GuildQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f GuildQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.GuildQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.GuildQuery", q)
|
||||
}
|
||||
|
||||
// The GuildMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type GuildMutationRuleFunc func(context.Context, *ent.GuildMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f GuildMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.GuildMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GuildMutation", m)
|
||||
}
|
||||
|
||||
// The SessionQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type SessionQueryRuleFunc func(context.Context, *ent.SessionQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f SessionQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.SessionQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.SessionQuery", q)
|
||||
}
|
||||
|
||||
// The SessionMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type SessionMutationRuleFunc func(context.Context, *ent.SessionMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f SessionMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.SessionMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SessionMutation", m)
|
||||
}
|
68
src/db/ent/runtime.go
Normal file
68
src/db/ent/runtime.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/challenge"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/guild"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/schema"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/session"
|
||||
)
|
||||
|
||||
// The init function reads all schema descriptors with runtime
|
||||
// code (default values, validators or hooks) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
challengeMixin := schema.Challenge{}.Mixin()
|
||||
challengeMixinFields0 := challengeMixin[0].Fields()
|
||||
challengeFields := schema.Challenge{}.Fields()
|
||||
_ = challengeFields
|
||||
// challengeDescCreateTime is the schema descriptor for create_time field.
|
||||
challengeDescCreateTime := challengeMixinFields0[0].Descriptor()
|
||||
// challenge.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
challenge.DefaultCreateTime = challengeDescCreateTime.Default.(func() time.Time)
|
||||
// challengeDescUpdateTime is the schema descriptor for update_time field.
|
||||
challengeDescUpdateTime := challengeMixinFields0[1].Descriptor()
|
||||
// challenge.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
challenge.DefaultUpdateTime = challengeDescUpdateTime.Default.(func() time.Time)
|
||||
// challenge.UpdateDefaultUpdateTime holds the default value on update for the update_time field.
|
||||
challenge.UpdateDefaultUpdateTime = challengeDescUpdateTime.UpdateDefault.(func() time.Time)
|
||||
// challengeDescExpiresAt is the schema descriptor for expires_at field.
|
||||
challengeDescExpiresAt := challengeFields[4].Descriptor()
|
||||
// challenge.DefaultExpiresAt holds the default value on creation for the expires_at field.
|
||||
challenge.DefaultExpiresAt = challengeDescExpiresAt.Default.(func() time.Time)
|
||||
guildMixin := schema.Guild{}.Mixin()
|
||||
guildMixinFields0 := guildMixin[0].Fields()
|
||||
guildFields := schema.Guild{}.Fields()
|
||||
_ = guildFields
|
||||
// guildDescCreateTime is the schema descriptor for create_time field.
|
||||
guildDescCreateTime := guildMixinFields0[0].Descriptor()
|
||||
// guild.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
guild.DefaultCreateTime = guildDescCreateTime.Default.(func() time.Time)
|
||||
// guildDescUpdateTime is the schema descriptor for update_time field.
|
||||
guildDescUpdateTime := guildMixinFields0[1].Descriptor()
|
||||
// guild.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
guild.DefaultUpdateTime = guildDescUpdateTime.Default.(func() time.Time)
|
||||
// guild.UpdateDefaultUpdateTime holds the default value on update for the update_time field.
|
||||
guild.UpdateDefaultUpdateTime = guildDescUpdateTime.UpdateDefault.(func() time.Time)
|
||||
sessionMixin := schema.Session{}.Mixin()
|
||||
sessionMixinFields0 := sessionMixin[0].Fields()
|
||||
sessionFields := schema.Session{}.Fields()
|
||||
_ = sessionFields
|
||||
// sessionDescCreateTime is the schema descriptor for create_time field.
|
||||
sessionDescCreateTime := sessionMixinFields0[0].Descriptor()
|
||||
// session.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
session.DefaultCreateTime = sessionDescCreateTime.Default.(func() time.Time)
|
||||
// sessionDescUpdateTime is the schema descriptor for update_time field.
|
||||
sessionDescUpdateTime := sessionMixinFields0[1].Descriptor()
|
||||
// session.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
session.DefaultUpdateTime = sessionDescUpdateTime.Default.(func() time.Time)
|
||||
// session.UpdateDefaultUpdateTime holds the default value on update for the update_time field.
|
||||
session.UpdateDefaultUpdateTime = sessionDescUpdateTime.UpdateDefault.(func() time.Time)
|
||||
// sessionDescExpiresAt is the schema descriptor for expires_at field.
|
||||
sessionDescExpiresAt := sessionFields[3].Descriptor()
|
||||
// session.DefaultExpiresAt holds the default value on creation for the expires_at field.
|
||||
session.DefaultExpiresAt = sessionDescExpiresAt.Default.(func() time.Time)
|
||||
}
|
8
src/db/ent/runtime/BUILD.bazel
Normal file
8
src/db/ent/runtime/BUILD.bazel
Normal file
|
@ -0,0 +1,8 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "runtime",
|
||||
srcs = ["runtime.go"],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/runtime",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
10
src/db/ent/runtime/runtime.go
Normal file
10
src/db/ent/runtime/runtime.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in github.com/roleypoly/roleypoly/src/db/ent/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.4.2" // Version of ent codegen.
|
||||
Sum = "h1:JzU5dYJH9XdjfIKgOiPPK3szkqLqcdPWgVder4Ogows=" // Sum of ent codegen.
|
||||
)
|
17
src/db/ent/schema/BUILD.bazel
Normal file
17
src/db/ent/schema/BUILD.bazel
Normal file
|
@ -0,0 +1,17 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "schema",
|
||||
srcs = [
|
||||
"challenge.go",
|
||||
"guild.go",
|
||||
"session.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/schema",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@com_github_facebook_ent//:ent",
|
||||
"@com_github_facebook_ent//schema/field",
|
||||
"@com_github_facebook_ent//schema/mixin",
|
||||
],
|
||||
)
|
46
src/db/ent/schema/challenge.go
Normal file
46
src/db/ent/schema/challenge.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/facebook/ent/schema/mixin"
|
||||
)
|
||||
|
||||
// Challenge holds the schema definition for the Challenge entity.
|
||||
type Challenge struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Challenge.
|
||||
func (Challenge) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Text("challenge_id").
|
||||
Immutable().Unique(),
|
||||
|
||||
field.Text("user_id").
|
||||
Immutable().Unique(),
|
||||
|
||||
field.String("human").Immutable().Unique(),
|
||||
field.String("magic").Immutable().Unique(),
|
||||
|
||||
field.Time("expires_at").
|
||||
Immutable().
|
||||
Default(func() time.Time {
|
||||
return time.Now().Add(5 * time.Minute)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Challenge.
|
||||
func (Challenge) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Mixin of the Challenge.
|
||||
func (Challenge) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixin.Time{},
|
||||
}
|
||||
}
|
44
src/db/ent/schema/guild.go
Normal file
44
src/db/ent/schema/guild.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/facebook/ent/schema/mixin"
|
||||
)
|
||||
|
||||
// Guild holds the schema definition for the Guild entity.
|
||||
type Guild struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
ID string
|
||||
Name string
|
||||
Hidden bool
|
||||
Type string
|
||||
Position int
|
||||
Roles []string
|
||||
}
|
||||
|
||||
// Fields of the Guild.
|
||||
func (Guild) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Text("snowflake").
|
||||
Immutable().Unique(),
|
||||
field.Text("message"),
|
||||
field.JSON("categories", []Category{}),
|
||||
field.Strings("entitlements"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Guild.
|
||||
func (Guild) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Mixin of the Guild.
|
||||
func (Guild) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixin.Time{},
|
||||
}
|
||||
}
|
47
src/db/ent/schema/session.go
Normal file
47
src/db/ent/schema/session.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/facebook/ent/schema/mixin"
|
||||
)
|
||||
|
||||
// Session holds the schema definition for the Session entity.
|
||||
type Session struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Session.
|
||||
func (Session) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Text("session_id").
|
||||
Immutable().Unique(),
|
||||
|
||||
field.Text("user_id").
|
||||
Immutable().Unique(),
|
||||
|
||||
field.Enum("source").
|
||||
Values("oauth", "dm").
|
||||
Immutable(),
|
||||
|
||||
field.Time("expires_at").
|
||||
Immutable().
|
||||
Default(func() time.Time {
|
||||
return time.Now().Add(6 * time.Hour)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Session.
|
||||
func (Session) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Mixin of the Session.
|
||||
func (Session) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixin.Time{},
|
||||
}
|
||||
}
|
137
src/db/ent/session.go
Normal file
137
src/db/ent/session.go
Normal file
|
@ -0,0 +1,137 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/session"
|
||||
)
|
||||
|
||||
// Session is the model entity for the Session schema.
|
||||
type Session struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime time.Time `json:"update_time,omitempty"`
|
||||
// SessionID holds the value of the "session_id" field.
|
||||
SessionID string `json:"session_id,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID string `json:"user_id,omitempty"`
|
||||
// Source holds the value of the "source" field.
|
||||
Source session.Source `json:"source,omitempty"`
|
||||
// ExpiresAt holds the value of the "expires_at" field.
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Session) scanValues() []interface{} {
|
||||
return []interface{}{
|
||||
&sql.NullInt64{}, // id
|
||||
&sql.NullTime{}, // create_time
|
||||
&sql.NullTime{}, // update_time
|
||||
&sql.NullString{}, // session_id
|
||||
&sql.NullString{}, // user_id
|
||||
&sql.NullString{}, // source
|
||||
&sql.NullTime{}, // expires_at
|
||||
}
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Session fields.
|
||||
func (s *Session) assignValues(values ...interface{}) error {
|
||||
if m, n := len(values), len(session.Columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
value, ok := values[0].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
s.ID = int(value.Int64)
|
||||
values = values[1:]
|
||||
if value, ok := values[0].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[0])
|
||||
} else if value.Valid {
|
||||
s.CreateTime = value.Time
|
||||
}
|
||||
if value, ok := values[1].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field update_time", values[1])
|
||||
} else if value.Valid {
|
||||
s.UpdateTime = value.Time
|
||||
}
|
||||
if value, ok := values[2].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field session_id", values[2])
|
||||
} else if value.Valid {
|
||||
s.SessionID = value.String
|
||||
}
|
||||
if value, ok := values[3].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[3])
|
||||
} else if value.Valid {
|
||||
s.UserID = value.String
|
||||
}
|
||||
if value, ok := values[4].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field source", values[4])
|
||||
} else if value.Valid {
|
||||
s.Source = session.Source(value.String)
|
||||
}
|
||||
if value, ok := values[5].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field expires_at", values[5])
|
||||
} else if value.Valid {
|
||||
s.ExpiresAt = value.Time
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Session.
|
||||
// Note that, you need to call Session.Unwrap() before calling this method, if this Session
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (s *Session) Update() *SessionUpdateOne {
|
||||
return (&SessionClient{config: s.config}).UpdateOne(s)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
|
||||
// so that all next queries will be executed through the driver which created the transaction.
|
||||
func (s *Session) Unwrap() *Session {
|
||||
tx, ok := s.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Session is not a transactional entity")
|
||||
}
|
||||
s.config.driver = tx.drv
|
||||
return s
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (s *Session) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Session(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", s.ID))
|
||||
builder.WriteString(", create_time=")
|
||||
builder.WriteString(s.CreateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", update_time=")
|
||||
builder.WriteString(s.UpdateTime.Format(time.ANSIC))
|
||||
builder.WriteString(", session_id=")
|
||||
builder.WriteString(s.SessionID)
|
||||
builder.WriteString(", user_id=")
|
||||
builder.WriteString(s.UserID)
|
||||
builder.WriteString(", source=")
|
||||
builder.WriteString(fmt.Sprintf("%v", s.Source))
|
||||
builder.WriteString(", expires_at=")
|
||||
builder.WriteString(s.ExpiresAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Sessions is a parsable slice of Session.
|
||||
type Sessions []*Session
|
||||
|
||||
func (s Sessions) config(cfg config) {
|
||||
for _i := range s {
|
||||
s[_i].config = cfg
|
||||
}
|
||||
}
|
15
src/db/ent/session/BUILD.bazel
Normal file
15
src/db/ent/session/BUILD.bazel
Normal file
|
@ -0,0 +1,15 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "session",
|
||||
srcs = [
|
||||
"session.go",
|
||||
"where.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/db/ent/session",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//src/db/ent/predicate",
|
||||
"@com_github_facebook_ent//dialect/sql",
|
||||
],
|
||||
)
|
75
src/db/ent/session/session.go
Normal file
75
src/db/ent/session/session.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the session type in the database.
|
||||
Label = "session"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||
FieldUpdateTime = "update_time"
|
||||
// FieldSessionID holds the string denoting the session_id field in the database.
|
||||
FieldSessionID = "session_id"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldSource holds the string denoting the source field in the database.
|
||||
FieldSource = "source"
|
||||
// FieldExpiresAt holds the string denoting the expires_at field in the database.
|
||||
FieldExpiresAt = "expires_at"
|
||||
|
||||
// Table holds the table name of the session in the database.
|
||||
Table = "sessions"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for session fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldSessionID,
|
||||
FieldUserID,
|
||||
FieldSource,
|
||||
FieldExpiresAt,
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
DefaultCreateTime func() time.Time
|
||||
// DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
DefaultUpdateTime func() time.Time
|
||||
// UpdateDefaultUpdateTime holds the default value on update for the update_time field.
|
||||
UpdateDefaultUpdateTime func() time.Time
|
||||
// DefaultExpiresAt holds the default value on creation for the expires_at field.
|
||||
DefaultExpiresAt func() time.Time
|
||||
)
|
||||
|
||||
// Source defines the type for the source enum field.
|
||||
type Source string
|
||||
|
||||
// Source values.
|
||||
const (
|
||||
SourceOauth Source = "oauth"
|
||||
SourceDm Source = "dm"
|
||||
)
|
||||
|
||||
func (s Source) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// SourceValidator is a validator for the "source" field enum values. It is called by the builders before save.
|
||||
func SourceValidator(s Source) error {
|
||||
switch s {
|
||||
case SourceOauth, SourceDm:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("session: invalid enum value for source field: %q", s)
|
||||
}
|
||||
}
|
658
src/db/ent/session/where.go
Normal file
658
src/db/ent/session/where.go
Normal file
|
@ -0,0 +1,658 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package session
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their identifier.
|
||||
func ID(id int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||
func UpdateTime(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionID applies equality check predicate on the "session_id" field. It's identical to SessionIDEQ.
|
||||
func SessionID(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
|
||||
func ExpiresAt(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...time.Time) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldCreateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...time.Time) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldCreateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldCreateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...time.Time) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldUpdateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...time.Time) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldUpdateTime), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldUpdateTime), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDEQ applies the EQ predicate on the "session_id" field.
|
||||
func SessionIDEQ(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDNEQ applies the NEQ predicate on the "session_id" field.
|
||||
func SessionIDNEQ(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDIn applies the In predicate on the "session_id" field.
|
||||
func SessionIDIn(vs ...string) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldSessionID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDNotIn applies the NotIn predicate on the "session_id" field.
|
||||
func SessionIDNotIn(vs ...string) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldSessionID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDGT applies the GT predicate on the "session_id" field.
|
||||
func SessionIDGT(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDGTE applies the GTE predicate on the "session_id" field.
|
||||
func SessionIDGTE(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDLT applies the LT predicate on the "session_id" field.
|
||||
func SessionIDLT(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDLTE applies the LTE predicate on the "session_id" field.
|
||||
func SessionIDLTE(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDContains applies the Contains predicate on the "session_id" field.
|
||||
func SessionIDContains(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDHasPrefix applies the HasPrefix predicate on the "session_id" field.
|
||||
func SessionIDHasPrefix(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDHasSuffix applies the HasSuffix predicate on the "session_id" field.
|
||||
func SessionIDHasSuffix(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDEqualFold applies the EqualFold predicate on the "session_id" field.
|
||||
func SessionIDEqualFold(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SessionIDContainsFold applies the ContainsFold predicate on the "session_id" field.
|
||||
func SessionIDContainsFold(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldSessionID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...string) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldUserID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...string) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldUserID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDGT applies the GT predicate on the "user_id" field.
|
||||
func UserIDGT(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDGTE applies the GTE predicate on the "user_id" field.
|
||||
func UserIDGTE(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDLT applies the LT predicate on the "user_id" field.
|
||||
func UserIDLT(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDLTE applies the LTE predicate on the "user_id" field.
|
||||
func UserIDLTE(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDContains applies the Contains predicate on the "user_id" field.
|
||||
func UserIDContains(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field.
|
||||
func UserIDHasPrefix(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field.
|
||||
func UserIDHasSuffix(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDEqualFold applies the EqualFold predicate on the "user_id" field.
|
||||
func UserIDEqualFold(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field.
|
||||
func UserIDContainsFold(v string) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldUserID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SourceEQ applies the EQ predicate on the "source" field.
|
||||
func SourceEQ(v Source) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldSource), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SourceNEQ applies the NEQ predicate on the "source" field.
|
||||
func SourceNEQ(v Source) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldSource), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SourceIn applies the In predicate on the "source" field.
|
||||
func SourceIn(vs ...Source) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldSource), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// SourceNotIn applies the NotIn predicate on the "source" field.
|
||||
func SourceNotIn(vs ...Source) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldSource), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
|
||||
func ExpiresAtEQ(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
|
||||
func ExpiresAtNEQ(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtIn applies the In predicate on the "expires_at" field.
|
||||
func ExpiresAtIn(vs ...time.Time) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldExpiresAt), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
|
||||
func ExpiresAtNotIn(vs ...time.Time) predicate.Session {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldExpiresAt), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
|
||||
func ExpiresAtGT(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
|
||||
func ExpiresAtGTE(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
|
||||
func ExpiresAtLT(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
|
||||
func ExpiresAtLTE(v time.Time) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldExpiresAt), v))
|
||||
})
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Session) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups list of predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Session) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Session) predicate.Session {
|
||||
return predicate.Session(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
298
src/db/ent/session_create.go
Normal file
298
src/db/ent/session_create.go
Normal file
|
@ -0,0 +1,298 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/session"
|
||||
)
|
||||
|
||||
// SessionCreate is the builder for creating a Session entity.
|
||||
type SessionCreate struct {
|
||||
config
|
||||
mutation *SessionMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreateTime sets the create_time field.
|
||||
func (sc *SessionCreate) SetCreateTime(t time.Time) *SessionCreate {
|
||||
sc.mutation.SetCreateTime(t)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableCreateTime sets the create_time field if the given value is not nil.
|
||||
func (sc *SessionCreate) SetNillableCreateTime(t *time.Time) *SessionCreate {
|
||||
if t != nil {
|
||||
sc.SetCreateTime(*t)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the update_time field.
|
||||
func (sc *SessionCreate) SetUpdateTime(t time.Time) *SessionCreate {
|
||||
sc.mutation.SetUpdateTime(t)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableUpdateTime sets the update_time field if the given value is not nil.
|
||||
func (sc *SessionCreate) SetNillableUpdateTime(t *time.Time) *SessionCreate {
|
||||
if t != nil {
|
||||
sc.SetUpdateTime(*t)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetSessionID sets the session_id field.
|
||||
func (sc *SessionCreate) SetSessionID(s string) *SessionCreate {
|
||||
sc.mutation.SetSessionID(s)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetUserID sets the user_id field.
|
||||
func (sc *SessionCreate) SetUserID(s string) *SessionCreate {
|
||||
sc.mutation.SetUserID(s)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetSource sets the source field.
|
||||
func (sc *SessionCreate) SetSource(s session.Source) *SessionCreate {
|
||||
sc.mutation.SetSource(s)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetExpiresAt sets the expires_at field.
|
||||
func (sc *SessionCreate) SetExpiresAt(t time.Time) *SessionCreate {
|
||||
sc.mutation.SetExpiresAt(t)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableExpiresAt sets the expires_at field if the given value is not nil.
|
||||
func (sc *SessionCreate) SetNillableExpiresAt(t *time.Time) *SessionCreate {
|
||||
if t != nil {
|
||||
sc.SetExpiresAt(*t)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// Mutation returns the SessionMutation object of the builder.
|
||||
func (sc *SessionCreate) Mutation() *SessionMutation {
|
||||
return sc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Session in the database.
|
||||
func (sc *SessionCreate) Save(ctx context.Context) (*Session, error) {
|
||||
if err := sc.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Session
|
||||
)
|
||||
if len(sc.hooks) == 0 {
|
||||
node, err = sc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SessionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
sc.mutation = mutation
|
||||
node, err = sc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(sc.hooks) - 1; i >= 0; i-- {
|
||||
mut = sc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, sc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (sc *SessionCreate) SaveX(ctx context.Context) *Session {
|
||||
v, err := sc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (sc *SessionCreate) preSave() error {
|
||||
if _, ok := sc.mutation.CreateTime(); !ok {
|
||||
v := session.DefaultCreateTime()
|
||||
sc.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := sc.mutation.UpdateTime(); !ok {
|
||||
v := session.DefaultUpdateTime()
|
||||
sc.mutation.SetUpdateTime(v)
|
||||
}
|
||||
if _, ok := sc.mutation.SessionID(); !ok {
|
||||
return &ValidationError{Name: "session_id", err: errors.New("ent: missing required field \"session_id\"")}
|
||||
}
|
||||
if _, ok := sc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New("ent: missing required field \"user_id\"")}
|
||||
}
|
||||
if _, ok := sc.mutation.Source(); !ok {
|
||||
return &ValidationError{Name: "source", err: errors.New("ent: missing required field \"source\"")}
|
||||
}
|
||||
if v, ok := sc.mutation.Source(); ok {
|
||||
if err := session.SourceValidator(v); err != nil {
|
||||
return &ValidationError{Name: "source", err: fmt.Errorf("ent: validator failed for field \"source\": %w", err)}
|
||||
}
|
||||
}
|
||||
if _, ok := sc.mutation.ExpiresAt(); !ok {
|
||||
v := session.DefaultExpiresAt()
|
||||
sc.mutation.SetExpiresAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *SessionCreate) sqlSave(ctx context.Context) (*Session, error) {
|
||||
s, _spec := sc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
s.ID = int(id)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (sc *SessionCreate) createSpec() (*Session, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
s = &Session{config: sc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: session.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: session.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := sc.mutation.CreateTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: session.FieldCreateTime,
|
||||
})
|
||||
s.CreateTime = value
|
||||
}
|
||||
if value, ok := sc.mutation.UpdateTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: session.FieldUpdateTime,
|
||||
})
|
||||
s.UpdateTime = value
|
||||
}
|
||||
if value, ok := sc.mutation.SessionID(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: session.FieldSessionID,
|
||||
})
|
||||
s.SessionID = value
|
||||
}
|
||||
if value, ok := sc.mutation.UserID(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: session.FieldUserID,
|
||||
})
|
||||
s.UserID = value
|
||||
}
|
||||
if value, ok := sc.mutation.Source(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: session.FieldSource,
|
||||
})
|
||||
s.Source = value
|
||||
}
|
||||
if value, ok := sc.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: session.FieldExpiresAt,
|
||||
})
|
||||
s.ExpiresAt = value
|
||||
}
|
||||
return s, _spec
|
||||
}
|
||||
|
||||
// SessionCreateBulk is the builder for creating a bulk of Session entities.
|
||||
type SessionCreateBulk struct {
|
||||
config
|
||||
builders []*SessionCreate
|
||||
}
|
||||
|
||||
// Save creates the Session entities in the database.
|
||||
func (scb *SessionCreateBulk) Save(ctx context.Context) ([]*Session, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
||||
nodes := make([]*Session, len(scb.builders))
|
||||
mutators := make([]Mutator, len(scb.builders))
|
||||
for i := range scb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := scb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
if err := builder.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation, ok := m.(*SessionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, scb.builders[i+1].mutation)
|
||||
} else {
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, scb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
}
|
||||
}
|
||||
mutation.done = true
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
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, scb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (scb *SessionCreateBulk) SaveX(ctx context.Context) []*Session {
|
||||
v, err := scb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
109
src/db/ent/session_delete.go
Normal file
109
src/db/ent/session_delete.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/session"
|
||||
)
|
||||
|
||||
// SessionDelete is the builder for deleting a Session entity.
|
||||
type SessionDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SessionMutation
|
||||
predicates []predicate.Session
|
||||
}
|
||||
|
||||
// Where adds a new predicate to the delete builder.
|
||||
func (sd *SessionDelete) Where(ps ...predicate.Session) *SessionDelete {
|
||||
sd.predicates = append(sd.predicates, ps...)
|
||||
return sd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (sd *SessionDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(sd.hooks) == 0 {
|
||||
affected, err = sd.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SessionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
sd.mutation = mutation
|
||||
affected, err = sd.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(sd.hooks) - 1; i >= 0; i-- {
|
||||
mut = sd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, sd.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sd *SessionDelete) ExecX(ctx context.Context) int {
|
||||
n, err := sd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (sd *SessionDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: session.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: session.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := sd.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, sd.driver, _spec)
|
||||
}
|
||||
|
||||
// SessionDeleteOne is the builder for deleting a single Session entity.
|
||||
type SessionDeleteOne struct {
|
||||
sd *SessionDelete
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (sdo *SessionDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := sdo.sd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{session.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sdo *SessionDeleteOne) ExecX(ctx context.Context) {
|
||||
sdo.sd.ExecX(ctx)
|
||||
}
|
866
src/db/ent/session_query.go
Normal file
866
src/db/ent/session_query.go
Normal file
|
@ -0,0 +1,866 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/session"
|
||||
)
|
||||
|
||||
// SessionQuery is the builder for querying Session entities.
|
||||
type SessionQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.Session
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (sq *SessionQuery) Where(ps ...predicate.Session) *SessionQuery {
|
||||
sq.predicates = append(sq.predicates, ps...)
|
||||
return sq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (sq *SessionQuery) Limit(limit int) *SessionQuery {
|
||||
sq.limit = &limit
|
||||
return sq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (sq *SessionQuery) Offset(offset int) *SessionQuery {
|
||||
sq.offset = &offset
|
||||
return sq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (sq *SessionQuery) Order(o ...OrderFunc) *SessionQuery {
|
||||
sq.order = append(sq.order, o...)
|
||||
return sq
|
||||
}
|
||||
|
||||
// First returns the first Session entity in the query. Returns *NotFoundError when no session was found.
|
||||
func (sq *SessionQuery) First(ctx context.Context) (*Session, error) {
|
||||
sSlice, err := sq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(sSlice) == 0 {
|
||||
return nil, &NotFoundError{session.Label}
|
||||
}
|
||||
return sSlice[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (sq *SessionQuery) FirstX(ctx context.Context) *Session {
|
||||
s, err := sq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// FirstID returns the first Session id in the query. Returns *NotFoundError when no id was found.
|
||||
func (sq *SessionQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = sq.Limit(1).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{session.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstXID is like FirstID, but panics if an error occurs.
|
||||
func (sq *SessionQuery) FirstXID(ctx context.Context) int {
|
||||
id, err := sq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns the only Session entity in the query, returns an error if not exactly one entity was returned.
|
||||
func (sq *SessionQuery) Only(ctx context.Context) (*Session, error) {
|
||||
sSlice, err := sq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(sSlice) {
|
||||
case 1:
|
||||
return sSlice[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{session.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{session.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (sq *SessionQuery) OnlyX(ctx context.Context) *Session {
|
||||
s, err := sq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// OnlyID returns the only Session id in the query, returns an error if not exactly one id was returned.
|
||||
func (sq *SessionQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = sq.Limit(2).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = &NotSingularError{session.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (sq *SessionQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := sq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Sessions.
|
||||
func (sq *SessionQuery) All(ctx context.Context) ([]*Session, error) {
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (sq *SessionQuery) AllX(ctx context.Context) []*Session {
|
||||
sSlice, err := sq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return sSlice
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Session ids.
|
||||
func (sq *SessionQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := sq.Select(session.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (sq *SessionQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := sq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (sq *SessionQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return sq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (sq *SessionQuery) CountX(ctx context.Context) int {
|
||||
count, err := sq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (sq *SessionQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return sq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (sq *SessionQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := sq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the query builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (sq *SessionQuery) Clone() *SessionQuery {
|
||||
return &SessionQuery{
|
||||
config: sq.config,
|
||||
limit: sq.limit,
|
||||
offset: sq.offset,
|
||||
order: append([]OrderFunc{}, sq.order...),
|
||||
unique: append([]string{}, sq.unique...),
|
||||
predicates: append([]predicate.Session{}, sq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: sq.sql.Clone(),
|
||||
path: sq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Session.Query().
|
||||
// GroupBy(session.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (sq *SessionQuery) GroupBy(field string, fields ...string) *SessionGroupBy {
|
||||
group := &SessionGroupBy{config: sq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
// Select one or more fields from the given query.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime time.Time `json:"create_time,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Session.Query().
|
||||
// Select(session.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (sq *SessionQuery) Select(field string, fields ...string) *SessionSelect {
|
||||
selector := &SessionSelect{config: sq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (sq *SessionQuery) prepareQuery(ctx context.Context) error {
|
||||
if sq.path != nil {
|
||||
prev, err := sq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sq *SessionQuery) sqlAll(ctx context.Context) ([]*Session, error) {
|
||||
var (
|
||||
nodes = []*Session{}
|
||||
_spec = sq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func() []interface{} {
|
||||
node := &Session{config: sq.config}
|
||||
nodes = append(nodes, node)
|
||||
values := node.scanValues()
|
||||
return values
|
||||
}
|
||||
_spec.Assign = func(values ...interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
return node.assignValues(values...)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, sq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (sq *SessionQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := sq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, sq.driver, _spec)
|
||||
}
|
||||
|
||||
func (sq *SessionQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := sq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %v", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (sq *SessionQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: session.Table,
|
||||
Columns: session.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: session.FieldID,
|
||||
},
|
||||
},
|
||||
From: sq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if ps := sq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := sq.limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := sq.offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := sq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (sq *SessionQuery) sqlQuery() *sql.Selector {
|
||||
builder := sql.Dialect(sq.driver.Dialect())
|
||||
t1 := builder.Table(session.Table)
|
||||
selector := builder.Select(t1.Columns(session.Columns...)...).From(t1)
|
||||
if sq.sql != nil {
|
||||
selector = sq.sql
|
||||
selector.Select(selector.Columns(session.Columns...)...)
|
||||
}
|
||||
for _, p := range sq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range sq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := sq.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 := sq.limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// SessionGroupBy is the builder for group-by Session entities.
|
||||
type SessionGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (sgb *SessionGroupBy) Aggregate(fns ...AggregateFunc) *SessionGroupBy {
|
||||
sgb.fns = append(sgb.fns, fns...)
|
||||
return sgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (sgb *SessionGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := sgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sgb.sql = query
|
||||
return sgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := sgb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(sgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := sgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := sgb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = sgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := sgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(sgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := sgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := sgb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = sgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := sgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(sgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := sgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := sgb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = sgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := sgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(sgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := sgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := sgb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (sgb *SessionGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = sgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (sgb *SessionGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := sgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (sgb *SessionGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := sgb.sqlQuery().Query()
|
||||
if err := sgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (sgb *SessionGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := sgb.sql
|
||||
columns := make([]string, 0, len(sgb.fields)+len(sgb.fns))
|
||||
columns = append(columns, sgb.fields...)
|
||||
for _, fn := range sgb.fns {
|
||||
columns = append(columns, fn(selector))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(sgb.fields...)
|
||||
}
|
||||
|
||||
// SessionSelect is the builder for select fields of Session entities.
|
||||
type SessionSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (ss *SessionSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ss.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ss.sql = query
|
||||
return ss.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (ss *SessionSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := ss.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(ss.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionSelect.Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := ss.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (ss *SessionSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := ss.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ss.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ss *SessionSelect) StringX(ctx context.Context) string {
|
||||
v, err := ss.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ss.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := ss.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (ss *SessionSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := ss.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ss.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ss *SessionSelect) IntX(ctx context.Context) int {
|
||||
v, err := ss.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ss.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := ss.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (ss *SessionSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := ss.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ss.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ss *SessionSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := ss.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ss.fields) > 1 {
|
||||
return nil, errors.New("ent: SessionSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := ss.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (ss *SessionSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := ss.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (ss *SessionSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ss.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{session.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SessionSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ss *SessionSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := ss.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ss *SessionSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := ss.sqlQuery().Query()
|
||||
if err := ss.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (ss *SessionSelect) sqlQuery() sql.Querier {
|
||||
selector := ss.sql
|
||||
selector.Select(selector.Columns(ss.fields...)...)
|
||||
return selector
|
||||
}
|
228
src/db/ent/session_update.go
Normal file
228
src/db/ent/session_update.go
Normal file
|
@ -0,0 +1,228 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/predicate"
|
||||
"github.com/roleypoly/roleypoly/src/db/ent/session"
|
||||
)
|
||||
|
||||
// SessionUpdate is the builder for updating Session entities.
|
||||
type SessionUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SessionMutation
|
||||
predicates []predicate.Session
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (su *SessionUpdate) Where(ps ...predicate.Session) *SessionUpdate {
|
||||
su.predicates = append(su.predicates, ps...)
|
||||
return su
|
||||
}
|
||||
|
||||
// Mutation returns the SessionMutation object of the builder.
|
||||
func (su *SessionUpdate) Mutation() *SessionMutation {
|
||||
return su.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (su *SessionUpdate) Save(ctx context.Context) (int, error) {
|
||||
if _, ok := su.mutation.UpdateTime(); !ok {
|
||||
v := session.UpdateDefaultUpdateTime()
|
||||
su.mutation.SetUpdateTime(v)
|
||||
}
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(su.hooks) == 0 {
|
||||
affected, err = su.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SessionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
su.mutation = mutation
|
||||
affected, err = su.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(su.hooks) - 1; i >= 0; i-- {
|
||||
mut = su.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, su.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (su *SessionUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := su.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (su *SessionUpdate) Exec(ctx context.Context) error {
|
||||
_, err := su.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (su *SessionUpdate) ExecX(ctx context.Context) {
|
||||
if err := su.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (su *SessionUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: session.Table,
|
||||
Columns: session.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: session.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := su.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := su.mutation.UpdateTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: session.FieldUpdateTime,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{session.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// SessionUpdateOne is the builder for updating a single Session entity.
|
||||
type SessionUpdateOne struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SessionMutation
|
||||
}
|
||||
|
||||
// Mutation returns the SessionMutation object of the builder.
|
||||
func (suo *SessionUpdateOne) Mutation() *SessionMutation {
|
||||
return suo.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (suo *SessionUpdateOne) Save(ctx context.Context) (*Session, error) {
|
||||
if _, ok := suo.mutation.UpdateTime(); !ok {
|
||||
v := session.UpdateDefaultUpdateTime()
|
||||
suo.mutation.SetUpdateTime(v)
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Session
|
||||
)
|
||||
if len(suo.hooks) == 0 {
|
||||
node, err = suo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SessionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
suo.mutation = mutation
|
||||
node, err = suo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(suo.hooks) - 1; i >= 0; i-- {
|
||||
mut = suo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, suo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (suo *SessionUpdateOne) SaveX(ctx context.Context) *Session {
|
||||
s, err := suo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (suo *SessionUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := suo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (suo *SessionUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := suo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (suo *SessionUpdateOne) sqlSave(ctx context.Context) (s *Session, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: session.Table,
|
||||
Columns: session.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: session.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := suo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Session.ID for update")}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if value, ok := suo.mutation.UpdateTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: session.FieldUpdateTime,
|
||||
})
|
||||
}
|
||||
s = &Session{config: suo.config}
|
||||
_spec.Assign = s.assignValues
|
||||
_spec.ScanValues = s.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{session.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return s, nil
|
||||
}
|
216
src/db/ent/tx.go
Normal file
216
src/db/ent/tx.go
Normal file
|
@ -0,0 +1,216 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/facebook/ent/dialect"
|
||||
)
|
||||
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Challenge is the client for interacting with the Challenge builders.
|
||||
Challenge *ChallengeClient
|
||||
// Guild is the client for interacting with the Guild builders.
|
||||
Guild *GuildClient
|
||||
// Session is the client for interacting with the Session builders.
|
||||
Session *SessionClient
|
||||
|
||||
// lazily loaded.
|
||||
client *Client
|
||||
clientOnce sync.Once
|
||||
|
||||
// completion callbacks.
|
||||
mu sync.Mutex
|
||||
onCommit []CommitHook
|
||||
onRollback []RollbackHook
|
||||
|
||||
// ctx lives for the life of the transaction. It is
|
||||
// the same context used by the underlying connection.
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type (
|
||||
// Committer is the interface that wraps the Committer method.
|
||||
Committer interface {
|
||||
Commit(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Committer. If f is a function with the appropriate
|
||||
// signature, CommitFunc(f) is a Committer that calls f.
|
||||
CommitFunc func(context.Context, *Tx) error
|
||||
|
||||
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||
// and returns a Committer. For example:
|
||||
//
|
||||
// hook := func(next ent.Committer) ent.Committer {
|
||||
// return ent.CommitFunc(func(context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Commit(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
CommitHook func(Committer) Committer
|
||||
)
|
||||
|
||||
// Commit calls f(ctx, m).
|
||||
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Commit commits the transaction.
|
||||
func (tx *Tx) Commit() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Commit()
|
||||
})
|
||||
tx.mu.Lock()
|
||||
hooks := append([]CommitHook(nil), tx.onCommit...)
|
||||
tx.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Commit(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnCommit adds a hook to call on commit.
|
||||
func (tx *Tx) OnCommit(f CommitHook) {
|
||||
tx.mu.Lock()
|
||||
defer tx.mu.Unlock()
|
||||
tx.onCommit = append(tx.onCommit, f)
|
||||
}
|
||||
|
||||
type (
|
||||
// Rollbacker is the interface that wraps the Rollbacker method.
|
||||
Rollbacker interface {
|
||||
Rollback(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Rollbacker. If f is a function with the appropriate
|
||||
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||
RollbackFunc func(context.Context, *Tx) error
|
||||
|
||||
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||
// and returns a Rollbacker. For example:
|
||||
//
|
||||
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||
// return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Rollback(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
RollbackHook func(Rollbacker) Rollbacker
|
||||
)
|
||||
|
||||
// Rollback calls f(ctx, m).
|
||||
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Rollback rollbacks the transaction.
|
||||
func (tx *Tx) Rollback() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Rollback()
|
||||
})
|
||||
tx.mu.Lock()
|
||||
hooks := append([]RollbackHook(nil), tx.onRollback...)
|
||||
tx.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Rollback(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnRollback adds a hook to call on rollback.
|
||||
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||
tx.mu.Lock()
|
||||
defer tx.mu.Unlock()
|
||||
tx.onRollback = append(tx.onRollback, f)
|
||||
}
|
||||
|
||||
// Client returns a Client that binds to current transaction.
|
||||
func (tx *Tx) Client() *Client {
|
||||
tx.clientOnce.Do(func() {
|
||||
tx.client = &Client{config: tx.config}
|
||||
tx.client.init()
|
||||
})
|
||||
return tx.client
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Challenge = NewChallengeClient(tx.config)
|
||||
tx.Guild = NewGuildClient(tx.config)
|
||||
tx.Session = NewSessionClient(tx.config)
|
||||
}
|
||||
|
||||
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||
// The idea is to support transactions without adding any extra code to the builders.
|
||||
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: Challenge.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
type txDriver struct {
|
||||
// the driver we started the transaction from.
|
||||
drv dialect.Driver
|
||||
// tx is the underlying transaction.
|
||||
tx dialect.Tx
|
||||
}
|
||||
|
||||
// newTx creates a new transactional driver.
|
||||
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||
tx, err := drv.Tx(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &txDriver{tx: tx, drv: drv}, nil
|
||||
}
|
||||
|
||||
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||
// from the internal builders. Should be called only by the internal builders.
|
||||
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||
|
||||
// Dialect returns the dialect of the driver we started the transaction from.
|
||||
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||
|
||||
// Close is a nop close.
|
||||
func (*txDriver) Close() error { return nil }
|
||||
|
||||
// Commit is a nop commit for the internal builders.
|
||||
// User must call `Tx.Commit` in order to commit the transaction.
|
||||
func (*txDriver) Commit() error { return nil }
|
||||
|
||||
// Rollback is a nop rollback for the internal builders.
|
||||
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||
func (*txDriver) Rollback() error { return nil }
|
||||
|
||||
// Exec calls tx.Exec.
|
||||
func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error {
|
||||
return tx.tx.Exec(ctx, query, args, v)
|
||||
}
|
||||
|
||||
// Query calls tx.Query.
|
||||
func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error {
|
||||
return tx.tx.Query(ctx, query, args, v)
|
||||
}
|
||||
|
||||
var _ dialect.Driver = (*txDriver)(nil)
|
4
src/discord-bot/.gitignore
vendored
Normal file
4
src/discord-bot/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
.env
|
||||
vendor
|
||||
discord
|
||||
discord.exe
|
28
src/discord-bot/BUILD.bazel
Normal file
28
src/discord-bot/BUILD.bazel
Normal file
|
@ -0,0 +1,28 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
|
||||
|
||||
go_library(
|
||||
name = "discord-bot_lib",
|
||||
srcs = ["discordbot.go"],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/discord-bot",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//src/common/version",
|
||||
"@com_github_bwmarrin_discordgo//:discordgo",
|
||||
"@com_github_joho_godotenv//autoload",
|
||||
"@com_github_lampjaw_discordclient//:discordclient",
|
||||
"@io_k8s_klog//:klog",
|
||||
],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "discord-bot_bin",
|
||||
embed = [":discord-bot_lib"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
go_image(
|
||||
name = "discord-bot",
|
||||
embed = [":discord-bot_lib"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
0
src/discord-bot/README.md
Normal file
0
src/discord-bot/README.md
Normal file
53
src/discord-bot/discordbot.go
Normal file
53
src/discord-bot/discordbot.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/lampjaw/discordclient"
|
||||
"github.com/roleypoly/roleypoly/src/common/version"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
func main() {
|
||||
klog.Info(version.StartupInfo("discord-bot"))
|
||||
|
||||
botToken := os.Getenv("DISCORD_BOT_TOKEN")
|
||||
botClientID := os.Getenv("DISCORD_CLIENT_ID")
|
||||
rootUsers := strings.Split(os.Getenv("ROOT_USERS"), ",")
|
||||
|
||||
discordClient := discordclient.NewDiscordClient(botToken, rootUsers[0], botClientID)
|
||||
discordClient.GatewayIntents = discordgo.IntentsNone
|
||||
|
||||
messageChannel, err := discordClient.Listen(-1)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
|
||||
defer awaitExit()
|
||||
|
||||
go processMessages(messageChannel)
|
||||
}
|
||||
|
||||
func processMessages(messageChannel <-chan discordclient.Message) {
|
||||
for {
|
||||
message := <-messageChannel
|
||||
klog.Infoln("message: ", message.Message())
|
||||
}
|
||||
}
|
||||
|
||||
func awaitExit() {
|
||||
syscallExit := make(chan os.Signal, 1)
|
||||
signal.Notify(
|
||||
syscallExit,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGTERM,
|
||||
os.Interrupt,
|
||||
os.Kill,
|
||||
)
|
||||
<-syscallExit
|
||||
}
|
16
src/gripkit/BUILD.bazel
Normal file
16
src/gripkit/BUILD.bazel
Normal file
|
@ -0,0 +1,16 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "gripkit",
|
||||
srcs = [
|
||||
"gripkit.go",
|
||||
"options.go",
|
||||
],
|
||||
importpath = "github.com/roleypoly/roleypoly/src/gripkit",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@com_github_improbable_eng_grpc_web//go/grpcweb",
|
||||
"@io_k8s_klog//:klog",
|
||||
"@org_golang_google_grpc//:go_default_library",
|
||||
],
|
||||
)
|
103
src/gripkit/gripkit.go
Normal file
103
src/gripkit/gripkit.go
Normal file
|
@ -0,0 +1,103 @@
|
|||
// Package gripkit provides wrappers and helpers for
|
||||
package gripkit // import "github.com/roleypoly/gripkit"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/improbable-eng/grpc-web/go/grpcweb"
|
||||
"google.golang.org/grpc"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
type Gripkit struct {
|
||||
Server *grpc.Server
|
||||
httpHandler *func(w http.ResponseWriter, r *http.Request)
|
||||
options *options
|
||||
grpcWebServer *grpcweb.WrappedGrpcServer
|
||||
ready bool
|
||||
}
|
||||
|
||||
func Create(options ...Option) *Gripkit {
|
||||
gkOptions := evaluateOptions(options...)
|
||||
grpcServer := grpc.NewServer(gkOptions.grpcOptions...)
|
||||
|
||||
var grpcWrapper *grpcweb.WrappedGrpcServer
|
||||
if gkOptions.wrapGrpcWeb {
|
||||
grpcWrapper = grpcweb.WrapServer(grpcServer, gkOptions.grpcWebOptions...)
|
||||
}
|
||||
|
||||
gk := &Gripkit{
|
||||
Server: grpcServer,
|
||||
grpcWebServer: grpcWrapper,
|
||||
options: gkOptions,
|
||||
ready: false,
|
||||
}
|
||||
|
||||
if gk.options.healthz != nil {
|
||||
if gk.options.healthz.UseDefault {
|
||||
if gk.options.healthz.Addr == "" {
|
||||
gk.options.healthz.Addr = ":10456"
|
||||
}
|
||||
|
||||
gk.options.healthz.Handler = gk.defaultHealthHandler
|
||||
}
|
||||
|
||||
go gk.startHealthzServer()
|
||||
}
|
||||
|
||||
return gk
|
||||
}
|
||||
|
||||
func (gk *Gripkit) Serve() error {
|
||||
handler := gk.Server.ServeHTTP
|
||||
if gk.options.wrapGrpcWeb {
|
||||
handler = gk.grpcWebServer.ServeHTTP
|
||||
}
|
||||
|
||||
httpHandler := http.HandlerFunc(handler)
|
||||
|
||||
if gk.options.wrapDebug {
|
||||
httpHandler = http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
source := "gRPC native"
|
||||
if req.Header.Get("X-Grpc-Web") == "1" {
|
||||
source = "gRPC web"
|
||||
}
|
||||
klog.Infoln("gRPC debug: url:", req.URL, "source:", source)
|
||||
handler(resp, req)
|
||||
})
|
||||
}
|
||||
|
||||
if gk.options.httpOptions.TLSCertPath == "" || gk.options.httpOptions.TLSKeyPath == "" {
|
||||
return http.ListenAndServe(
|
||||
gk.options.httpOptions.Addr,
|
||||
httpHandler,
|
||||
)
|
||||
}
|
||||
|
||||
gk.ready = true
|
||||
|
||||
return http.ListenAndServeTLS(
|
||||
gk.options.httpOptions.Addr,
|
||||
gk.options.httpOptions.TLSCertPath,
|
||||
gk.options.httpOptions.TLSKeyPath,
|
||||
httpHandler,
|
||||
)
|
||||
}
|
||||
|
||||
func (gk *Gripkit) startHealthzServer() {
|
||||
klog.Infoln("Starting /healthz server on", gk.options.healthz.Addr)
|
||||
err := http.ListenAndServe(gk.options.healthz.Addr, gk.options.healthz.Handler)
|
||||
if err != nil {
|
||||
klog.Errorln("/healthz server failed to start", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (gk *Gripkit) defaultHealthHandler(rw http.ResponseWriter, r *http.Request) {
|
||||
if gk.ready {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
rw.Write([]byte(`OK`))
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusServiceUnavailable)
|
||||
rw.Write([]byte(`Not Ready`))
|
||||
}
|
||||
}
|
103
src/gripkit/options.go
Normal file
103
src/gripkit/options.go
Normal file
|
@ -0,0 +1,103 @@
|
|||
package gripkit
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/improbable-eng/grpc-web/go/grpcweb"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type HTTPOptions struct {
|
||||
TLSCertPath string
|
||||
TLSKeyPath string
|
||||
Addr string
|
||||
}
|
||||
|
||||
type HealthzOptions struct {
|
||||
UseDefault bool
|
||||
Handler http.HandlerFunc
|
||||
|
||||
// Optional IP:Port string, defaults to :10456
|
||||
Addr string
|
||||
}
|
||||
|
||||
type Option func(*options)
|
||||
|
||||
type options struct {
|
||||
wrapGrpcWeb bool
|
||||
grpcWebOptions []grpcweb.Option
|
||||
httpOptions HTTPOptions
|
||||
grpcOptions []grpc.ServerOption
|
||||
wrapDebug bool
|
||||
healthz *HealthzOptions
|
||||
}
|
||||
|
||||
var (
|
||||
defaultOptions = &options{
|
||||
wrapGrpcWeb: false,
|
||||
grpcWebOptions: []grpcweb.Option{},
|
||||
grpcOptions: []grpc.ServerOption{},
|
||||
wrapDebug: false,
|
||||
httpOptions: HTTPOptions{
|
||||
Addr: ":8080",
|
||||
TLSKeyPath: "",
|
||||
TLSCertPath: "",
|
||||
},
|
||||
healthz: &HealthzOptions{
|
||||
UseDefault: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func evaluateOptions(optionList ...Option) *options {
|
||||
evaluatedOptions := defaultOptions
|
||||
|
||||
for _, optionFunc := range optionList {
|
||||
if optionFunc != nil {
|
||||
optionFunc(evaluatedOptions)
|
||||
}
|
||||
}
|
||||
|
||||
return evaluatedOptions
|
||||
}
|
||||
|
||||
func WithDebug() Option {
|
||||
return func(o *options) {
|
||||
o.wrapDebug = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithGrpcWeb(opts ...grpcweb.Option) Option {
|
||||
return func(o *options) {
|
||||
o.wrapGrpcWeb = true
|
||||
o.grpcWebOptions = opts
|
||||
}
|
||||
}
|
||||
|
||||
func WithOptions(opts ...grpc.ServerOption) Option {
|
||||
return func(o *options) {
|
||||
o.grpcOptions = opts
|
||||
}
|
||||
}
|
||||
|
||||
func WithHTTPOptions(opts HTTPOptions) Option {
|
||||
return func(o *options) {
|
||||
o.httpOptions = opts
|
||||
}
|
||||
}
|
||||
|
||||
// WithHealthz adds a custom /healthz handler to the gRPC HTTP server. Pass nil to disable.
|
||||
func WithHealthz(hzOpts *HealthzOptions) Option {
|
||||
return func(o *options) {
|
||||
if hzOpts == nil {
|
||||
o.healthz = nil
|
||||
return
|
||||
}
|
||||
|
||||
if hzOpts.Addr != "" {
|
||||
o.healthz.Addr = hzOpts.Addr
|
||||
}
|
||||
|
||||
o.healthz.Handler = hzOpts.Handler
|
||||
}
|
||||
}
|
11
src/jstest/BUILD.bazel
Normal file
11
src/jstest/BUILD.bazel
Normal file
|
@ -0,0 +1,11 @@
|
|||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
ts_library(
|
||||
name = "jstest",
|
||||
srcs = glob(["*.ts"]),
|
||||
deps = [
|
||||
# "//path/to/other:library"
|
||||
],
|
||||
)
|
1
src/jstest/index.ts
Normal file
1
src/jstest/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export const aaa = "aa";
|
Loading…
Add table
Add a link
Reference in a new issue