feat: ent ORM, admin UI, client auth, Fyne GUI, Windows/MSI packaging

This commit is contained in:
kannn
2026-05-29 08:58:22 +00:00
Unverified
parent 8563a5fc74
commit a0a42a4966
81 changed files with 17144 additions and 89 deletions
+769
View File
@@ -0,0 +1,769 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"log"
"reflect"
"github.com/fatedier/frp/pkg/db/ent/migrate"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
"github.com/fatedier/frp/pkg/db/ent/proxy"
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// 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
// FrpcClient is the client for interacting with the FrpcClient builders.
FrpcClient *FrpcClientClient
// Proxy is the client for interacting with the Proxy builders.
Proxy *ProxyClient
// ServerConfig is the client for interacting with the ServerConfig builders.
ServerConfig *ServerConfigClient
// User is the client for interacting with the User builders.
User *UserClient
}
// NewClient creates a new client configured with the given options.
func NewClient(opts ...Option) *Client {
client := &Client{config: newConfig(opts...)}
client.init()
return client
}
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.FrpcClient = NewFrpcClientClient(c.config)
c.Proxy = NewProxyClient(c.config)
c.ServerConfig = NewServerConfigClient(c.config)
c.User = NewUserClient(c.config)
}
type (
// config is the configuration for the client and its builder.
config struct {
// driver used for executing database requests.
driver dialect.Driver
// debug enable a debug logging.
debug bool
// log used for logging on debug mode.
log func(...any)
// hooks to execute on mutations.
hooks *hooks
// interceptors to execute on queries.
inters *inters
}
// Option function to configure the client.
Option func(*config)
)
// newConfig creates a new config for the client.
func newConfig(opts ...Option) config {
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
cfg.options(opts...)
return cfg
}
// options applies the options on the config object.
func (c *config) options(opts ...Option) {
for _, opt := range opts {
opt(c)
}
if c.debug {
c.driver = dialect.Debug(c.driver, c.log)
}
}
// Debug enables debug logging on the ent.Driver.
func Debug() Option {
return func(c *config) {
c.debug = true
}
}
// Log sets the logging function for debug mode.
func Log(fn func(...any)) Option {
return func(c *config) {
c.log = fn
}
}
// Driver configures the client driver.
func Driver(driver dialect.Driver) Option {
return func(c *config) {
c.driver = driver
}
}
// Open opens a database/sql.DB specified by the driver name and
// the data source name, and returns a new client attached to it.
// Optional parameters can be added for configuring the client.
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
switch driverName {
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
drv, err := sql.Open(driverName, dataSourceName)
if err != nil {
return nil, err
}
return NewClient(append(options, Driver(drv))...), nil
default:
return nil, fmt.Errorf("unsupported driver: %q", driverName)
}
}
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
// Tx returns a new transactional client. The provided context
// is used until the transaction is committed or rolled back.
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, ErrTxStarted
}
tx, err := newTx(ctx, c.driver)
if err != nil {
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = tx
return &Tx{
ctx: ctx,
config: cfg,
FrpcClient: NewFrpcClientClient(cfg),
Proxy: NewProxyClient(cfg),
ServerConfig: NewServerConfigClient(cfg),
User: NewUserClient(cfg),
}, nil
}
// BeginTx returns a transactional client with specified options.
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, errors.New("ent: cannot start a transaction within a transaction")
}
tx, err := c.driver.(interface {
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
}).BeginTx(ctx, opts)
if err != nil {
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = &txDriver{tx: tx, drv: c.driver}
return &Tx{
ctx: ctx,
config: cfg,
FrpcClient: NewFrpcClientClient(cfg),
Proxy: NewProxyClient(cfg),
ServerConfig: NewServerConfigClient(cfg),
User: NewUserClient(cfg),
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// FrpcClient.
// Query().
// Count(ctx)
func (c *Client) Debug() *Client {
if c.debug {
return c
}
cfg := c.config
cfg.driver = dialect.Debug(c.driver, c.log)
client := &Client{config: cfg}
client.init()
return client
}
// Close closes the database connection and prevents new queries from starting.
func (c *Client) Close() error {
return c.driver.Close()
}
// Use adds the mutation hooks to all the entity clients.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
c.FrpcClient.Use(hooks...)
c.Proxy.Use(hooks...)
c.ServerConfig.Use(hooks...)
c.User.Use(hooks...)
}
// Intercept adds the query interceptors to all the entity clients.
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
c.FrpcClient.Intercept(interceptors...)
c.Proxy.Intercept(interceptors...)
c.ServerConfig.Intercept(interceptors...)
c.User.Intercept(interceptors...)
}
// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
switch m := m.(type) {
case *FrpcClientMutation:
return c.FrpcClient.mutate(ctx, m)
case *ProxyMutation:
return c.Proxy.mutate(ctx, m)
case *ServerConfigMutation:
return c.ServerConfig.mutate(ctx, m)
case *UserMutation:
return c.User.mutate(ctx, m)
default:
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
}
}
// FrpcClientClient is a client for the FrpcClient schema.
type FrpcClientClient struct {
config
}
// NewFrpcClientClient returns a client for the FrpcClient from the given config.
func NewFrpcClientClient(c config) *FrpcClientClient {
return &FrpcClientClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `frpcclient.Hooks(f(g(h())))`.
func (c *FrpcClientClient) Use(hooks ...Hook) {
c.hooks.FrpcClient = append(c.hooks.FrpcClient, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `frpcclient.Intercept(f(g(h())))`.
func (c *FrpcClientClient) Intercept(interceptors ...Interceptor) {
c.inters.FrpcClient = append(c.inters.FrpcClient, interceptors...)
}
// Create returns a builder for creating a FrpcClient entity.
func (c *FrpcClientClient) Create() *FrpcClientCreate {
mutation := newFrpcClientMutation(c.config, OpCreate)
return &FrpcClientCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of FrpcClient entities.
func (c *FrpcClientClient) CreateBulk(builders ...*FrpcClientCreate) *FrpcClientCreateBulk {
return &FrpcClientCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *FrpcClientClient) MapCreateBulk(slice any, setFunc func(*FrpcClientCreate, int)) *FrpcClientCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &FrpcClientCreateBulk{err: fmt.Errorf("calling to FrpcClientClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*FrpcClientCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &FrpcClientCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for FrpcClient.
func (c *FrpcClientClient) Update() *FrpcClientUpdate {
mutation := newFrpcClientMutation(c.config, OpUpdate)
return &FrpcClientUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *FrpcClientClient) UpdateOne(_m *FrpcClient) *FrpcClientUpdateOne {
mutation := newFrpcClientMutation(c.config, OpUpdateOne, withFrpcClient(_m))
return &FrpcClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *FrpcClientClient) UpdateOneID(id int) *FrpcClientUpdateOne {
mutation := newFrpcClientMutation(c.config, OpUpdateOne, withFrpcClientID(id))
return &FrpcClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for FrpcClient.
func (c *FrpcClientClient) Delete() *FrpcClientDelete {
mutation := newFrpcClientMutation(c.config, OpDelete)
return &FrpcClientDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *FrpcClientClient) DeleteOne(_m *FrpcClient) *FrpcClientDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *FrpcClientClient) DeleteOneID(id int) *FrpcClientDeleteOne {
builder := c.Delete().Where(frpcclient.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &FrpcClientDeleteOne{builder}
}
// Query returns a query builder for FrpcClient.
func (c *FrpcClientClient) Query() *FrpcClientQuery {
return &FrpcClientQuery{
config: c.config,
ctx: &QueryContext{Type: TypeFrpcClient},
inters: c.Interceptors(),
}
}
// Get returns a FrpcClient entity by its id.
func (c *FrpcClientClient) Get(ctx context.Context, id int) (*FrpcClient, error) {
return c.Query().Where(frpcclient.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *FrpcClientClient) GetX(ctx context.Context, id int) *FrpcClient {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *FrpcClientClient) Hooks() []Hook {
return c.hooks.FrpcClient
}
// Interceptors returns the client interceptors.
func (c *FrpcClientClient) Interceptors() []Interceptor {
return c.inters.FrpcClient
}
func (c *FrpcClientClient) mutate(ctx context.Context, m *FrpcClientMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&FrpcClientCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&FrpcClientUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&FrpcClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&FrpcClientDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown FrpcClient mutation op: %q", m.Op())
}
}
// ProxyClient is a client for the Proxy schema.
type ProxyClient struct {
config
}
// NewProxyClient returns a client for the Proxy from the given config.
func NewProxyClient(c config) *ProxyClient {
return &ProxyClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `proxy.Hooks(f(g(h())))`.
func (c *ProxyClient) Use(hooks ...Hook) {
c.hooks.Proxy = append(c.hooks.Proxy, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `proxy.Intercept(f(g(h())))`.
func (c *ProxyClient) Intercept(interceptors ...Interceptor) {
c.inters.Proxy = append(c.inters.Proxy, interceptors...)
}
// Create returns a builder for creating a Proxy entity.
func (c *ProxyClient) Create() *ProxyCreate {
mutation := newProxyMutation(c.config, OpCreate)
return &ProxyCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Proxy entities.
func (c *ProxyClient) CreateBulk(builders ...*ProxyCreate) *ProxyCreateBulk {
return &ProxyCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *ProxyClient) MapCreateBulk(slice any, setFunc func(*ProxyCreate, int)) *ProxyCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ProxyCreateBulk{err: fmt.Errorf("calling to ProxyClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ProxyCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ProxyCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Proxy.
func (c *ProxyClient) Update() *ProxyUpdate {
mutation := newProxyMutation(c.config, OpUpdate)
return &ProxyUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ProxyClient) UpdateOne(_m *Proxy) *ProxyUpdateOne {
mutation := newProxyMutation(c.config, OpUpdateOne, withProxy(_m))
return &ProxyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ProxyClient) UpdateOneID(id int) *ProxyUpdateOne {
mutation := newProxyMutation(c.config, OpUpdateOne, withProxyID(id))
return &ProxyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Proxy.
func (c *ProxyClient) Delete() *ProxyDelete {
mutation := newProxyMutation(c.config, OpDelete)
return &ProxyDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ProxyClient) DeleteOne(_m *Proxy) *ProxyDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ProxyClient) DeleteOneID(id int) *ProxyDeleteOne {
builder := c.Delete().Where(proxy.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ProxyDeleteOne{builder}
}
// Query returns a query builder for Proxy.
func (c *ProxyClient) Query() *ProxyQuery {
return &ProxyQuery{
config: c.config,
ctx: &QueryContext{Type: TypeProxy},
inters: c.Interceptors(),
}
}
// Get returns a Proxy entity by its id.
func (c *ProxyClient) Get(ctx context.Context, id int) (*Proxy, error) {
return c.Query().Where(proxy.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ProxyClient) GetX(ctx context.Context, id int) *Proxy {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *ProxyClient) Hooks() []Hook {
return c.hooks.Proxy
}
// Interceptors returns the client interceptors.
func (c *ProxyClient) Interceptors() []Interceptor {
return c.inters.Proxy
}
func (c *ProxyClient) mutate(ctx context.Context, m *ProxyMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ProxyCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ProxyUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ProxyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ProxyDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Proxy mutation op: %q", m.Op())
}
}
// ServerConfigClient is a client for the ServerConfig schema.
type ServerConfigClient struct {
config
}
// NewServerConfigClient returns a client for the ServerConfig from the given config.
func NewServerConfigClient(c config) *ServerConfigClient {
return &ServerConfigClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `serverconfig.Hooks(f(g(h())))`.
func (c *ServerConfigClient) Use(hooks ...Hook) {
c.hooks.ServerConfig = append(c.hooks.ServerConfig, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `serverconfig.Intercept(f(g(h())))`.
func (c *ServerConfigClient) Intercept(interceptors ...Interceptor) {
c.inters.ServerConfig = append(c.inters.ServerConfig, interceptors...)
}
// Create returns a builder for creating a ServerConfig entity.
func (c *ServerConfigClient) Create() *ServerConfigCreate {
mutation := newServerConfigMutation(c.config, OpCreate)
return &ServerConfigCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of ServerConfig entities.
func (c *ServerConfigClient) CreateBulk(builders ...*ServerConfigCreate) *ServerConfigCreateBulk {
return &ServerConfigCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *ServerConfigClient) MapCreateBulk(slice any, setFunc func(*ServerConfigCreate, int)) *ServerConfigCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ServerConfigCreateBulk{err: fmt.Errorf("calling to ServerConfigClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ServerConfigCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ServerConfigCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for ServerConfig.
func (c *ServerConfigClient) Update() *ServerConfigUpdate {
mutation := newServerConfigMutation(c.config, OpUpdate)
return &ServerConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ServerConfigClient) UpdateOne(_m *ServerConfig) *ServerConfigUpdateOne {
mutation := newServerConfigMutation(c.config, OpUpdateOne, withServerConfig(_m))
return &ServerConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ServerConfigClient) UpdateOneID(id int) *ServerConfigUpdateOne {
mutation := newServerConfigMutation(c.config, OpUpdateOne, withServerConfigID(id))
return &ServerConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for ServerConfig.
func (c *ServerConfigClient) Delete() *ServerConfigDelete {
mutation := newServerConfigMutation(c.config, OpDelete)
return &ServerConfigDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ServerConfigClient) DeleteOne(_m *ServerConfig) *ServerConfigDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ServerConfigClient) DeleteOneID(id int) *ServerConfigDeleteOne {
builder := c.Delete().Where(serverconfig.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ServerConfigDeleteOne{builder}
}
// Query returns a query builder for ServerConfig.
func (c *ServerConfigClient) Query() *ServerConfigQuery {
return &ServerConfigQuery{
config: c.config,
ctx: &QueryContext{Type: TypeServerConfig},
inters: c.Interceptors(),
}
}
// Get returns a ServerConfig entity by its id.
func (c *ServerConfigClient) Get(ctx context.Context, id int) (*ServerConfig, error) {
return c.Query().Where(serverconfig.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ServerConfigClient) GetX(ctx context.Context, id int) *ServerConfig {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *ServerConfigClient) Hooks() []Hook {
return c.hooks.ServerConfig
}
// Interceptors returns the client interceptors.
func (c *ServerConfigClient) Interceptors() []Interceptor {
return c.inters.ServerConfig
}
func (c *ServerConfigClient) mutate(ctx context.Context, m *ServerConfigMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ServerConfigCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ServerConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ServerConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ServerConfigDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown ServerConfig mutation op: %q", m.Op())
}
}
// UserClient is a client for the User schema.
type UserClient struct {
config
}
// NewUserClient returns a client for the User from the given config.
func NewUserClient(c config) *UserClient {
return &UserClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`.
func (c *UserClient) Use(hooks ...Hook) {
c.hooks.User = append(c.hooks.User, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`.
func (c *UserClient) Intercept(interceptors ...Interceptor) {
c.inters.User = append(c.inters.User, interceptors...)
}
// Create returns a builder for creating a User entity.
func (c *UserClient) Create() *UserCreate {
mutation := newUserMutation(c.config, OpCreate)
return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of User entities.
func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk {
return &UserCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*UserCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &UserCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for User.
func (c *UserClient) Update() *UserUpdate {
mutation := newUserMutation(c.config, OpUpdate)
return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *UserClient) UpdateOne(_m *User) *UserUpdateOne {
mutation := newUserMutation(c.config, OpUpdateOne, withUser(_m))
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *UserClient) UpdateOneID(id int) *UserUpdateOne {
mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id))
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for User.
func (c *UserClient) Delete() *UserDelete {
mutation := newUserMutation(c.config, OpDelete)
return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *UserClient) DeleteOne(_m *User) *UserDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
builder := c.Delete().Where(user.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &UserDeleteOne{builder}
}
// Query returns a query builder for User.
func (c *UserClient) Query() *UserQuery {
return &UserQuery{
config: c.config,
ctx: &QueryContext{Type: TypeUser},
inters: c.Interceptors(),
}
}
// Get returns a User entity by its id.
func (c *UserClient) Get(ctx context.Context, id int) (*User, error) {
return c.Query().Where(user.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *UserClient) GetX(ctx context.Context, id int) *User {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *UserClient) Hooks() []Hook {
return c.hooks.User
}
// Interceptors returns the client interceptors.
func (c *UserClient) Interceptors() []Interceptor {
return c.inters.User
}
func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op())
}
}
// hooks and interceptors per client, for fast access.
type (
hooks struct {
FrpcClient, Proxy, ServerConfig, User []ent.Hook
}
inters struct {
FrpcClient, Proxy, ServerConfig, User []ent.Interceptor
}
)
+614
View File
@@ -0,0 +1,614 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"reflect"
"sync"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
"github.com/fatedier/frp/pkg/db/ent/proxy"
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// ent aliases to avoid import conflicts in user's code.
type (
Op = ent.Op
Hook = ent.Hook
Value = ent.Value
Query = ent.Query
QueryContext = ent.QueryContext
Querier = ent.Querier
QuerierFunc = ent.QuerierFunc
Interceptor = ent.Interceptor
InterceptFunc = ent.InterceptFunc
Traverser = ent.Traverser
TraverseFunc = ent.TraverseFunc
Policy = ent.Policy
Mutator = ent.Mutator
Mutation = ent.Mutation
MutateFunc = ent.MutateFunc
)
type clientCtxKey struct{}
// FromContext returns a Client stored inside a context, or nil if there isn't one.
func FromContext(ctx context.Context) *Client {
c, _ := ctx.Value(clientCtxKey{}).(*Client)
return c
}
// NewContext returns a new context with the given Client attached.
func NewContext(parent context.Context, c *Client) context.Context {
return context.WithValue(parent, clientCtxKey{}, c)
}
type txCtxKey struct{}
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
func TxFromContext(ctx context.Context) *Tx {
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
return tx
}
// NewTxContext returns a new context with the given Tx attached.
func NewTxContext(parent context.Context, tx *Tx) context.Context {
return context.WithValue(parent, txCtxKey{}, tx)
}
// OrderFunc applies an ordering on the sql selector.
// Deprecated: Use Asc/Desc functions or the package builders instead.
type OrderFunc func(*sql.Selector)
var (
initCheck sync.Once
columnCheck sql.ColumnCheck
)
// checkColumn checks if the column exists in the given table.
func checkColumn(t, c string) error {
initCheck.Do(func() {
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
frpcclient.Table: frpcclient.ValidColumn,
proxy.Table: proxy.ValidColumn,
serverconfig.Table: serverconfig.ValidColumn,
user.Table: user.ValidColumn,
})
})
return columnCheck(t, c)
}
// Asc applies the given fields in ASC order.
func Asc(fields ...string) func(*sql.Selector) {
return func(s *sql.Selector) {
for _, f := range fields {
if err := checkColumn(s.TableName(), f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
}
s.OrderBy(sql.Asc(s.C(f)))
}
}
}
// Desc applies the given fields in DESC order.
func Desc(fields ...string) func(*sql.Selector) {
return func(s *sql.Selector) {
for _, f := range fields {
if err := checkColumn(s.TableName(), f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
}
s.OrderBy(sql.Desc(s.C(f)))
}
}
}
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
type AggregateFunc func(*sql.Selector) string
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
//
// GroupBy(field1, field2).
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
// Scan(ctx, &v)
func As(fn AggregateFunc, end string) AggregateFunc {
return func(s *sql.Selector) string {
return sql.As(fn(s), end)
}
}
// Count applies the "count" aggregation function on each group.
func Count() AggregateFunc {
return func(s *sql.Selector) string {
return sql.Count("*")
}
}
// Max applies the "max" aggregation function on the given field of each group.
func Max(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Max(s.C(field))
}
}
// Mean applies the "mean" aggregation function on the given field of each group.
func Mean(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Avg(s.C(field))
}
}
// Min applies the "min" aggregation function on the given field of each group.
func Min(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Min(s.C(field))
}
}
// Sum applies the "sum" aggregation function on the given field of each group.
func Sum(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Sum(s.C(field))
}
}
// ValidationError returns when validating a field or edge fails.
type ValidationError struct {
Name string // Field or edge name.
err error
}
// Error implements the error interface.
func (e *ValidationError) Error() string {
return e.err.Error()
}
// Unwrap implements the errors.Wrapper interface.
func (e *ValidationError) Unwrap() error {
return e.err
}
// IsValidationError returns a boolean indicating whether the error is a validation error.
func IsValidationError(err error) bool {
if err == nil {
return false
}
var e *ValidationError
return errors.As(err, &e)
}
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
type NotFoundError struct {
label string
}
// Error implements the error interface.
func (e *NotFoundError) Error() string {
return "ent: " + e.label + " not found"
}
// IsNotFound returns a boolean indicating whether the error is a not found error.
func IsNotFound(err error) bool {
if err == nil {
return false
}
var e *NotFoundError
return errors.As(err, &e)
}
// MaskNotFound masks not found error.
func MaskNotFound(err error) error {
if IsNotFound(err) {
return nil
}
return err
}
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
type NotSingularError struct {
label string
}
// Error implements the error interface.
func (e *NotSingularError) Error() string {
return "ent: " + e.label + " not singular"
}
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
func IsNotSingular(err error) bool {
if err == nil {
return false
}
var e *NotSingularError
return errors.As(err, &e)
}
// NotLoadedError returns when trying to get a node that was not loaded by the query.
type NotLoadedError struct {
edge string
}
// Error implements the error interface.
func (e *NotLoadedError) Error() string {
return "ent: " + e.edge + " edge was not loaded"
}
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
func IsNotLoaded(err error) bool {
if err == nil {
return false
}
var e *NotLoadedError
return errors.As(err, &e)
}
// ConstraintError returns when trying to create/update one or more entities and
// one or more of their constraints failed. For example, violation of edge or
// field uniqueness.
type ConstraintError struct {
msg string
wrap error
}
// Error implements the error interface.
func (e ConstraintError) Error() string {
return "ent: constraint failed: " + e.msg
}
// Unwrap implements the errors.Wrapper interface.
func (e *ConstraintError) Unwrap() error {
return e.wrap
}
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
func IsConstraintError(err error) bool {
if err == nil {
return false
}
var e *ConstraintError
return errors.As(err, &e)
}
// selector embedded by the different Select/GroupBy builders.
type selector struct {
label string
flds *[]string
fns []AggregateFunc
scan func(context.Context, any) error
}
// ScanX is like Scan, but panics if an error occurs.
func (s *selector) ScanX(ctx context.Context, v any) {
if err := s.scan(ctx, v); err != nil {
panic(err)
}
}
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
func (s *selector) Strings(ctx context.Context) ([]string, error) {
if len(*s.flds) > 1 {
return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field")
}
var v []string
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// StringsX is like Strings, but panics if an error occurs.
func (s *selector) StringsX(ctx context.Context) []string {
v, err := s.Strings(ctx)
if err != nil {
panic(err)
}
return v
}
// String returns a single string from a selector. It is only allowed when selecting one field.
func (s *selector) String(ctx context.Context) (_ string, err error) {
var v []string
if v, err = s.Strings(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v))
}
return
}
// StringX is like String, but panics if an error occurs.
func (s *selector) StringX(ctx context.Context) string {
v, err := s.String(ctx)
if err != nil {
panic(err)
}
return v
}
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
func (s *selector) Ints(ctx context.Context) ([]int, error) {
if len(*s.flds) > 1 {
return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field")
}
var v []int
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// IntsX is like Ints, but panics if an error occurs.
func (s *selector) IntsX(ctx context.Context) []int {
v, err := s.Ints(ctx)
if err != nil {
panic(err)
}
return v
}
// Int returns a single int from a selector. It is only allowed when selecting one field.
func (s *selector) Int(ctx context.Context) (_ int, err error) {
var v []int
if v, err = s.Ints(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v))
}
return
}
// IntX is like Int, but panics if an error occurs.
func (s *selector) IntX(ctx context.Context) int {
v, err := s.Int(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
if len(*s.flds) > 1 {
return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field")
}
var v []float64
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// Float64sX is like Float64s, but panics if an error occurs.
func (s *selector) Float64sX(ctx context.Context) []float64 {
v, err := s.Float64s(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
var v []float64
if v, err = s.Float64s(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v))
}
return
}
// Float64X is like Float64, but panics if an error occurs.
func (s *selector) Float64X(ctx context.Context) float64 {
v, err := s.Float64(ctx)
if err != nil {
panic(err)
}
return v
}
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
if len(*s.flds) > 1 {
return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field")
}
var v []bool
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// BoolsX is like Bools, but panics if an error occurs.
func (s *selector) BoolsX(ctx context.Context) []bool {
v, err := s.Bools(ctx)
if err != nil {
panic(err)
}
return v
}
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
var v []bool
if v, err = s.Bools(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v))
}
return
}
// BoolX is like Bool, but panics if an error occurs.
func (s *selector) BoolX(ctx context.Context) bool {
v, err := s.Bool(ctx)
if err != nil {
panic(err)
}
return v
}
// withHooks invokes the builder operation with the given hooks, if any.
func withHooks[V Value, M any, PM interface {
*M
Mutation
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
if len(hooks) == 0 {
return exec(ctx)
}
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutationT, ok := any(m).(PM)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
// Set the mutation to the builder.
*mutation = *mutationT
return exec(ctx)
})
for i := len(hooks) - 1; i >= 0; i-- {
if hooks[i] == nil {
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = hooks[i](mut)
}
v, err := mut.Mutate(ctx, mutation)
if err != nil {
return value, err
}
nv, ok := v.(V)
if !ok {
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
}
return nv, nil
}
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
if ent.QueryFromContext(ctx) == nil {
qc.Op = op
ctx = ent.NewQueryContext(ctx, qc)
}
return ctx
}
func querierAll[V Value, Q interface {
sqlAll(context.Context, ...queryHook) (V, error)
}]() Querier {
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
query, ok := q.(Q)
if !ok {
return nil, fmt.Errorf("unexpected query type %T", q)
}
return query.sqlAll(ctx)
})
}
func querierCount[Q interface {
sqlCount(context.Context) (int, error)
}]() Querier {
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
query, ok := q.(Q)
if !ok {
return nil, fmt.Errorf("unexpected query type %T", q)
}
return query.sqlCount(ctx)
})
}
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
for i := len(inters) - 1; i >= 0; i-- {
qr = inters[i].Intercept(qr)
}
rv, err := qr.Query(ctx, q)
if err != nil {
return v, err
}
vt, ok := rv.(V)
if !ok {
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
}
return vt, nil
}
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
sqlScan(context.Context, Q1, any) error
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
rv := reflect.ValueOf(v)
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
query, ok := q.(Q1)
if !ok {
return nil, fmt.Errorf("unexpected query type %T", q)
}
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
return nil, err
}
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
return rv.Elem().Interface(), nil
}
return v, nil
})
for i := len(inters) - 1; i >= 0; i-- {
qr = inters[i].Intercept(qr)
}
vv, err := qr.Query(ctx, rootQuery)
if err != nil {
return err
}
switch rv2 := reflect.ValueOf(vv); {
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
case rv.Type() == rv2.Type():
rv.Elem().Set(rv2.Elem())
case rv.Elem().Type() == rv2.Type():
rv.Elem().Set(rv2)
}
return nil
}
// queryHook describes an internal hook for the different sqlAll methods.
type queryHook func(context.Context, *sqlgraph.QuerySpec)
+84
View File
@@ -0,0 +1,84 @@
// Code generated by ent, DO NOT EDIT.
package enttest
import (
"context"
"github.com/fatedier/frp/pkg/db/ent"
// required by schema hooks.
_ "github.com/fatedier/frp/pkg/db/ent/runtime"
"entgo.io/ent/dialect/sql/schema"
"github.com/fatedier/frp/pkg/db/ent/migrate"
)
type (
// TestingT is the interface that is shared between
// testing.T and testing.B and used by enttest.
TestingT interface {
FailNow()
Error(...any)
}
// Option configures client creation.
Option func(*options)
options struct {
opts []ent.Option
migrateOpts []schema.MigrateOption
}
)
// WithOptions forwards options to client creation.
func WithOptions(opts ...ent.Option) Option {
return func(o *options) {
o.opts = append(o.opts, opts...)
}
}
// WithMigrateOptions forwards options to auto migration.
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
return func(o *options) {
o.migrateOpts = append(o.migrateOpts, opts...)
}
}
func newOptions(opts []Option) *options {
o := &options{}
for _, opt := range opts {
opt(o)
}
return o
}
// Open calls ent.Open and auto-run migration.
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
o := newOptions(opts)
c, err := ent.Open(driverName, dataSourceName, o.opts...)
if err != nil {
t.Error(err)
t.FailNow()
}
migrateSchema(t, c, o)
return c
}
// NewClient calls ent.NewClient and auto-run migration.
func NewClient(t TestingT, opts ...Option) *ent.Client {
o := newOptions(opts)
c := ent.NewClient(o.opts...)
migrateSchema(t, c, o)
return c
}
func migrateSchema(t TestingT, c *ent.Client, o *options) {
tables, err := schema.CopyTables(migrate.Tables)
if err != nil {
t.Error(err)
t.FailNow()
}
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
t.Error(err)
t.FailNow()
}
}
+194
View File
@@ -0,0 +1,194 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
)
// FrpcClient is the model entity for the FrpcClient schema.
type FrpcClient struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Key holds the value of the "key" field.
Key string `json:"key,omitempty"`
// Addr holds the value of the "addr" field.
Addr string `json:"addr,omitempty"`
// Port holds the value of the "port" field.
Port int `json:"port,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// Metadata holds the value of the "metadata" field.
Metadata string `json:"metadata,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// LastSeen holds the value of the "last_seen" field.
LastSeen time.Time `json:"last_seen,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*FrpcClient) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case frpcclient.FieldID, frpcclient.FieldPort:
values[i] = new(sql.NullInt64)
case frpcclient.FieldName, frpcclient.FieldKey, frpcclient.FieldAddr, frpcclient.FieldStatus, frpcclient.FieldMetadata:
values[i] = new(sql.NullString)
case frpcclient.FieldCreatedAt, frpcclient.FieldUpdatedAt, frpcclient.FieldLastSeen:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the FrpcClient fields.
func (_m *FrpcClient) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case frpcclient.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int(value.Int64)
case frpcclient.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case frpcclient.FieldKey:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field key", values[i])
} else if value.Valid {
_m.Key = value.String
}
case frpcclient.FieldAddr:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field addr", values[i])
} else if value.Valid {
_m.Addr = value.String
}
case frpcclient.FieldPort:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field port", values[i])
} else if value.Valid {
_m.Port = int(value.Int64)
}
case frpcclient.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = value.String
}
case frpcclient.FieldMetadata:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field metadata", values[i])
} else if value.Valid {
_m.Metadata = value.String
}
case frpcclient.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case frpcclient.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
case frpcclient.FieldLastSeen:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field last_seen", values[i])
} else if value.Valid {
_m.LastSeen = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the FrpcClient.
// This includes values selected through modifiers, order, etc.
func (_m *FrpcClient) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this FrpcClient.
// Note that you need to call FrpcClient.Unwrap() before calling this method if this FrpcClient
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *FrpcClient) Update() *FrpcClientUpdateOne {
return NewFrpcClientClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the FrpcClient entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *FrpcClient) Unwrap() *FrpcClient {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: FrpcClient is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *FrpcClient) String() string {
var builder strings.Builder
builder.WriteString("FrpcClient(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("key=")
builder.WriteString(_m.Key)
builder.WriteString(", ")
builder.WriteString("addr=")
builder.WriteString(_m.Addr)
builder.WriteString(", ")
builder.WriteString("port=")
builder.WriteString(fmt.Sprintf("%v", _m.Port))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(_m.Status)
builder.WriteString(", ")
builder.WriteString("metadata=")
builder.WriteString(_m.Metadata)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("last_seen=")
builder.WriteString(_m.LastSeen.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// FrpcClients is a parsable slice of FrpcClient.
type FrpcClients []*FrpcClient
+134
View File
@@ -0,0 +1,134 @@
// Code generated by ent, DO NOT EDIT.
package frpcclient
import (
"time"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the frpcclient type in the database.
Label = "frpc_client"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldKey holds the string denoting the key field in the database.
FieldKey = "key"
// FieldAddr holds the string denoting the addr field in the database.
FieldAddr = "addr"
// FieldPort holds the string denoting the port field in the database.
FieldPort = "port"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldMetadata holds the string denoting the metadata field in the database.
FieldMetadata = "metadata"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldLastSeen holds the string denoting the last_seen field in the database.
FieldLastSeen = "last_seen"
// Table holds the table name of the frpcclient in the database.
Table = "frpc_clients"
)
// Columns holds all SQL columns for frpcclient fields.
var Columns = []string{
FieldID,
FieldName,
FieldKey,
FieldAddr,
FieldPort,
FieldStatus,
FieldMetadata,
FieldCreatedAt,
FieldUpdatedAt,
FieldLastSeen,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultKey holds the default value on creation for the "key" field.
DefaultKey string
// DefaultAddr holds the default value on creation for the "addr" field.
DefaultAddr string
// DefaultPort holds the default value on creation for the "port" field.
DefaultPort int
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
// DefaultMetadata holds the default value on creation for the "metadata" field.
DefaultMetadata string
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// DefaultLastSeen holds the default value on creation for the "last_seen" field.
DefaultLastSeen func() time.Time
)
// OrderOption defines the ordering options for the FrpcClient queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByKey orders the results by the key field.
func ByKey(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldKey, opts...).ToFunc()
}
// ByAddr orders the results by the addr field.
func ByAddr(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAddr, opts...).ToFunc()
}
// ByPort orders the results by the port field.
func ByPort(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPort, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByMetadata orders the results by the metadata field.
func ByMetadata(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMetadata, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByLastSeen orders the results by the last_seen field.
func ByLastSeen(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLastSeen, opts...).ToFunc()
}
+610
View File
@@ -0,0 +1,610 @@
// Code generated by ent, DO NOT EDIT.
package frpcclient
import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldName, v))
}
// Key applies equality check predicate on the "key" field. It's identical to KeyEQ.
func Key(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldKey, v))
}
// Addr applies equality check predicate on the "addr" field. It's identical to AddrEQ.
func Addr(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldAddr, v))
}
// Port applies equality check predicate on the "port" field. It's identical to PortEQ.
func Port(v int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldPort, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldStatus, v))
}
// Metadata applies equality check predicate on the "metadata" field. It's identical to MetadataEQ.
func Metadata(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldMetadata, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldUpdatedAt, v))
}
// LastSeen applies equality check predicate on the "last_seen" field. It's identical to LastSeenEQ.
func LastSeen(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldLastSeen, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContainsFold(FieldName, v))
}
// KeyEQ applies the EQ predicate on the "key" field.
func KeyEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldKey, v))
}
// KeyNEQ applies the NEQ predicate on the "key" field.
func KeyNEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldKey, v))
}
// KeyIn applies the In predicate on the "key" field.
func KeyIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldKey, vs...))
}
// KeyNotIn applies the NotIn predicate on the "key" field.
func KeyNotIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldKey, vs...))
}
// KeyGT applies the GT predicate on the "key" field.
func KeyGT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldKey, v))
}
// KeyGTE applies the GTE predicate on the "key" field.
func KeyGTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldKey, v))
}
// KeyLT applies the LT predicate on the "key" field.
func KeyLT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldKey, v))
}
// KeyLTE applies the LTE predicate on the "key" field.
func KeyLTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldKey, v))
}
// KeyContains applies the Contains predicate on the "key" field.
func KeyContains(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContains(FieldKey, v))
}
// KeyHasPrefix applies the HasPrefix predicate on the "key" field.
func KeyHasPrefix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasPrefix(FieldKey, v))
}
// KeyHasSuffix applies the HasSuffix predicate on the "key" field.
func KeyHasSuffix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasSuffix(FieldKey, v))
}
// KeyEqualFold applies the EqualFold predicate on the "key" field.
func KeyEqualFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEqualFold(FieldKey, v))
}
// KeyContainsFold applies the ContainsFold predicate on the "key" field.
func KeyContainsFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContainsFold(FieldKey, v))
}
// AddrEQ applies the EQ predicate on the "addr" field.
func AddrEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldAddr, v))
}
// AddrNEQ applies the NEQ predicate on the "addr" field.
func AddrNEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldAddr, v))
}
// AddrIn applies the In predicate on the "addr" field.
func AddrIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldAddr, vs...))
}
// AddrNotIn applies the NotIn predicate on the "addr" field.
func AddrNotIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldAddr, vs...))
}
// AddrGT applies the GT predicate on the "addr" field.
func AddrGT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldAddr, v))
}
// AddrGTE applies the GTE predicate on the "addr" field.
func AddrGTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldAddr, v))
}
// AddrLT applies the LT predicate on the "addr" field.
func AddrLT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldAddr, v))
}
// AddrLTE applies the LTE predicate on the "addr" field.
func AddrLTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldAddr, v))
}
// AddrContains applies the Contains predicate on the "addr" field.
func AddrContains(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContains(FieldAddr, v))
}
// AddrHasPrefix applies the HasPrefix predicate on the "addr" field.
func AddrHasPrefix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasPrefix(FieldAddr, v))
}
// AddrHasSuffix applies the HasSuffix predicate on the "addr" field.
func AddrHasSuffix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasSuffix(FieldAddr, v))
}
// AddrEqualFold applies the EqualFold predicate on the "addr" field.
func AddrEqualFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEqualFold(FieldAddr, v))
}
// AddrContainsFold applies the ContainsFold predicate on the "addr" field.
func AddrContainsFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContainsFold(FieldAddr, v))
}
// PortEQ applies the EQ predicate on the "port" field.
func PortEQ(v int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldPort, v))
}
// PortNEQ applies the NEQ predicate on the "port" field.
func PortNEQ(v int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldPort, v))
}
// PortIn applies the In predicate on the "port" field.
func PortIn(vs ...int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldPort, vs...))
}
// PortNotIn applies the NotIn predicate on the "port" field.
func PortNotIn(vs ...int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldPort, vs...))
}
// PortGT applies the GT predicate on the "port" field.
func PortGT(v int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldPort, v))
}
// PortGTE applies the GTE predicate on the "port" field.
func PortGTE(v int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldPort, v))
}
// PortLT applies the LT predicate on the "port" field.
func PortLT(v int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldPort, v))
}
// PortLTE applies the LTE predicate on the "port" field.
func PortLTE(v int) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldPort, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldStatus, vs...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldStatus, v))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldStatus, v))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldStatus, v))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldStatus, v))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContains(FieldStatus, v))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasPrefix(FieldStatus, v))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasSuffix(FieldStatus, v))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEqualFold(FieldStatus, v))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContainsFold(FieldStatus, v))
}
// MetadataEQ applies the EQ predicate on the "metadata" field.
func MetadataEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldMetadata, v))
}
// MetadataNEQ applies the NEQ predicate on the "metadata" field.
func MetadataNEQ(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldMetadata, v))
}
// MetadataIn applies the In predicate on the "metadata" field.
func MetadataIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldMetadata, vs...))
}
// MetadataNotIn applies the NotIn predicate on the "metadata" field.
func MetadataNotIn(vs ...string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldMetadata, vs...))
}
// MetadataGT applies the GT predicate on the "metadata" field.
func MetadataGT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldMetadata, v))
}
// MetadataGTE applies the GTE predicate on the "metadata" field.
func MetadataGTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldMetadata, v))
}
// MetadataLT applies the LT predicate on the "metadata" field.
func MetadataLT(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldMetadata, v))
}
// MetadataLTE applies the LTE predicate on the "metadata" field.
func MetadataLTE(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldMetadata, v))
}
// MetadataContains applies the Contains predicate on the "metadata" field.
func MetadataContains(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContains(FieldMetadata, v))
}
// MetadataHasPrefix applies the HasPrefix predicate on the "metadata" field.
func MetadataHasPrefix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasPrefix(FieldMetadata, v))
}
// MetadataHasSuffix applies the HasSuffix predicate on the "metadata" field.
func MetadataHasSuffix(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldHasSuffix(FieldMetadata, v))
}
// MetadataEqualFold applies the EqualFold predicate on the "metadata" field.
func MetadataEqualFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEqualFold(FieldMetadata, v))
}
// MetadataContainsFold applies the ContainsFold predicate on the "metadata" field.
func MetadataContainsFold(v string) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldContainsFold(FieldMetadata, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldUpdatedAt, v))
}
// LastSeenEQ applies the EQ predicate on the "last_seen" field.
func LastSeenEQ(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldEQ(FieldLastSeen, v))
}
// LastSeenNEQ applies the NEQ predicate on the "last_seen" field.
func LastSeenNEQ(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNEQ(FieldLastSeen, v))
}
// LastSeenIn applies the In predicate on the "last_seen" field.
func LastSeenIn(vs ...time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIn(FieldLastSeen, vs...))
}
// LastSeenNotIn applies the NotIn predicate on the "last_seen" field.
func LastSeenNotIn(vs ...time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotIn(FieldLastSeen, vs...))
}
// LastSeenGT applies the GT predicate on the "last_seen" field.
func LastSeenGT(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGT(FieldLastSeen, v))
}
// LastSeenGTE applies the GTE predicate on the "last_seen" field.
func LastSeenGTE(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldGTE(FieldLastSeen, v))
}
// LastSeenLT applies the LT predicate on the "last_seen" field.
func LastSeenLT(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLT(FieldLastSeen, v))
}
// LastSeenLTE applies the LTE predicate on the "last_seen" field.
func LastSeenLTE(v time.Time) predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldLTE(FieldLastSeen, v))
}
// LastSeenIsNil applies the IsNil predicate on the "last_seen" field.
func LastSeenIsNil() predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldIsNull(FieldLastSeen))
}
// LastSeenNotNil applies the NotNil predicate on the "last_seen" field.
func LastSeenNotNil() predicate.FrpcClient {
return predicate.FrpcClient(sql.FieldNotNull(FieldLastSeen))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.FrpcClient) predicate.FrpcClient {
return predicate.FrpcClient(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.FrpcClient) predicate.FrpcClient {
return predicate.FrpcClient(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.FrpcClient) predicate.FrpcClient {
return predicate.FrpcClient(sql.NotPredicates(p))
}
+387
View File
@@ -0,0 +1,387 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
)
// FrpcClientCreate is the builder for creating a FrpcClient entity.
type FrpcClientCreate struct {
config
mutation *FrpcClientMutation
hooks []Hook
}
// SetName sets the "name" field.
func (_c *FrpcClientCreate) SetName(v string) *FrpcClientCreate {
_c.mutation.SetName(v)
return _c
}
// SetKey sets the "key" field.
func (_c *FrpcClientCreate) SetKey(v string) *FrpcClientCreate {
_c.mutation.SetKey(v)
return _c
}
// SetNillableKey sets the "key" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillableKey(v *string) *FrpcClientCreate {
if v != nil {
_c.SetKey(*v)
}
return _c
}
// SetAddr sets the "addr" field.
func (_c *FrpcClientCreate) SetAddr(v string) *FrpcClientCreate {
_c.mutation.SetAddr(v)
return _c
}
// SetNillableAddr sets the "addr" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillableAddr(v *string) *FrpcClientCreate {
if v != nil {
_c.SetAddr(*v)
}
return _c
}
// SetPort sets the "port" field.
func (_c *FrpcClientCreate) SetPort(v int) *FrpcClientCreate {
_c.mutation.SetPort(v)
return _c
}
// SetNillablePort sets the "port" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillablePort(v *int) *FrpcClientCreate {
if v != nil {
_c.SetPort(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *FrpcClientCreate) SetStatus(v string) *FrpcClientCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillableStatus(v *string) *FrpcClientCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetMetadata sets the "metadata" field.
func (_c *FrpcClientCreate) SetMetadata(v string) *FrpcClientCreate {
_c.mutation.SetMetadata(v)
return _c
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillableMetadata(v *string) *FrpcClientCreate {
if v != nil {
_c.SetMetadata(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *FrpcClientCreate) SetCreatedAt(v time.Time) *FrpcClientCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillableCreatedAt(v *time.Time) *FrpcClientCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *FrpcClientCreate) SetUpdatedAt(v time.Time) *FrpcClientCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillableUpdatedAt(v *time.Time) *FrpcClientCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetLastSeen sets the "last_seen" field.
func (_c *FrpcClientCreate) SetLastSeen(v time.Time) *FrpcClientCreate {
_c.mutation.SetLastSeen(v)
return _c
}
// SetNillableLastSeen sets the "last_seen" field if the given value is not nil.
func (_c *FrpcClientCreate) SetNillableLastSeen(v *time.Time) *FrpcClientCreate {
if v != nil {
_c.SetLastSeen(*v)
}
return _c
}
// Mutation returns the FrpcClientMutation object of the builder.
func (_c *FrpcClientCreate) Mutation() *FrpcClientMutation {
return _c.mutation
}
// Save creates the FrpcClient in the database.
func (_c *FrpcClientCreate) Save(ctx context.Context) (*FrpcClient, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *FrpcClientCreate) SaveX(ctx context.Context) *FrpcClient {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *FrpcClientCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *FrpcClientCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *FrpcClientCreate) defaults() {
if _, ok := _c.mutation.Key(); !ok {
v := frpcclient.DefaultKey
_c.mutation.SetKey(v)
}
if _, ok := _c.mutation.Addr(); !ok {
v := frpcclient.DefaultAddr
_c.mutation.SetAddr(v)
}
if _, ok := _c.mutation.Port(); !ok {
v := frpcclient.DefaultPort
_c.mutation.SetPort(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := frpcclient.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.Metadata(); !ok {
v := frpcclient.DefaultMetadata
_c.mutation.SetMetadata(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := frpcclient.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := frpcclient.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.LastSeen(); !ok {
v := frpcclient.DefaultLastSeen()
_c.mutation.SetLastSeen(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *FrpcClientCreate) check() error {
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "FrpcClient.name"`)}
}
if _, ok := _c.mutation.Key(); !ok {
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "FrpcClient.key"`)}
}
if _, ok := _c.mutation.Addr(); !ok {
return &ValidationError{Name: "addr", err: errors.New(`ent: missing required field "FrpcClient.addr"`)}
}
if _, ok := _c.mutation.Port(); !ok {
return &ValidationError{Name: "port", err: errors.New(`ent: missing required field "FrpcClient.port"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "FrpcClient.status"`)}
}
if _, ok := _c.mutation.Metadata(); !ok {
return &ValidationError{Name: "metadata", err: errors.New(`ent: missing required field "FrpcClient.metadata"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "FrpcClient.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "FrpcClient.updated_at"`)}
}
return nil
}
func (_c *FrpcClientCreate) sqlSave(ctx context.Context) (*FrpcClient, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *FrpcClientCreate) createSpec() (*FrpcClient, *sqlgraph.CreateSpec) {
var (
_node = &FrpcClient{config: _c.config}
_spec = sqlgraph.NewCreateSpec(frpcclient.Table, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
)
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(frpcclient.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.Key(); ok {
_spec.SetField(frpcclient.FieldKey, field.TypeString, value)
_node.Key = value
}
if value, ok := _c.mutation.Addr(); ok {
_spec.SetField(frpcclient.FieldAddr, field.TypeString, value)
_node.Addr = value
}
if value, ok := _c.mutation.Port(); ok {
_spec.SetField(frpcclient.FieldPort, field.TypeInt, value)
_node.Port = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(frpcclient.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.Metadata(); ok {
_spec.SetField(frpcclient.FieldMetadata, field.TypeString, value)
_node.Metadata = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(frpcclient.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(frpcclient.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.LastSeen(); ok {
_spec.SetField(frpcclient.FieldLastSeen, field.TypeTime, value)
_node.LastSeen = value
}
return _node, _spec
}
// FrpcClientCreateBulk is the builder for creating many FrpcClient entities in bulk.
type FrpcClientCreateBulk struct {
config
err error
builders []*FrpcClientCreate
}
// Save creates the FrpcClient entities in the database.
func (_c *FrpcClientCreateBulk) Save(ctx context.Context) ([]*FrpcClient, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*FrpcClient, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*FrpcClientMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *FrpcClientCreateBulk) SaveX(ctx context.Context) []*FrpcClient {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *FrpcClientCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *FrpcClientCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
+88
View File
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
"github.com/fatedier/frp/pkg/db/ent/predicate"
)
// FrpcClientDelete is the builder for deleting a FrpcClient entity.
type FrpcClientDelete struct {
config
hooks []Hook
mutation *FrpcClientMutation
}
// Where appends a list predicates to the FrpcClientDelete builder.
func (_d *FrpcClientDelete) Where(ps ...predicate.FrpcClient) *FrpcClientDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *FrpcClientDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *FrpcClientDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *FrpcClientDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(frpcclient.Table, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// FrpcClientDeleteOne is the builder for deleting a single FrpcClient entity.
type FrpcClientDeleteOne struct {
_d *FrpcClientDelete
}
// Where appends a list predicates to the FrpcClientDelete builder.
func (_d *FrpcClientDeleteOne) Where(ps ...predicate.FrpcClient) *FrpcClientDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *FrpcClientDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{frpcclient.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *FrpcClientDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+527
View File
@@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
"github.com/fatedier/frp/pkg/db/ent/predicate"
)
// FrpcClientQuery is the builder for querying FrpcClient entities.
type FrpcClientQuery struct {
config
ctx *QueryContext
order []frpcclient.OrderOption
inters []Interceptor
predicates []predicate.FrpcClient
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the FrpcClientQuery builder.
func (_q *FrpcClientQuery) Where(ps ...predicate.FrpcClient) *FrpcClientQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *FrpcClientQuery) Limit(limit int) *FrpcClientQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *FrpcClientQuery) Offset(offset int) *FrpcClientQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *FrpcClientQuery) Unique(unique bool) *FrpcClientQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *FrpcClientQuery) Order(o ...frpcclient.OrderOption) *FrpcClientQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first FrpcClient entity from the query.
// Returns a *NotFoundError when no FrpcClient was found.
func (_q *FrpcClientQuery) First(ctx context.Context) (*FrpcClient, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{frpcclient.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *FrpcClientQuery) FirstX(ctx context.Context) *FrpcClient {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first FrpcClient ID from the query.
// Returns a *NotFoundError when no FrpcClient ID was found.
func (_q *FrpcClientQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{frpcclient.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *FrpcClientQuery) FirstIDX(ctx context.Context) int {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single FrpcClient entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one FrpcClient entity is found.
// Returns a *NotFoundError when no FrpcClient entities are found.
func (_q *FrpcClientQuery) Only(ctx context.Context) (*FrpcClient, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{frpcclient.Label}
default:
return nil, &NotSingularError{frpcclient.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *FrpcClientQuery) OnlyX(ctx context.Context) *FrpcClient {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only FrpcClient ID in the query.
// Returns a *NotSingularError when more than one FrpcClient ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *FrpcClientQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{frpcclient.Label}
default:
err = &NotSingularError{frpcclient.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *FrpcClientQuery) OnlyIDX(ctx context.Context) int {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of FrpcClients.
func (_q *FrpcClientQuery) All(ctx context.Context) ([]*FrpcClient, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*FrpcClient, *FrpcClientQuery]()
return withInterceptors[[]*FrpcClient](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *FrpcClientQuery) AllX(ctx context.Context) []*FrpcClient {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of FrpcClient IDs.
func (_q *FrpcClientQuery) IDs(ctx context.Context) (ids []int, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(frpcclient.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *FrpcClientQuery) IDsX(ctx context.Context) []int {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *FrpcClientQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*FrpcClientQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *FrpcClientQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *FrpcClientQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *FrpcClientQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the FrpcClientQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *FrpcClientQuery) Clone() *FrpcClientQuery {
if _q == nil {
return nil
}
return &FrpcClientQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]frpcclient.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.FrpcClient{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.FrpcClient.Query().
// GroupBy(frpcclient.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *FrpcClientQuery) GroupBy(field string, fields ...string) *FrpcClientGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &FrpcClientGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = frpcclient.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// }
//
// client.FrpcClient.Query().
// Select(frpcclient.FieldName).
// Scan(ctx, &v)
func (_q *FrpcClientQuery) Select(fields ...string) *FrpcClientSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &FrpcClientSelect{FrpcClientQuery: _q}
sbuild.label = frpcclient.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a FrpcClientSelect configured with the given aggregations.
func (_q *FrpcClientQuery) Aggregate(fns ...AggregateFunc) *FrpcClientSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *FrpcClientQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !frpcclient.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *FrpcClientQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*FrpcClient, error) {
var (
nodes = []*FrpcClient{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*FrpcClient).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &FrpcClient{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *FrpcClientQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *FrpcClientQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(frpcclient.Table, frpcclient.Columns, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, frpcclient.FieldID)
for i := range fields {
if fields[i] != frpcclient.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *FrpcClientQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(frpcclient.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = frpcclient.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// FrpcClientGroupBy is the group-by builder for FrpcClient entities.
type FrpcClientGroupBy struct {
selector
build *FrpcClientQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *FrpcClientGroupBy) Aggregate(fns ...AggregateFunc) *FrpcClientGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *FrpcClientGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*FrpcClientQuery, *FrpcClientGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *FrpcClientGroupBy) sqlScan(ctx context.Context, root *FrpcClientQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// FrpcClientSelect is the builder for selecting fields of FrpcClient entities.
type FrpcClientSelect struct {
*FrpcClientQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *FrpcClientSelect) Aggregate(fns ...AggregateFunc) *FrpcClientSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *FrpcClientSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*FrpcClientQuery, *FrpcClientSelect](ctx, _s.FrpcClientQuery, _s, _s.inters, v)
}
func (_s *FrpcClientSelect) sqlScan(ctx context.Context, root *FrpcClientQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
+522
View File
@@ -0,0 +1,522 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
"github.com/fatedier/frp/pkg/db/ent/predicate"
)
// FrpcClientUpdate is the builder for updating FrpcClient entities.
type FrpcClientUpdate struct {
config
hooks []Hook
mutation *FrpcClientMutation
}
// Where appends a list predicates to the FrpcClientUpdate builder.
func (_u *FrpcClientUpdate) Where(ps ...predicate.FrpcClient) *FrpcClientUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetName sets the "name" field.
func (_u *FrpcClientUpdate) SetName(v string) *FrpcClientUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillableName(v *string) *FrpcClientUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetKey sets the "key" field.
func (_u *FrpcClientUpdate) SetKey(v string) *FrpcClientUpdate {
_u.mutation.SetKey(v)
return _u
}
// SetNillableKey sets the "key" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillableKey(v *string) *FrpcClientUpdate {
if v != nil {
_u.SetKey(*v)
}
return _u
}
// SetAddr sets the "addr" field.
func (_u *FrpcClientUpdate) SetAddr(v string) *FrpcClientUpdate {
_u.mutation.SetAddr(v)
return _u
}
// SetNillableAddr sets the "addr" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillableAddr(v *string) *FrpcClientUpdate {
if v != nil {
_u.SetAddr(*v)
}
return _u
}
// SetPort sets the "port" field.
func (_u *FrpcClientUpdate) SetPort(v int) *FrpcClientUpdate {
_u.mutation.ResetPort()
_u.mutation.SetPort(v)
return _u
}
// SetNillablePort sets the "port" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillablePort(v *int) *FrpcClientUpdate {
if v != nil {
_u.SetPort(*v)
}
return _u
}
// AddPort adds value to the "port" field.
func (_u *FrpcClientUpdate) AddPort(v int) *FrpcClientUpdate {
_u.mutation.AddPort(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *FrpcClientUpdate) SetStatus(v string) *FrpcClientUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillableStatus(v *string) *FrpcClientUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *FrpcClientUpdate) SetMetadata(v string) *FrpcClientUpdate {
_u.mutation.SetMetadata(v)
return _u
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillableMetadata(v *string) *FrpcClientUpdate {
if v != nil {
_u.SetMetadata(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *FrpcClientUpdate) SetCreatedAt(v time.Time) *FrpcClientUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillableCreatedAt(v *time.Time) *FrpcClientUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *FrpcClientUpdate) SetUpdatedAt(v time.Time) *FrpcClientUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetLastSeen sets the "last_seen" field.
func (_u *FrpcClientUpdate) SetLastSeen(v time.Time) *FrpcClientUpdate {
_u.mutation.SetLastSeen(v)
return _u
}
// SetNillableLastSeen sets the "last_seen" field if the given value is not nil.
func (_u *FrpcClientUpdate) SetNillableLastSeen(v *time.Time) *FrpcClientUpdate {
if v != nil {
_u.SetLastSeen(*v)
}
return _u
}
// ClearLastSeen clears the value of the "last_seen" field.
func (_u *FrpcClientUpdate) ClearLastSeen() *FrpcClientUpdate {
_u.mutation.ClearLastSeen()
return _u
}
// Mutation returns the FrpcClientMutation object of the builder.
func (_u *FrpcClientUpdate) Mutation() *FrpcClientMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *FrpcClientUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *FrpcClientUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *FrpcClientUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *FrpcClientUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *FrpcClientUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := frpcclient.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *FrpcClientUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(frpcclient.Table, frpcclient.Columns, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(frpcclient.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Key(); ok {
_spec.SetField(frpcclient.FieldKey, field.TypeString, value)
}
if value, ok := _u.mutation.Addr(); ok {
_spec.SetField(frpcclient.FieldAddr, field.TypeString, value)
}
if value, ok := _u.mutation.Port(); ok {
_spec.SetField(frpcclient.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPort(); ok {
_spec.AddField(frpcclient.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(frpcclient.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(frpcclient.FieldMetadata, field.TypeString, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(frpcclient.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(frpcclient.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.LastSeen(); ok {
_spec.SetField(frpcclient.FieldLastSeen, field.TypeTime, value)
}
if _u.mutation.LastSeenCleared() {
_spec.ClearField(frpcclient.FieldLastSeen, field.TypeTime)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{frpcclient.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// FrpcClientUpdateOne is the builder for updating a single FrpcClient entity.
type FrpcClientUpdateOne struct {
config
fields []string
hooks []Hook
mutation *FrpcClientMutation
}
// SetName sets the "name" field.
func (_u *FrpcClientUpdateOne) SetName(v string) *FrpcClientUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillableName(v *string) *FrpcClientUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetKey sets the "key" field.
func (_u *FrpcClientUpdateOne) SetKey(v string) *FrpcClientUpdateOne {
_u.mutation.SetKey(v)
return _u
}
// SetNillableKey sets the "key" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillableKey(v *string) *FrpcClientUpdateOne {
if v != nil {
_u.SetKey(*v)
}
return _u
}
// SetAddr sets the "addr" field.
func (_u *FrpcClientUpdateOne) SetAddr(v string) *FrpcClientUpdateOne {
_u.mutation.SetAddr(v)
return _u
}
// SetNillableAddr sets the "addr" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillableAddr(v *string) *FrpcClientUpdateOne {
if v != nil {
_u.SetAddr(*v)
}
return _u
}
// SetPort sets the "port" field.
func (_u *FrpcClientUpdateOne) SetPort(v int) *FrpcClientUpdateOne {
_u.mutation.ResetPort()
_u.mutation.SetPort(v)
return _u
}
// SetNillablePort sets the "port" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillablePort(v *int) *FrpcClientUpdateOne {
if v != nil {
_u.SetPort(*v)
}
return _u
}
// AddPort adds value to the "port" field.
func (_u *FrpcClientUpdateOne) AddPort(v int) *FrpcClientUpdateOne {
_u.mutation.AddPort(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *FrpcClientUpdateOne) SetStatus(v string) *FrpcClientUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillableStatus(v *string) *FrpcClientUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *FrpcClientUpdateOne) SetMetadata(v string) *FrpcClientUpdateOne {
_u.mutation.SetMetadata(v)
return _u
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillableMetadata(v *string) *FrpcClientUpdateOne {
if v != nil {
_u.SetMetadata(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *FrpcClientUpdateOne) SetCreatedAt(v time.Time) *FrpcClientUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillableCreatedAt(v *time.Time) *FrpcClientUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *FrpcClientUpdateOne) SetUpdatedAt(v time.Time) *FrpcClientUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetLastSeen sets the "last_seen" field.
func (_u *FrpcClientUpdateOne) SetLastSeen(v time.Time) *FrpcClientUpdateOne {
_u.mutation.SetLastSeen(v)
return _u
}
// SetNillableLastSeen sets the "last_seen" field if the given value is not nil.
func (_u *FrpcClientUpdateOne) SetNillableLastSeen(v *time.Time) *FrpcClientUpdateOne {
if v != nil {
_u.SetLastSeen(*v)
}
return _u
}
// ClearLastSeen clears the value of the "last_seen" field.
func (_u *FrpcClientUpdateOne) ClearLastSeen() *FrpcClientUpdateOne {
_u.mutation.ClearLastSeen()
return _u
}
// Mutation returns the FrpcClientMutation object of the builder.
func (_u *FrpcClientUpdateOne) Mutation() *FrpcClientMutation {
return _u.mutation
}
// Where appends a list predicates to the FrpcClientUpdate builder.
func (_u *FrpcClientUpdateOne) Where(ps ...predicate.FrpcClient) *FrpcClientUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *FrpcClientUpdateOne) Select(field string, fields ...string) *FrpcClientUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated FrpcClient entity.
func (_u *FrpcClientUpdateOne) Save(ctx context.Context) (*FrpcClient, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *FrpcClientUpdateOne) SaveX(ctx context.Context) *FrpcClient {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *FrpcClientUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *FrpcClientUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *FrpcClientUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := frpcclient.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *FrpcClientUpdateOne) sqlSave(ctx context.Context) (_node *FrpcClient, err error) {
_spec := sqlgraph.NewUpdateSpec(frpcclient.Table, frpcclient.Columns, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "FrpcClient.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, frpcclient.FieldID)
for _, f := range fields {
if !frpcclient.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != frpcclient.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(frpcclient.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Key(); ok {
_spec.SetField(frpcclient.FieldKey, field.TypeString, value)
}
if value, ok := _u.mutation.Addr(); ok {
_spec.SetField(frpcclient.FieldAddr, field.TypeString, value)
}
if value, ok := _u.mutation.Port(); ok {
_spec.SetField(frpcclient.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPort(); ok {
_spec.AddField(frpcclient.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(frpcclient.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(frpcclient.FieldMetadata, field.TypeString, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(frpcclient.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(frpcclient.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.LastSeen(); ok {
_spec.SetField(frpcclient.FieldLastSeen, field.TypeTime, value)
}
if _u.mutation.LastSeenCleared() {
_spec.ClearField(frpcclient.FieldLastSeen, field.TypeTime)
}
_node = &FrpcClient{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{frpcclient.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+3
View File
@@ -0,0 +1,3 @@
package ent
//go:generate go run entgo.io/ent/cmd/ent generate ./schema
+235
View File
@@ -0,0 +1,235 @@
// Code generated by ent, DO NOT EDIT.
package hook
import (
"context"
"fmt"
"github.com/fatedier/frp/pkg/db/ent"
)
// The FrpcClientFunc type is an adapter to allow the use of ordinary
// function as FrpcClient mutator.
type FrpcClientFunc func(context.Context, *ent.FrpcClientMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f FrpcClientFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.FrpcClientMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.FrpcClientMutation", m)
}
// The ProxyFunc type is an adapter to allow the use of ordinary
// function as Proxy mutator.
type ProxyFunc func(context.Context, *ent.ProxyMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f ProxyFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.ProxyMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProxyMutation", m)
}
// The ServerConfigFunc type is an adapter to allow the use of ordinary
// function as ServerConfig mutator.
type ServerConfigFunc func(context.Context, *ent.ServerConfigMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f ServerConfigFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.ServerConfigMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ServerConfigMutation", m)
}
// The UserFunc type is an adapter to allow the use of ordinary
// function as User mutator.
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.UserMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
}
// Condition is a hook condition function.
type Condition func(context.Context, ent.Mutation) bool
// And groups conditions with the AND operator.
func And(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if !first(ctx, m) || !second(ctx, m) {
return false
}
for _, cond := range rest {
if !cond(ctx, m) {
return false
}
}
return true
}
}
// Or groups conditions with the OR operator.
func Or(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if first(ctx, m) || second(ctx, m) {
return true
}
for _, cond := range rest {
if cond(ctx, m) {
return true
}
}
return false
}
}
// Not negates a given condition.
func Not(cond Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
return !cond(ctx, m)
}
}
// HasOp is a condition testing mutation operation.
func HasOp(op ent.Op) Condition {
return func(_ context.Context, m ent.Mutation) bool {
return m.Op().Is(op)
}
}
// HasAddedFields is a condition validating `.AddedField` on fields.
func HasAddedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.AddedField(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.AddedField(field); !exists {
return false
}
}
return true
}
}
// HasClearedFields is a condition validating `.FieldCleared` on fields.
func HasClearedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if exists := m.FieldCleared(field); !exists {
return false
}
for _, field := range fields {
if exists := m.FieldCleared(field); !exists {
return false
}
}
return true
}
}
// HasFields is a condition validating `.Field` on fields.
func HasFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.Field(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.Field(field); !exists {
return false
}
}
return true
}
}
// If executes the given hook under condition.
//
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
func If(hk ent.Hook, cond Condition) ent.Hook {
return func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if cond(ctx, m) {
return hk(next).Mutate(ctx, m)
}
return next.Mutate(ctx, m)
})
}
}
// On executes the given hook only for the given operation.
//
// hook.On(Log, ent.Delete|ent.Create)
func On(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, HasOp(op))
}
// Unless skips the given hook only for the given operation.
//
// hook.Unless(Log, ent.Update|ent.UpdateOne)
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, Not(HasOp(op)))
}
// FixedError is a hook returning a fixed error.
func FixedError(err error) ent.Hook {
return func(ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
return nil, err
})
}
}
// Reject returns a hook that rejects all operations that match op.
//
// func (T) Hooks() []ent.Hook {
// return []ent.Hook{
// Reject(ent.Delete|ent.Update),
// }
// }
func Reject(op ent.Op) ent.Hook {
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
return On(hk, op)
}
// Chain acts as a list of hooks and is effectively immutable.
// Once created, it will always hold the same set of hooks in the same order.
type Chain struct {
hooks []ent.Hook
}
// NewChain creates a new chain of hooks.
func NewChain(hooks ...ent.Hook) Chain {
return Chain{append([]ent.Hook(nil), hooks...)}
}
// Hook chains the list of hooks and returns the final hook.
func (c Chain) Hook() ent.Hook {
return func(mutator ent.Mutator) ent.Mutator {
for i := len(c.hooks) - 1; i >= 0; i-- {
mutator = c.hooks[i](mutator)
}
return mutator
}
}
// Append extends a chain, adding the specified hook
// as the last ones in the mutation flow.
func (c Chain) Append(hooks ...ent.Hook) Chain {
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
newHooks = append(newHooks, c.hooks...)
newHooks = append(newHooks, hooks...)
return Chain{newHooks}
}
// Extend extends a chain, adding the specified chain
// as the last ones in the mutation flow.
func (c Chain) Extend(chain Chain) Chain {
return c.Append(chain.hooks...)
}
+64
View File
@@ -0,0 +1,64 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"context"
"fmt"
"io"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql/schema"
)
var (
// WithGlobalUniqueID sets the universal ids options to the migration.
// If this option is enabled, ent migration will allocate a 1<<32 range
// for the ids of each entity (table).
// Note that this option cannot be applied on tables that already exist.
WithGlobalUniqueID = schema.WithGlobalUniqueID
// WithDropColumn sets the drop column option to the migration.
// If this option is enabled, ent migration will drop old columns
// that were used for both fields and edges. This defaults to false.
WithDropColumn = schema.WithDropColumn
// WithDropIndex sets the drop index option to the migration.
// If this option is enabled, ent migration will drop old indexes
// that were defined in the schema. This defaults to false.
// Note that unique constraints are defined using `UNIQUE INDEX`,
// and therefore, it's recommended to enable this option to get more
// flexibility in the schema changes.
WithDropIndex = schema.WithDropIndex
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
WithForeignKeys = schema.WithForeignKeys
)
// Schema is the API for creating, migrating and dropping a schema.
type Schema struct {
drv dialect.Driver
}
// NewSchema creates a new schema client.
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
// Create creates all schema resources.
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
return Create(ctx, s, Tables, opts...)
}
// Create creates all table resources using the given schema driver.
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, tables...)
}
// WriteTo writes the schema changes to w instead of running them against the database.
//
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
// log.Fatal(err)
// }
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
}
+89
View File
@@ -0,0 +1,89 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// FrpcClientsColumns holds the columns for the "frpc_clients" table.
FrpcClientsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "name", Type: field.TypeString, Unique: true},
{Name: "key", Type: field.TypeString, Default: ""},
{Name: "addr", Type: field.TypeString, Default: ""},
{Name: "port", Type: field.TypeInt, Default: 0},
{Name: "status", Type: field.TypeString, Default: "offline"},
{Name: "metadata", Type: field.TypeString, Default: "{}"},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "last_seen", Type: field.TypeTime, Nullable: true},
}
// FrpcClientsTable holds the schema information for the "frpc_clients" table.
FrpcClientsTable = &schema.Table{
Name: "frpc_clients",
Columns: FrpcClientsColumns,
PrimaryKey: []*schema.Column{FrpcClientsColumns[0]},
}
// ProxiesColumns holds the columns for the "proxies" table.
ProxiesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "name", Type: field.TypeString},
{Name: "proxy_type", Type: field.TypeString, Default: "tcp"},
{Name: "local_ip", Type: field.TypeString, Default: "127.0.0.1"},
{Name: "local_port", Type: field.TypeInt},
{Name: "remote_port", Type: field.TypeInt, Default: 0},
{Name: "status", Type: field.TypeString, Default: "inactive"},
{Name: "custom_domains", Type: field.TypeString, Default: ""},
{Name: "metadata", Type: field.TypeString, Default: "{}"},
{Name: "client_id", Type: field.TypeInt, Default: 0},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
}
// ProxiesTable holds the schema information for the "proxies" table.
ProxiesTable = &schema.Table{
Name: "proxies",
Columns: ProxiesColumns,
PrimaryKey: []*schema.Column{ProxiesColumns[0]},
}
// ServerConfigsColumns holds the columns for the "server_configs" table.
ServerConfigsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "key", Type: field.TypeString, Unique: true},
{Name: "value", Type: field.TypeString},
}
// ServerConfigsTable holds the schema information for the "server_configs" table.
ServerConfigsTable = &schema.Table{
Name: "server_configs",
Columns: ServerConfigsColumns,
PrimaryKey: []*schema.Column{ServerConfigsColumns[0]},
}
// UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "username", Type: field.TypeString, Unique: true},
{Name: "password", Type: field.TypeString},
{Name: "name", Type: field.TypeString, Default: ""},
{Name: "role", Type: field.TypeString, Default: "admin"},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
}
// UsersTable holds the schema information for the "users" table.
UsersTable = &schema.Table{
Name: "users",
Columns: UsersColumns,
PrimaryKey: []*schema.Column{UsersColumns[0]},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
FrpcClientsTable,
ProxiesTable,
ServerConfigsTable,
UsersTable,
}
)
func init() {
}
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
// Code generated by ent, DO NOT EDIT.
package predicate
import (
"entgo.io/ent/dialect/sql"
)
// FrpcClient is the predicate function for frpcclient builders.
type FrpcClient func(*sql.Selector)
// Proxy is the predicate function for proxy builders.
type Proxy func(*sql.Selector)
// ServerConfig is the predicate function for serverconfig builders.
type ServerConfig func(*sql.Selector)
// User is the predicate function for user builders.
type User func(*sql.Selector)
+216
View File
@@ -0,0 +1,216 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/proxy"
)
// Proxy is the model entity for the Proxy schema.
type Proxy struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// ProxyType holds the value of the "proxy_type" field.
ProxyType string `json:"proxy_type,omitempty"`
// LocalIP holds the value of the "local_ip" field.
LocalIP string `json:"local_ip,omitempty"`
// LocalPort holds the value of the "local_port" field.
LocalPort int `json:"local_port,omitempty"`
// RemotePort holds the value of the "remote_port" field.
RemotePort int `json:"remote_port,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// CustomDomains holds the value of the "custom_domains" field.
CustomDomains string `json:"custom_domains,omitempty"`
// Metadata holds the value of the "metadata" field.
Metadata string `json:"metadata,omitempty"`
// ClientID holds the value of the "client_id" field.
ClientID int `json:"client_id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Proxy) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case proxy.FieldID, proxy.FieldLocalPort, proxy.FieldRemotePort, proxy.FieldClientID:
values[i] = new(sql.NullInt64)
case proxy.FieldName, proxy.FieldProxyType, proxy.FieldLocalIP, proxy.FieldStatus, proxy.FieldCustomDomains, proxy.FieldMetadata:
values[i] = new(sql.NullString)
case proxy.FieldCreatedAt, proxy.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Proxy fields.
func (_m *Proxy) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case proxy.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int(value.Int64)
case proxy.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case proxy.FieldProxyType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field proxy_type", values[i])
} else if value.Valid {
_m.ProxyType = value.String
}
case proxy.FieldLocalIP:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field local_ip", values[i])
} else if value.Valid {
_m.LocalIP = value.String
}
case proxy.FieldLocalPort:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field local_port", values[i])
} else if value.Valid {
_m.LocalPort = int(value.Int64)
}
case proxy.FieldRemotePort:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field remote_port", values[i])
} else if value.Valid {
_m.RemotePort = int(value.Int64)
}
case proxy.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = value.String
}
case proxy.FieldCustomDomains:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field custom_domains", values[i])
} else if value.Valid {
_m.CustomDomains = value.String
}
case proxy.FieldMetadata:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field metadata", values[i])
} else if value.Valid {
_m.Metadata = value.String
}
case proxy.FieldClientID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field client_id", values[i])
} else if value.Valid {
_m.ClientID = int(value.Int64)
}
case proxy.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case proxy.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Proxy.
// This includes values selected through modifiers, order, etc.
func (_m *Proxy) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this Proxy.
// Note that you need to call Proxy.Unwrap() before calling this method if this Proxy
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Proxy) Update() *ProxyUpdateOne {
return NewProxyClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Proxy entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *Proxy) Unwrap() *Proxy {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Proxy is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Proxy) String() string {
var builder strings.Builder
builder.WriteString("Proxy(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("proxy_type=")
builder.WriteString(_m.ProxyType)
builder.WriteString(", ")
builder.WriteString("local_ip=")
builder.WriteString(_m.LocalIP)
builder.WriteString(", ")
builder.WriteString("local_port=")
builder.WriteString(fmt.Sprintf("%v", _m.LocalPort))
builder.WriteString(", ")
builder.WriteString("remote_port=")
builder.WriteString(fmt.Sprintf("%v", _m.RemotePort))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(_m.Status)
builder.WriteString(", ")
builder.WriteString("custom_domains=")
builder.WriteString(_m.CustomDomains)
builder.WriteString(", ")
builder.WriteString("metadata=")
builder.WriteString(_m.Metadata)
builder.WriteString(", ")
builder.WriteString("client_id=")
builder.WriteString(fmt.Sprintf("%v", _m.ClientID))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Proxies is a parsable slice of Proxy.
type Proxies []*Proxy
+152
View File
@@ -0,0 +1,152 @@
// Code generated by ent, DO NOT EDIT.
package proxy
import (
"time"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the proxy type in the database.
Label = "proxy"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldProxyType holds the string denoting the proxy_type field in the database.
FieldProxyType = "proxy_type"
// FieldLocalIP holds the string denoting the local_ip field in the database.
FieldLocalIP = "local_ip"
// FieldLocalPort holds the string denoting the local_port field in the database.
FieldLocalPort = "local_port"
// FieldRemotePort holds the string denoting the remote_port field in the database.
FieldRemotePort = "remote_port"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldCustomDomains holds the string denoting the custom_domains field in the database.
FieldCustomDomains = "custom_domains"
// FieldMetadata holds the string denoting the metadata field in the database.
FieldMetadata = "metadata"
// FieldClientID holds the string denoting the client_id field in the database.
FieldClientID = "client_id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// Table holds the table name of the proxy in the database.
Table = "proxies"
)
// Columns holds all SQL columns for proxy fields.
var Columns = []string{
FieldID,
FieldName,
FieldProxyType,
FieldLocalIP,
FieldLocalPort,
FieldRemotePort,
FieldStatus,
FieldCustomDomains,
FieldMetadata,
FieldClientID,
FieldCreatedAt,
FieldUpdatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultProxyType holds the default value on creation for the "proxy_type" field.
DefaultProxyType string
// DefaultLocalIP holds the default value on creation for the "local_ip" field.
DefaultLocalIP string
// DefaultRemotePort holds the default value on creation for the "remote_port" field.
DefaultRemotePort int
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
// DefaultCustomDomains holds the default value on creation for the "custom_domains" field.
DefaultCustomDomains string
// DefaultMetadata holds the default value on creation for the "metadata" field.
DefaultMetadata string
// DefaultClientID holds the default value on creation for the "client_id" field.
DefaultClientID int
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the Proxy queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByProxyType orders the results by the proxy_type field.
func ByProxyType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldProxyType, opts...).ToFunc()
}
// ByLocalIP orders the results by the local_ip field.
func ByLocalIP(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLocalIP, opts...).ToFunc()
}
// ByLocalPort orders the results by the local_port field.
func ByLocalPort(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLocalPort, opts...).ToFunc()
}
// ByRemotePort orders the results by the remote_port field.
func ByRemotePort(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRemotePort, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByCustomDomains orders the results by the custom_domains field.
func ByCustomDomains(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCustomDomains, opts...).ToFunc()
}
// ByMetadata orders the results by the metadata field.
func ByMetadata(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMetadata, opts...).ToFunc()
}
// ByClientID orders the results by the client_id field.
func ByClientID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldClientID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
+715
View File
@@ -0,0 +1,715 @@
// Code generated by ent, DO NOT EDIT.
package proxy
import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldName, v))
}
// ProxyType applies equality check predicate on the "proxy_type" field. It's identical to ProxyTypeEQ.
func ProxyType(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldProxyType, v))
}
// LocalIP applies equality check predicate on the "local_ip" field. It's identical to LocalIPEQ.
func LocalIP(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldLocalIP, v))
}
// LocalPort applies equality check predicate on the "local_port" field. It's identical to LocalPortEQ.
func LocalPort(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldLocalPort, v))
}
// RemotePort applies equality check predicate on the "remote_port" field. It's identical to RemotePortEQ.
func RemotePort(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldRemotePort, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldStatus, v))
}
// CustomDomains applies equality check predicate on the "custom_domains" field. It's identical to CustomDomainsEQ.
func CustomDomains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldCustomDomains, v))
}
// Metadata applies equality check predicate on the "metadata" field. It's identical to MetadataEQ.
func Metadata(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldMetadata, v))
}
// ClientID applies equality check predicate on the "client_id" field. It's identical to ClientIDEQ.
func ClientID(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldClientID, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldUpdatedAt, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldName, v))
}
// ProxyTypeEQ applies the EQ predicate on the "proxy_type" field.
func ProxyTypeEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldProxyType, v))
}
// ProxyTypeNEQ applies the NEQ predicate on the "proxy_type" field.
func ProxyTypeNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldProxyType, v))
}
// ProxyTypeIn applies the In predicate on the "proxy_type" field.
func ProxyTypeIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldProxyType, vs...))
}
// ProxyTypeNotIn applies the NotIn predicate on the "proxy_type" field.
func ProxyTypeNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldProxyType, vs...))
}
// ProxyTypeGT applies the GT predicate on the "proxy_type" field.
func ProxyTypeGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldProxyType, v))
}
// ProxyTypeGTE applies the GTE predicate on the "proxy_type" field.
func ProxyTypeGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldProxyType, v))
}
// ProxyTypeLT applies the LT predicate on the "proxy_type" field.
func ProxyTypeLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldProxyType, v))
}
// ProxyTypeLTE applies the LTE predicate on the "proxy_type" field.
func ProxyTypeLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldProxyType, v))
}
// ProxyTypeContains applies the Contains predicate on the "proxy_type" field.
func ProxyTypeContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldProxyType, v))
}
// ProxyTypeHasPrefix applies the HasPrefix predicate on the "proxy_type" field.
func ProxyTypeHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldProxyType, v))
}
// ProxyTypeHasSuffix applies the HasSuffix predicate on the "proxy_type" field.
func ProxyTypeHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldProxyType, v))
}
// ProxyTypeEqualFold applies the EqualFold predicate on the "proxy_type" field.
func ProxyTypeEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldProxyType, v))
}
// ProxyTypeContainsFold applies the ContainsFold predicate on the "proxy_type" field.
func ProxyTypeContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldProxyType, v))
}
// LocalIPEQ applies the EQ predicate on the "local_ip" field.
func LocalIPEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldLocalIP, v))
}
// LocalIPNEQ applies the NEQ predicate on the "local_ip" field.
func LocalIPNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldLocalIP, v))
}
// LocalIPIn applies the In predicate on the "local_ip" field.
func LocalIPIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldLocalIP, vs...))
}
// LocalIPNotIn applies the NotIn predicate on the "local_ip" field.
func LocalIPNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldLocalIP, vs...))
}
// LocalIPGT applies the GT predicate on the "local_ip" field.
func LocalIPGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldLocalIP, v))
}
// LocalIPGTE applies the GTE predicate on the "local_ip" field.
func LocalIPGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldLocalIP, v))
}
// LocalIPLT applies the LT predicate on the "local_ip" field.
func LocalIPLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldLocalIP, v))
}
// LocalIPLTE applies the LTE predicate on the "local_ip" field.
func LocalIPLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldLocalIP, v))
}
// LocalIPContains applies the Contains predicate on the "local_ip" field.
func LocalIPContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldLocalIP, v))
}
// LocalIPHasPrefix applies the HasPrefix predicate on the "local_ip" field.
func LocalIPHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldLocalIP, v))
}
// LocalIPHasSuffix applies the HasSuffix predicate on the "local_ip" field.
func LocalIPHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldLocalIP, v))
}
// LocalIPEqualFold applies the EqualFold predicate on the "local_ip" field.
func LocalIPEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldLocalIP, v))
}
// LocalIPContainsFold applies the ContainsFold predicate on the "local_ip" field.
func LocalIPContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldLocalIP, v))
}
// LocalPortEQ applies the EQ predicate on the "local_port" field.
func LocalPortEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldLocalPort, v))
}
// LocalPortNEQ applies the NEQ predicate on the "local_port" field.
func LocalPortNEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldLocalPort, v))
}
// LocalPortIn applies the In predicate on the "local_port" field.
func LocalPortIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldLocalPort, vs...))
}
// LocalPortNotIn applies the NotIn predicate on the "local_port" field.
func LocalPortNotIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldLocalPort, vs...))
}
// LocalPortGT applies the GT predicate on the "local_port" field.
func LocalPortGT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldLocalPort, v))
}
// LocalPortGTE applies the GTE predicate on the "local_port" field.
func LocalPortGTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldLocalPort, v))
}
// LocalPortLT applies the LT predicate on the "local_port" field.
func LocalPortLT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldLocalPort, v))
}
// LocalPortLTE applies the LTE predicate on the "local_port" field.
func LocalPortLTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldLocalPort, v))
}
// RemotePortEQ applies the EQ predicate on the "remote_port" field.
func RemotePortEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldRemotePort, v))
}
// RemotePortNEQ applies the NEQ predicate on the "remote_port" field.
func RemotePortNEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldRemotePort, v))
}
// RemotePortIn applies the In predicate on the "remote_port" field.
func RemotePortIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldRemotePort, vs...))
}
// RemotePortNotIn applies the NotIn predicate on the "remote_port" field.
func RemotePortNotIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldRemotePort, vs...))
}
// RemotePortGT applies the GT predicate on the "remote_port" field.
func RemotePortGT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldRemotePort, v))
}
// RemotePortGTE applies the GTE predicate on the "remote_port" field.
func RemotePortGTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldRemotePort, v))
}
// RemotePortLT applies the LT predicate on the "remote_port" field.
func RemotePortLT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldRemotePort, v))
}
// RemotePortLTE applies the LTE predicate on the "remote_port" field.
func RemotePortLTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldRemotePort, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldStatus, vs...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldStatus, v))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldStatus, v))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldStatus, v))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldStatus, v))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldStatus, v))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldStatus, v))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldStatus, v))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldStatus, v))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldStatus, v))
}
// CustomDomainsEQ applies the EQ predicate on the "custom_domains" field.
func CustomDomainsEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldCustomDomains, v))
}
// CustomDomainsNEQ applies the NEQ predicate on the "custom_domains" field.
func CustomDomainsNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldCustomDomains, v))
}
// CustomDomainsIn applies the In predicate on the "custom_domains" field.
func CustomDomainsIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldCustomDomains, vs...))
}
// CustomDomainsNotIn applies the NotIn predicate on the "custom_domains" field.
func CustomDomainsNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldCustomDomains, vs...))
}
// CustomDomainsGT applies the GT predicate on the "custom_domains" field.
func CustomDomainsGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldCustomDomains, v))
}
// CustomDomainsGTE applies the GTE predicate on the "custom_domains" field.
func CustomDomainsGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldCustomDomains, v))
}
// CustomDomainsLT applies the LT predicate on the "custom_domains" field.
func CustomDomainsLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldCustomDomains, v))
}
// CustomDomainsLTE applies the LTE predicate on the "custom_domains" field.
func CustomDomainsLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldCustomDomains, v))
}
// CustomDomainsContains applies the Contains predicate on the "custom_domains" field.
func CustomDomainsContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldCustomDomains, v))
}
// CustomDomainsHasPrefix applies the HasPrefix predicate on the "custom_domains" field.
func CustomDomainsHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldCustomDomains, v))
}
// CustomDomainsHasSuffix applies the HasSuffix predicate on the "custom_domains" field.
func CustomDomainsHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldCustomDomains, v))
}
// CustomDomainsEqualFold applies the EqualFold predicate on the "custom_domains" field.
func CustomDomainsEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldCustomDomains, v))
}
// CustomDomainsContainsFold applies the ContainsFold predicate on the "custom_domains" field.
func CustomDomainsContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldCustomDomains, v))
}
// MetadataEQ applies the EQ predicate on the "metadata" field.
func MetadataEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldMetadata, v))
}
// MetadataNEQ applies the NEQ predicate on the "metadata" field.
func MetadataNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldMetadata, v))
}
// MetadataIn applies the In predicate on the "metadata" field.
func MetadataIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldMetadata, vs...))
}
// MetadataNotIn applies the NotIn predicate on the "metadata" field.
func MetadataNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldMetadata, vs...))
}
// MetadataGT applies the GT predicate on the "metadata" field.
func MetadataGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldMetadata, v))
}
// MetadataGTE applies the GTE predicate on the "metadata" field.
func MetadataGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldMetadata, v))
}
// MetadataLT applies the LT predicate on the "metadata" field.
func MetadataLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldMetadata, v))
}
// MetadataLTE applies the LTE predicate on the "metadata" field.
func MetadataLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldMetadata, v))
}
// MetadataContains applies the Contains predicate on the "metadata" field.
func MetadataContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldMetadata, v))
}
// MetadataHasPrefix applies the HasPrefix predicate on the "metadata" field.
func MetadataHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldMetadata, v))
}
// MetadataHasSuffix applies the HasSuffix predicate on the "metadata" field.
func MetadataHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldMetadata, v))
}
// MetadataEqualFold applies the EqualFold predicate on the "metadata" field.
func MetadataEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldMetadata, v))
}
// MetadataContainsFold applies the ContainsFold predicate on the "metadata" field.
func MetadataContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldMetadata, v))
}
// ClientIDEQ applies the EQ predicate on the "client_id" field.
func ClientIDEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldClientID, v))
}
// ClientIDNEQ applies the NEQ predicate on the "client_id" field.
func ClientIDNEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldClientID, v))
}
// ClientIDIn applies the In predicate on the "client_id" field.
func ClientIDIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldClientID, vs...))
}
// ClientIDNotIn applies the NotIn predicate on the "client_id" field.
func ClientIDNotIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldClientID, vs...))
}
// ClientIDGT applies the GT predicate on the "client_id" field.
func ClientIDGT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldClientID, v))
}
// ClientIDGTE applies the GTE predicate on the "client_id" field.
func ClientIDGTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldClientID, v))
}
// ClientIDLT applies the LT predicate on the "client_id" field.
func ClientIDLT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldClientID, v))
}
// ClientIDLTE applies the LTE predicate on the "client_id" field.
func ClientIDLTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldClientID, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldUpdatedAt, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Proxy) predicate.Proxy {
return predicate.Proxy(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Proxy) predicate.Proxy {
return predicate.Proxy(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Proxy) predicate.Proxy {
return predicate.Proxy(sql.NotPredicates(p))
}
+428
View File
@@ -0,0 +1,428 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/proxy"
)
// ProxyCreate is the builder for creating a Proxy entity.
type ProxyCreate struct {
config
mutation *ProxyMutation
hooks []Hook
}
// SetName sets the "name" field.
func (_c *ProxyCreate) SetName(v string) *ProxyCreate {
_c.mutation.SetName(v)
return _c
}
// SetProxyType sets the "proxy_type" field.
func (_c *ProxyCreate) SetProxyType(v string) *ProxyCreate {
_c.mutation.SetProxyType(v)
return _c
}
// SetNillableProxyType sets the "proxy_type" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableProxyType(v *string) *ProxyCreate {
if v != nil {
_c.SetProxyType(*v)
}
return _c
}
// SetLocalIP sets the "local_ip" field.
func (_c *ProxyCreate) SetLocalIP(v string) *ProxyCreate {
_c.mutation.SetLocalIP(v)
return _c
}
// SetNillableLocalIP sets the "local_ip" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableLocalIP(v *string) *ProxyCreate {
if v != nil {
_c.SetLocalIP(*v)
}
return _c
}
// SetLocalPort sets the "local_port" field.
func (_c *ProxyCreate) SetLocalPort(v int) *ProxyCreate {
_c.mutation.SetLocalPort(v)
return _c
}
// SetRemotePort sets the "remote_port" field.
func (_c *ProxyCreate) SetRemotePort(v int) *ProxyCreate {
_c.mutation.SetRemotePort(v)
return _c
}
// SetNillableRemotePort sets the "remote_port" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableRemotePort(v *int) *ProxyCreate {
if v != nil {
_c.SetRemotePort(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *ProxyCreate) SetStatus(v string) *ProxyCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableStatus(v *string) *ProxyCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetCustomDomains sets the "custom_domains" field.
func (_c *ProxyCreate) SetCustomDomains(v string) *ProxyCreate {
_c.mutation.SetCustomDomains(v)
return _c
}
// SetNillableCustomDomains sets the "custom_domains" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableCustomDomains(v *string) *ProxyCreate {
if v != nil {
_c.SetCustomDomains(*v)
}
return _c
}
// SetMetadata sets the "metadata" field.
func (_c *ProxyCreate) SetMetadata(v string) *ProxyCreate {
_c.mutation.SetMetadata(v)
return _c
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableMetadata(v *string) *ProxyCreate {
if v != nil {
_c.SetMetadata(*v)
}
return _c
}
// SetClientID sets the "client_id" field.
func (_c *ProxyCreate) SetClientID(v int) *ProxyCreate {
_c.mutation.SetClientID(v)
return _c
}
// SetNillableClientID sets the "client_id" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableClientID(v *int) *ProxyCreate {
if v != nil {
_c.SetClientID(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *ProxyCreate) SetCreatedAt(v time.Time) *ProxyCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableCreatedAt(v *time.Time) *ProxyCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *ProxyCreate) SetUpdatedAt(v time.Time) *ProxyCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableUpdatedAt(v *time.Time) *ProxyCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// Mutation returns the ProxyMutation object of the builder.
func (_c *ProxyCreate) Mutation() *ProxyMutation {
return _c.mutation
}
// Save creates the Proxy in the database.
func (_c *ProxyCreate) Save(ctx context.Context) (*Proxy, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ProxyCreate) SaveX(ctx context.Context) *Proxy {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ProxyCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ProxyCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *ProxyCreate) defaults() {
if _, ok := _c.mutation.ProxyType(); !ok {
v := proxy.DefaultProxyType
_c.mutation.SetProxyType(v)
}
if _, ok := _c.mutation.LocalIP(); !ok {
v := proxy.DefaultLocalIP
_c.mutation.SetLocalIP(v)
}
if _, ok := _c.mutation.RemotePort(); !ok {
v := proxy.DefaultRemotePort
_c.mutation.SetRemotePort(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := proxy.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.CustomDomains(); !ok {
v := proxy.DefaultCustomDomains
_c.mutation.SetCustomDomains(v)
}
if _, ok := _c.mutation.Metadata(); !ok {
v := proxy.DefaultMetadata
_c.mutation.SetMetadata(v)
}
if _, ok := _c.mutation.ClientID(); !ok {
v := proxy.DefaultClientID
_c.mutation.SetClientID(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := proxy.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := proxy.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ProxyCreate) check() error {
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Proxy.name"`)}
}
if _, ok := _c.mutation.ProxyType(); !ok {
return &ValidationError{Name: "proxy_type", err: errors.New(`ent: missing required field "Proxy.proxy_type"`)}
}
if _, ok := _c.mutation.LocalIP(); !ok {
return &ValidationError{Name: "local_ip", err: errors.New(`ent: missing required field "Proxy.local_ip"`)}
}
if _, ok := _c.mutation.LocalPort(); !ok {
return &ValidationError{Name: "local_port", err: errors.New(`ent: missing required field "Proxy.local_port"`)}
}
if _, ok := _c.mutation.RemotePort(); !ok {
return &ValidationError{Name: "remote_port", err: errors.New(`ent: missing required field "Proxy.remote_port"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Proxy.status"`)}
}
if _, ok := _c.mutation.CustomDomains(); !ok {
return &ValidationError{Name: "custom_domains", err: errors.New(`ent: missing required field "Proxy.custom_domains"`)}
}
if _, ok := _c.mutation.Metadata(); !ok {
return &ValidationError{Name: "metadata", err: errors.New(`ent: missing required field "Proxy.metadata"`)}
}
if _, ok := _c.mutation.ClientID(); !ok {
return &ValidationError{Name: "client_id", err: errors.New(`ent: missing required field "Proxy.client_id"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Proxy.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Proxy.updated_at"`)}
}
return nil
}
func (_c *ProxyCreate) sqlSave(ctx context.Context) (*Proxy, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *ProxyCreate) createSpec() (*Proxy, *sqlgraph.CreateSpec) {
var (
_node = &Proxy{config: _c.config}
_spec = sqlgraph.NewCreateSpec(proxy.Table, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
)
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.ProxyType(); ok {
_spec.SetField(proxy.FieldProxyType, field.TypeString, value)
_node.ProxyType = value
}
if value, ok := _c.mutation.LocalIP(); ok {
_spec.SetField(proxy.FieldLocalIP, field.TypeString, value)
_node.LocalIP = value
}
if value, ok := _c.mutation.LocalPort(); ok {
_spec.SetField(proxy.FieldLocalPort, field.TypeInt, value)
_node.LocalPort = value
}
if value, ok := _c.mutation.RemotePort(); ok {
_spec.SetField(proxy.FieldRemotePort, field.TypeInt, value)
_node.RemotePort = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.CustomDomains(); ok {
_spec.SetField(proxy.FieldCustomDomains, field.TypeString, value)
_node.CustomDomains = value
}
if value, ok := _c.mutation.Metadata(); ok {
_spec.SetField(proxy.FieldMetadata, field.TypeString, value)
_node.Metadata = value
}
if value, ok := _c.mutation.ClientID(); ok {
_spec.SetField(proxy.FieldClientID, field.TypeInt, value)
_node.ClientID = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
return _node, _spec
}
// ProxyCreateBulk is the builder for creating many Proxy entities in bulk.
type ProxyCreateBulk struct {
config
err error
builders []*ProxyCreate
}
// Save creates the Proxy entities in the database.
func (_c *ProxyCreateBulk) Save(ctx context.Context) ([]*Proxy, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Proxy, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*ProxyMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *ProxyCreateBulk) SaveX(ctx context.Context) []*Proxy {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ProxyCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ProxyCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
+88
View File
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/proxy"
)
// ProxyDelete is the builder for deleting a Proxy entity.
type ProxyDelete struct {
config
hooks []Hook
mutation *ProxyMutation
}
// Where appends a list predicates to the ProxyDelete builder.
func (_d *ProxyDelete) Where(ps ...predicate.Proxy) *ProxyDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *ProxyDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ProxyDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *ProxyDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(proxy.Table, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// ProxyDeleteOne is the builder for deleting a single Proxy entity.
type ProxyDeleteOne struct {
_d *ProxyDelete
}
// Where appends a list predicates to the ProxyDelete builder.
func (_d *ProxyDeleteOne) Where(ps ...predicate.Proxy) *ProxyDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *ProxyDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{proxy.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ProxyDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+527
View File
@@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/proxy"
)
// ProxyQuery is the builder for querying Proxy entities.
type ProxyQuery struct {
config
ctx *QueryContext
order []proxy.OrderOption
inters []Interceptor
predicates []predicate.Proxy
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ProxyQuery builder.
func (_q *ProxyQuery) Where(ps ...predicate.Proxy) *ProxyQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *ProxyQuery) Limit(limit int) *ProxyQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *ProxyQuery) Offset(offset int) *ProxyQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *ProxyQuery) Unique(unique bool) *ProxyQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *ProxyQuery) Order(o ...proxy.OrderOption) *ProxyQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first Proxy entity from the query.
// Returns a *NotFoundError when no Proxy was found.
func (_q *ProxyQuery) First(ctx context.Context) (*Proxy, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{proxy.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *ProxyQuery) FirstX(ctx context.Context) *Proxy {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first Proxy ID from the query.
// Returns a *NotFoundError when no Proxy ID was found.
func (_q *ProxyQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{proxy.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *ProxyQuery) FirstIDX(ctx context.Context) int {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single Proxy entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Proxy entity is found.
// Returns a *NotFoundError when no Proxy entities are found.
func (_q *ProxyQuery) Only(ctx context.Context) (*Proxy, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{proxy.Label}
default:
return nil, &NotSingularError{proxy.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *ProxyQuery) OnlyX(ctx context.Context) *Proxy {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only Proxy ID in the query.
// Returns a *NotSingularError when more than one Proxy ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *ProxyQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{proxy.Label}
default:
err = &NotSingularError{proxy.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *ProxyQuery) OnlyIDX(ctx context.Context) int {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of Proxies.
func (_q *ProxyQuery) All(ctx context.Context) ([]*Proxy, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Proxy, *ProxyQuery]()
return withInterceptors[[]*Proxy](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *ProxyQuery) AllX(ctx context.Context) []*Proxy {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of Proxy IDs.
func (_q *ProxyQuery) IDs(ctx context.Context) (ids []int, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(proxy.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *ProxyQuery) IDsX(ctx context.Context) []int {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *ProxyQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*ProxyQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *ProxyQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *ProxyQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *ProxyQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ProxyQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *ProxyQuery) Clone() *ProxyQuery {
if _q == nil {
return nil
}
return &ProxyQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]proxy.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.Proxy{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Proxy.Query().
// GroupBy(proxy.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *ProxyQuery) GroupBy(field string, fields ...string) *ProxyGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &ProxyGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = proxy.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// }
//
// client.Proxy.Query().
// Select(proxy.FieldName).
// Scan(ctx, &v)
func (_q *ProxyQuery) Select(fields ...string) *ProxySelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &ProxySelect{ProxyQuery: _q}
sbuild.label = proxy.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ProxySelect configured with the given aggregations.
func (_q *ProxyQuery) Aggregate(fns ...AggregateFunc) *ProxySelect {
return _q.Select().Aggregate(fns...)
}
func (_q *ProxyQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !proxy.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *ProxyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Proxy, error) {
var (
nodes = []*Proxy{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Proxy).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Proxy{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *ProxyQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *ProxyQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, proxy.FieldID)
for i := range fields {
if fields[i] != proxy.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *ProxyQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(proxy.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = proxy.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ProxyGroupBy is the group-by builder for Proxy entities.
type ProxyGroupBy struct {
selector
build *ProxyQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *ProxyGroupBy) Aggregate(fns ...AggregateFunc) *ProxyGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *ProxyGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ProxyQuery, *ProxyGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *ProxyGroupBy) sqlScan(ctx context.Context, root *ProxyQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ProxySelect is the builder for selecting fields of Proxy entities.
type ProxySelect struct {
*ProxyQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *ProxySelect) Aggregate(fns ...AggregateFunc) *ProxySelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *ProxySelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ProxyQuery, *ProxySelect](ctx, _s.ProxyQuery, _s, _s.inters, v)
}
func (_s *ProxySelect) sqlScan(ctx context.Context, root *ProxyQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
+612
View File
@@ -0,0 +1,612 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/proxy"
)
// ProxyUpdate is the builder for updating Proxy entities.
type ProxyUpdate struct {
config
hooks []Hook
mutation *ProxyMutation
}
// Where appends a list predicates to the ProxyUpdate builder.
func (_u *ProxyUpdate) Where(ps ...predicate.Proxy) *ProxyUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetName sets the "name" field.
func (_u *ProxyUpdate) SetName(v string) *ProxyUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableName(v *string) *ProxyUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProxyType sets the "proxy_type" field.
func (_u *ProxyUpdate) SetProxyType(v string) *ProxyUpdate {
_u.mutation.SetProxyType(v)
return _u
}
// SetNillableProxyType sets the "proxy_type" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableProxyType(v *string) *ProxyUpdate {
if v != nil {
_u.SetProxyType(*v)
}
return _u
}
// SetLocalIP sets the "local_ip" field.
func (_u *ProxyUpdate) SetLocalIP(v string) *ProxyUpdate {
_u.mutation.SetLocalIP(v)
return _u
}
// SetNillableLocalIP sets the "local_ip" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableLocalIP(v *string) *ProxyUpdate {
if v != nil {
_u.SetLocalIP(*v)
}
return _u
}
// SetLocalPort sets the "local_port" field.
func (_u *ProxyUpdate) SetLocalPort(v int) *ProxyUpdate {
_u.mutation.ResetLocalPort()
_u.mutation.SetLocalPort(v)
return _u
}
// SetNillableLocalPort sets the "local_port" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableLocalPort(v *int) *ProxyUpdate {
if v != nil {
_u.SetLocalPort(*v)
}
return _u
}
// AddLocalPort adds value to the "local_port" field.
func (_u *ProxyUpdate) AddLocalPort(v int) *ProxyUpdate {
_u.mutation.AddLocalPort(v)
return _u
}
// SetRemotePort sets the "remote_port" field.
func (_u *ProxyUpdate) SetRemotePort(v int) *ProxyUpdate {
_u.mutation.ResetRemotePort()
_u.mutation.SetRemotePort(v)
return _u
}
// SetNillableRemotePort sets the "remote_port" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableRemotePort(v *int) *ProxyUpdate {
if v != nil {
_u.SetRemotePort(*v)
}
return _u
}
// AddRemotePort adds value to the "remote_port" field.
func (_u *ProxyUpdate) AddRemotePort(v int) *ProxyUpdate {
_u.mutation.AddRemotePort(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *ProxyUpdate) SetStatus(v string) *ProxyUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableStatus(v *string) *ProxyUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetCustomDomains sets the "custom_domains" field.
func (_u *ProxyUpdate) SetCustomDomains(v string) *ProxyUpdate {
_u.mutation.SetCustomDomains(v)
return _u
}
// SetNillableCustomDomains sets the "custom_domains" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableCustomDomains(v *string) *ProxyUpdate {
if v != nil {
_u.SetCustomDomains(*v)
}
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *ProxyUpdate) SetMetadata(v string) *ProxyUpdate {
_u.mutation.SetMetadata(v)
return _u
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableMetadata(v *string) *ProxyUpdate {
if v != nil {
_u.SetMetadata(*v)
}
return _u
}
// SetClientID sets the "client_id" field.
func (_u *ProxyUpdate) SetClientID(v int) *ProxyUpdate {
_u.mutation.ResetClientID()
_u.mutation.SetClientID(v)
return _u
}
// SetNillableClientID sets the "client_id" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableClientID(v *int) *ProxyUpdate {
if v != nil {
_u.SetClientID(*v)
}
return _u
}
// AddClientID adds value to the "client_id" field.
func (_u *ProxyUpdate) AddClientID(v int) *ProxyUpdate {
_u.mutation.AddClientID(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ProxyUpdate) SetCreatedAt(v time.Time) *ProxyUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableCreatedAt(v *time.Time) *ProxyUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProxyUpdate) SetUpdatedAt(v time.Time) *ProxyUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdate) Mutation() *ProxyMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ProxyUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProxyUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ProxyUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProxyUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ProxyUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := proxy.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *ProxyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.ProxyType(); ok {
_spec.SetField(proxy.FieldProxyType, field.TypeString, value)
}
if value, ok := _u.mutation.LocalIP(); ok {
_spec.SetField(proxy.FieldLocalIP, field.TypeString, value)
}
if value, ok := _u.mutation.LocalPort(); ok {
_spec.SetField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedLocalPort(); ok {
_spec.AddField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.RemotePort(); ok {
_spec.SetField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRemotePort(); ok {
_spec.AddField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.CustomDomains(); ok {
_spec.SetField(proxy.FieldCustomDomains, field.TypeString, value)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(proxy.FieldMetadata, field.TypeString, value)
}
if value, ok := _u.mutation.ClientID(); ok {
_spec.SetField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedClientID(); ok {
_spec.AddField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{proxy.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ProxyUpdateOne is the builder for updating a single Proxy entity.
type ProxyUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ProxyMutation
}
// SetName sets the "name" field.
func (_u *ProxyUpdateOne) SetName(v string) *ProxyUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableName(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProxyType sets the "proxy_type" field.
func (_u *ProxyUpdateOne) SetProxyType(v string) *ProxyUpdateOne {
_u.mutation.SetProxyType(v)
return _u
}
// SetNillableProxyType sets the "proxy_type" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableProxyType(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetProxyType(*v)
}
return _u
}
// SetLocalIP sets the "local_ip" field.
func (_u *ProxyUpdateOne) SetLocalIP(v string) *ProxyUpdateOne {
_u.mutation.SetLocalIP(v)
return _u
}
// SetNillableLocalIP sets the "local_ip" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableLocalIP(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetLocalIP(*v)
}
return _u
}
// SetLocalPort sets the "local_port" field.
func (_u *ProxyUpdateOne) SetLocalPort(v int) *ProxyUpdateOne {
_u.mutation.ResetLocalPort()
_u.mutation.SetLocalPort(v)
return _u
}
// SetNillableLocalPort sets the "local_port" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableLocalPort(v *int) *ProxyUpdateOne {
if v != nil {
_u.SetLocalPort(*v)
}
return _u
}
// AddLocalPort adds value to the "local_port" field.
func (_u *ProxyUpdateOne) AddLocalPort(v int) *ProxyUpdateOne {
_u.mutation.AddLocalPort(v)
return _u
}
// SetRemotePort sets the "remote_port" field.
func (_u *ProxyUpdateOne) SetRemotePort(v int) *ProxyUpdateOne {
_u.mutation.ResetRemotePort()
_u.mutation.SetRemotePort(v)
return _u
}
// SetNillableRemotePort sets the "remote_port" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableRemotePort(v *int) *ProxyUpdateOne {
if v != nil {
_u.SetRemotePort(*v)
}
return _u
}
// AddRemotePort adds value to the "remote_port" field.
func (_u *ProxyUpdateOne) AddRemotePort(v int) *ProxyUpdateOne {
_u.mutation.AddRemotePort(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *ProxyUpdateOne) SetStatus(v string) *ProxyUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableStatus(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetCustomDomains sets the "custom_domains" field.
func (_u *ProxyUpdateOne) SetCustomDomains(v string) *ProxyUpdateOne {
_u.mutation.SetCustomDomains(v)
return _u
}
// SetNillableCustomDomains sets the "custom_domains" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableCustomDomains(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetCustomDomains(*v)
}
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *ProxyUpdateOne) SetMetadata(v string) *ProxyUpdateOne {
_u.mutation.SetMetadata(v)
return _u
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableMetadata(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetMetadata(*v)
}
return _u
}
// SetClientID sets the "client_id" field.
func (_u *ProxyUpdateOne) SetClientID(v int) *ProxyUpdateOne {
_u.mutation.ResetClientID()
_u.mutation.SetClientID(v)
return _u
}
// SetNillableClientID sets the "client_id" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableClientID(v *int) *ProxyUpdateOne {
if v != nil {
_u.SetClientID(*v)
}
return _u
}
// AddClientID adds value to the "client_id" field.
func (_u *ProxyUpdateOne) AddClientID(v int) *ProxyUpdateOne {
_u.mutation.AddClientID(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ProxyUpdateOne) SetCreatedAt(v time.Time) *ProxyUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableCreatedAt(v *time.Time) *ProxyUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProxyUpdateOne) SetUpdatedAt(v time.Time) *ProxyUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdateOne) Mutation() *ProxyMutation {
return _u.mutation
}
// Where appends a list predicates to the ProxyUpdate builder.
func (_u *ProxyUpdateOne) Where(ps ...predicate.Proxy) *ProxyUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ProxyUpdateOne) Select(field string, fields ...string) *ProxyUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Proxy entity.
func (_u *ProxyUpdateOne) Save(ctx context.Context) (*Proxy, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProxyUpdateOne) SaveX(ctx context.Context) *Proxy {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ProxyUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProxyUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ProxyUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := proxy.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *ProxyUpdateOne) sqlSave(ctx context.Context) (_node *Proxy, err error) {
_spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Proxy.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, proxy.FieldID)
for _, f := range fields {
if !proxy.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != proxy.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.ProxyType(); ok {
_spec.SetField(proxy.FieldProxyType, field.TypeString, value)
}
if value, ok := _u.mutation.LocalIP(); ok {
_spec.SetField(proxy.FieldLocalIP, field.TypeString, value)
}
if value, ok := _u.mutation.LocalPort(); ok {
_spec.SetField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedLocalPort(); ok {
_spec.AddField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.RemotePort(); ok {
_spec.SetField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRemotePort(); ok {
_spec.AddField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.CustomDomains(); ok {
_spec.SetField(proxy.FieldCustomDomains, field.TypeString, value)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(proxy.FieldMetadata, field.TypeString, value)
}
if value, ok := _u.mutation.ClientID(); ok {
_spec.SetField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedClientID(); ok {
_spec.AddField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
}
_node = &Proxy{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{proxy.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+114
View File
@@ -0,0 +1,114 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"time"
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
"github.com/fatedier/frp/pkg/db/ent/proxy"
"github.com/fatedier/frp/pkg/db/ent/schema"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// The init function reads all schema descriptors with runtime code
// (default values, validators, hooks and policies) and stitches it
// to their package variables.
func init() {
frpcclientFields := schema.FrpcClient{}.Fields()
_ = frpcclientFields
// frpcclientDescKey is the schema descriptor for key field.
frpcclientDescKey := frpcclientFields[1].Descriptor()
// frpcclient.DefaultKey holds the default value on creation for the key field.
frpcclient.DefaultKey = frpcclientDescKey.Default.(string)
// frpcclientDescAddr is the schema descriptor for addr field.
frpcclientDescAddr := frpcclientFields[2].Descriptor()
// frpcclient.DefaultAddr holds the default value on creation for the addr field.
frpcclient.DefaultAddr = frpcclientDescAddr.Default.(string)
// frpcclientDescPort is the schema descriptor for port field.
frpcclientDescPort := frpcclientFields[3].Descriptor()
// frpcclient.DefaultPort holds the default value on creation for the port field.
frpcclient.DefaultPort = frpcclientDescPort.Default.(int)
// frpcclientDescStatus is the schema descriptor for status field.
frpcclientDescStatus := frpcclientFields[4].Descriptor()
// frpcclient.DefaultStatus holds the default value on creation for the status field.
frpcclient.DefaultStatus = frpcclientDescStatus.Default.(string)
// frpcclientDescMetadata is the schema descriptor for metadata field.
frpcclientDescMetadata := frpcclientFields[5].Descriptor()
// frpcclient.DefaultMetadata holds the default value on creation for the metadata field.
frpcclient.DefaultMetadata = frpcclientDescMetadata.Default.(string)
// frpcclientDescCreatedAt is the schema descriptor for created_at field.
frpcclientDescCreatedAt := frpcclientFields[6].Descriptor()
// frpcclient.DefaultCreatedAt holds the default value on creation for the created_at field.
frpcclient.DefaultCreatedAt = frpcclientDescCreatedAt.Default.(func() time.Time)
// frpcclientDescUpdatedAt is the schema descriptor for updated_at field.
frpcclientDescUpdatedAt := frpcclientFields[7].Descriptor()
// frpcclient.DefaultUpdatedAt holds the default value on creation for the updated_at field.
frpcclient.DefaultUpdatedAt = frpcclientDescUpdatedAt.Default.(func() time.Time)
// frpcclient.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
frpcclient.UpdateDefaultUpdatedAt = frpcclientDescUpdatedAt.UpdateDefault.(func() time.Time)
// frpcclientDescLastSeen is the schema descriptor for last_seen field.
frpcclientDescLastSeen := frpcclientFields[8].Descriptor()
// frpcclient.DefaultLastSeen holds the default value on creation for the last_seen field.
frpcclient.DefaultLastSeen = frpcclientDescLastSeen.Default.(func() time.Time)
proxyFields := schema.Proxy{}.Fields()
_ = proxyFields
// proxyDescProxyType is the schema descriptor for proxy_type field.
proxyDescProxyType := proxyFields[1].Descriptor()
// proxy.DefaultProxyType holds the default value on creation for the proxy_type field.
proxy.DefaultProxyType = proxyDescProxyType.Default.(string)
// proxyDescLocalIP is the schema descriptor for local_ip field.
proxyDescLocalIP := proxyFields[2].Descriptor()
// proxy.DefaultLocalIP holds the default value on creation for the local_ip field.
proxy.DefaultLocalIP = proxyDescLocalIP.Default.(string)
// proxyDescRemotePort is the schema descriptor for remote_port field.
proxyDescRemotePort := proxyFields[4].Descriptor()
// proxy.DefaultRemotePort holds the default value on creation for the remote_port field.
proxy.DefaultRemotePort = proxyDescRemotePort.Default.(int)
// proxyDescStatus is the schema descriptor for status field.
proxyDescStatus := proxyFields[5].Descriptor()
// proxy.DefaultStatus holds the default value on creation for the status field.
proxy.DefaultStatus = proxyDescStatus.Default.(string)
// proxyDescCustomDomains is the schema descriptor for custom_domains field.
proxyDescCustomDomains := proxyFields[6].Descriptor()
// proxy.DefaultCustomDomains holds the default value on creation for the custom_domains field.
proxy.DefaultCustomDomains = proxyDescCustomDomains.Default.(string)
// proxyDescMetadata is the schema descriptor for metadata field.
proxyDescMetadata := proxyFields[7].Descriptor()
// proxy.DefaultMetadata holds the default value on creation for the metadata field.
proxy.DefaultMetadata = proxyDescMetadata.Default.(string)
// proxyDescClientID is the schema descriptor for client_id field.
proxyDescClientID := proxyFields[8].Descriptor()
// proxy.DefaultClientID holds the default value on creation for the client_id field.
proxy.DefaultClientID = proxyDescClientID.Default.(int)
// proxyDescCreatedAt is the schema descriptor for created_at field.
proxyDescCreatedAt := proxyFields[9].Descriptor()
// proxy.DefaultCreatedAt holds the default value on creation for the created_at field.
proxy.DefaultCreatedAt = proxyDescCreatedAt.Default.(func() time.Time)
// proxyDescUpdatedAt is the schema descriptor for updated_at field.
proxyDescUpdatedAt := proxyFields[10].Descriptor()
// proxy.DefaultUpdatedAt holds the default value on creation for the updated_at field.
proxy.DefaultUpdatedAt = proxyDescUpdatedAt.Default.(func() time.Time)
// proxy.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
proxy.UpdateDefaultUpdatedAt = proxyDescUpdatedAt.UpdateDefault.(func() time.Time)
userFields := schema.User{}.Fields()
_ = userFields
// userDescName is the schema descriptor for name field.
userDescName := userFields[2].Descriptor()
// user.DefaultName holds the default value on creation for the name field.
user.DefaultName = userDescName.Default.(string)
// userDescRole is the schema descriptor for role field.
userDescRole := userFields[3].Descriptor()
// user.DefaultRole holds the default value on creation for the role field.
user.DefaultRole = userDescRole.Default.(string)
// userDescCreatedAt is the schema descriptor for created_at field.
userDescCreatedAt := userFields[4].Descriptor()
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
// userDescUpdatedAt is the schema descriptor for updated_at field.
userDescUpdatedAt := userFields[5].Descriptor()
// user.DefaultUpdatedAt holds the default value on creation for the updated_at field.
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time)
// user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
user.UpdateDefaultUpdatedAt = userDescUpdatedAt.UpdateDefault.(func() time.Time)
}
+10
View File
@@ -0,0 +1,10 @@
// Code generated by ent, DO NOT EDIT.
package runtime
// The schema-stitching logic is generated in github.com/fatedier/frp/pkg/db/ent/runtime.go
const (
Version = "v0.14.6" // Version of ent codegen.
Sum = "h1:/f2696BpwuWAEEG6PVGWflg6+Inrpq4pRWuNlWz/Skk=" // Sum of ent codegen.
)
+26
View File
@@ -0,0 +1,26 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
type FrpcClient struct {
ent.Schema
}
func (FrpcClient) Fields() []ent.Field {
return []ent.Field{
field.String("name").Unique(),
field.String("key").Default(""),
field.String("addr").Default(""),
field.Int("port").Default(0),
field.String("status").Default("offline"),
field.String("metadata").Default("{}"),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
field.Time("last_seen").Optional().Default(time.Now),
}
}
+28
View File
@@ -0,0 +1,28 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
type Proxy struct {
ent.Schema
}
func (Proxy) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
field.String("proxy_type").Default("tcp"),
field.String("local_ip").Default("127.0.0.1"),
field.Int("local_port"),
field.Int("remote_port").Default(0),
field.String("status").Default("inactive"),
field.String("custom_domains").Default(""),
field.String("metadata").Default("{}"),
field.Int("client_id").Default(0),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
}
}
+17
View File
@@ -0,0 +1,17 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
type ServerConfig struct {
ent.Schema
}
func (ServerConfig) Fields() []ent.Field {
return []ent.Field{
field.String("key").Unique(),
field.String("value"),
}
}
+23
View File
@@ -0,0 +1,23 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
type User struct {
ent.Schema
}
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("username").Unique(),
field.String("password"),
field.String("name").Default(""),
field.String("role").Default("admin"),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
}
}
+114
View File
@@ -0,0 +1,114 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
)
// ServerConfig is the model entity for the ServerConfig schema.
type ServerConfig struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Key holds the value of the "key" field.
Key string `json:"key,omitempty"`
// Value holds the value of the "value" field.
Value string `json:"value,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*ServerConfig) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case serverconfig.FieldID:
values[i] = new(sql.NullInt64)
case serverconfig.FieldKey, serverconfig.FieldValue:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ServerConfig fields.
func (_m *ServerConfig) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case serverconfig.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int(value.Int64)
case serverconfig.FieldKey:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field key", values[i])
} else if value.Valid {
_m.Key = value.String
}
case serverconfig.FieldValue:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field value", values[i])
} else if value.Valid {
_m.Value = value.String
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// GetValue returns the ent.Value that was dynamically selected and assigned to the ServerConfig.
// This includes values selected through modifiers, order, etc.
func (_m *ServerConfig) GetValue(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this ServerConfig.
// Note that you need to call ServerConfig.Unwrap() before calling this method if this ServerConfig
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *ServerConfig) Update() *ServerConfigUpdateOne {
return NewServerConfigClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the ServerConfig entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *ServerConfig) Unwrap() *ServerConfig {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: ServerConfig is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *ServerConfig) String() string {
var builder strings.Builder
builder.WriteString("ServerConfig(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("key=")
builder.WriteString(_m.Key)
builder.WriteString(", ")
builder.WriteString("value=")
builder.WriteString(_m.Value)
builder.WriteByte(')')
return builder.String()
}
// ServerConfigs is a parsable slice of ServerConfig.
type ServerConfigs []*ServerConfig
+55
View File
@@ -0,0 +1,55 @@
// Code generated by ent, DO NOT EDIT.
package serverconfig
import (
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the serverconfig type in the database.
Label = "server_config"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldKey holds the string denoting the key field in the database.
FieldKey = "key"
// FieldValue holds the string denoting the value field in the database.
FieldValue = "value"
// Table holds the table name of the serverconfig in the database.
Table = "server_configs"
)
// Columns holds all SQL columns for serverconfig fields.
var Columns = []string{
FieldID,
FieldKey,
FieldValue,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
// OrderOption defines the ordering options for the ServerConfig queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByKey orders the results by the key field.
func ByKey(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldKey, opts...).ToFunc()
}
// ByValue orders the results by the value field.
func ByValue(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldValue, opts...).ToFunc()
}
+208
View File
@@ -0,0 +1,208 @@
// Code generated by ent, DO NOT EDIT.
package serverconfig
import (
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldLTE(FieldID, id))
}
// Key applies equality check predicate on the "key" field. It's identical to KeyEQ.
func Key(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEQ(FieldKey, v))
}
// Value applies equality check predicate on the "value" field. It's identical to ValueEQ.
func Value(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEQ(FieldValue, v))
}
// KeyEQ applies the EQ predicate on the "key" field.
func KeyEQ(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEQ(FieldKey, v))
}
// KeyNEQ applies the NEQ predicate on the "key" field.
func KeyNEQ(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldNEQ(FieldKey, v))
}
// KeyIn applies the In predicate on the "key" field.
func KeyIn(vs ...string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldIn(FieldKey, vs...))
}
// KeyNotIn applies the NotIn predicate on the "key" field.
func KeyNotIn(vs ...string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldNotIn(FieldKey, vs...))
}
// KeyGT applies the GT predicate on the "key" field.
func KeyGT(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldGT(FieldKey, v))
}
// KeyGTE applies the GTE predicate on the "key" field.
func KeyGTE(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldGTE(FieldKey, v))
}
// KeyLT applies the LT predicate on the "key" field.
func KeyLT(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldLT(FieldKey, v))
}
// KeyLTE applies the LTE predicate on the "key" field.
func KeyLTE(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldLTE(FieldKey, v))
}
// KeyContains applies the Contains predicate on the "key" field.
func KeyContains(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldContains(FieldKey, v))
}
// KeyHasPrefix applies the HasPrefix predicate on the "key" field.
func KeyHasPrefix(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldHasPrefix(FieldKey, v))
}
// KeyHasSuffix applies the HasSuffix predicate on the "key" field.
func KeyHasSuffix(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldHasSuffix(FieldKey, v))
}
// KeyEqualFold applies the EqualFold predicate on the "key" field.
func KeyEqualFold(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEqualFold(FieldKey, v))
}
// KeyContainsFold applies the ContainsFold predicate on the "key" field.
func KeyContainsFold(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldContainsFold(FieldKey, v))
}
// ValueEQ applies the EQ predicate on the "value" field.
func ValueEQ(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEQ(FieldValue, v))
}
// ValueNEQ applies the NEQ predicate on the "value" field.
func ValueNEQ(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldNEQ(FieldValue, v))
}
// ValueIn applies the In predicate on the "value" field.
func ValueIn(vs ...string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldIn(FieldValue, vs...))
}
// ValueNotIn applies the NotIn predicate on the "value" field.
func ValueNotIn(vs ...string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldNotIn(FieldValue, vs...))
}
// ValueGT applies the GT predicate on the "value" field.
func ValueGT(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldGT(FieldValue, v))
}
// ValueGTE applies the GTE predicate on the "value" field.
func ValueGTE(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldGTE(FieldValue, v))
}
// ValueLT applies the LT predicate on the "value" field.
func ValueLT(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldLT(FieldValue, v))
}
// ValueLTE applies the LTE predicate on the "value" field.
func ValueLTE(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldLTE(FieldValue, v))
}
// ValueContains applies the Contains predicate on the "value" field.
func ValueContains(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldContains(FieldValue, v))
}
// ValueHasPrefix applies the HasPrefix predicate on the "value" field.
func ValueHasPrefix(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldHasPrefix(FieldValue, v))
}
// ValueHasSuffix applies the HasSuffix predicate on the "value" field.
func ValueHasSuffix(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldHasSuffix(FieldValue, v))
}
// ValueEqualFold applies the EqualFold predicate on the "value" field.
func ValueEqualFold(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldEqualFold(FieldValue, v))
}
// ValueContainsFold applies the ContainsFold predicate on the "value" field.
func ValueContainsFold(v string) predicate.ServerConfig {
return predicate.ServerConfig(sql.FieldContainsFold(FieldValue, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.ServerConfig) predicate.ServerConfig {
return predicate.ServerConfig(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.ServerConfig) predicate.ServerConfig {
return predicate.ServerConfig(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.ServerConfig) predicate.ServerConfig {
return predicate.ServerConfig(sql.NotPredicates(p))
}
+196
View File
@@ -0,0 +1,196 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
)
// ServerConfigCreate is the builder for creating a ServerConfig entity.
type ServerConfigCreate struct {
config
mutation *ServerConfigMutation
hooks []Hook
}
// SetKey sets the "key" field.
func (_c *ServerConfigCreate) SetKey(v string) *ServerConfigCreate {
_c.mutation.SetKey(v)
return _c
}
// SetValue sets the "value" field.
func (_c *ServerConfigCreate) SetValue(v string) *ServerConfigCreate {
_c.mutation.SetValue(v)
return _c
}
// Mutation returns the ServerConfigMutation object of the builder.
func (_c *ServerConfigCreate) Mutation() *ServerConfigMutation {
return _c.mutation
}
// Save creates the ServerConfig in the database.
func (_c *ServerConfigCreate) Save(ctx context.Context) (*ServerConfig, error) {
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ServerConfigCreate) SaveX(ctx context.Context) *ServerConfig {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ServerConfigCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ServerConfigCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ServerConfigCreate) check() error {
if _, ok := _c.mutation.Key(); !ok {
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "ServerConfig.key"`)}
}
if _, ok := _c.mutation.Value(); !ok {
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "ServerConfig.value"`)}
}
return nil
}
func (_c *ServerConfigCreate) sqlSave(ctx context.Context) (*ServerConfig, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *ServerConfigCreate) createSpec() (*ServerConfig, *sqlgraph.CreateSpec) {
var (
_node = &ServerConfig{config: _c.config}
_spec = sqlgraph.NewCreateSpec(serverconfig.Table, sqlgraph.NewFieldSpec(serverconfig.FieldID, field.TypeInt))
)
if value, ok := _c.mutation.Key(); ok {
_spec.SetField(serverconfig.FieldKey, field.TypeString, value)
_node.Key = value
}
if value, ok := _c.mutation.Value(); ok {
_spec.SetField(serverconfig.FieldValue, field.TypeString, value)
_node.Value = value
}
return _node, _spec
}
// ServerConfigCreateBulk is the builder for creating many ServerConfig entities in bulk.
type ServerConfigCreateBulk struct {
config
err error
builders []*ServerConfigCreate
}
// Save creates the ServerConfig entities in the database.
func (_c *ServerConfigCreateBulk) Save(ctx context.Context) ([]*ServerConfig, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*ServerConfig, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*ServerConfigMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *ServerConfigCreateBulk) SaveX(ctx context.Context) []*ServerConfig {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ServerConfigCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ServerConfigCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
+88
View File
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
)
// ServerConfigDelete is the builder for deleting a ServerConfig entity.
type ServerConfigDelete struct {
config
hooks []Hook
mutation *ServerConfigMutation
}
// Where appends a list predicates to the ServerConfigDelete builder.
func (_d *ServerConfigDelete) Where(ps ...predicate.ServerConfig) *ServerConfigDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *ServerConfigDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ServerConfigDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *ServerConfigDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(serverconfig.Table, sqlgraph.NewFieldSpec(serverconfig.FieldID, field.TypeInt))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// ServerConfigDeleteOne is the builder for deleting a single ServerConfig entity.
type ServerConfigDeleteOne struct {
_d *ServerConfigDelete
}
// Where appends a list predicates to the ServerConfigDelete builder.
func (_d *ServerConfigDeleteOne) Where(ps ...predicate.ServerConfig) *ServerConfigDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *ServerConfigDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{serverconfig.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ServerConfigDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+527
View File
@@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
)
// ServerConfigQuery is the builder for querying ServerConfig entities.
type ServerConfigQuery struct {
config
ctx *QueryContext
order []serverconfig.OrderOption
inters []Interceptor
predicates []predicate.ServerConfig
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ServerConfigQuery builder.
func (_q *ServerConfigQuery) Where(ps ...predicate.ServerConfig) *ServerConfigQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *ServerConfigQuery) Limit(limit int) *ServerConfigQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *ServerConfigQuery) Offset(offset int) *ServerConfigQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *ServerConfigQuery) Unique(unique bool) *ServerConfigQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *ServerConfigQuery) Order(o ...serverconfig.OrderOption) *ServerConfigQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first ServerConfig entity from the query.
// Returns a *NotFoundError when no ServerConfig was found.
func (_q *ServerConfigQuery) First(ctx context.Context) (*ServerConfig, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{serverconfig.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *ServerConfigQuery) FirstX(ctx context.Context) *ServerConfig {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first ServerConfig ID from the query.
// Returns a *NotFoundError when no ServerConfig ID was found.
func (_q *ServerConfigQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{serverconfig.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *ServerConfigQuery) FirstIDX(ctx context.Context) int {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single ServerConfig entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one ServerConfig entity is found.
// Returns a *NotFoundError when no ServerConfig entities are found.
func (_q *ServerConfigQuery) Only(ctx context.Context) (*ServerConfig, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{serverconfig.Label}
default:
return nil, &NotSingularError{serverconfig.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *ServerConfigQuery) OnlyX(ctx context.Context) *ServerConfig {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only ServerConfig ID in the query.
// Returns a *NotSingularError when more than one ServerConfig ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *ServerConfigQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{serverconfig.Label}
default:
err = &NotSingularError{serverconfig.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *ServerConfigQuery) OnlyIDX(ctx context.Context) int {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of ServerConfigs.
func (_q *ServerConfigQuery) All(ctx context.Context) ([]*ServerConfig, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*ServerConfig, *ServerConfigQuery]()
return withInterceptors[[]*ServerConfig](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *ServerConfigQuery) AllX(ctx context.Context) []*ServerConfig {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of ServerConfig IDs.
func (_q *ServerConfigQuery) IDs(ctx context.Context) (ids []int, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(serverconfig.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *ServerConfigQuery) IDsX(ctx context.Context) []int {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *ServerConfigQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*ServerConfigQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *ServerConfigQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *ServerConfigQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *ServerConfigQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ServerConfigQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *ServerConfigQuery) Clone() *ServerConfigQuery {
if _q == nil {
return nil
}
return &ServerConfigQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]serverconfig.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.ServerConfig{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Key string `json:"key,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.ServerConfig.Query().
// GroupBy(serverconfig.FieldKey).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *ServerConfigQuery) GroupBy(field string, fields ...string) *ServerConfigGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &ServerConfigGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = serverconfig.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Key string `json:"key,omitempty"`
// }
//
// client.ServerConfig.Query().
// Select(serverconfig.FieldKey).
// Scan(ctx, &v)
func (_q *ServerConfigQuery) Select(fields ...string) *ServerConfigSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &ServerConfigSelect{ServerConfigQuery: _q}
sbuild.label = serverconfig.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ServerConfigSelect configured with the given aggregations.
func (_q *ServerConfigQuery) Aggregate(fns ...AggregateFunc) *ServerConfigSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *ServerConfigQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !serverconfig.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *ServerConfigQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ServerConfig, error) {
var (
nodes = []*ServerConfig{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*ServerConfig).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &ServerConfig{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *ServerConfigQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *ServerConfigQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(serverconfig.Table, serverconfig.Columns, sqlgraph.NewFieldSpec(serverconfig.FieldID, field.TypeInt))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, serverconfig.FieldID)
for i := range fields {
if fields[i] != serverconfig.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *ServerConfigQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(serverconfig.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = serverconfig.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ServerConfigGroupBy is the group-by builder for ServerConfig entities.
type ServerConfigGroupBy struct {
selector
build *ServerConfigQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *ServerConfigGroupBy) Aggregate(fns ...AggregateFunc) *ServerConfigGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *ServerConfigGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ServerConfigQuery, *ServerConfigGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *ServerConfigGroupBy) sqlScan(ctx context.Context, root *ServerConfigQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ServerConfigSelect is the builder for selecting fields of ServerConfig entities.
type ServerConfigSelect struct {
*ServerConfigQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *ServerConfigSelect) Aggregate(fns ...AggregateFunc) *ServerConfigSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *ServerConfigSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ServerConfigQuery, *ServerConfigSelect](ctx, _s.ServerConfigQuery, _s, _s.inters, v)
}
func (_s *ServerConfigSelect) sqlScan(ctx context.Context, root *ServerConfigQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
+243
View File
@@ -0,0 +1,243 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/serverconfig"
)
// ServerConfigUpdate is the builder for updating ServerConfig entities.
type ServerConfigUpdate struct {
config
hooks []Hook
mutation *ServerConfigMutation
}
// Where appends a list predicates to the ServerConfigUpdate builder.
func (_u *ServerConfigUpdate) Where(ps ...predicate.ServerConfig) *ServerConfigUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetKey sets the "key" field.
func (_u *ServerConfigUpdate) SetKey(v string) *ServerConfigUpdate {
_u.mutation.SetKey(v)
return _u
}
// SetNillableKey sets the "key" field if the given value is not nil.
func (_u *ServerConfigUpdate) SetNillableKey(v *string) *ServerConfigUpdate {
if v != nil {
_u.SetKey(*v)
}
return _u
}
// SetValue sets the "value" field.
func (_u *ServerConfigUpdate) SetValue(v string) *ServerConfigUpdate {
_u.mutation.SetValue(v)
return _u
}
// SetNillableValue sets the "value" field if the given value is not nil.
func (_u *ServerConfigUpdate) SetNillableValue(v *string) *ServerConfigUpdate {
if v != nil {
_u.SetValue(*v)
}
return _u
}
// Mutation returns the ServerConfigMutation object of the builder.
func (_u *ServerConfigUpdate) Mutation() *ServerConfigMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ServerConfigUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ServerConfigUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ServerConfigUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ServerConfigUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ServerConfigUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(serverconfig.Table, serverconfig.Columns, sqlgraph.NewFieldSpec(serverconfig.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Key(); ok {
_spec.SetField(serverconfig.FieldKey, field.TypeString, value)
}
if value, ok := _u.mutation.Value(); ok {
_spec.SetField(serverconfig.FieldValue, field.TypeString, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{serverconfig.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ServerConfigUpdateOne is the builder for updating a single ServerConfig entity.
type ServerConfigUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ServerConfigMutation
}
// SetKey sets the "key" field.
func (_u *ServerConfigUpdateOne) SetKey(v string) *ServerConfigUpdateOne {
_u.mutation.SetKey(v)
return _u
}
// SetNillableKey sets the "key" field if the given value is not nil.
func (_u *ServerConfigUpdateOne) SetNillableKey(v *string) *ServerConfigUpdateOne {
if v != nil {
_u.SetKey(*v)
}
return _u
}
// SetValue sets the "value" field.
func (_u *ServerConfigUpdateOne) SetValue(v string) *ServerConfigUpdateOne {
_u.mutation.SetValue(v)
return _u
}
// SetNillableValue sets the "value" field if the given value is not nil.
func (_u *ServerConfigUpdateOne) SetNillableValue(v *string) *ServerConfigUpdateOne {
if v != nil {
_u.SetValue(*v)
}
return _u
}
// Mutation returns the ServerConfigMutation object of the builder.
func (_u *ServerConfigUpdateOne) Mutation() *ServerConfigMutation {
return _u.mutation
}
// Where appends a list predicates to the ServerConfigUpdate builder.
func (_u *ServerConfigUpdateOne) Where(ps ...predicate.ServerConfig) *ServerConfigUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ServerConfigUpdateOne) Select(field string, fields ...string) *ServerConfigUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated ServerConfig entity.
func (_u *ServerConfigUpdateOne) Save(ctx context.Context) (*ServerConfig, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ServerConfigUpdateOne) SaveX(ctx context.Context) *ServerConfig {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ServerConfigUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ServerConfigUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ServerConfigUpdateOne) sqlSave(ctx context.Context) (_node *ServerConfig, err error) {
_spec := sqlgraph.NewUpdateSpec(serverconfig.Table, serverconfig.Columns, sqlgraph.NewFieldSpec(serverconfig.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ServerConfig.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, serverconfig.FieldID)
for _, f := range fields {
if !serverconfig.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != serverconfig.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Key(); ok {
_spec.SetField(serverconfig.FieldKey, field.TypeString, value)
}
if value, ok := _u.mutation.Value(); ok {
_spec.SetField(serverconfig.FieldValue, field.TypeString, value)
}
_node = &ServerConfig{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{serverconfig.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+219
View File
@@ -0,0 +1,219 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"sync"
"entgo.io/ent/dialect"
)
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// FrpcClient is the client for interacting with the FrpcClient builders.
FrpcClient *FrpcClientClient
// Proxy is the client for interacting with the Proxy builders.
Proxy *ProxyClient
// ServerConfig is the client for interacting with the ServerConfig builders.
ServerConfig *ServerConfigClient
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// ctx lives for the life of the transaction. It is
// the same context used by the underlying connection.
ctx context.Context
}
type (
// Committer is the interface that wraps the Commit method.
Committer interface {
Commit(context.Context, *Tx) error
}
// The CommitFunc type is an adapter to allow the use of ordinary
// function as a Committer. If f is a function with the appropriate
// signature, CommitFunc(f) is a Committer that calls f.
CommitFunc func(context.Context, *Tx) error
// CommitHook defines the "commit middleware". A function that gets a Committer
// and returns a Committer. For example:
//
// hook := func(next ent.Committer) ent.Committer {
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Commit(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
CommitHook func(Committer) Committer
)
// Commit calls f(ctx, m).
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Commit commits the transaction.
func (tx *Tx) Commit() error {
txDriver := tx.config.driver.(*txDriver)
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
return txDriver.tx.Commit()
})
txDriver.mu.Lock()
hooks := append([]CommitHook(nil), txDriver.onCommit...)
txDriver.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Commit(tx.ctx, tx)
}
// OnCommit adds a hook to call on commit.
func (tx *Tx) OnCommit(f CommitHook) {
txDriver := tx.config.driver.(*txDriver)
txDriver.mu.Lock()
txDriver.onCommit = append(txDriver.onCommit, f)
txDriver.mu.Unlock()
}
type (
// Rollbacker is the interface that wraps the Rollback method.
Rollbacker interface {
Rollback(context.Context, *Tx) error
}
// The RollbackFunc type is an adapter to allow the use of ordinary
// function as a Rollbacker. If f is a function with the appropriate
// signature, RollbackFunc(f) is a Rollbacker that calls f.
RollbackFunc func(context.Context, *Tx) error
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
// and returns a Rollbacker. For example:
//
// hook := func(next ent.Rollbacker) ent.Rollbacker {
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Rollback(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
RollbackHook func(Rollbacker) Rollbacker
)
// Rollback calls f(ctx, m).
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Rollback rollbacks the transaction.
func (tx *Tx) Rollback() error {
txDriver := tx.config.driver.(*txDriver)
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
return txDriver.tx.Rollback()
})
txDriver.mu.Lock()
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
txDriver.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Rollback(tx.ctx, tx)
}
// OnRollback adds a hook to call on rollback.
func (tx *Tx) OnRollback(f RollbackHook) {
txDriver := tx.config.driver.(*txDriver)
txDriver.mu.Lock()
txDriver.onRollback = append(txDriver.onRollback, f)
txDriver.mu.Unlock()
}
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {
tx.FrpcClient = NewFrpcClientClient(tx.config)
tx.Proxy = NewProxyClient(tx.config)
tx.ServerConfig = NewServerConfigClient(tx.config)
tx.User = NewUserClient(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: FrpcClient.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.
type txDriver struct {
// the driver we started the transaction from.
drv dialect.Driver
// tx is the underlying transaction.
tx dialect.Tx
// completion hooks.
mu sync.Mutex
onCommit []CommitHook
onRollback []RollbackHook
}
// newTx creates a new transactional driver.
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
tx, err := drv.Tx(ctx)
if err != nil {
return nil, err
}
return &txDriver{tx: tx, drv: drv}, nil
}
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
// from the internal builders. Should be called only by the internal builders.
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
// Dialect returns the dialect of the driver we started the transaction from.
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
// Close is a nop close.
func (*txDriver) Close() error { return nil }
// Commit is a nop commit for the internal builders.
// User must call `Tx.Commit` in order to commit the transaction.
func (*txDriver) Commit() error { return nil }
// Rollback is a nop rollback for the internal builders.
// User must call `Tx.Rollback` in order to rollback the transaction.
func (*txDriver) Rollback() error { return nil }
// Exec calls tx.Exec.
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
return tx.tx.Exec(ctx, query, args, v)
}
// Query calls tx.Query.
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
return tx.tx.Query(ctx, query, args, v)
}
var _ dialect.Driver = (*txDriver)(nil)
+161
View File
@@ -0,0 +1,161 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// User is the model entity for the User schema.
type User struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Username holds the value of the "username" field.
Username string `json:"username,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"password,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Role holds the value of the "role" field.
Role string `json:"role,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case user.FieldID:
values[i] = new(sql.NullInt64)
case user.FieldUsername, user.FieldPassword, user.FieldName, user.FieldRole:
values[i] = new(sql.NullString)
case user.FieldCreatedAt, user.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the User fields.
func (_m *User) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case user.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int(value.Int64)
case user.FieldUsername:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field username", values[i])
} else if value.Valid {
_m.Username = value.String
}
case user.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
_m.Password = value.String
}
case user.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case user.FieldRole:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field role", values[i])
} else if value.Valid {
_m.Role = value.String
}
case user.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case user.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the User.
// This includes values selected through modifiers, order, etc.
func (_m *User) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this User.
// Note that you need to call User.Unwrap() before calling this method if this User
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *User) Update() *UserUpdateOne {
return NewUserClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the User entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *User) Unwrap() *User {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: User is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *User) String() string {
var builder strings.Builder
builder.WriteString("User(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("username=")
builder.WriteString(_m.Username)
builder.WriteString(", ")
builder.WriteString("password=")
builder.WriteString(_m.Password)
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("role=")
builder.WriteString(_m.Role)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Users is a parsable slice of User.
type Users []*User
+102
View File
@@ -0,0 +1,102 @@
// Code generated by ent, DO NOT EDIT.
package user
import (
"time"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the user type in the database.
Label = "user"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldUsername holds the string denoting the username field in the database.
FieldUsername = "username"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldRole holds the string denoting the role field in the database.
FieldRole = "role"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// Table holds the table name of the user in the database.
Table = "users"
)
// Columns holds all SQL columns for user fields.
var Columns = []string{
FieldID,
FieldUsername,
FieldPassword,
FieldName,
FieldRole,
FieldCreatedAt,
FieldUpdatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultName holds the default value on creation for the "name" field.
DefaultName string
// DefaultRole holds the default value on creation for the "role" field.
DefaultRole string
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the User queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByUsername orders the results by the username field.
func ByUsername(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUsername, opts...).ToFunc()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByRole orders the results by the role field.
func ByRole(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRole, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
+440
View File
@@ -0,0 +1,440 @@
// Code generated by ent, DO NOT EDIT.
package user
import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/fatedier/frp/pkg/db/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.User {
return predicate.User(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.User {
return predicate.User(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.User {
return predicate.User(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.User {
return predicate.User(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.User {
return predicate.User(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.User {
return predicate.User(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.User {
return predicate.User(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.User {
return predicate.User(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.User {
return predicate.User(sql.FieldLTE(FieldID, id))
}
// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ.
func Username(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldUsername, v))
}
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
func Password(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldPassword, v))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldName, v))
}
// Role applies equality check predicate on the "role" field. It's identical to RoleEQ.
func Role(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldRole, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
}
// UsernameEQ applies the EQ predicate on the "username" field.
func UsernameEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldUsername, v))
}
// UsernameNEQ applies the NEQ predicate on the "username" field.
func UsernameNEQ(v string) predicate.User {
return predicate.User(sql.FieldNEQ(FieldUsername, v))
}
// UsernameIn applies the In predicate on the "username" field.
func UsernameIn(vs ...string) predicate.User {
return predicate.User(sql.FieldIn(FieldUsername, vs...))
}
// UsernameNotIn applies the NotIn predicate on the "username" field.
func UsernameNotIn(vs ...string) predicate.User {
return predicate.User(sql.FieldNotIn(FieldUsername, vs...))
}
// UsernameGT applies the GT predicate on the "username" field.
func UsernameGT(v string) predicate.User {
return predicate.User(sql.FieldGT(FieldUsername, v))
}
// UsernameGTE applies the GTE predicate on the "username" field.
func UsernameGTE(v string) predicate.User {
return predicate.User(sql.FieldGTE(FieldUsername, v))
}
// UsernameLT applies the LT predicate on the "username" field.
func UsernameLT(v string) predicate.User {
return predicate.User(sql.FieldLT(FieldUsername, v))
}
// UsernameLTE applies the LTE predicate on the "username" field.
func UsernameLTE(v string) predicate.User {
return predicate.User(sql.FieldLTE(FieldUsername, v))
}
// UsernameContains applies the Contains predicate on the "username" field.
func UsernameContains(v string) predicate.User {
return predicate.User(sql.FieldContains(FieldUsername, v))
}
// UsernameHasPrefix applies the HasPrefix predicate on the "username" field.
func UsernameHasPrefix(v string) predicate.User {
return predicate.User(sql.FieldHasPrefix(FieldUsername, v))
}
// UsernameHasSuffix applies the HasSuffix predicate on the "username" field.
func UsernameHasSuffix(v string) predicate.User {
return predicate.User(sql.FieldHasSuffix(FieldUsername, v))
}
// UsernameEqualFold applies the EqualFold predicate on the "username" field.
func UsernameEqualFold(v string) predicate.User {
return predicate.User(sql.FieldEqualFold(FieldUsername, v))
}
// UsernameContainsFold applies the ContainsFold predicate on the "username" field.
func UsernameContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldUsername, v))
}
// PasswordEQ applies the EQ predicate on the "password" field.
func PasswordEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldPassword, v))
}
// PasswordNEQ applies the NEQ predicate on the "password" field.
func PasswordNEQ(v string) predicate.User {
return predicate.User(sql.FieldNEQ(FieldPassword, v))
}
// PasswordIn applies the In predicate on the "password" field.
func PasswordIn(vs ...string) predicate.User {
return predicate.User(sql.FieldIn(FieldPassword, vs...))
}
// PasswordNotIn applies the NotIn predicate on the "password" field.
func PasswordNotIn(vs ...string) predicate.User {
return predicate.User(sql.FieldNotIn(FieldPassword, vs...))
}
// PasswordGT applies the GT predicate on the "password" field.
func PasswordGT(v string) predicate.User {
return predicate.User(sql.FieldGT(FieldPassword, v))
}
// PasswordGTE applies the GTE predicate on the "password" field.
func PasswordGTE(v string) predicate.User {
return predicate.User(sql.FieldGTE(FieldPassword, v))
}
// PasswordLT applies the LT predicate on the "password" field.
func PasswordLT(v string) predicate.User {
return predicate.User(sql.FieldLT(FieldPassword, v))
}
// PasswordLTE applies the LTE predicate on the "password" field.
func PasswordLTE(v string) predicate.User {
return predicate.User(sql.FieldLTE(FieldPassword, v))
}
// PasswordContains applies the Contains predicate on the "password" field.
func PasswordContains(v string) predicate.User {
return predicate.User(sql.FieldContains(FieldPassword, v))
}
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
func PasswordHasPrefix(v string) predicate.User {
return predicate.User(sql.FieldHasPrefix(FieldPassword, v))
}
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
func PasswordHasSuffix(v string) predicate.User {
return predicate.User(sql.FieldHasSuffix(FieldPassword, v))
}
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
func PasswordEqualFold(v string) predicate.User {
return predicate.User(sql.FieldEqualFold(FieldPassword, v))
}
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
func PasswordContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldPassword, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.User {
return predicate.User(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.User {
return predicate.User(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.User {
return predicate.User(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.User {
return predicate.User(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.User {
return predicate.User(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.User {
return predicate.User(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.User {
return predicate.User(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.User {
return predicate.User(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.User {
return predicate.User(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.User {
return predicate.User(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.User {
return predicate.User(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldName, v))
}
// RoleEQ applies the EQ predicate on the "role" field.
func RoleEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldRole, v))
}
// RoleNEQ applies the NEQ predicate on the "role" field.
func RoleNEQ(v string) predicate.User {
return predicate.User(sql.FieldNEQ(FieldRole, v))
}
// RoleIn applies the In predicate on the "role" field.
func RoleIn(vs ...string) predicate.User {
return predicate.User(sql.FieldIn(FieldRole, vs...))
}
// RoleNotIn applies the NotIn predicate on the "role" field.
func RoleNotIn(vs ...string) predicate.User {
return predicate.User(sql.FieldNotIn(FieldRole, vs...))
}
// RoleGT applies the GT predicate on the "role" field.
func RoleGT(v string) predicate.User {
return predicate.User(sql.FieldGT(FieldRole, v))
}
// RoleGTE applies the GTE predicate on the "role" field.
func RoleGTE(v string) predicate.User {
return predicate.User(sql.FieldGTE(FieldRole, v))
}
// RoleLT applies the LT predicate on the "role" field.
func RoleLT(v string) predicate.User {
return predicate.User(sql.FieldLT(FieldRole, v))
}
// RoleLTE applies the LTE predicate on the "role" field.
func RoleLTE(v string) predicate.User {
return predicate.User(sql.FieldLTE(FieldRole, v))
}
// RoleContains applies the Contains predicate on the "role" field.
func RoleContains(v string) predicate.User {
return predicate.User(sql.FieldContains(FieldRole, v))
}
// RoleHasPrefix applies the HasPrefix predicate on the "role" field.
func RoleHasPrefix(v string) predicate.User {
return predicate.User(sql.FieldHasPrefix(FieldRole, v))
}
// RoleHasSuffix applies the HasSuffix predicate on the "role" field.
func RoleHasSuffix(v string) predicate.User {
return predicate.User(sql.FieldHasSuffix(FieldRole, v))
}
// RoleEqualFold applies the EqualFold predicate on the "role" field.
func RoleEqualFold(v string) predicate.User {
return predicate.User(sql.FieldEqualFold(FieldRole, v))
}
// RoleContainsFold applies the ContainsFold predicate on the "role" field.
func RoleContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldRole, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.User {
return predicate.User(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.User {
return predicate.User(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.User {
return predicate.User(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.User {
return predicate.User(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.User {
return predicate.User(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.User {
return predicate.User(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.User {
return predicate.User(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.User {
return predicate.User(sql.FieldLTE(FieldUpdatedAt, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.User) predicate.User {
return predicate.User(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.User) predicate.User {
return predicate.User(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.User) predicate.User {
return predicate.User(sql.NotPredicates(p))
}
+303
View File
@@ -0,0 +1,303 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// UserCreate is the builder for creating a User entity.
type UserCreate struct {
config
mutation *UserMutation
hooks []Hook
}
// SetUsername sets the "username" field.
func (_c *UserCreate) SetUsername(v string) *UserCreate {
_c.mutation.SetUsername(v)
return _c
}
// SetPassword sets the "password" field.
func (_c *UserCreate) SetPassword(v string) *UserCreate {
_c.mutation.SetPassword(v)
return _c
}
// SetName sets the "name" field.
func (_c *UserCreate) SetName(v string) *UserCreate {
_c.mutation.SetName(v)
return _c
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_c *UserCreate) SetNillableName(v *string) *UserCreate {
if v != nil {
_c.SetName(*v)
}
return _c
}
// SetRole sets the "role" field.
func (_c *UserCreate) SetRole(v string) *UserCreate {
_c.mutation.SetRole(v)
return _c
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (_c *UserCreate) SetNillableRole(v *string) *UserCreate {
if v != nil {
_c.SetRole(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *UserCreate) SetNillableCreatedAt(v *time.Time) *UserCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *UserCreate) SetUpdatedAt(v time.Time) *UserCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *UserCreate) SetNillableUpdatedAt(v *time.Time) *UserCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// Mutation returns the UserMutation object of the builder.
func (_c *UserCreate) Mutation() *UserMutation {
return _c.mutation
}
// Save creates the User in the database.
func (_c *UserCreate) Save(ctx context.Context) (*User, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *UserCreate) SaveX(ctx context.Context) *User {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UserCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UserCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *UserCreate) defaults() {
if _, ok := _c.mutation.Name(); !ok {
v := user.DefaultName
_c.mutation.SetName(v)
}
if _, ok := _c.mutation.Role(); !ok {
v := user.DefaultRole
_c.mutation.SetRole(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := user.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := user.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *UserCreate) check() error {
if _, ok := _c.mutation.Username(); !ok {
return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "User.username"`)}
}
if _, ok := _c.mutation.Password(); !ok {
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "User.password"`)}
}
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "User.name"`)}
}
if _, ok := _c.mutation.Role(); !ok {
return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "User.role"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)}
}
return nil
}
func (_c *UserCreate) sqlSave(ctx context.Context) (*User, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
var (
_node = &User{config: _c.config}
_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
)
if value, ok := _c.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
_node.Username = value
}
if value, ok := _c.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value)
_node.Password = value
}
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(user.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.Role(); ok {
_spec.SetField(user.FieldRole, field.TypeString, value)
_node.Role = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
return _node, _spec
}
// UserCreateBulk is the builder for creating many User entities in bulk.
type UserCreateBulk struct {
config
err error
builders []*UserCreate
}
// Save creates the User entities in the database.
func (_c *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*User, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*UserMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *UserCreateBulk) SaveX(ctx context.Context) []*User {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UserCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UserCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
+88
View File
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// UserDelete is the builder for deleting a User entity.
type UserDelete struct {
config
hooks []Hook
mutation *UserMutation
}
// Where appends a list predicates to the UserDelete builder.
func (_d *UserDelete) Where(ps ...predicate.User) *UserDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *UserDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *UserDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *UserDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// UserDeleteOne is the builder for deleting a single User entity.
type UserDeleteOne struct {
_d *UserDelete
}
// Where appends a list predicates to the UserDelete builder.
func (_d *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *UserDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{user.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *UserDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+527
View File
@@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// UserQuery is the builder for querying User entities.
type UserQuery struct {
config
ctx *QueryContext
order []user.OrderOption
inters []Interceptor
predicates []predicate.User
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the UserQuery builder.
func (_q *UserQuery) Where(ps ...predicate.User) *UserQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *UserQuery) Limit(limit int) *UserQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *UserQuery) Offset(offset int) *UserQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *UserQuery) Unique(unique bool) *UserQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *UserQuery) Order(o ...user.OrderOption) *UserQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first User entity from the query.
// Returns a *NotFoundError when no User was found.
func (_q *UserQuery) First(ctx context.Context) (*User, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{user.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *UserQuery) FirstX(ctx context.Context) *User {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first User ID from the query.
// Returns a *NotFoundError when no User ID was found.
func (_q *UserQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{user.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *UserQuery) FirstIDX(ctx context.Context) int {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single User entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one User entity is found.
// Returns a *NotFoundError when no User entities are found.
func (_q *UserQuery) Only(ctx context.Context) (*User, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{user.Label}
default:
return nil, &NotSingularError{user.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *UserQuery) OnlyX(ctx context.Context) *User {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only User ID in the query.
// Returns a *NotSingularError when more than one User ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{user.Label}
default:
err = &NotSingularError{user.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *UserQuery) OnlyIDX(ctx context.Context) int {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of Users.
func (_q *UserQuery) All(ctx context.Context) ([]*User, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*User, *UserQuery]()
return withInterceptors[[]*User](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *UserQuery) AllX(ctx context.Context) []*User {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of User IDs.
func (_q *UserQuery) IDs(ctx context.Context) (ids []int, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(user.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *UserQuery) IDsX(ctx context.Context) []int {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *UserQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*UserQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *UserQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *UserQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *UserQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the UserQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *UserQuery) Clone() *UserQuery {
if _q == nil {
return nil
}
return &UserQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]user.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.User{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Username string `json:"username,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.User.Query().
// GroupBy(user.FieldUsername).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &UserGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = user.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Username string `json:"username,omitempty"`
// }
//
// client.User.Query().
// Select(user.FieldUsername).
// Scan(ctx, &v)
func (_q *UserQuery) Select(fields ...string) *UserSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &UserSelect{UserQuery: _q}
sbuild.label = user.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a UserSelect configured with the given aggregations.
func (_q *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *UserQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !user.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
var (
nodes = []*User{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*User).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &User{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *UserQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
for i := range fields {
if fields[i] != user.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(user.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = user.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// UserGroupBy is the group-by builder for User entities.
type UserGroupBy struct {
selector
build *UserQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *UserGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// UserSelect is the builder for selecting fields of User entities.
type UserSelect struct {
*UserQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *UserSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*UserQuery, *UserSelect](ctx, _s.UserQuery, _s, _s.inters, v)
}
func (_s *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
+382
View File
@@ -0,0 +1,382 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/fatedier/frp/pkg/db/ent/predicate"
"github.com/fatedier/frp/pkg/db/ent/user"
)
// UserUpdate is the builder for updating User entities.
type UserUpdate struct {
config
hooks []Hook
mutation *UserMutation
}
// Where appends a list predicates to the UserUpdate builder.
func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUsername sets the "username" field.
func (_u *UserUpdate) SetUsername(v string) *UserUpdate {
_u.mutation.SetUsername(v)
return _u
}
// SetNillableUsername sets the "username" field if the given value is not nil.
func (_u *UserUpdate) SetNillableUsername(v *string) *UserUpdate {
if v != nil {
_u.SetUsername(*v)
}
return _u
}
// SetPassword sets the "password" field.
func (_u *UserUpdate) SetPassword(v string) *UserUpdate {
_u.mutation.SetPassword(v)
return _u
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (_u *UserUpdate) SetNillablePassword(v *string) *UserUpdate {
if v != nil {
_u.SetPassword(*v)
}
return _u
}
// SetName sets the "name" field.
func (_u *UserUpdate) SetName(v string) *UserUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *UserUpdate) SetNillableName(v *string) *UserUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetRole sets the "role" field.
func (_u *UserUpdate) SetRole(v string) *UserUpdate {
_u.mutation.SetRole(v)
return _u
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (_u *UserUpdate) SetNillableRole(v *string) *UserUpdate {
if v != nil {
_u.SetRole(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *UserUpdate) SetCreatedAt(v time.Time) *UserUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *UserUpdate) SetNillableCreatedAt(v *time.Time) *UserUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the UserMutation object of the builder.
func (_u *UserUpdate) Mutation() *UserMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *UserUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *UserUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *UserUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *UserUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := user.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
}
if value, ok := _u.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(user.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Role(); ok {
_spec.SetField(user.FieldRole, field.TypeString, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// UserUpdateOne is the builder for updating a single User entity.
type UserUpdateOne struct {
config
fields []string
hooks []Hook
mutation *UserMutation
}
// SetUsername sets the "username" field.
func (_u *UserUpdateOne) SetUsername(v string) *UserUpdateOne {
_u.mutation.SetUsername(v)
return _u
}
// SetNillableUsername sets the "username" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableUsername(v *string) *UserUpdateOne {
if v != nil {
_u.SetUsername(*v)
}
return _u
}
// SetPassword sets the "password" field.
func (_u *UserUpdateOne) SetPassword(v string) *UserUpdateOne {
_u.mutation.SetPassword(v)
return _u
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillablePassword(v *string) *UserUpdateOne {
if v != nil {
_u.SetPassword(*v)
}
return _u
}
// SetName sets the "name" field.
func (_u *UserUpdateOne) SetName(v string) *UserUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableName(v *string) *UserUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetRole sets the "role" field.
func (_u *UserUpdateOne) SetRole(v string) *UserUpdateOne {
_u.mutation.SetRole(v)
return _u
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableRole(v *string) *UserUpdateOne {
if v != nil {
_u.SetRole(*v)
}
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *UserUpdateOne) SetCreatedAt(v time.Time) *UserUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableCreatedAt(v *time.Time) *UserUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the UserMutation object of the builder.
func (_u *UserUpdateOne) Mutation() *UserMutation {
return _u.mutation
}
// Where appends a list predicates to the UserUpdate builder.
func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated User entity.
func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *UserUpdateOne) SaveX(ctx context.Context) *User {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *UserUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *UserUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *UserUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := user.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
for _, f := range fields {
if !user.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != user.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Username(); ok {
_spec.SetField(user.FieldUsername, field.TypeString, value)
}
if value, ok := _u.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(user.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Role(); ok {
_spec.SetField(user.FieldRole, field.TypeString, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
_node = &User{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}