mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 11:39:46 +08:00
feat: add goreleaser
This commit is contained in:
155
ent/client.go
155
ent/client.go
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"polaris/ent/migrate"
|
||||
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -32,6 +33,8 @@ type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// Blocklist is the client for interacting with the Blocklist builders.
|
||||
Blocklist *BlocklistClient
|
||||
// DownloadClients is the client for interacting with the DownloadClients builders.
|
||||
DownloadClients *DownloadClientsClient
|
||||
// Episode is the client for interacting with the Episode builders.
|
||||
@@ -61,6 +64,7 @@ func NewClient(opts ...Option) *Client {
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Blocklist = NewBlocklistClient(c.config)
|
||||
c.DownloadClients = NewDownloadClientsClient(c.config)
|
||||
c.Episode = NewEpisodeClient(c.config)
|
||||
c.History = NewHistoryClient(c.config)
|
||||
@@ -162,6 +166,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Blocklist: NewBlocklistClient(cfg),
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
@@ -190,6 +195,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Blocklist: NewBlocklistClient(cfg),
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
@@ -205,7 +211,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// DownloadClients.
|
||||
// Blocklist.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
@@ -228,8 +234,8 @@ func (c *Client) Close() error {
|
||||
// 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.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
|
||||
c.Media, c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -239,8 +245,8 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
// 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.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
|
||||
c.Media, c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -249,6 +255,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *BlocklistMutation:
|
||||
return c.Blocklist.mutate(ctx, m)
|
||||
case *DownloadClientsMutation:
|
||||
return c.DownloadClients.mutate(ctx, m)
|
||||
case *EpisodeMutation:
|
||||
@@ -272,6 +280,139 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// BlocklistClient is a client for the Blocklist schema.
|
||||
type BlocklistClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewBlocklistClient returns a client for the Blocklist from the given config.
|
||||
func NewBlocklistClient(c config) *BlocklistClient {
|
||||
return &BlocklistClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `blocklist.Hooks(f(g(h())))`.
|
||||
func (c *BlocklistClient) Use(hooks ...Hook) {
|
||||
c.hooks.Blocklist = append(c.hooks.Blocklist, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `blocklist.Intercept(f(g(h())))`.
|
||||
func (c *BlocklistClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Blocklist = append(c.inters.Blocklist, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Blocklist entity.
|
||||
func (c *BlocklistClient) Create() *BlocklistCreate {
|
||||
mutation := newBlocklistMutation(c.config, OpCreate)
|
||||
return &BlocklistCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Blocklist entities.
|
||||
func (c *BlocklistClient) CreateBulk(builders ...*BlocklistCreate) *BlocklistCreateBulk {
|
||||
return &BlocklistCreateBulk{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 *BlocklistClient) MapCreateBulk(slice any, setFunc func(*BlocklistCreate, int)) *BlocklistCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &BlocklistCreateBulk{err: fmt.Errorf("calling to BlocklistClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*BlocklistCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &BlocklistCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Blocklist.
|
||||
func (c *BlocklistClient) Update() *BlocklistUpdate {
|
||||
mutation := newBlocklistMutation(c.config, OpUpdate)
|
||||
return &BlocklistUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *BlocklistClient) UpdateOne(b *Blocklist) *BlocklistUpdateOne {
|
||||
mutation := newBlocklistMutation(c.config, OpUpdateOne, withBlocklist(b))
|
||||
return &BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *BlocklistClient) UpdateOneID(id int) *BlocklistUpdateOne {
|
||||
mutation := newBlocklistMutation(c.config, OpUpdateOne, withBlocklistID(id))
|
||||
return &BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Blocklist.
|
||||
func (c *BlocklistClient) Delete() *BlocklistDelete {
|
||||
mutation := newBlocklistMutation(c.config, OpDelete)
|
||||
return &BlocklistDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *BlocklistClient) DeleteOne(b *Blocklist) *BlocklistDeleteOne {
|
||||
return c.DeleteOneID(b.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *BlocklistClient) DeleteOneID(id int) *BlocklistDeleteOne {
|
||||
builder := c.Delete().Where(blocklist.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &BlocklistDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Blocklist.
|
||||
func (c *BlocklistClient) Query() *BlocklistQuery {
|
||||
return &BlocklistQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeBlocklist},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Blocklist entity by its id.
|
||||
func (c *BlocklistClient) Get(ctx context.Context, id int) (*Blocklist, error) {
|
||||
return c.Query().Where(blocklist.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *BlocklistClient) GetX(ctx context.Context, id int) *Blocklist {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *BlocklistClient) Hooks() []Hook {
|
||||
return c.hooks.Blocklist
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *BlocklistClient) Interceptors() []Interceptor {
|
||||
return c.inters.Blocklist
|
||||
}
|
||||
|
||||
func (c *BlocklistClient) mutate(ctx context.Context, m *BlocklistMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&BlocklistCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&BlocklistUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&BlocklistDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Blocklist mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// DownloadClientsClient is a client for the DownloadClients schema.
|
||||
type DownloadClientsClient struct {
|
||||
config
|
||||
@@ -1504,11 +1645,11 @@ func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value,
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
NotificationClient, Settings, Storage []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
NotificationClient, Settings, Storage []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user