代码拉取完成,页面将自动刷新
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"log"
"reflect"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/migrate"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/deviceduration"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/devicedurationelephant"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/deviceevent"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/devicekpi"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/deviceofflinetime"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/deviceonlinetime"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/deviceontimedaily"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/deviceupstercycle"
"gitee.com/yuLingNet/simple-iot-data-rpc/ent/deviceupsterstatistics"
stdsql "database/sql"
)
// Client is the client that holds all ent builders.
type Client struct {
config
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// DeviceDuration is the client for interacting with the DeviceDuration builders.
DeviceDuration *DeviceDurationClient
// DeviceDurationElephant is the client for interacting with the DeviceDurationElephant builders.
DeviceDurationElephant *DeviceDurationElephantClient
// DeviceEvent is the client for interacting with the DeviceEvent builders.
DeviceEvent *DeviceEventClient
// DeviceKpi is the client for interacting with the DeviceKpi builders.
DeviceKpi *DeviceKpiClient
// DeviceOfflineTime is the client for interacting with the DeviceOfflineTime builders.
DeviceOfflineTime *DeviceOfflineTimeClient
// DeviceOnTimeDaily is the client for interacting with the DeviceOnTimeDaily builders.
DeviceOnTimeDaily *DeviceOnTimeDailyClient
// DeviceOnlineTime is the client for interacting with the DeviceOnlineTime builders.
DeviceOnlineTime *DeviceOnlineTimeClient
// DeviceUpsterCycle is the client for interacting with the DeviceUpsterCycle builders.
DeviceUpsterCycle *DeviceUpsterCycleClient
// DeviceUpsterStatistics is the client for interacting with the DeviceUpsterStatistics builders.
DeviceUpsterStatistics *DeviceUpsterStatisticsClient
}
// 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.DeviceDuration = NewDeviceDurationClient(c.config)
c.DeviceDurationElephant = NewDeviceDurationElephantClient(c.config)
c.DeviceEvent = NewDeviceEventClient(c.config)
c.DeviceKpi = NewDeviceKpiClient(c.config)
c.DeviceOfflineTime = NewDeviceOfflineTimeClient(c.config)
c.DeviceOnTimeDaily = NewDeviceOnTimeDailyClient(c.config)
c.DeviceOnlineTime = NewDeviceOnlineTimeClient(c.config)
c.DeviceUpsterCycle = NewDeviceUpsterCycleClient(c.config)
c.DeviceUpsterStatistics = NewDeviceUpsterStatisticsClient(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,
DeviceDuration: NewDeviceDurationClient(cfg),
DeviceDurationElephant: NewDeviceDurationElephantClient(cfg),
DeviceEvent: NewDeviceEventClient(cfg),
DeviceKpi: NewDeviceKpiClient(cfg),
DeviceOfflineTime: NewDeviceOfflineTimeClient(cfg),
DeviceOnTimeDaily: NewDeviceOnTimeDailyClient(cfg),
DeviceOnlineTime: NewDeviceOnlineTimeClient(cfg),
DeviceUpsterCycle: NewDeviceUpsterCycleClient(cfg),
DeviceUpsterStatistics: NewDeviceUpsterStatisticsClient(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,
DeviceDuration: NewDeviceDurationClient(cfg),
DeviceDurationElephant: NewDeviceDurationElephantClient(cfg),
DeviceEvent: NewDeviceEventClient(cfg),
DeviceKpi: NewDeviceKpiClient(cfg),
DeviceOfflineTime: NewDeviceOfflineTimeClient(cfg),
DeviceOnTimeDaily: NewDeviceOnTimeDailyClient(cfg),
DeviceOnlineTime: NewDeviceOnlineTimeClient(cfg),
DeviceUpsterCycle: NewDeviceUpsterCycleClient(cfg),
DeviceUpsterStatistics: NewDeviceUpsterStatisticsClient(cfg),
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// DeviceDuration.
// 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) {
for _, n := range []interface{ Use(...Hook) }{
c.DeviceDuration, c.DeviceDurationElephant, c.DeviceEvent, c.DeviceKpi,
c.DeviceOfflineTime, c.DeviceOnTimeDaily, c.DeviceOnlineTime,
c.DeviceUpsterCycle, c.DeviceUpsterStatistics,
} {
n.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) {
for _, n := range []interface{ Intercept(...Interceptor) }{
c.DeviceDuration, c.DeviceDurationElephant, c.DeviceEvent, c.DeviceKpi,
c.DeviceOfflineTime, c.DeviceOnTimeDaily, c.DeviceOnlineTime,
c.DeviceUpsterCycle, c.DeviceUpsterStatistics,
} {
n.Intercept(interceptors...)
}
}
// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
switch m := m.(type) {
case *DeviceDurationMutation:
return c.DeviceDuration.mutate(ctx, m)
case *DeviceDurationElephantMutation:
return c.DeviceDurationElephant.mutate(ctx, m)
case *DeviceEventMutation:
return c.DeviceEvent.mutate(ctx, m)
case *DeviceKpiMutation:
return c.DeviceKpi.mutate(ctx, m)
case *DeviceOfflineTimeMutation:
return c.DeviceOfflineTime.mutate(ctx, m)
case *DeviceOnTimeDailyMutation:
return c.DeviceOnTimeDaily.mutate(ctx, m)
case *DeviceOnlineTimeMutation:
return c.DeviceOnlineTime.mutate(ctx, m)
case *DeviceUpsterCycleMutation:
return c.DeviceUpsterCycle.mutate(ctx, m)
case *DeviceUpsterStatisticsMutation:
return c.DeviceUpsterStatistics.mutate(ctx, m)
default:
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
}
}
// DeviceDurationClient is a client for the DeviceDuration schema.
type DeviceDurationClient struct {
config
}
// NewDeviceDurationClient returns a client for the DeviceDuration from the given config.
func NewDeviceDurationClient(c config) *DeviceDurationClient {
return &DeviceDurationClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `deviceduration.Hooks(f(g(h())))`.
func (c *DeviceDurationClient) Use(hooks ...Hook) {
c.hooks.DeviceDuration = append(c.hooks.DeviceDuration, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `deviceduration.Intercept(f(g(h())))`.
func (c *DeviceDurationClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceDuration = append(c.inters.DeviceDuration, interceptors...)
}
// Create returns a builder for creating a DeviceDuration entity.
func (c *DeviceDurationClient) Create() *DeviceDurationCreate {
mutation := newDeviceDurationMutation(c.config, OpCreate)
return &DeviceDurationCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceDuration entities.
func (c *DeviceDurationClient) CreateBulk(builders ...*DeviceDurationCreate) *DeviceDurationCreateBulk {
return &DeviceDurationCreateBulk{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 *DeviceDurationClient) MapCreateBulk(slice any, setFunc func(*DeviceDurationCreate, int)) *DeviceDurationCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceDurationCreateBulk{err: fmt.Errorf("calling to DeviceDurationClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceDurationCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceDurationCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceDuration.
func (c *DeviceDurationClient) Update() *DeviceDurationUpdate {
mutation := newDeviceDurationMutation(c.config, OpUpdate)
return &DeviceDurationUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceDurationClient) UpdateOne(dd *DeviceDuration) *DeviceDurationUpdateOne {
mutation := newDeviceDurationMutation(c.config, OpUpdateOne, withDeviceDuration(dd))
return &DeviceDurationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceDurationClient) UpdateOneID(id uint64) *DeviceDurationUpdateOne {
mutation := newDeviceDurationMutation(c.config, OpUpdateOne, withDeviceDurationID(id))
return &DeviceDurationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceDuration.
func (c *DeviceDurationClient) Delete() *DeviceDurationDelete {
mutation := newDeviceDurationMutation(c.config, OpDelete)
return &DeviceDurationDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceDurationClient) DeleteOne(dd *DeviceDuration) *DeviceDurationDeleteOne {
return c.DeleteOneID(dd.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceDurationClient) DeleteOneID(id uint64) *DeviceDurationDeleteOne {
builder := c.Delete().Where(deviceduration.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceDurationDeleteOne{builder}
}
// Query returns a query builder for DeviceDuration.
func (c *DeviceDurationClient) Query() *DeviceDurationQuery {
return &DeviceDurationQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceDuration},
inters: c.Interceptors(),
}
}
// Get returns a DeviceDuration entity by its id.
func (c *DeviceDurationClient) Get(ctx context.Context, id uint64) (*DeviceDuration, error) {
return c.Query().Where(deviceduration.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceDurationClient) GetX(ctx context.Context, id uint64) *DeviceDuration {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceDurationClient) Hooks() []Hook {
return c.hooks.DeviceDuration
}
// Interceptors returns the client interceptors.
func (c *DeviceDurationClient) Interceptors() []Interceptor {
return c.inters.DeviceDuration
}
func (c *DeviceDurationClient) mutate(ctx context.Context, m *DeviceDurationMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceDurationCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceDurationUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceDurationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceDurationDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceDuration mutation op: %q", m.Op())
}
}
// DeviceDurationElephantClient is a client for the DeviceDurationElephant schema.
type DeviceDurationElephantClient struct {
config
}
// NewDeviceDurationElephantClient returns a client for the DeviceDurationElephant from the given config.
func NewDeviceDurationElephantClient(c config) *DeviceDurationElephantClient {
return &DeviceDurationElephantClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `devicedurationelephant.Hooks(f(g(h())))`.
func (c *DeviceDurationElephantClient) Use(hooks ...Hook) {
c.hooks.DeviceDurationElephant = append(c.hooks.DeviceDurationElephant, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `devicedurationelephant.Intercept(f(g(h())))`.
func (c *DeviceDurationElephantClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceDurationElephant = append(c.inters.DeviceDurationElephant, interceptors...)
}
// Create returns a builder for creating a DeviceDurationElephant entity.
func (c *DeviceDurationElephantClient) Create() *DeviceDurationElephantCreate {
mutation := newDeviceDurationElephantMutation(c.config, OpCreate)
return &DeviceDurationElephantCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceDurationElephant entities.
func (c *DeviceDurationElephantClient) CreateBulk(builders ...*DeviceDurationElephantCreate) *DeviceDurationElephantCreateBulk {
return &DeviceDurationElephantCreateBulk{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 *DeviceDurationElephantClient) MapCreateBulk(slice any, setFunc func(*DeviceDurationElephantCreate, int)) *DeviceDurationElephantCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceDurationElephantCreateBulk{err: fmt.Errorf("calling to DeviceDurationElephantClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceDurationElephantCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceDurationElephantCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceDurationElephant.
func (c *DeviceDurationElephantClient) Update() *DeviceDurationElephantUpdate {
mutation := newDeviceDurationElephantMutation(c.config, OpUpdate)
return &DeviceDurationElephantUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceDurationElephantClient) UpdateOne(dde *DeviceDurationElephant) *DeviceDurationElephantUpdateOne {
mutation := newDeviceDurationElephantMutation(c.config, OpUpdateOne, withDeviceDurationElephant(dde))
return &DeviceDurationElephantUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceDurationElephantClient) UpdateOneID(id uint64) *DeviceDurationElephantUpdateOne {
mutation := newDeviceDurationElephantMutation(c.config, OpUpdateOne, withDeviceDurationElephantID(id))
return &DeviceDurationElephantUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceDurationElephant.
func (c *DeviceDurationElephantClient) Delete() *DeviceDurationElephantDelete {
mutation := newDeviceDurationElephantMutation(c.config, OpDelete)
return &DeviceDurationElephantDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceDurationElephantClient) DeleteOne(dde *DeviceDurationElephant) *DeviceDurationElephantDeleteOne {
return c.DeleteOneID(dde.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceDurationElephantClient) DeleteOneID(id uint64) *DeviceDurationElephantDeleteOne {
builder := c.Delete().Where(devicedurationelephant.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceDurationElephantDeleteOne{builder}
}
// Query returns a query builder for DeviceDurationElephant.
func (c *DeviceDurationElephantClient) Query() *DeviceDurationElephantQuery {
return &DeviceDurationElephantQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceDurationElephant},
inters: c.Interceptors(),
}
}
// Get returns a DeviceDurationElephant entity by its id.
func (c *DeviceDurationElephantClient) Get(ctx context.Context, id uint64) (*DeviceDurationElephant, error) {
return c.Query().Where(devicedurationelephant.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceDurationElephantClient) GetX(ctx context.Context, id uint64) *DeviceDurationElephant {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceDurationElephantClient) Hooks() []Hook {
return c.hooks.DeviceDurationElephant
}
// Interceptors returns the client interceptors.
func (c *DeviceDurationElephantClient) Interceptors() []Interceptor {
return c.inters.DeviceDurationElephant
}
func (c *DeviceDurationElephantClient) mutate(ctx context.Context, m *DeviceDurationElephantMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceDurationElephantCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceDurationElephantUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceDurationElephantUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceDurationElephantDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceDurationElephant mutation op: %q", m.Op())
}
}
// DeviceEventClient is a client for the DeviceEvent schema.
type DeviceEventClient struct {
config
}
// NewDeviceEventClient returns a client for the DeviceEvent from the given config.
func NewDeviceEventClient(c config) *DeviceEventClient {
return &DeviceEventClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `deviceevent.Hooks(f(g(h())))`.
func (c *DeviceEventClient) Use(hooks ...Hook) {
c.hooks.DeviceEvent = append(c.hooks.DeviceEvent, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `deviceevent.Intercept(f(g(h())))`.
func (c *DeviceEventClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceEvent = append(c.inters.DeviceEvent, interceptors...)
}
// Create returns a builder for creating a DeviceEvent entity.
func (c *DeviceEventClient) Create() *DeviceEventCreate {
mutation := newDeviceEventMutation(c.config, OpCreate)
return &DeviceEventCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceEvent entities.
func (c *DeviceEventClient) CreateBulk(builders ...*DeviceEventCreate) *DeviceEventCreateBulk {
return &DeviceEventCreateBulk{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 *DeviceEventClient) MapCreateBulk(slice any, setFunc func(*DeviceEventCreate, int)) *DeviceEventCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceEventCreateBulk{err: fmt.Errorf("calling to DeviceEventClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceEventCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceEventCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceEvent.
func (c *DeviceEventClient) Update() *DeviceEventUpdate {
mutation := newDeviceEventMutation(c.config, OpUpdate)
return &DeviceEventUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceEventClient) UpdateOne(de *DeviceEvent) *DeviceEventUpdateOne {
mutation := newDeviceEventMutation(c.config, OpUpdateOne, withDeviceEvent(de))
return &DeviceEventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceEventClient) UpdateOneID(id uint64) *DeviceEventUpdateOne {
mutation := newDeviceEventMutation(c.config, OpUpdateOne, withDeviceEventID(id))
return &DeviceEventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceEvent.
func (c *DeviceEventClient) Delete() *DeviceEventDelete {
mutation := newDeviceEventMutation(c.config, OpDelete)
return &DeviceEventDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceEventClient) DeleteOne(de *DeviceEvent) *DeviceEventDeleteOne {
return c.DeleteOneID(de.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceEventClient) DeleteOneID(id uint64) *DeviceEventDeleteOne {
builder := c.Delete().Where(deviceevent.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceEventDeleteOne{builder}
}
// Query returns a query builder for DeviceEvent.
func (c *DeviceEventClient) Query() *DeviceEventQuery {
return &DeviceEventQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceEvent},
inters: c.Interceptors(),
}
}
// Get returns a DeviceEvent entity by its id.
func (c *DeviceEventClient) Get(ctx context.Context, id uint64) (*DeviceEvent, error) {
return c.Query().Where(deviceevent.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceEventClient) GetX(ctx context.Context, id uint64) *DeviceEvent {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceEventClient) Hooks() []Hook {
return c.hooks.DeviceEvent
}
// Interceptors returns the client interceptors.
func (c *DeviceEventClient) Interceptors() []Interceptor {
return c.inters.DeviceEvent
}
func (c *DeviceEventClient) mutate(ctx context.Context, m *DeviceEventMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceEventCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceEventUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceEventUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceEventDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceEvent mutation op: %q", m.Op())
}
}
// DeviceKpiClient is a client for the DeviceKpi schema.
type DeviceKpiClient struct {
config
}
// NewDeviceKpiClient returns a client for the DeviceKpi from the given config.
func NewDeviceKpiClient(c config) *DeviceKpiClient {
return &DeviceKpiClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `devicekpi.Hooks(f(g(h())))`.
func (c *DeviceKpiClient) Use(hooks ...Hook) {
c.hooks.DeviceKpi = append(c.hooks.DeviceKpi, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `devicekpi.Intercept(f(g(h())))`.
func (c *DeviceKpiClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceKpi = append(c.inters.DeviceKpi, interceptors...)
}
// Create returns a builder for creating a DeviceKpi entity.
func (c *DeviceKpiClient) Create() *DeviceKpiCreate {
mutation := newDeviceKpiMutation(c.config, OpCreate)
return &DeviceKpiCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceKpi entities.
func (c *DeviceKpiClient) CreateBulk(builders ...*DeviceKpiCreate) *DeviceKpiCreateBulk {
return &DeviceKpiCreateBulk{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 *DeviceKpiClient) MapCreateBulk(slice any, setFunc func(*DeviceKpiCreate, int)) *DeviceKpiCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceKpiCreateBulk{err: fmt.Errorf("calling to DeviceKpiClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceKpiCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceKpiCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceKpi.
func (c *DeviceKpiClient) Update() *DeviceKpiUpdate {
mutation := newDeviceKpiMutation(c.config, OpUpdate)
return &DeviceKpiUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceKpiClient) UpdateOne(dk *DeviceKpi) *DeviceKpiUpdateOne {
mutation := newDeviceKpiMutation(c.config, OpUpdateOne, withDeviceKpi(dk))
return &DeviceKpiUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceKpiClient) UpdateOneID(id uint64) *DeviceKpiUpdateOne {
mutation := newDeviceKpiMutation(c.config, OpUpdateOne, withDeviceKpiID(id))
return &DeviceKpiUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceKpi.
func (c *DeviceKpiClient) Delete() *DeviceKpiDelete {
mutation := newDeviceKpiMutation(c.config, OpDelete)
return &DeviceKpiDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceKpiClient) DeleteOne(dk *DeviceKpi) *DeviceKpiDeleteOne {
return c.DeleteOneID(dk.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceKpiClient) DeleteOneID(id uint64) *DeviceKpiDeleteOne {
builder := c.Delete().Where(devicekpi.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceKpiDeleteOne{builder}
}
// Query returns a query builder for DeviceKpi.
func (c *DeviceKpiClient) Query() *DeviceKpiQuery {
return &DeviceKpiQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceKpi},
inters: c.Interceptors(),
}
}
// Get returns a DeviceKpi entity by its id.
func (c *DeviceKpiClient) Get(ctx context.Context, id uint64) (*DeviceKpi, error) {
return c.Query().Where(devicekpi.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceKpiClient) GetX(ctx context.Context, id uint64) *DeviceKpi {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceKpiClient) Hooks() []Hook {
return c.hooks.DeviceKpi
}
// Interceptors returns the client interceptors.
func (c *DeviceKpiClient) Interceptors() []Interceptor {
return c.inters.DeviceKpi
}
func (c *DeviceKpiClient) mutate(ctx context.Context, m *DeviceKpiMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceKpiCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceKpiUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceKpiUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceKpiDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceKpi mutation op: %q", m.Op())
}
}
// DeviceOfflineTimeClient is a client for the DeviceOfflineTime schema.
type DeviceOfflineTimeClient struct {
config
}
// NewDeviceOfflineTimeClient returns a client for the DeviceOfflineTime from the given config.
func NewDeviceOfflineTimeClient(c config) *DeviceOfflineTimeClient {
return &DeviceOfflineTimeClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `deviceofflinetime.Hooks(f(g(h())))`.
func (c *DeviceOfflineTimeClient) Use(hooks ...Hook) {
c.hooks.DeviceOfflineTime = append(c.hooks.DeviceOfflineTime, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `deviceofflinetime.Intercept(f(g(h())))`.
func (c *DeviceOfflineTimeClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceOfflineTime = append(c.inters.DeviceOfflineTime, interceptors...)
}
// Create returns a builder for creating a DeviceOfflineTime entity.
func (c *DeviceOfflineTimeClient) Create() *DeviceOfflineTimeCreate {
mutation := newDeviceOfflineTimeMutation(c.config, OpCreate)
return &DeviceOfflineTimeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceOfflineTime entities.
func (c *DeviceOfflineTimeClient) CreateBulk(builders ...*DeviceOfflineTimeCreate) *DeviceOfflineTimeCreateBulk {
return &DeviceOfflineTimeCreateBulk{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 *DeviceOfflineTimeClient) MapCreateBulk(slice any, setFunc func(*DeviceOfflineTimeCreate, int)) *DeviceOfflineTimeCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceOfflineTimeCreateBulk{err: fmt.Errorf("calling to DeviceOfflineTimeClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceOfflineTimeCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceOfflineTimeCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceOfflineTime.
func (c *DeviceOfflineTimeClient) Update() *DeviceOfflineTimeUpdate {
mutation := newDeviceOfflineTimeMutation(c.config, OpUpdate)
return &DeviceOfflineTimeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceOfflineTimeClient) UpdateOne(dot *DeviceOfflineTime) *DeviceOfflineTimeUpdateOne {
mutation := newDeviceOfflineTimeMutation(c.config, OpUpdateOne, withDeviceOfflineTime(dot))
return &DeviceOfflineTimeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceOfflineTimeClient) UpdateOneID(id uint64) *DeviceOfflineTimeUpdateOne {
mutation := newDeviceOfflineTimeMutation(c.config, OpUpdateOne, withDeviceOfflineTimeID(id))
return &DeviceOfflineTimeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceOfflineTime.
func (c *DeviceOfflineTimeClient) Delete() *DeviceOfflineTimeDelete {
mutation := newDeviceOfflineTimeMutation(c.config, OpDelete)
return &DeviceOfflineTimeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceOfflineTimeClient) DeleteOne(dot *DeviceOfflineTime) *DeviceOfflineTimeDeleteOne {
return c.DeleteOneID(dot.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceOfflineTimeClient) DeleteOneID(id uint64) *DeviceOfflineTimeDeleteOne {
builder := c.Delete().Where(deviceofflinetime.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceOfflineTimeDeleteOne{builder}
}
// Query returns a query builder for DeviceOfflineTime.
func (c *DeviceOfflineTimeClient) Query() *DeviceOfflineTimeQuery {
return &DeviceOfflineTimeQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceOfflineTime},
inters: c.Interceptors(),
}
}
// Get returns a DeviceOfflineTime entity by its id.
func (c *DeviceOfflineTimeClient) Get(ctx context.Context, id uint64) (*DeviceOfflineTime, error) {
return c.Query().Where(deviceofflinetime.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceOfflineTimeClient) GetX(ctx context.Context, id uint64) *DeviceOfflineTime {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceOfflineTimeClient) Hooks() []Hook {
return c.hooks.DeviceOfflineTime
}
// Interceptors returns the client interceptors.
func (c *DeviceOfflineTimeClient) Interceptors() []Interceptor {
return c.inters.DeviceOfflineTime
}
func (c *DeviceOfflineTimeClient) mutate(ctx context.Context, m *DeviceOfflineTimeMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceOfflineTimeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceOfflineTimeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceOfflineTimeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceOfflineTimeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceOfflineTime mutation op: %q", m.Op())
}
}
// DeviceOnTimeDailyClient is a client for the DeviceOnTimeDaily schema.
type DeviceOnTimeDailyClient struct {
config
}
// NewDeviceOnTimeDailyClient returns a client for the DeviceOnTimeDaily from the given config.
func NewDeviceOnTimeDailyClient(c config) *DeviceOnTimeDailyClient {
return &DeviceOnTimeDailyClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `deviceontimedaily.Hooks(f(g(h())))`.
func (c *DeviceOnTimeDailyClient) Use(hooks ...Hook) {
c.hooks.DeviceOnTimeDaily = append(c.hooks.DeviceOnTimeDaily, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `deviceontimedaily.Intercept(f(g(h())))`.
func (c *DeviceOnTimeDailyClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceOnTimeDaily = append(c.inters.DeviceOnTimeDaily, interceptors...)
}
// Create returns a builder for creating a DeviceOnTimeDaily entity.
func (c *DeviceOnTimeDailyClient) Create() *DeviceOnTimeDailyCreate {
mutation := newDeviceOnTimeDailyMutation(c.config, OpCreate)
return &DeviceOnTimeDailyCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceOnTimeDaily entities.
func (c *DeviceOnTimeDailyClient) CreateBulk(builders ...*DeviceOnTimeDailyCreate) *DeviceOnTimeDailyCreateBulk {
return &DeviceOnTimeDailyCreateBulk{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 *DeviceOnTimeDailyClient) MapCreateBulk(slice any, setFunc func(*DeviceOnTimeDailyCreate, int)) *DeviceOnTimeDailyCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceOnTimeDailyCreateBulk{err: fmt.Errorf("calling to DeviceOnTimeDailyClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceOnTimeDailyCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceOnTimeDailyCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceOnTimeDaily.
func (c *DeviceOnTimeDailyClient) Update() *DeviceOnTimeDailyUpdate {
mutation := newDeviceOnTimeDailyMutation(c.config, OpUpdate)
return &DeviceOnTimeDailyUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceOnTimeDailyClient) UpdateOne(dotd *DeviceOnTimeDaily) *DeviceOnTimeDailyUpdateOne {
mutation := newDeviceOnTimeDailyMutation(c.config, OpUpdateOne, withDeviceOnTimeDaily(dotd))
return &DeviceOnTimeDailyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceOnTimeDailyClient) UpdateOneID(id uint64) *DeviceOnTimeDailyUpdateOne {
mutation := newDeviceOnTimeDailyMutation(c.config, OpUpdateOne, withDeviceOnTimeDailyID(id))
return &DeviceOnTimeDailyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceOnTimeDaily.
func (c *DeviceOnTimeDailyClient) Delete() *DeviceOnTimeDailyDelete {
mutation := newDeviceOnTimeDailyMutation(c.config, OpDelete)
return &DeviceOnTimeDailyDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceOnTimeDailyClient) DeleteOne(dotd *DeviceOnTimeDaily) *DeviceOnTimeDailyDeleteOne {
return c.DeleteOneID(dotd.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceOnTimeDailyClient) DeleteOneID(id uint64) *DeviceOnTimeDailyDeleteOne {
builder := c.Delete().Where(deviceontimedaily.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceOnTimeDailyDeleteOne{builder}
}
// Query returns a query builder for DeviceOnTimeDaily.
func (c *DeviceOnTimeDailyClient) Query() *DeviceOnTimeDailyQuery {
return &DeviceOnTimeDailyQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceOnTimeDaily},
inters: c.Interceptors(),
}
}
// Get returns a DeviceOnTimeDaily entity by its id.
func (c *DeviceOnTimeDailyClient) Get(ctx context.Context, id uint64) (*DeviceOnTimeDaily, error) {
return c.Query().Where(deviceontimedaily.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceOnTimeDailyClient) GetX(ctx context.Context, id uint64) *DeviceOnTimeDaily {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceOnTimeDailyClient) Hooks() []Hook {
return c.hooks.DeviceOnTimeDaily
}
// Interceptors returns the client interceptors.
func (c *DeviceOnTimeDailyClient) Interceptors() []Interceptor {
return c.inters.DeviceOnTimeDaily
}
func (c *DeviceOnTimeDailyClient) mutate(ctx context.Context, m *DeviceOnTimeDailyMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceOnTimeDailyCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceOnTimeDailyUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceOnTimeDailyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceOnTimeDailyDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceOnTimeDaily mutation op: %q", m.Op())
}
}
// DeviceOnlineTimeClient is a client for the DeviceOnlineTime schema.
type DeviceOnlineTimeClient struct {
config
}
// NewDeviceOnlineTimeClient returns a client for the DeviceOnlineTime from the given config.
func NewDeviceOnlineTimeClient(c config) *DeviceOnlineTimeClient {
return &DeviceOnlineTimeClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `deviceonlinetime.Hooks(f(g(h())))`.
func (c *DeviceOnlineTimeClient) Use(hooks ...Hook) {
c.hooks.DeviceOnlineTime = append(c.hooks.DeviceOnlineTime, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `deviceonlinetime.Intercept(f(g(h())))`.
func (c *DeviceOnlineTimeClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceOnlineTime = append(c.inters.DeviceOnlineTime, interceptors...)
}
// Create returns a builder for creating a DeviceOnlineTime entity.
func (c *DeviceOnlineTimeClient) Create() *DeviceOnlineTimeCreate {
mutation := newDeviceOnlineTimeMutation(c.config, OpCreate)
return &DeviceOnlineTimeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceOnlineTime entities.
func (c *DeviceOnlineTimeClient) CreateBulk(builders ...*DeviceOnlineTimeCreate) *DeviceOnlineTimeCreateBulk {
return &DeviceOnlineTimeCreateBulk{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 *DeviceOnlineTimeClient) MapCreateBulk(slice any, setFunc func(*DeviceOnlineTimeCreate, int)) *DeviceOnlineTimeCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceOnlineTimeCreateBulk{err: fmt.Errorf("calling to DeviceOnlineTimeClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceOnlineTimeCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceOnlineTimeCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceOnlineTime.
func (c *DeviceOnlineTimeClient) Update() *DeviceOnlineTimeUpdate {
mutation := newDeviceOnlineTimeMutation(c.config, OpUpdate)
return &DeviceOnlineTimeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceOnlineTimeClient) UpdateOne(dot *DeviceOnlineTime) *DeviceOnlineTimeUpdateOne {
mutation := newDeviceOnlineTimeMutation(c.config, OpUpdateOne, withDeviceOnlineTime(dot))
return &DeviceOnlineTimeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceOnlineTimeClient) UpdateOneID(id uint64) *DeviceOnlineTimeUpdateOne {
mutation := newDeviceOnlineTimeMutation(c.config, OpUpdateOne, withDeviceOnlineTimeID(id))
return &DeviceOnlineTimeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceOnlineTime.
func (c *DeviceOnlineTimeClient) Delete() *DeviceOnlineTimeDelete {
mutation := newDeviceOnlineTimeMutation(c.config, OpDelete)
return &DeviceOnlineTimeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceOnlineTimeClient) DeleteOne(dot *DeviceOnlineTime) *DeviceOnlineTimeDeleteOne {
return c.DeleteOneID(dot.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceOnlineTimeClient) DeleteOneID(id uint64) *DeviceOnlineTimeDeleteOne {
builder := c.Delete().Where(deviceonlinetime.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceOnlineTimeDeleteOne{builder}
}
// Query returns a query builder for DeviceOnlineTime.
func (c *DeviceOnlineTimeClient) Query() *DeviceOnlineTimeQuery {
return &DeviceOnlineTimeQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceOnlineTime},
inters: c.Interceptors(),
}
}
// Get returns a DeviceOnlineTime entity by its id.
func (c *DeviceOnlineTimeClient) Get(ctx context.Context, id uint64) (*DeviceOnlineTime, error) {
return c.Query().Where(deviceonlinetime.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceOnlineTimeClient) GetX(ctx context.Context, id uint64) *DeviceOnlineTime {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceOnlineTimeClient) Hooks() []Hook {
return c.hooks.DeviceOnlineTime
}
// Interceptors returns the client interceptors.
func (c *DeviceOnlineTimeClient) Interceptors() []Interceptor {
return c.inters.DeviceOnlineTime
}
func (c *DeviceOnlineTimeClient) mutate(ctx context.Context, m *DeviceOnlineTimeMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceOnlineTimeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceOnlineTimeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceOnlineTimeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceOnlineTimeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceOnlineTime mutation op: %q", m.Op())
}
}
// DeviceUpsterCycleClient is a client for the DeviceUpsterCycle schema.
type DeviceUpsterCycleClient struct {
config
}
// NewDeviceUpsterCycleClient returns a client for the DeviceUpsterCycle from the given config.
func NewDeviceUpsterCycleClient(c config) *DeviceUpsterCycleClient {
return &DeviceUpsterCycleClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `deviceupstercycle.Hooks(f(g(h())))`.
func (c *DeviceUpsterCycleClient) Use(hooks ...Hook) {
c.hooks.DeviceUpsterCycle = append(c.hooks.DeviceUpsterCycle, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `deviceupstercycle.Intercept(f(g(h())))`.
func (c *DeviceUpsterCycleClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceUpsterCycle = append(c.inters.DeviceUpsterCycle, interceptors...)
}
// Create returns a builder for creating a DeviceUpsterCycle entity.
func (c *DeviceUpsterCycleClient) Create() *DeviceUpsterCycleCreate {
mutation := newDeviceUpsterCycleMutation(c.config, OpCreate)
return &DeviceUpsterCycleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceUpsterCycle entities.
func (c *DeviceUpsterCycleClient) CreateBulk(builders ...*DeviceUpsterCycleCreate) *DeviceUpsterCycleCreateBulk {
return &DeviceUpsterCycleCreateBulk{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 *DeviceUpsterCycleClient) MapCreateBulk(slice any, setFunc func(*DeviceUpsterCycleCreate, int)) *DeviceUpsterCycleCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceUpsterCycleCreateBulk{err: fmt.Errorf("calling to DeviceUpsterCycleClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceUpsterCycleCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceUpsterCycleCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceUpsterCycle.
func (c *DeviceUpsterCycleClient) Update() *DeviceUpsterCycleUpdate {
mutation := newDeviceUpsterCycleMutation(c.config, OpUpdate)
return &DeviceUpsterCycleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceUpsterCycleClient) UpdateOne(duc *DeviceUpsterCycle) *DeviceUpsterCycleUpdateOne {
mutation := newDeviceUpsterCycleMutation(c.config, OpUpdateOne, withDeviceUpsterCycle(duc))
return &DeviceUpsterCycleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceUpsterCycleClient) UpdateOneID(id uint64) *DeviceUpsterCycleUpdateOne {
mutation := newDeviceUpsterCycleMutation(c.config, OpUpdateOne, withDeviceUpsterCycleID(id))
return &DeviceUpsterCycleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceUpsterCycle.
func (c *DeviceUpsterCycleClient) Delete() *DeviceUpsterCycleDelete {
mutation := newDeviceUpsterCycleMutation(c.config, OpDelete)
return &DeviceUpsterCycleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceUpsterCycleClient) DeleteOne(duc *DeviceUpsterCycle) *DeviceUpsterCycleDeleteOne {
return c.DeleteOneID(duc.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceUpsterCycleClient) DeleteOneID(id uint64) *DeviceUpsterCycleDeleteOne {
builder := c.Delete().Where(deviceupstercycle.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceUpsterCycleDeleteOne{builder}
}
// Query returns a query builder for DeviceUpsterCycle.
func (c *DeviceUpsterCycleClient) Query() *DeviceUpsterCycleQuery {
return &DeviceUpsterCycleQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceUpsterCycle},
inters: c.Interceptors(),
}
}
// Get returns a DeviceUpsterCycle entity by its id.
func (c *DeviceUpsterCycleClient) Get(ctx context.Context, id uint64) (*DeviceUpsterCycle, error) {
return c.Query().Where(deviceupstercycle.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceUpsterCycleClient) GetX(ctx context.Context, id uint64) *DeviceUpsterCycle {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceUpsterCycleClient) Hooks() []Hook {
return c.hooks.DeviceUpsterCycle
}
// Interceptors returns the client interceptors.
func (c *DeviceUpsterCycleClient) Interceptors() []Interceptor {
return c.inters.DeviceUpsterCycle
}
func (c *DeviceUpsterCycleClient) mutate(ctx context.Context, m *DeviceUpsterCycleMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceUpsterCycleCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceUpsterCycleUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceUpsterCycleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceUpsterCycleDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceUpsterCycle mutation op: %q", m.Op())
}
}
// DeviceUpsterStatisticsClient is a client for the DeviceUpsterStatistics schema.
type DeviceUpsterStatisticsClient struct {
config
}
// NewDeviceUpsterStatisticsClient returns a client for the DeviceUpsterStatistics from the given config.
func NewDeviceUpsterStatisticsClient(c config) *DeviceUpsterStatisticsClient {
return &DeviceUpsterStatisticsClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `deviceupsterstatistics.Hooks(f(g(h())))`.
func (c *DeviceUpsterStatisticsClient) Use(hooks ...Hook) {
c.hooks.DeviceUpsterStatistics = append(c.hooks.DeviceUpsterStatistics, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `deviceupsterstatistics.Intercept(f(g(h())))`.
func (c *DeviceUpsterStatisticsClient) Intercept(interceptors ...Interceptor) {
c.inters.DeviceUpsterStatistics = append(c.inters.DeviceUpsterStatistics, interceptors...)
}
// Create returns a builder for creating a DeviceUpsterStatistics entity.
func (c *DeviceUpsterStatisticsClient) Create() *DeviceUpsterStatisticsCreate {
mutation := newDeviceUpsterStatisticsMutation(c.config, OpCreate)
return &DeviceUpsterStatisticsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DeviceUpsterStatistics entities.
func (c *DeviceUpsterStatisticsClient) CreateBulk(builders ...*DeviceUpsterStatisticsCreate) *DeviceUpsterStatisticsCreateBulk {
return &DeviceUpsterStatisticsCreateBulk{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 *DeviceUpsterStatisticsClient) MapCreateBulk(slice any, setFunc func(*DeviceUpsterStatisticsCreate, int)) *DeviceUpsterStatisticsCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &DeviceUpsterStatisticsCreateBulk{err: fmt.Errorf("calling to DeviceUpsterStatisticsClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*DeviceUpsterStatisticsCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &DeviceUpsterStatisticsCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DeviceUpsterStatistics.
func (c *DeviceUpsterStatisticsClient) Update() *DeviceUpsterStatisticsUpdate {
mutation := newDeviceUpsterStatisticsMutation(c.config, OpUpdate)
return &DeviceUpsterStatisticsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DeviceUpsterStatisticsClient) UpdateOne(dus *DeviceUpsterStatistics) *DeviceUpsterStatisticsUpdateOne {
mutation := newDeviceUpsterStatisticsMutation(c.config, OpUpdateOne, withDeviceUpsterStatistics(dus))
return &DeviceUpsterStatisticsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DeviceUpsterStatisticsClient) UpdateOneID(id uint64) *DeviceUpsterStatisticsUpdateOne {
mutation := newDeviceUpsterStatisticsMutation(c.config, OpUpdateOne, withDeviceUpsterStatisticsID(id))
return &DeviceUpsterStatisticsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DeviceUpsterStatistics.
func (c *DeviceUpsterStatisticsClient) Delete() *DeviceUpsterStatisticsDelete {
mutation := newDeviceUpsterStatisticsMutation(c.config, OpDelete)
return &DeviceUpsterStatisticsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *DeviceUpsterStatisticsClient) DeleteOne(dus *DeviceUpsterStatistics) *DeviceUpsterStatisticsDeleteOne {
return c.DeleteOneID(dus.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DeviceUpsterStatisticsClient) DeleteOneID(id uint64) *DeviceUpsterStatisticsDeleteOne {
builder := c.Delete().Where(deviceupsterstatistics.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DeviceUpsterStatisticsDeleteOne{builder}
}
// Query returns a query builder for DeviceUpsterStatistics.
func (c *DeviceUpsterStatisticsClient) Query() *DeviceUpsterStatisticsQuery {
return &DeviceUpsterStatisticsQuery{
config: c.config,
ctx: &QueryContext{Type: TypeDeviceUpsterStatistics},
inters: c.Interceptors(),
}
}
// Get returns a DeviceUpsterStatistics entity by its id.
func (c *DeviceUpsterStatisticsClient) Get(ctx context.Context, id uint64) (*DeviceUpsterStatistics, error) {
return c.Query().Where(deviceupsterstatistics.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DeviceUpsterStatisticsClient) GetX(ctx context.Context, id uint64) *DeviceUpsterStatistics {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DeviceUpsterStatisticsClient) Hooks() []Hook {
return c.hooks.DeviceUpsterStatistics
}
// Interceptors returns the client interceptors.
func (c *DeviceUpsterStatisticsClient) Interceptors() []Interceptor {
return c.inters.DeviceUpsterStatistics
}
func (c *DeviceUpsterStatisticsClient) mutate(ctx context.Context, m *DeviceUpsterStatisticsMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&DeviceUpsterStatisticsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&DeviceUpsterStatisticsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&DeviceUpsterStatisticsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&DeviceUpsterStatisticsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown DeviceUpsterStatistics mutation op: %q", m.Op())
}
}
// hooks and interceptors per client, for fast access.
type (
hooks struct {
DeviceDuration, DeviceDurationElephant, DeviceEvent, DeviceKpi,
DeviceOfflineTime, DeviceOnTimeDaily, DeviceOnlineTime, DeviceUpsterCycle,
DeviceUpsterStatistics []ent.Hook
}
inters struct {
DeviceDuration, DeviceDurationElephant, DeviceEvent, DeviceKpi,
DeviceOfflineTime, DeviceOnTimeDaily, DeviceOnlineTime, DeviceUpsterCycle,
DeviceUpsterStatistics []ent.Interceptor
}
)
// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
// See, database/sql#DB.ExecContext for more information.
func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
ex, ok := c.driver.(interface {
ExecContext(context.Context, string, ...any) (stdsql.Result, error)
})
if !ok {
return nil, fmt.Errorf("Driver.ExecContext is not supported")
}
return ex.ExecContext(ctx, query, args...)
}
// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
// See, database/sql#DB.QueryContext for more information.
func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
q, ok := c.driver.(interface {
QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
})
if !ok {
return nil, fmt.Errorf("Driver.QueryContext is not supported")
}
return q.QueryContext(ctx, query, args...)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。