implement download feature

This commit is contained in:
Simon Ding
2024-07-10 17:35:16 +08:00
parent d7d5c72518
commit e500aaed1e
43 changed files with 4903 additions and 227 deletions

View File

@@ -5,8 +5,34 @@ const (
SettingLanguage = "language"
SettingJacketUrl = "jacket_url"
SettingJacketApiKey = "jacket_api_key"
SettingDownloadDir = "download_dir"
)
const (
IndexerTorznabImpl = "torznab"
)
)
type ResolutionType string
const (
Any ResolutionType = "any"
R720p ResolutionType = "720p"
R1080p ResolutionType = "1080p"
R4k ResolutionType = "4k"
)
func (r ResolutionType) String() string {
return string(r)
}
const (
ImplLocal = "local"
ImplWebdav = "webdav"
)
func StorageImplementations() []string {
return []string{
ImplLocal,
ImplWebdav,
}
}

135
db/db.go
View File

@@ -6,10 +6,14 @@ import (
"fmt"
"polaris/ent"
"polaris/ent/downloadclients"
"polaris/ent/history"
"polaris/ent/indexers"
"polaris/ent/series"
"polaris/ent/settings"
"polaris/ent/storage"
"polaris/log"
"slices"
"time"
"entgo.io/ent/dialect"
tmdb "github.com/cyruzin/golang-tmdb"
@@ -65,19 +69,32 @@ func (c *Client) GetLanguage() string {
return lang
}
func (c *Client) AddWatchlist(path string, detail *tmdb.TVDetails, episodes []int) (*ent.Series, error) {
func (c *Client) AddWatchlist(storageId int, nameEn string, detail *tmdb.TVDetails, episodes []int, res ResolutionType) (*ent.Series, error) {
count := c.ent.Series.Query().Where(series.TmdbID(int(detail.ID))).CountX(context.Background())
if count > 0 {
return nil, fmt.Errorf("tv series %s already in watchlist", detail.Name)
}
if res == "" {
res = R1080p
}
if storageId == 0 {
r, err := c.ent.Storage.Query().Where(storage.Default(true)).First(context.TODO())
if err == nil {
log.Infof("use default storage: %v", r.Name)
storageId = r.ID
}
}
r, err := c.ent.Series.Create().
SetTmdbID(int(detail.ID)).
SetPath(path).
SetStorageID(storageId).
SetOverview(detail.Overview).
SetName(detail.Name).
SetNameEn(nameEn).
SetOriginalName(detail.OriginalName).
SetPosterPath(detail.PosterPath).
SetAirDate(detail.FirstAirDate).
SetResolution(res.String()).
AddEpisodeIDs(episodes...).
Save(context.TODO())
return r, err
@@ -206,3 +223,117 @@ func (c *Client) GetAllDonloadClients() []*ent.DownloadClients {
func (c *Client) DeleteDownloadCLient(id int) {
c.ent.DownloadClients.Delete().Where(downloadclients.ID(id)).Exec(context.TODO())
}
// Storage is the model entity for the Storage schema.
type StorageInfo struct {
Name string `json:"name"`
Implementation string `json:"implementation"`
Path string `json:"path"`
User string `json:"user"`
Password string `json:"password"`
Default bool `json:"default"`
}
func (c *Client) AddStorage(s StorageInfo) error {
if !slices.Contains(StorageImplementations(), s.Implementation) {
return fmt.Errorf("implementation not supported: %v", s.Implementation)
}
count := c.ent.Storage.Query().Where(storage.Name(s.Name)).CountX(context.TODO())
if count > 0 {
//storage already exist, edit exist one
return c.ent.Storage.Update().Where(storage.Name(s.Name)).
SetImplementation(s.Implementation).
SetPath(s.Path).
SetUser(s.User).
SetPassword(s.Password).Exec(context.TODO())
}
_, err := c.ent.Storage.Create().SetName(s.Name).
SetImplementation(s.Implementation).
SetPath(s.Path).
SetUser(s.User).
SetPassword(s.Password).Save(context.TODO())
if err != nil {
return err
}
if s.Default {
return c.SetDefaultStorageByName(s.Name)
}
return nil
}
func (c *Client) GetAllStorage() []*ent.Storage {
data, err := c.ent.Storage.Query().Where(storage.Deleted(false)).All(context.TODO())
if err != nil {
log.Errorf("get storage: %v", err)
return nil
}
return data
}
func (c *Client) GetStorage(id int) *ent.Storage {
r, err := c.ent.Storage.Query().Where(storage.ID(id)).First(context.TODO())
if err != nil {
//use default storage
return c.ent.Storage.Query().Where(storage.Default(true)).FirstX(context.TODO())
}
return r
}
func (c *Client) DeleteStorage(id int) error {
return c.ent.Storage.Update().Where(storage.ID(id)).SetDeleted(true).Exec(context.TODO())
}
func (c *Client) SetDefaultStorage(id int) error {
err := c.ent.Storage.Update().Where(storage.ID(id)).SetDefault(true).Exec(context.TODO())
if err != nil {
return err
}
err = c.ent.Storage.Update().Where(storage.Or(storage.ID(id))).SetDefault(false).Exec(context.TODO())
return err
}
func (c *Client) SetDefaultStorageByName(name string) error {
err := c.ent.Storage.Update().Where(storage.Name(name)).SetDefault(true).Exec(context.TODO())
if err != nil {
return err
}
err = c.ent.Storage.Update().Where(storage.Or(storage.Name(name))).SetDefault(false).Exec(context.TODO())
return err
}
func (c *Client) SaveHistoryRecord(h ent.History) (*ent.History,error) {
return c.ent.History.Create().SetSeriesID(h.SeriesID).SetEpisodeID(h.EpisodeID).SetDate(time.Now()).
SetCompleted(h.Completed).SetTargetDir(h.TargetDir).SetSourceTitle(h.SourceTitle).SetSaved(h.Saved).Save(context.TODO())
}
func (c *Client) SetHistoryComplete(id int) error {
return c.ent.History.Update().Where(history.ID(id)).SetCompleted(true).Exec(context.TODO())
}
func (c *Client) GetHistories() ent.Histories {
h, err := c.ent.History.Query().All(context.TODO())
if err != nil {
return nil
}
return h
}
func (c *Client) GetHistory(id int) *ent.History {
return c.ent.History.Query().Where(history.ID(id)).FirstX(context.TODO())
}
func (c *Client) DeleteHistory(id int) error {
_, err := c.ent.History.Delete().Where(history.ID(id)).Exec(context.Background())
return err
}
func (c *Client) GetDownloadDir() string {
r, err := c.ent.Settings.Query().Where(settings.Key(SettingDownloadDir)).First(context.TODO())
if err != nil {
return "/download"
}
return r.Value
}

View File

@@ -17,6 +17,7 @@ import (
"polaris/ent/indexers"
"polaris/ent/series"
"polaris/ent/settings"
"polaris/ent/storage"
"entgo.io/ent"
"entgo.io/ent/dialect"
@@ -41,6 +42,8 @@ type Client struct {
Series *SeriesClient
// Settings is the client for interacting with the Settings builders.
Settings *SettingsClient
// Storage is the client for interacting with the Storage builders.
Storage *StorageClient
}
// NewClient creates a new client configured with the given options.
@@ -58,6 +61,7 @@ func (c *Client) init() {
c.Indexers = NewIndexersClient(c.config)
c.Series = NewSeriesClient(c.config)
c.Settings = NewSettingsClient(c.config)
c.Storage = NewStorageClient(c.config)
}
type (
@@ -156,6 +160,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
Indexers: NewIndexersClient(cfg),
Series: NewSeriesClient(cfg),
Settings: NewSettingsClient(cfg),
Storage: NewStorageClient(cfg),
}, nil
}
@@ -181,6 +186,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
Indexers: NewIndexersClient(cfg),
Series: NewSeriesClient(cfg),
Settings: NewSettingsClient(cfg),
Storage: NewStorageClient(cfg),
}, nil
}
@@ -211,6 +217,7 @@ func (c *Client) Close() error {
func (c *Client) Use(hooks ...Hook) {
for _, n := range []interface{ Use(...Hook) }{
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Series, c.Settings,
c.Storage,
} {
n.Use(hooks...)
}
@@ -221,6 +228,7 @@ func (c *Client) Use(hooks ...Hook) {
func (c *Client) Intercept(interceptors ...Interceptor) {
for _, n := range []interface{ Intercept(...Interceptor) }{
c.DownloadClients, c.Episode, c.History, c.Indexers, c.Series, c.Settings,
c.Storage,
} {
n.Intercept(interceptors...)
}
@@ -241,6 +249,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.Series.mutate(ctx, m)
case *SettingsMutation:
return c.Settings.mutate(ctx, m)
case *StorageMutation:
return c.Storage.mutate(ctx, m)
default:
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
}
@@ -1076,12 +1086,147 @@ func (c *SettingsClient) mutate(ctx context.Context, m *SettingsMutation) (Value
}
}
// StorageClient is a client for the Storage schema.
type StorageClient struct {
config
}
// NewStorageClient returns a client for the Storage from the given config.
func NewStorageClient(c config) *StorageClient {
return &StorageClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `storage.Hooks(f(g(h())))`.
func (c *StorageClient) Use(hooks ...Hook) {
c.hooks.Storage = append(c.hooks.Storage, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `storage.Intercept(f(g(h())))`.
func (c *StorageClient) Intercept(interceptors ...Interceptor) {
c.inters.Storage = append(c.inters.Storage, interceptors...)
}
// Create returns a builder for creating a Storage entity.
func (c *StorageClient) Create() *StorageCreate {
mutation := newStorageMutation(c.config, OpCreate)
return &StorageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Storage entities.
func (c *StorageClient) CreateBulk(builders ...*StorageCreate) *StorageCreateBulk {
return &StorageCreateBulk{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 *StorageClient) MapCreateBulk(slice any, setFunc func(*StorageCreate, int)) *StorageCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &StorageCreateBulk{err: fmt.Errorf("calling to StorageClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*StorageCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &StorageCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Storage.
func (c *StorageClient) Update() *StorageUpdate {
mutation := newStorageMutation(c.config, OpUpdate)
return &StorageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *StorageClient) UpdateOne(s *Storage) *StorageUpdateOne {
mutation := newStorageMutation(c.config, OpUpdateOne, withStorage(s))
return &StorageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *StorageClient) UpdateOneID(id int) *StorageUpdateOne {
mutation := newStorageMutation(c.config, OpUpdateOne, withStorageID(id))
return &StorageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Storage.
func (c *StorageClient) Delete() *StorageDelete {
mutation := newStorageMutation(c.config, OpDelete)
return &StorageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *StorageClient) DeleteOne(s *Storage) *StorageDeleteOne {
return c.DeleteOneID(s.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *StorageClient) DeleteOneID(id int) *StorageDeleteOne {
builder := c.Delete().Where(storage.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &StorageDeleteOne{builder}
}
// Query returns a query builder for Storage.
func (c *StorageClient) Query() *StorageQuery {
return &StorageQuery{
config: c.config,
ctx: &QueryContext{Type: TypeStorage},
inters: c.Interceptors(),
}
}
// Get returns a Storage entity by its id.
func (c *StorageClient) Get(ctx context.Context, id int) (*Storage, error) {
return c.Query().Where(storage.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *StorageClient) GetX(ctx context.Context, id int) *Storage {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *StorageClient) Hooks() []Hook {
return c.hooks.Storage
}
// Interceptors returns the client interceptors.
func (c *StorageClient) Interceptors() []Interceptor {
return c.inters.Storage
}
func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&StorageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&StorageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&StorageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&StorageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown Storage mutation op: %q", m.Op())
}
}
// hooks and interceptors per client, for fast access.
type (
hooks struct {
DownloadClients, Episode, History, Indexers, Series, Settings []ent.Hook
DownloadClients, Episode, History, Indexers, Series, Settings,
Storage []ent.Hook
}
inters struct {
DownloadClients, Episode, History, Indexers, Series, Settings []ent.Interceptor
DownloadClients, Episode, History, Indexers, Series, Settings,
Storage []ent.Interceptor
}
)

View File

@@ -12,6 +12,7 @@ import (
"polaris/ent/indexers"
"polaris/ent/series"
"polaris/ent/settings"
"polaris/ent/storage"
"reflect"
"sync"
@@ -84,6 +85,7 @@ func checkColumn(table, column string) error {
indexers.Table: indexers.ValidColumn,
series.Table: series.ValidColumn,
settings.Table: settings.ValidColumn,
storage.Table: storage.ValidColumn,
})
})
return columnCheck(table, column)

View File

@@ -24,7 +24,13 @@ type History struct {
// SourceTitle holds the value of the "source_title" field.
SourceTitle string `json:"source_title,omitempty"`
// Date holds the value of the "date" field.
Date time.Time `json:"date,omitempty"`
Date time.Time `json:"date,omitempty"`
// TargetDir holds the value of the "target_dir" field.
TargetDir string `json:"target_dir,omitempty"`
// Completed holds the value of the "completed" field.
Completed bool `json:"completed,omitempty"`
// Saved holds the value of the "saved" field.
Saved string `json:"saved,omitempty"`
selectValues sql.SelectValues
}
@@ -33,9 +39,11 @@ func (*History) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case history.FieldCompleted:
values[i] = new(sql.NullBool)
case history.FieldID, history.FieldSeriesID, history.FieldEpisodeID:
values[i] = new(sql.NullInt64)
case history.FieldSourceTitle:
case history.FieldSourceTitle, history.FieldTargetDir, history.FieldSaved:
values[i] = new(sql.NullString)
case history.FieldDate:
values[i] = new(sql.NullTime)
@@ -84,6 +92,24 @@ func (h *History) assignValues(columns []string, values []any) error {
} else if value.Valid {
h.Date = value.Time
}
case history.FieldTargetDir:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field target_dir", values[i])
} else if value.Valid {
h.TargetDir = value.String
}
case history.FieldCompleted:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field completed", values[i])
} else if value.Valid {
h.Completed = value.Bool
}
case history.FieldSaved:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field saved", values[i])
} else if value.Valid {
h.Saved = value.String
}
default:
h.selectValues.Set(columns[i], values[i])
}
@@ -131,6 +157,15 @@ func (h *History) String() string {
builder.WriteString(", ")
builder.WriteString("date=")
builder.WriteString(h.Date.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("target_dir=")
builder.WriteString(h.TargetDir)
builder.WriteString(", ")
builder.WriteString("completed=")
builder.WriteString(fmt.Sprintf("%v", h.Completed))
builder.WriteString(", ")
builder.WriteString("saved=")
builder.WriteString(h.Saved)
builder.WriteByte(')')
return builder.String()
}

View File

@@ -19,6 +19,12 @@ const (
FieldSourceTitle = "source_title"
// FieldDate holds the string denoting the date field in the database.
FieldDate = "date"
// FieldTargetDir holds the string denoting the target_dir field in the database.
FieldTargetDir = "target_dir"
// FieldCompleted holds the string denoting the completed field in the database.
FieldCompleted = "completed"
// FieldSaved holds the string denoting the saved field in the database.
FieldSaved = "saved"
// Table holds the table name of the history in the database.
Table = "histories"
)
@@ -30,6 +36,9 @@ var Columns = []string{
FieldEpisodeID,
FieldSourceTitle,
FieldDate,
FieldTargetDir,
FieldCompleted,
FieldSaved,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -42,6 +51,11 @@ func ValidColumn(column string) bool {
return false
}
var (
// DefaultCompleted holds the default value on creation for the "completed" field.
DefaultCompleted bool
)
// OrderOption defines the ordering options for the History queries.
type OrderOption func(*sql.Selector)
@@ -69,3 +83,18 @@ func BySourceTitle(opts ...sql.OrderTermOption) OrderOption {
func ByDate(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDate, opts...).ToFunc()
}
// ByTargetDir orders the results by the target_dir field.
func ByTargetDir(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTargetDir, opts...).ToFunc()
}
// ByCompleted orders the results by the completed field.
func ByCompleted(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCompleted, opts...).ToFunc()
}
// BySaved orders the results by the saved field.
func BySaved(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSaved, opts...).ToFunc()
}

View File

@@ -74,6 +74,21 @@ func Date(v time.Time) predicate.History {
return predicate.History(sql.FieldEQ(FieldDate, v))
}
// TargetDir applies equality check predicate on the "target_dir" field. It's identical to TargetDirEQ.
func TargetDir(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldTargetDir, v))
}
// Completed applies equality check predicate on the "completed" field. It's identical to CompletedEQ.
func Completed(v bool) predicate.History {
return predicate.History(sql.FieldEQ(FieldCompleted, v))
}
// Saved applies equality check predicate on the "saved" field. It's identical to SavedEQ.
func Saved(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldSaved, v))
}
// SeriesIDEQ applies the EQ predicate on the "series_id" field.
func SeriesIDEQ(v int) predicate.History {
return predicate.History(sql.FieldEQ(FieldSeriesID, v))
@@ -259,6 +274,156 @@ func DateLTE(v time.Time) predicate.History {
return predicate.History(sql.FieldLTE(FieldDate, v))
}
// TargetDirEQ applies the EQ predicate on the "target_dir" field.
func TargetDirEQ(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldTargetDir, v))
}
// TargetDirNEQ applies the NEQ predicate on the "target_dir" field.
func TargetDirNEQ(v string) predicate.History {
return predicate.History(sql.FieldNEQ(FieldTargetDir, v))
}
// TargetDirIn applies the In predicate on the "target_dir" field.
func TargetDirIn(vs ...string) predicate.History {
return predicate.History(sql.FieldIn(FieldTargetDir, vs...))
}
// TargetDirNotIn applies the NotIn predicate on the "target_dir" field.
func TargetDirNotIn(vs ...string) predicate.History {
return predicate.History(sql.FieldNotIn(FieldTargetDir, vs...))
}
// TargetDirGT applies the GT predicate on the "target_dir" field.
func TargetDirGT(v string) predicate.History {
return predicate.History(sql.FieldGT(FieldTargetDir, v))
}
// TargetDirGTE applies the GTE predicate on the "target_dir" field.
func TargetDirGTE(v string) predicate.History {
return predicate.History(sql.FieldGTE(FieldTargetDir, v))
}
// TargetDirLT applies the LT predicate on the "target_dir" field.
func TargetDirLT(v string) predicate.History {
return predicate.History(sql.FieldLT(FieldTargetDir, v))
}
// TargetDirLTE applies the LTE predicate on the "target_dir" field.
func TargetDirLTE(v string) predicate.History {
return predicate.History(sql.FieldLTE(FieldTargetDir, v))
}
// TargetDirContains applies the Contains predicate on the "target_dir" field.
func TargetDirContains(v string) predicate.History {
return predicate.History(sql.FieldContains(FieldTargetDir, v))
}
// TargetDirHasPrefix applies the HasPrefix predicate on the "target_dir" field.
func TargetDirHasPrefix(v string) predicate.History {
return predicate.History(sql.FieldHasPrefix(FieldTargetDir, v))
}
// TargetDirHasSuffix applies the HasSuffix predicate on the "target_dir" field.
func TargetDirHasSuffix(v string) predicate.History {
return predicate.History(sql.FieldHasSuffix(FieldTargetDir, v))
}
// TargetDirEqualFold applies the EqualFold predicate on the "target_dir" field.
func TargetDirEqualFold(v string) predicate.History {
return predicate.History(sql.FieldEqualFold(FieldTargetDir, v))
}
// TargetDirContainsFold applies the ContainsFold predicate on the "target_dir" field.
func TargetDirContainsFold(v string) predicate.History {
return predicate.History(sql.FieldContainsFold(FieldTargetDir, v))
}
// CompletedEQ applies the EQ predicate on the "completed" field.
func CompletedEQ(v bool) predicate.History {
return predicate.History(sql.FieldEQ(FieldCompleted, v))
}
// CompletedNEQ applies the NEQ predicate on the "completed" field.
func CompletedNEQ(v bool) predicate.History {
return predicate.History(sql.FieldNEQ(FieldCompleted, v))
}
// SavedEQ applies the EQ predicate on the "saved" field.
func SavedEQ(v string) predicate.History {
return predicate.History(sql.FieldEQ(FieldSaved, v))
}
// SavedNEQ applies the NEQ predicate on the "saved" field.
func SavedNEQ(v string) predicate.History {
return predicate.History(sql.FieldNEQ(FieldSaved, v))
}
// SavedIn applies the In predicate on the "saved" field.
func SavedIn(vs ...string) predicate.History {
return predicate.History(sql.FieldIn(FieldSaved, vs...))
}
// SavedNotIn applies the NotIn predicate on the "saved" field.
func SavedNotIn(vs ...string) predicate.History {
return predicate.History(sql.FieldNotIn(FieldSaved, vs...))
}
// SavedGT applies the GT predicate on the "saved" field.
func SavedGT(v string) predicate.History {
return predicate.History(sql.FieldGT(FieldSaved, v))
}
// SavedGTE applies the GTE predicate on the "saved" field.
func SavedGTE(v string) predicate.History {
return predicate.History(sql.FieldGTE(FieldSaved, v))
}
// SavedLT applies the LT predicate on the "saved" field.
func SavedLT(v string) predicate.History {
return predicate.History(sql.FieldLT(FieldSaved, v))
}
// SavedLTE applies the LTE predicate on the "saved" field.
func SavedLTE(v string) predicate.History {
return predicate.History(sql.FieldLTE(FieldSaved, v))
}
// SavedContains applies the Contains predicate on the "saved" field.
func SavedContains(v string) predicate.History {
return predicate.History(sql.FieldContains(FieldSaved, v))
}
// SavedHasPrefix applies the HasPrefix predicate on the "saved" field.
func SavedHasPrefix(v string) predicate.History {
return predicate.History(sql.FieldHasPrefix(FieldSaved, v))
}
// SavedHasSuffix applies the HasSuffix predicate on the "saved" field.
func SavedHasSuffix(v string) predicate.History {
return predicate.History(sql.FieldHasSuffix(FieldSaved, v))
}
// SavedIsNil applies the IsNil predicate on the "saved" field.
func SavedIsNil() predicate.History {
return predicate.History(sql.FieldIsNull(FieldSaved))
}
// SavedNotNil applies the NotNil predicate on the "saved" field.
func SavedNotNil() predicate.History {
return predicate.History(sql.FieldNotNull(FieldSaved))
}
// SavedEqualFold applies the EqualFold predicate on the "saved" field.
func SavedEqualFold(v string) predicate.History {
return predicate.History(sql.FieldEqualFold(FieldSaved, v))
}
// SavedContainsFold applies the ContainsFold predicate on the "saved" field.
func SavedContainsFold(v string) predicate.History {
return predicate.History(sql.FieldContainsFold(FieldSaved, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.History) predicate.History {
return predicate.History(sql.AndPredicates(predicates...))

View File

@@ -44,6 +44,40 @@ func (hc *HistoryCreate) SetDate(t time.Time) *HistoryCreate {
return hc
}
// SetTargetDir sets the "target_dir" field.
func (hc *HistoryCreate) SetTargetDir(s string) *HistoryCreate {
hc.mutation.SetTargetDir(s)
return hc
}
// SetCompleted sets the "completed" field.
func (hc *HistoryCreate) SetCompleted(b bool) *HistoryCreate {
hc.mutation.SetCompleted(b)
return hc
}
// SetNillableCompleted sets the "completed" field if the given value is not nil.
func (hc *HistoryCreate) SetNillableCompleted(b *bool) *HistoryCreate {
if b != nil {
hc.SetCompleted(*b)
}
return hc
}
// SetSaved sets the "saved" field.
func (hc *HistoryCreate) SetSaved(s string) *HistoryCreate {
hc.mutation.SetSaved(s)
return hc
}
// SetNillableSaved sets the "saved" field if the given value is not nil.
func (hc *HistoryCreate) SetNillableSaved(s *string) *HistoryCreate {
if s != nil {
hc.SetSaved(*s)
}
return hc
}
// Mutation returns the HistoryMutation object of the builder.
func (hc *HistoryCreate) Mutation() *HistoryMutation {
return hc.mutation
@@ -51,6 +85,7 @@ func (hc *HistoryCreate) Mutation() *HistoryMutation {
// Save creates the History in the database.
func (hc *HistoryCreate) Save(ctx context.Context) (*History, error) {
hc.defaults()
return withHooks(ctx, hc.sqlSave, hc.mutation, hc.hooks)
}
@@ -76,6 +111,14 @@ func (hc *HistoryCreate) ExecX(ctx context.Context) {
}
}
// defaults sets the default values of the builder before save.
func (hc *HistoryCreate) defaults() {
if _, ok := hc.mutation.Completed(); !ok {
v := history.DefaultCompleted
hc.mutation.SetCompleted(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (hc *HistoryCreate) check() error {
if _, ok := hc.mutation.SeriesID(); !ok {
@@ -90,6 +133,12 @@ func (hc *HistoryCreate) check() error {
if _, ok := hc.mutation.Date(); !ok {
return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "History.date"`)}
}
if _, ok := hc.mutation.TargetDir(); !ok {
return &ValidationError{Name: "target_dir", err: errors.New(`ent: missing required field "History.target_dir"`)}
}
if _, ok := hc.mutation.Completed(); !ok {
return &ValidationError{Name: "completed", err: errors.New(`ent: missing required field "History.completed"`)}
}
return nil
}
@@ -132,6 +181,18 @@ func (hc *HistoryCreate) createSpec() (*History, *sqlgraph.CreateSpec) {
_spec.SetField(history.FieldDate, field.TypeTime, value)
_node.Date = value
}
if value, ok := hc.mutation.TargetDir(); ok {
_spec.SetField(history.FieldTargetDir, field.TypeString, value)
_node.TargetDir = value
}
if value, ok := hc.mutation.Completed(); ok {
_spec.SetField(history.FieldCompleted, field.TypeBool, value)
_node.Completed = value
}
if value, ok := hc.mutation.Saved(); ok {
_spec.SetField(history.FieldSaved, field.TypeString, value)
_node.Saved = value
}
return _node, _spec
}
@@ -153,6 +214,7 @@ func (hcb *HistoryCreateBulk) Save(ctx context.Context) ([]*History, error) {
for i := range hcb.builders {
func(i int, root context.Context) {
builder := hcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*HistoryMutation)
if !ok {

View File

@@ -98,6 +98,54 @@ func (hu *HistoryUpdate) SetNillableDate(t *time.Time) *HistoryUpdate {
return hu
}
// SetTargetDir sets the "target_dir" field.
func (hu *HistoryUpdate) SetTargetDir(s string) *HistoryUpdate {
hu.mutation.SetTargetDir(s)
return hu
}
// SetNillableTargetDir sets the "target_dir" field if the given value is not nil.
func (hu *HistoryUpdate) SetNillableTargetDir(s *string) *HistoryUpdate {
if s != nil {
hu.SetTargetDir(*s)
}
return hu
}
// SetCompleted sets the "completed" field.
func (hu *HistoryUpdate) SetCompleted(b bool) *HistoryUpdate {
hu.mutation.SetCompleted(b)
return hu
}
// SetNillableCompleted sets the "completed" field if the given value is not nil.
func (hu *HistoryUpdate) SetNillableCompleted(b *bool) *HistoryUpdate {
if b != nil {
hu.SetCompleted(*b)
}
return hu
}
// SetSaved sets the "saved" field.
func (hu *HistoryUpdate) SetSaved(s string) *HistoryUpdate {
hu.mutation.SetSaved(s)
return hu
}
// SetNillableSaved sets the "saved" field if the given value is not nil.
func (hu *HistoryUpdate) SetNillableSaved(s *string) *HistoryUpdate {
if s != nil {
hu.SetSaved(*s)
}
return hu
}
// ClearSaved clears the value of the "saved" field.
func (hu *HistoryUpdate) ClearSaved() *HistoryUpdate {
hu.mutation.ClearSaved()
return hu
}
// Mutation returns the HistoryMutation object of the builder.
func (hu *HistoryUpdate) Mutation() *HistoryMutation {
return hu.mutation
@@ -157,6 +205,18 @@ func (hu *HistoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := hu.mutation.Date(); ok {
_spec.SetField(history.FieldDate, field.TypeTime, value)
}
if value, ok := hu.mutation.TargetDir(); ok {
_spec.SetField(history.FieldTargetDir, field.TypeString, value)
}
if value, ok := hu.mutation.Completed(); ok {
_spec.SetField(history.FieldCompleted, field.TypeBool, value)
}
if value, ok := hu.mutation.Saved(); ok {
_spec.SetField(history.FieldSaved, field.TypeString, value)
}
if hu.mutation.SavedCleared() {
_spec.ClearField(history.FieldSaved, field.TypeString)
}
if n, err = sqlgraph.UpdateNodes(ctx, hu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{history.Label}
@@ -247,6 +307,54 @@ func (huo *HistoryUpdateOne) SetNillableDate(t *time.Time) *HistoryUpdateOne {
return huo
}
// SetTargetDir sets the "target_dir" field.
func (huo *HistoryUpdateOne) SetTargetDir(s string) *HistoryUpdateOne {
huo.mutation.SetTargetDir(s)
return huo
}
// SetNillableTargetDir sets the "target_dir" field if the given value is not nil.
func (huo *HistoryUpdateOne) SetNillableTargetDir(s *string) *HistoryUpdateOne {
if s != nil {
huo.SetTargetDir(*s)
}
return huo
}
// SetCompleted sets the "completed" field.
func (huo *HistoryUpdateOne) SetCompleted(b bool) *HistoryUpdateOne {
huo.mutation.SetCompleted(b)
return huo
}
// SetNillableCompleted sets the "completed" field if the given value is not nil.
func (huo *HistoryUpdateOne) SetNillableCompleted(b *bool) *HistoryUpdateOne {
if b != nil {
huo.SetCompleted(*b)
}
return huo
}
// SetSaved sets the "saved" field.
func (huo *HistoryUpdateOne) SetSaved(s string) *HistoryUpdateOne {
huo.mutation.SetSaved(s)
return huo
}
// SetNillableSaved sets the "saved" field if the given value is not nil.
func (huo *HistoryUpdateOne) SetNillableSaved(s *string) *HistoryUpdateOne {
if s != nil {
huo.SetSaved(*s)
}
return huo
}
// ClearSaved clears the value of the "saved" field.
func (huo *HistoryUpdateOne) ClearSaved() *HistoryUpdateOne {
huo.mutation.ClearSaved()
return huo
}
// Mutation returns the HistoryMutation object of the builder.
func (huo *HistoryUpdateOne) Mutation() *HistoryMutation {
return huo.mutation
@@ -336,6 +444,18 @@ func (huo *HistoryUpdateOne) sqlSave(ctx context.Context) (_node *History, err e
if value, ok := huo.mutation.Date(); ok {
_spec.SetField(history.FieldDate, field.TypeTime, value)
}
if value, ok := huo.mutation.TargetDir(); ok {
_spec.SetField(history.FieldTargetDir, field.TypeString, value)
}
if value, ok := huo.mutation.Completed(); ok {
_spec.SetField(history.FieldCompleted, field.TypeBool, value)
}
if value, ok := huo.mutation.Saved(); ok {
_spec.SetField(history.FieldSaved, field.TypeString, value)
}
if huo.mutation.SavedCleared() {
_spec.ClearField(history.FieldSaved, field.TypeString)
}
_node = &History{config: huo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues

View File

@@ -80,6 +80,18 @@ func (f SettingsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SettingsMutation", m)
}
// The StorageFunc type is an adapter to allow the use of ordinary
// function as Storage mutator.
type StorageFunc func(context.Context, *ent.StorageMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f StorageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.StorageMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StorageMutation", m)
}
// Condition is a hook condition function.
type Condition func(context.Context, ent.Mutation) bool

View File

@@ -60,6 +60,9 @@ var (
{Name: "episode_id", Type: field.TypeInt},
{Name: "source_title", Type: field.TypeString},
{Name: "date", Type: field.TypeTime},
{Name: "target_dir", Type: field.TypeString},
{Name: "completed", Type: field.TypeBool, Default: false},
{Name: "saved", Type: field.TypeString, Nullable: true},
}
// HistoriesTable holds the schema information for the "histories" table.
HistoriesTable = &schema.Table{
@@ -88,12 +91,14 @@ var (
{Name: "tmdb_id", Type: field.TypeInt},
{Name: "imdb_id", Type: field.TypeString, Nullable: true},
{Name: "name", Type: field.TypeString},
{Name: "name_en", Type: field.TypeString, Nullable: true},
{Name: "original_name", Type: field.TypeString},
{Name: "overview", Type: field.TypeString},
{Name: "path", Type: field.TypeString},
{Name: "poster_path", Type: field.TypeString, Nullable: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "air_date", Type: field.TypeString, Default: ""},
{Name: "resolution", Type: field.TypeString, Default: ""},
{Name: "storage_id", Type: field.TypeInt, Nullable: true},
}
// SeriesTable holds the schema information for the "series" table.
SeriesTable = &schema.Table{
@@ -113,6 +118,23 @@ var (
Columns: SettingsColumns,
PrimaryKey: []*schema.Column{SettingsColumns[0]},
}
// StoragesColumns holds the columns for the "storages" table.
StoragesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "name", Type: field.TypeString, Unique: true},
{Name: "implementation", Type: field.TypeString},
{Name: "path", Type: field.TypeString},
{Name: "user", Type: field.TypeString, Nullable: true},
{Name: "password", Type: field.TypeString, Nullable: true},
{Name: "deleted", Type: field.TypeBool, Default: false},
{Name: "default", Type: field.TypeBool, Default: false},
}
// StoragesTable holds the schema information for the "storages" table.
StoragesTable = &schema.Table{
Name: "storages",
Columns: StoragesColumns,
PrimaryKey: []*schema.Column{StoragesColumns[0]},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
DownloadClientsTable,
@@ -121,6 +143,7 @@ var (
IndexersTable,
SeriesTable,
SettingsTable,
StoragesTable,
}
)

View File

File diff suppressed because it is too large Load Diff

View File

@@ -23,3 +23,6 @@ type Series func(*sql.Selector)
// Settings is the predicate function for settings builders.
type Settings func(*sql.Selector)
// Storage is the predicate function for storage builders.
type Storage func(*sql.Selector)

View File

@@ -4,9 +4,11 @@ package ent
import (
"polaris/ent/downloadclients"
"polaris/ent/history"
"polaris/ent/indexers"
"polaris/ent/schema"
"polaris/ent/series"
"polaris/ent/storage"
"time"
)
@@ -44,6 +46,12 @@ func init() {
downloadclientsDescTags := downloadclientsFields[10].Descriptor()
// downloadclients.DefaultTags holds the default value on creation for the tags field.
downloadclients.DefaultTags = downloadclientsDescTags.Default.(string)
historyFields := schema.History{}.Fields()
_ = historyFields
// historyDescCompleted is the schema descriptor for completed field.
historyDescCompleted := historyFields[5].Descriptor()
// history.DefaultCompleted holds the default value on creation for the completed field.
history.DefaultCompleted = historyDescCompleted.Default.(bool)
indexersFields := schema.Indexers{}.Fields()
_ = indexersFields
// indexersDescEnableRss is the schema descriptor for enable_rss field.
@@ -60,4 +68,18 @@ func init() {
seriesDescAirDate := seriesFields[8].Descriptor()
// series.DefaultAirDate holds the default value on creation for the air_date field.
series.DefaultAirDate = seriesDescAirDate.Default.(string)
// seriesDescResolution is the schema descriptor for resolution field.
seriesDescResolution := seriesFields[9].Descriptor()
// series.DefaultResolution holds the default value on creation for the resolution field.
series.DefaultResolution = seriesDescResolution.Default.(string)
storageFields := schema.Storage{}.Fields()
_ = storageFields
// storageDescDeleted is the schema descriptor for deleted field.
storageDescDeleted := storageFields[5].Descriptor()
// storage.DefaultDeleted holds the default value on creation for the deleted field.
storage.DefaultDeleted = storageDescDeleted.Default.(bool)
// storageDescDefault is the schema descriptor for default field.
storageDescDefault := storageFields[6].Descriptor()
// storage.DefaultDefault holds the default value on creation for the default field.
storage.DefaultDefault = storageDescDefault.Default.(bool)
}

View File

@@ -17,6 +17,9 @@ func (History) Fields() []ent.Field {
field.Int("episode_id"),
field.String("source_title"),
field.Time("date"),
field.String("target_dir"),
field.Bool("completed").Default(false),
field.String("saved").Optional(),
}
}

View File

@@ -19,12 +19,14 @@ func (Series) Fields() []ent.Field {
field.Int("tmdb_id"),
field.String("imdb_id").Optional(),
field.String("name"),
field.String("name_en").Optional(),
field.String("original_name"),
field.String("overview"),
field.String("path"),
field.String("poster_path").Optional(),
field.Time("created_at").Default(time.Now()),
field.String("air_date").Default(""),
field.String("resolution").Default(""),
field.Int("storage_id").Optional(),
}
}

29
ent/schema/storage.go Normal file
View File

@@ -0,0 +1,29 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
// Storage holds the schema definition for the Storage entity.
type Storage struct {
ent.Schema
}
// Fields of the Storage.
func (Storage) Fields() []ent.Field {
return []ent.Field{
field.String("name").Unique(),
field.String("implementation"),
field.String("path"),
field.String("user").Optional(),
field.String("password").Optional(),
field.Bool("deleted").Default(false),
field.Bool("default").Default(false),
}
}
// Edges of the Storage.
func (Storage) Edges() []ent.Edge {
return nil
}

View File

@@ -23,18 +23,22 @@ type Series struct {
ImdbID string `json:"imdb_id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// NameEn holds the value of the "name_en" field.
NameEn string `json:"name_en,omitempty"`
// OriginalName holds the value of the "original_name" field.
OriginalName string `json:"original_name,omitempty"`
// Overview holds the value of the "overview" field.
Overview string `json:"overview,omitempty"`
// Path holds the value of the "path" field.
Path string `json:"path,omitempty"`
// PosterPath holds the value of the "poster_path" field.
PosterPath string `json:"poster_path,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// AirDate holds the value of the "air_date" field.
AirDate string `json:"air_date,omitempty"`
// Resolution holds the value of the "resolution" field.
Resolution string `json:"resolution,omitempty"`
// StorageID holds the value of the "storage_id" field.
StorageID int `json:"storage_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SeriesQuery when eager-loading is set.
Edges SeriesEdges `json:"edges"`
@@ -64,9 +68,9 @@ func (*Series) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case series.FieldID, series.FieldTmdbID:
case series.FieldID, series.FieldTmdbID, series.FieldStorageID:
values[i] = new(sql.NullInt64)
case series.FieldImdbID, series.FieldName, series.FieldOriginalName, series.FieldOverview, series.FieldPath, series.FieldPosterPath, series.FieldAirDate:
case series.FieldImdbID, series.FieldName, series.FieldNameEn, series.FieldOriginalName, series.FieldOverview, series.FieldPosterPath, series.FieldAirDate, series.FieldResolution:
values[i] = new(sql.NullString)
case series.FieldCreatedAt:
values[i] = new(sql.NullTime)
@@ -109,6 +113,12 @@ func (s *Series) assignValues(columns []string, values []any) error {
} else if value.Valid {
s.Name = value.String
}
case series.FieldNameEn:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name_en", values[i])
} else if value.Valid {
s.NameEn = value.String
}
case series.FieldOriginalName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field original_name", values[i])
@@ -121,12 +131,6 @@ func (s *Series) assignValues(columns []string, values []any) error {
} else if value.Valid {
s.Overview = value.String
}
case series.FieldPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field path", values[i])
} else if value.Valid {
s.Path = value.String
}
case series.FieldPosterPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field poster_path", values[i])
@@ -145,6 +149,18 @@ func (s *Series) assignValues(columns []string, values []any) error {
} else if value.Valid {
s.AirDate = value.String
}
case series.FieldResolution:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field resolution", values[i])
} else if value.Valid {
s.Resolution = value.String
}
case series.FieldStorageID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field storage_id", values[i])
} else if value.Valid {
s.StorageID = int(value.Int64)
}
default:
s.selectValues.Set(columns[i], values[i])
}
@@ -195,15 +211,15 @@ func (s *Series) String() string {
builder.WriteString("name=")
builder.WriteString(s.Name)
builder.WriteString(", ")
builder.WriteString("name_en=")
builder.WriteString(s.NameEn)
builder.WriteString(", ")
builder.WriteString("original_name=")
builder.WriteString(s.OriginalName)
builder.WriteString(", ")
builder.WriteString("overview=")
builder.WriteString(s.Overview)
builder.WriteString(", ")
builder.WriteString("path=")
builder.WriteString(s.Path)
builder.WriteString(", ")
builder.WriteString("poster_path=")
builder.WriteString(s.PosterPath)
builder.WriteString(", ")
@@ -212,6 +228,12 @@ func (s *Series) String() string {
builder.WriteString(", ")
builder.WriteString("air_date=")
builder.WriteString(s.AirDate)
builder.WriteString(", ")
builder.WriteString("resolution=")
builder.WriteString(s.Resolution)
builder.WriteString(", ")
builder.WriteString("storage_id=")
builder.WriteString(fmt.Sprintf("%v", s.StorageID))
builder.WriteByte(')')
return builder.String()
}

View File

@@ -20,18 +20,22 @@ const (
FieldImdbID = "imdb_id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldNameEn holds the string denoting the name_en field in the database.
FieldNameEn = "name_en"
// FieldOriginalName holds the string denoting the original_name field in the database.
FieldOriginalName = "original_name"
// FieldOverview holds the string denoting the overview field in the database.
FieldOverview = "overview"
// FieldPath holds the string denoting the path field in the database.
FieldPath = "path"
// FieldPosterPath holds the string denoting the poster_path field in the database.
FieldPosterPath = "poster_path"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldAirDate holds the string denoting the air_date field in the database.
FieldAirDate = "air_date"
// FieldResolution holds the string denoting the resolution field in the database.
FieldResolution = "resolution"
// FieldStorageID holds the string denoting the storage_id field in the database.
FieldStorageID = "storage_id"
// EdgeEpisodes holds the string denoting the episodes edge name in mutations.
EdgeEpisodes = "episodes"
// Table holds the table name of the series in the database.
@@ -51,12 +55,14 @@ var Columns = []string{
FieldTmdbID,
FieldImdbID,
FieldName,
FieldNameEn,
FieldOriginalName,
FieldOverview,
FieldPath,
FieldPosterPath,
FieldCreatedAt,
FieldAirDate,
FieldResolution,
FieldStorageID,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -74,6 +80,8 @@ var (
DefaultCreatedAt time.Time
// DefaultAirDate holds the default value on creation for the "air_date" field.
DefaultAirDate string
// DefaultResolution holds the default value on creation for the "resolution" field.
DefaultResolution string
)
// OrderOption defines the ordering options for the Series queries.
@@ -99,6 +107,11 @@ func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByNameEn orders the results by the name_en field.
func ByNameEn(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldNameEn, opts...).ToFunc()
}
// ByOriginalName orders the results by the original_name field.
func ByOriginalName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOriginalName, opts...).ToFunc()
@@ -109,11 +122,6 @@ func ByOverview(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOverview, opts...).ToFunc()
}
// ByPath orders the results by the path field.
func ByPath(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPath, opts...).ToFunc()
}
// ByPosterPath orders the results by the poster_path field.
func ByPosterPath(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPosterPath, opts...).ToFunc()
@@ -129,6 +137,16 @@ func ByAirDate(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAirDate, opts...).ToFunc()
}
// ByResolution orders the results by the resolution field.
func ByResolution(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldResolution, opts...).ToFunc()
}
// ByStorageID orders the results by the storage_id field.
func ByStorageID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStorageID, opts...).ToFunc()
}
// ByEpisodesCount orders the results by episodes count.
func ByEpisodesCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {

View File

@@ -70,6 +70,11 @@ func Name(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldName, v))
}
// NameEn applies equality check predicate on the "name_en" field. It's identical to NameEnEQ.
func NameEn(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldNameEn, v))
}
// OriginalName applies equality check predicate on the "original_name" field. It's identical to OriginalNameEQ.
func OriginalName(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldOriginalName, v))
@@ -80,11 +85,6 @@ func Overview(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldOverview, v))
}
// Path applies equality check predicate on the "path" field. It's identical to PathEQ.
func Path(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldPath, v))
}
// PosterPath applies equality check predicate on the "poster_path" field. It's identical to PosterPathEQ.
func PosterPath(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldPosterPath, v))
@@ -100,6 +100,16 @@ func AirDate(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldAirDate, v))
}
// Resolution applies equality check predicate on the "resolution" field. It's identical to ResolutionEQ.
func Resolution(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldResolution, v))
}
// StorageID applies equality check predicate on the "storage_id" field. It's identical to StorageIDEQ.
func StorageID(v int) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldStorageID, v))
}
// TmdbIDEQ applies the EQ predicate on the "tmdb_id" field.
func TmdbIDEQ(v int) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldTmdbID, v))
@@ -280,6 +290,81 @@ func NameContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldName, v))
}
// NameEnEQ applies the EQ predicate on the "name_en" field.
func NameEnEQ(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldNameEn, v))
}
// NameEnNEQ applies the NEQ predicate on the "name_en" field.
func NameEnNEQ(v string) predicate.Series {
return predicate.Series(sql.FieldNEQ(FieldNameEn, v))
}
// NameEnIn applies the In predicate on the "name_en" field.
func NameEnIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldIn(FieldNameEn, vs...))
}
// NameEnNotIn applies the NotIn predicate on the "name_en" field.
func NameEnNotIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldNotIn(FieldNameEn, vs...))
}
// NameEnGT applies the GT predicate on the "name_en" field.
func NameEnGT(v string) predicate.Series {
return predicate.Series(sql.FieldGT(FieldNameEn, v))
}
// NameEnGTE applies the GTE predicate on the "name_en" field.
func NameEnGTE(v string) predicate.Series {
return predicate.Series(sql.FieldGTE(FieldNameEn, v))
}
// NameEnLT applies the LT predicate on the "name_en" field.
func NameEnLT(v string) predicate.Series {
return predicate.Series(sql.FieldLT(FieldNameEn, v))
}
// NameEnLTE applies the LTE predicate on the "name_en" field.
func NameEnLTE(v string) predicate.Series {
return predicate.Series(sql.FieldLTE(FieldNameEn, v))
}
// NameEnContains applies the Contains predicate on the "name_en" field.
func NameEnContains(v string) predicate.Series {
return predicate.Series(sql.FieldContains(FieldNameEn, v))
}
// NameEnHasPrefix applies the HasPrefix predicate on the "name_en" field.
func NameEnHasPrefix(v string) predicate.Series {
return predicate.Series(sql.FieldHasPrefix(FieldNameEn, v))
}
// NameEnHasSuffix applies the HasSuffix predicate on the "name_en" field.
func NameEnHasSuffix(v string) predicate.Series {
return predicate.Series(sql.FieldHasSuffix(FieldNameEn, v))
}
// NameEnIsNil applies the IsNil predicate on the "name_en" field.
func NameEnIsNil() predicate.Series {
return predicate.Series(sql.FieldIsNull(FieldNameEn))
}
// NameEnNotNil applies the NotNil predicate on the "name_en" field.
func NameEnNotNil() predicate.Series {
return predicate.Series(sql.FieldNotNull(FieldNameEn))
}
// NameEnEqualFold applies the EqualFold predicate on the "name_en" field.
func NameEnEqualFold(v string) predicate.Series {
return predicate.Series(sql.FieldEqualFold(FieldNameEn, v))
}
// NameEnContainsFold applies the ContainsFold predicate on the "name_en" field.
func NameEnContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldNameEn, v))
}
// OriginalNameEQ applies the EQ predicate on the "original_name" field.
func OriginalNameEQ(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldOriginalName, v))
@@ -410,71 +495,6 @@ func OverviewContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldOverview, v))
}
// PathEQ applies the EQ predicate on the "path" field.
func PathEQ(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldPath, v))
}
// PathNEQ applies the NEQ predicate on the "path" field.
func PathNEQ(v string) predicate.Series {
return predicate.Series(sql.FieldNEQ(FieldPath, v))
}
// PathIn applies the In predicate on the "path" field.
func PathIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldIn(FieldPath, vs...))
}
// PathNotIn applies the NotIn predicate on the "path" field.
func PathNotIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldNotIn(FieldPath, vs...))
}
// PathGT applies the GT predicate on the "path" field.
func PathGT(v string) predicate.Series {
return predicate.Series(sql.FieldGT(FieldPath, v))
}
// PathGTE applies the GTE predicate on the "path" field.
func PathGTE(v string) predicate.Series {
return predicate.Series(sql.FieldGTE(FieldPath, v))
}
// PathLT applies the LT predicate on the "path" field.
func PathLT(v string) predicate.Series {
return predicate.Series(sql.FieldLT(FieldPath, v))
}
// PathLTE applies the LTE predicate on the "path" field.
func PathLTE(v string) predicate.Series {
return predicate.Series(sql.FieldLTE(FieldPath, v))
}
// PathContains applies the Contains predicate on the "path" field.
func PathContains(v string) predicate.Series {
return predicate.Series(sql.FieldContains(FieldPath, v))
}
// PathHasPrefix applies the HasPrefix predicate on the "path" field.
func PathHasPrefix(v string) predicate.Series {
return predicate.Series(sql.FieldHasPrefix(FieldPath, v))
}
// PathHasSuffix applies the HasSuffix predicate on the "path" field.
func PathHasSuffix(v string) predicate.Series {
return predicate.Series(sql.FieldHasSuffix(FieldPath, v))
}
// PathEqualFold applies the EqualFold predicate on the "path" field.
func PathEqualFold(v string) predicate.Series {
return predicate.Series(sql.FieldEqualFold(FieldPath, v))
}
// PathContainsFold applies the ContainsFold predicate on the "path" field.
func PathContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldPath, v))
}
// PosterPathEQ applies the EQ predicate on the "poster_path" field.
func PosterPathEQ(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldPosterPath, v))
@@ -655,6 +675,121 @@ func AirDateContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldAirDate, v))
}
// ResolutionEQ applies the EQ predicate on the "resolution" field.
func ResolutionEQ(v string) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldResolution, v))
}
// ResolutionNEQ applies the NEQ predicate on the "resolution" field.
func ResolutionNEQ(v string) predicate.Series {
return predicate.Series(sql.FieldNEQ(FieldResolution, v))
}
// ResolutionIn applies the In predicate on the "resolution" field.
func ResolutionIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldIn(FieldResolution, vs...))
}
// ResolutionNotIn applies the NotIn predicate on the "resolution" field.
func ResolutionNotIn(vs ...string) predicate.Series {
return predicate.Series(sql.FieldNotIn(FieldResolution, vs...))
}
// ResolutionGT applies the GT predicate on the "resolution" field.
func ResolutionGT(v string) predicate.Series {
return predicate.Series(sql.FieldGT(FieldResolution, v))
}
// ResolutionGTE applies the GTE predicate on the "resolution" field.
func ResolutionGTE(v string) predicate.Series {
return predicate.Series(sql.FieldGTE(FieldResolution, v))
}
// ResolutionLT applies the LT predicate on the "resolution" field.
func ResolutionLT(v string) predicate.Series {
return predicate.Series(sql.FieldLT(FieldResolution, v))
}
// ResolutionLTE applies the LTE predicate on the "resolution" field.
func ResolutionLTE(v string) predicate.Series {
return predicate.Series(sql.FieldLTE(FieldResolution, v))
}
// ResolutionContains applies the Contains predicate on the "resolution" field.
func ResolutionContains(v string) predicate.Series {
return predicate.Series(sql.FieldContains(FieldResolution, v))
}
// ResolutionHasPrefix applies the HasPrefix predicate on the "resolution" field.
func ResolutionHasPrefix(v string) predicate.Series {
return predicate.Series(sql.FieldHasPrefix(FieldResolution, v))
}
// ResolutionHasSuffix applies the HasSuffix predicate on the "resolution" field.
func ResolutionHasSuffix(v string) predicate.Series {
return predicate.Series(sql.FieldHasSuffix(FieldResolution, v))
}
// ResolutionEqualFold applies the EqualFold predicate on the "resolution" field.
func ResolutionEqualFold(v string) predicate.Series {
return predicate.Series(sql.FieldEqualFold(FieldResolution, v))
}
// ResolutionContainsFold applies the ContainsFold predicate on the "resolution" field.
func ResolutionContainsFold(v string) predicate.Series {
return predicate.Series(sql.FieldContainsFold(FieldResolution, v))
}
// StorageIDEQ applies the EQ predicate on the "storage_id" field.
func StorageIDEQ(v int) predicate.Series {
return predicate.Series(sql.FieldEQ(FieldStorageID, v))
}
// StorageIDNEQ applies the NEQ predicate on the "storage_id" field.
func StorageIDNEQ(v int) predicate.Series {
return predicate.Series(sql.FieldNEQ(FieldStorageID, v))
}
// StorageIDIn applies the In predicate on the "storage_id" field.
func StorageIDIn(vs ...int) predicate.Series {
return predicate.Series(sql.FieldIn(FieldStorageID, vs...))
}
// StorageIDNotIn applies the NotIn predicate on the "storage_id" field.
func StorageIDNotIn(vs ...int) predicate.Series {
return predicate.Series(sql.FieldNotIn(FieldStorageID, vs...))
}
// StorageIDGT applies the GT predicate on the "storage_id" field.
func StorageIDGT(v int) predicate.Series {
return predicate.Series(sql.FieldGT(FieldStorageID, v))
}
// StorageIDGTE applies the GTE predicate on the "storage_id" field.
func StorageIDGTE(v int) predicate.Series {
return predicate.Series(sql.FieldGTE(FieldStorageID, v))
}
// StorageIDLT applies the LT predicate on the "storage_id" field.
func StorageIDLT(v int) predicate.Series {
return predicate.Series(sql.FieldLT(FieldStorageID, v))
}
// StorageIDLTE applies the LTE predicate on the "storage_id" field.
func StorageIDLTE(v int) predicate.Series {
return predicate.Series(sql.FieldLTE(FieldStorageID, v))
}
// StorageIDIsNil applies the IsNil predicate on the "storage_id" field.
func StorageIDIsNil() predicate.Series {
return predicate.Series(sql.FieldIsNull(FieldStorageID))
}
// StorageIDNotNil applies the NotNil predicate on the "storage_id" field.
func StorageIDNotNil() predicate.Series {
return predicate.Series(sql.FieldNotNull(FieldStorageID))
}
// HasEpisodes applies the HasEdge predicate on the "episodes" edge.
func HasEpisodes() predicate.Series {
return predicate.Series(func(s *sql.Selector) {

View File

@@ -47,6 +47,20 @@ func (sc *SeriesCreate) SetName(s string) *SeriesCreate {
return sc
}
// SetNameEn sets the "name_en" field.
func (sc *SeriesCreate) SetNameEn(s string) *SeriesCreate {
sc.mutation.SetNameEn(s)
return sc
}
// SetNillableNameEn sets the "name_en" field if the given value is not nil.
func (sc *SeriesCreate) SetNillableNameEn(s *string) *SeriesCreate {
if s != nil {
sc.SetNameEn(*s)
}
return sc
}
// SetOriginalName sets the "original_name" field.
func (sc *SeriesCreate) SetOriginalName(s string) *SeriesCreate {
sc.mutation.SetOriginalName(s)
@@ -59,12 +73,6 @@ func (sc *SeriesCreate) SetOverview(s string) *SeriesCreate {
return sc
}
// SetPath sets the "path" field.
func (sc *SeriesCreate) SetPath(s string) *SeriesCreate {
sc.mutation.SetPath(s)
return sc
}
// SetPosterPath sets the "poster_path" field.
func (sc *SeriesCreate) SetPosterPath(s string) *SeriesCreate {
sc.mutation.SetPosterPath(s)
@@ -107,6 +115,34 @@ func (sc *SeriesCreate) SetNillableAirDate(s *string) *SeriesCreate {
return sc
}
// SetResolution sets the "resolution" field.
func (sc *SeriesCreate) SetResolution(s string) *SeriesCreate {
sc.mutation.SetResolution(s)
return sc
}
// SetNillableResolution sets the "resolution" field if the given value is not nil.
func (sc *SeriesCreate) SetNillableResolution(s *string) *SeriesCreate {
if s != nil {
sc.SetResolution(*s)
}
return sc
}
// SetStorageID sets the "storage_id" field.
func (sc *SeriesCreate) SetStorageID(i int) *SeriesCreate {
sc.mutation.SetStorageID(i)
return sc
}
// SetNillableStorageID sets the "storage_id" field if the given value is not nil.
func (sc *SeriesCreate) SetNillableStorageID(i *int) *SeriesCreate {
if i != nil {
sc.SetStorageID(*i)
}
return sc
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (sc *SeriesCreate) AddEpisodeIDs(ids ...int) *SeriesCreate {
sc.mutation.AddEpisodeIDs(ids...)
@@ -165,6 +201,10 @@ func (sc *SeriesCreate) defaults() {
v := series.DefaultAirDate
sc.mutation.SetAirDate(v)
}
if _, ok := sc.mutation.Resolution(); !ok {
v := series.DefaultResolution
sc.mutation.SetResolution(v)
}
}
// check runs all checks and user-defined validators on the builder.
@@ -181,15 +221,15 @@ func (sc *SeriesCreate) check() error {
if _, ok := sc.mutation.Overview(); !ok {
return &ValidationError{Name: "overview", err: errors.New(`ent: missing required field "Series.overview"`)}
}
if _, ok := sc.mutation.Path(); !ok {
return &ValidationError{Name: "path", err: errors.New(`ent: missing required field "Series.path"`)}
}
if _, ok := sc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Series.created_at"`)}
}
if _, ok := sc.mutation.AirDate(); !ok {
return &ValidationError{Name: "air_date", err: errors.New(`ent: missing required field "Series.air_date"`)}
}
if _, ok := sc.mutation.Resolution(); !ok {
return &ValidationError{Name: "resolution", err: errors.New(`ent: missing required field "Series.resolution"`)}
}
return nil
}
@@ -228,6 +268,10 @@ func (sc *SeriesCreate) createSpec() (*Series, *sqlgraph.CreateSpec) {
_spec.SetField(series.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := sc.mutation.NameEn(); ok {
_spec.SetField(series.FieldNameEn, field.TypeString, value)
_node.NameEn = value
}
if value, ok := sc.mutation.OriginalName(); ok {
_spec.SetField(series.FieldOriginalName, field.TypeString, value)
_node.OriginalName = value
@@ -236,10 +280,6 @@ func (sc *SeriesCreate) createSpec() (*Series, *sqlgraph.CreateSpec) {
_spec.SetField(series.FieldOverview, field.TypeString, value)
_node.Overview = value
}
if value, ok := sc.mutation.Path(); ok {
_spec.SetField(series.FieldPath, field.TypeString, value)
_node.Path = value
}
if value, ok := sc.mutation.PosterPath(); ok {
_spec.SetField(series.FieldPosterPath, field.TypeString, value)
_node.PosterPath = value
@@ -252,6 +292,14 @@ func (sc *SeriesCreate) createSpec() (*Series, *sqlgraph.CreateSpec) {
_spec.SetField(series.FieldAirDate, field.TypeString, value)
_node.AirDate = value
}
if value, ok := sc.mutation.Resolution(); ok {
_spec.SetField(series.FieldResolution, field.TypeString, value)
_node.Resolution = value
}
if value, ok := sc.mutation.StorageID(); ok {
_spec.SetField(series.FieldStorageID, field.TypeInt, value)
_node.StorageID = value
}
if nodes := sc.mutation.EpisodesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,

View File

@@ -84,6 +84,26 @@ func (su *SeriesUpdate) SetNillableName(s *string) *SeriesUpdate {
return su
}
// SetNameEn sets the "name_en" field.
func (su *SeriesUpdate) SetNameEn(s string) *SeriesUpdate {
su.mutation.SetNameEn(s)
return su
}
// SetNillableNameEn sets the "name_en" field if the given value is not nil.
func (su *SeriesUpdate) SetNillableNameEn(s *string) *SeriesUpdate {
if s != nil {
su.SetNameEn(*s)
}
return su
}
// ClearNameEn clears the value of the "name_en" field.
func (su *SeriesUpdate) ClearNameEn() *SeriesUpdate {
su.mutation.ClearNameEn()
return su
}
// SetOriginalName sets the "original_name" field.
func (su *SeriesUpdate) SetOriginalName(s string) *SeriesUpdate {
su.mutation.SetOriginalName(s)
@@ -112,20 +132,6 @@ func (su *SeriesUpdate) SetNillableOverview(s *string) *SeriesUpdate {
return su
}
// SetPath sets the "path" field.
func (su *SeriesUpdate) SetPath(s string) *SeriesUpdate {
su.mutation.SetPath(s)
return su
}
// SetNillablePath sets the "path" field if the given value is not nil.
func (su *SeriesUpdate) SetNillablePath(s *string) *SeriesUpdate {
if s != nil {
su.SetPath(*s)
}
return su
}
// SetPosterPath sets the "poster_path" field.
func (su *SeriesUpdate) SetPosterPath(s string) *SeriesUpdate {
su.mutation.SetPosterPath(s)
@@ -174,6 +180,47 @@ func (su *SeriesUpdate) SetNillableAirDate(s *string) *SeriesUpdate {
return su
}
// SetResolution sets the "resolution" field.
func (su *SeriesUpdate) SetResolution(s string) *SeriesUpdate {
su.mutation.SetResolution(s)
return su
}
// SetNillableResolution sets the "resolution" field if the given value is not nil.
func (su *SeriesUpdate) SetNillableResolution(s *string) *SeriesUpdate {
if s != nil {
su.SetResolution(*s)
}
return su
}
// SetStorageID sets the "storage_id" field.
func (su *SeriesUpdate) SetStorageID(i int) *SeriesUpdate {
su.mutation.ResetStorageID()
su.mutation.SetStorageID(i)
return su
}
// SetNillableStorageID sets the "storage_id" field if the given value is not nil.
func (su *SeriesUpdate) SetNillableStorageID(i *int) *SeriesUpdate {
if i != nil {
su.SetStorageID(*i)
}
return su
}
// AddStorageID adds i to the "storage_id" field.
func (su *SeriesUpdate) AddStorageID(i int) *SeriesUpdate {
su.mutation.AddStorageID(i)
return su
}
// ClearStorageID clears the value of the "storage_id" field.
func (su *SeriesUpdate) ClearStorageID() *SeriesUpdate {
su.mutation.ClearStorageID()
return su
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (su *SeriesUpdate) AddEpisodeIDs(ids ...int) *SeriesUpdate {
su.mutation.AddEpisodeIDs(ids...)
@@ -266,15 +313,18 @@ func (su *SeriesUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := su.mutation.Name(); ok {
_spec.SetField(series.FieldName, field.TypeString, value)
}
if value, ok := su.mutation.NameEn(); ok {
_spec.SetField(series.FieldNameEn, field.TypeString, value)
}
if su.mutation.NameEnCleared() {
_spec.ClearField(series.FieldNameEn, field.TypeString)
}
if value, ok := su.mutation.OriginalName(); ok {
_spec.SetField(series.FieldOriginalName, field.TypeString, value)
}
if value, ok := su.mutation.Overview(); ok {
_spec.SetField(series.FieldOverview, field.TypeString, value)
}
if value, ok := su.mutation.Path(); ok {
_spec.SetField(series.FieldPath, field.TypeString, value)
}
if value, ok := su.mutation.PosterPath(); ok {
_spec.SetField(series.FieldPosterPath, field.TypeString, value)
}
@@ -287,6 +337,18 @@ func (su *SeriesUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := su.mutation.AirDate(); ok {
_spec.SetField(series.FieldAirDate, field.TypeString, value)
}
if value, ok := su.mutation.Resolution(); ok {
_spec.SetField(series.FieldResolution, field.TypeString, value)
}
if value, ok := su.mutation.StorageID(); ok {
_spec.SetField(series.FieldStorageID, field.TypeInt, value)
}
if value, ok := su.mutation.AddedStorageID(); ok {
_spec.AddField(series.FieldStorageID, field.TypeInt, value)
}
if su.mutation.StorageIDCleared() {
_spec.ClearField(series.FieldStorageID, field.TypeInt)
}
if su.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -407,6 +469,26 @@ func (suo *SeriesUpdateOne) SetNillableName(s *string) *SeriesUpdateOne {
return suo
}
// SetNameEn sets the "name_en" field.
func (suo *SeriesUpdateOne) SetNameEn(s string) *SeriesUpdateOne {
suo.mutation.SetNameEn(s)
return suo
}
// SetNillableNameEn sets the "name_en" field if the given value is not nil.
func (suo *SeriesUpdateOne) SetNillableNameEn(s *string) *SeriesUpdateOne {
if s != nil {
suo.SetNameEn(*s)
}
return suo
}
// ClearNameEn clears the value of the "name_en" field.
func (suo *SeriesUpdateOne) ClearNameEn() *SeriesUpdateOne {
suo.mutation.ClearNameEn()
return suo
}
// SetOriginalName sets the "original_name" field.
func (suo *SeriesUpdateOne) SetOriginalName(s string) *SeriesUpdateOne {
suo.mutation.SetOriginalName(s)
@@ -435,20 +517,6 @@ func (suo *SeriesUpdateOne) SetNillableOverview(s *string) *SeriesUpdateOne {
return suo
}
// SetPath sets the "path" field.
func (suo *SeriesUpdateOne) SetPath(s string) *SeriesUpdateOne {
suo.mutation.SetPath(s)
return suo
}
// SetNillablePath sets the "path" field if the given value is not nil.
func (suo *SeriesUpdateOne) SetNillablePath(s *string) *SeriesUpdateOne {
if s != nil {
suo.SetPath(*s)
}
return suo
}
// SetPosterPath sets the "poster_path" field.
func (suo *SeriesUpdateOne) SetPosterPath(s string) *SeriesUpdateOne {
suo.mutation.SetPosterPath(s)
@@ -497,6 +565,47 @@ func (suo *SeriesUpdateOne) SetNillableAirDate(s *string) *SeriesUpdateOne {
return suo
}
// SetResolution sets the "resolution" field.
func (suo *SeriesUpdateOne) SetResolution(s string) *SeriesUpdateOne {
suo.mutation.SetResolution(s)
return suo
}
// SetNillableResolution sets the "resolution" field if the given value is not nil.
func (suo *SeriesUpdateOne) SetNillableResolution(s *string) *SeriesUpdateOne {
if s != nil {
suo.SetResolution(*s)
}
return suo
}
// SetStorageID sets the "storage_id" field.
func (suo *SeriesUpdateOne) SetStorageID(i int) *SeriesUpdateOne {
suo.mutation.ResetStorageID()
suo.mutation.SetStorageID(i)
return suo
}
// SetNillableStorageID sets the "storage_id" field if the given value is not nil.
func (suo *SeriesUpdateOne) SetNillableStorageID(i *int) *SeriesUpdateOne {
if i != nil {
suo.SetStorageID(*i)
}
return suo
}
// AddStorageID adds i to the "storage_id" field.
func (suo *SeriesUpdateOne) AddStorageID(i int) *SeriesUpdateOne {
suo.mutation.AddStorageID(i)
return suo
}
// ClearStorageID clears the value of the "storage_id" field.
func (suo *SeriesUpdateOne) ClearStorageID() *SeriesUpdateOne {
suo.mutation.ClearStorageID()
return suo
}
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
func (suo *SeriesUpdateOne) AddEpisodeIDs(ids ...int) *SeriesUpdateOne {
suo.mutation.AddEpisodeIDs(ids...)
@@ -619,15 +728,18 @@ func (suo *SeriesUpdateOne) sqlSave(ctx context.Context) (_node *Series, err err
if value, ok := suo.mutation.Name(); ok {
_spec.SetField(series.FieldName, field.TypeString, value)
}
if value, ok := suo.mutation.NameEn(); ok {
_spec.SetField(series.FieldNameEn, field.TypeString, value)
}
if suo.mutation.NameEnCleared() {
_spec.ClearField(series.FieldNameEn, field.TypeString)
}
if value, ok := suo.mutation.OriginalName(); ok {
_spec.SetField(series.FieldOriginalName, field.TypeString, value)
}
if value, ok := suo.mutation.Overview(); ok {
_spec.SetField(series.FieldOverview, field.TypeString, value)
}
if value, ok := suo.mutation.Path(); ok {
_spec.SetField(series.FieldPath, field.TypeString, value)
}
if value, ok := suo.mutation.PosterPath(); ok {
_spec.SetField(series.FieldPosterPath, field.TypeString, value)
}
@@ -640,6 +752,18 @@ func (suo *SeriesUpdateOne) sqlSave(ctx context.Context) (_node *Series, err err
if value, ok := suo.mutation.AirDate(); ok {
_spec.SetField(series.FieldAirDate, field.TypeString, value)
}
if value, ok := suo.mutation.Resolution(); ok {
_spec.SetField(series.FieldResolution, field.TypeString, value)
}
if value, ok := suo.mutation.StorageID(); ok {
_spec.SetField(series.FieldStorageID, field.TypeInt, value)
}
if value, ok := suo.mutation.AddedStorageID(); ok {
_spec.AddField(series.FieldStorageID, field.TypeInt, value)
}
if suo.mutation.StorageIDCleared() {
_spec.ClearField(series.FieldStorageID, field.TypeInt)
}
if suo.mutation.EpisodesCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,

171
ent/storage.go Normal file
View File

@@ -0,0 +1,171 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"polaris/ent/storage"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Storage is the model entity for the Storage schema.
type Storage 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"`
// Implementation holds the value of the "implementation" field.
Implementation string `json:"implementation,omitempty"`
// Path holds the value of the "path" field.
Path string `json:"path,omitempty"`
// User holds the value of the "user" field.
User string `json:"user,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"password,omitempty"`
// Deleted holds the value of the "deleted" field.
Deleted bool `json:"deleted,omitempty"`
// Default holds the value of the "default" field.
Default bool `json:"default,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Storage) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case storage.FieldDeleted, storage.FieldDefault:
values[i] = new(sql.NullBool)
case storage.FieldID:
values[i] = new(sql.NullInt64)
case storage.FieldName, storage.FieldImplementation, storage.FieldPath, storage.FieldUser, storage.FieldPassword:
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 Storage fields.
func (s *Storage) 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 storage.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
s.ID = int(value.Int64)
case storage.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
s.Name = value.String
}
case storage.FieldImplementation:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field implementation", values[i])
} else if value.Valid {
s.Implementation = value.String
}
case storage.FieldPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field path", values[i])
} else if value.Valid {
s.Path = value.String
}
case storage.FieldUser:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field user", values[i])
} else if value.Valid {
s.User = value.String
}
case storage.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
s.Password = value.String
}
case storage.FieldDeleted:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field deleted", values[i])
} else if value.Valid {
s.Deleted = value.Bool
}
case storage.FieldDefault:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field default", values[i])
} else if value.Valid {
s.Default = value.Bool
}
default:
s.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Storage.
// This includes values selected through modifiers, order, etc.
func (s *Storage) Value(name string) (ent.Value, error) {
return s.selectValues.Get(name)
}
// Update returns a builder for updating this Storage.
// Note that you need to call Storage.Unwrap() before calling this method if this Storage
// was returned from a transaction, and the transaction was committed or rolled back.
func (s *Storage) Update() *StorageUpdateOne {
return NewStorageClient(s.config).UpdateOne(s)
}
// Unwrap unwraps the Storage 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 (s *Storage) Unwrap() *Storage {
_tx, ok := s.config.driver.(*txDriver)
if !ok {
panic("ent: Storage is not a transactional entity")
}
s.config.driver = _tx.drv
return s
}
// String implements the fmt.Stringer.
func (s *Storage) String() string {
var builder strings.Builder
builder.WriteString("Storage(")
builder.WriteString(fmt.Sprintf("id=%v, ", s.ID))
builder.WriteString("name=")
builder.WriteString(s.Name)
builder.WriteString(", ")
builder.WriteString("implementation=")
builder.WriteString(s.Implementation)
builder.WriteString(", ")
builder.WriteString("path=")
builder.WriteString(s.Path)
builder.WriteString(", ")
builder.WriteString("user=")
builder.WriteString(s.User)
builder.WriteString(", ")
builder.WriteString("password=")
builder.WriteString(s.Password)
builder.WriteString(", ")
builder.WriteString("deleted=")
builder.WriteString(fmt.Sprintf("%v", s.Deleted))
builder.WriteString(", ")
builder.WriteString("default=")
builder.WriteString(fmt.Sprintf("%v", s.Default))
builder.WriteByte(')')
return builder.String()
}
// Storages is a parsable slice of Storage.
type Storages []*Storage

102
ent/storage/storage.go Normal file
View File

@@ -0,0 +1,102 @@
// Code generated by ent, DO NOT EDIT.
package storage
import (
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the storage type in the database.
Label = "storage"
// 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"
// FieldImplementation holds the string denoting the implementation field in the database.
FieldImplementation = "implementation"
// FieldPath holds the string denoting the path field in the database.
FieldPath = "path"
// FieldUser holds the string denoting the user field in the database.
FieldUser = "user"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// FieldDeleted holds the string denoting the deleted field in the database.
FieldDeleted = "deleted"
// FieldDefault holds the string denoting the default field in the database.
FieldDefault = "default"
// Table holds the table name of the storage in the database.
Table = "storages"
)
// Columns holds all SQL columns for storage fields.
var Columns = []string{
FieldID,
FieldName,
FieldImplementation,
FieldPath,
FieldUser,
FieldPassword,
FieldDeleted,
FieldDefault,
}
// 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 (
// DefaultDeleted holds the default value on creation for the "deleted" field.
DefaultDeleted bool
// DefaultDefault holds the default value on creation for the "default" field.
DefaultDefault bool
)
// OrderOption defines the ordering options for the Storage 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()
}
// ByImplementation orders the results by the implementation field.
func ByImplementation(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldImplementation, opts...).ToFunc()
}
// ByPath orders the results by the path field.
func ByPath(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPath, opts...).ToFunc()
}
// ByUser orders the results by the user field.
func ByUser(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUser, opts...).ToFunc()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByDeleted orders the results by the deleted field.
func ByDeleted(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDeleted, opts...).ToFunc()
}
// ByDefault orders the results by the default field.
func ByDefault(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDefault, opts...).ToFunc()
}

469
ent/storage/where.go Normal file
View File

@@ -0,0 +1,469 @@
// Code generated by ent, DO NOT EDIT.
package storage
import (
"polaris/ent/predicate"
"entgo.io/ent/dialect/sql"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldName, v))
}
// Implementation applies equality check predicate on the "implementation" field. It's identical to ImplementationEQ.
func Implementation(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldImplementation, v))
}
// Path applies equality check predicate on the "path" field. It's identical to PathEQ.
func Path(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldPath, v))
}
// User applies equality check predicate on the "user" field. It's identical to UserEQ.
func User(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldUser, v))
}
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
func Password(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldPassword, v))
}
// Deleted applies equality check predicate on the "deleted" field. It's identical to DeletedEQ.
func Deleted(v bool) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldDeleted, v))
}
// Default applies equality check predicate on the "default" field. It's identical to DefaultEQ.
func Default(v bool) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldDefault, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.Storage {
return predicate.Storage(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldContainsFold(FieldName, v))
}
// ImplementationEQ applies the EQ predicate on the "implementation" field.
func ImplementationEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldImplementation, v))
}
// ImplementationNEQ applies the NEQ predicate on the "implementation" field.
func ImplementationNEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldImplementation, v))
}
// ImplementationIn applies the In predicate on the "implementation" field.
func ImplementationIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldImplementation, vs...))
}
// ImplementationNotIn applies the NotIn predicate on the "implementation" field.
func ImplementationNotIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldImplementation, vs...))
}
// ImplementationGT applies the GT predicate on the "implementation" field.
func ImplementationGT(v string) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldImplementation, v))
}
// ImplementationGTE applies the GTE predicate on the "implementation" field.
func ImplementationGTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldImplementation, v))
}
// ImplementationLT applies the LT predicate on the "implementation" field.
func ImplementationLT(v string) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldImplementation, v))
}
// ImplementationLTE applies the LTE predicate on the "implementation" field.
func ImplementationLTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldImplementation, v))
}
// ImplementationContains applies the Contains predicate on the "implementation" field.
func ImplementationContains(v string) predicate.Storage {
return predicate.Storage(sql.FieldContains(FieldImplementation, v))
}
// ImplementationHasPrefix applies the HasPrefix predicate on the "implementation" field.
func ImplementationHasPrefix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasPrefix(FieldImplementation, v))
}
// ImplementationHasSuffix applies the HasSuffix predicate on the "implementation" field.
func ImplementationHasSuffix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasSuffix(FieldImplementation, v))
}
// ImplementationEqualFold applies the EqualFold predicate on the "implementation" field.
func ImplementationEqualFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldEqualFold(FieldImplementation, v))
}
// ImplementationContainsFold applies the ContainsFold predicate on the "implementation" field.
func ImplementationContainsFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldContainsFold(FieldImplementation, v))
}
// PathEQ applies the EQ predicate on the "path" field.
func PathEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldPath, v))
}
// PathNEQ applies the NEQ predicate on the "path" field.
func PathNEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldPath, v))
}
// PathIn applies the In predicate on the "path" field.
func PathIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldPath, vs...))
}
// PathNotIn applies the NotIn predicate on the "path" field.
func PathNotIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldPath, vs...))
}
// PathGT applies the GT predicate on the "path" field.
func PathGT(v string) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldPath, v))
}
// PathGTE applies the GTE predicate on the "path" field.
func PathGTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldPath, v))
}
// PathLT applies the LT predicate on the "path" field.
func PathLT(v string) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldPath, v))
}
// PathLTE applies the LTE predicate on the "path" field.
func PathLTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldPath, v))
}
// PathContains applies the Contains predicate on the "path" field.
func PathContains(v string) predicate.Storage {
return predicate.Storage(sql.FieldContains(FieldPath, v))
}
// PathHasPrefix applies the HasPrefix predicate on the "path" field.
func PathHasPrefix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasPrefix(FieldPath, v))
}
// PathHasSuffix applies the HasSuffix predicate on the "path" field.
func PathHasSuffix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasSuffix(FieldPath, v))
}
// PathEqualFold applies the EqualFold predicate on the "path" field.
func PathEqualFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldEqualFold(FieldPath, v))
}
// PathContainsFold applies the ContainsFold predicate on the "path" field.
func PathContainsFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldContainsFold(FieldPath, v))
}
// UserEQ applies the EQ predicate on the "user" field.
func UserEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldUser, v))
}
// UserNEQ applies the NEQ predicate on the "user" field.
func UserNEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldUser, v))
}
// UserIn applies the In predicate on the "user" field.
func UserIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldUser, vs...))
}
// UserNotIn applies the NotIn predicate on the "user" field.
func UserNotIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldUser, vs...))
}
// UserGT applies the GT predicate on the "user" field.
func UserGT(v string) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldUser, v))
}
// UserGTE applies the GTE predicate on the "user" field.
func UserGTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldUser, v))
}
// UserLT applies the LT predicate on the "user" field.
func UserLT(v string) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldUser, v))
}
// UserLTE applies the LTE predicate on the "user" field.
func UserLTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldUser, v))
}
// UserContains applies the Contains predicate on the "user" field.
func UserContains(v string) predicate.Storage {
return predicate.Storage(sql.FieldContains(FieldUser, v))
}
// UserHasPrefix applies the HasPrefix predicate on the "user" field.
func UserHasPrefix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasPrefix(FieldUser, v))
}
// UserHasSuffix applies the HasSuffix predicate on the "user" field.
func UserHasSuffix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasSuffix(FieldUser, v))
}
// UserIsNil applies the IsNil predicate on the "user" field.
func UserIsNil() predicate.Storage {
return predicate.Storage(sql.FieldIsNull(FieldUser))
}
// UserNotNil applies the NotNil predicate on the "user" field.
func UserNotNil() predicate.Storage {
return predicate.Storage(sql.FieldNotNull(FieldUser))
}
// UserEqualFold applies the EqualFold predicate on the "user" field.
func UserEqualFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldEqualFold(FieldUser, v))
}
// UserContainsFold applies the ContainsFold predicate on the "user" field.
func UserContainsFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldContainsFold(FieldUser, v))
}
// PasswordEQ applies the EQ predicate on the "password" field.
func PasswordEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldPassword, v))
}
// PasswordNEQ applies the NEQ predicate on the "password" field.
func PasswordNEQ(v string) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldPassword, v))
}
// PasswordIn applies the In predicate on the "password" field.
func PasswordIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldIn(FieldPassword, vs...))
}
// PasswordNotIn applies the NotIn predicate on the "password" field.
func PasswordNotIn(vs ...string) predicate.Storage {
return predicate.Storage(sql.FieldNotIn(FieldPassword, vs...))
}
// PasswordGT applies the GT predicate on the "password" field.
func PasswordGT(v string) predicate.Storage {
return predicate.Storage(sql.FieldGT(FieldPassword, v))
}
// PasswordGTE applies the GTE predicate on the "password" field.
func PasswordGTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldGTE(FieldPassword, v))
}
// PasswordLT applies the LT predicate on the "password" field.
func PasswordLT(v string) predicate.Storage {
return predicate.Storage(sql.FieldLT(FieldPassword, v))
}
// PasswordLTE applies the LTE predicate on the "password" field.
func PasswordLTE(v string) predicate.Storage {
return predicate.Storage(sql.FieldLTE(FieldPassword, v))
}
// PasswordContains applies the Contains predicate on the "password" field.
func PasswordContains(v string) predicate.Storage {
return predicate.Storage(sql.FieldContains(FieldPassword, v))
}
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
func PasswordHasPrefix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasPrefix(FieldPassword, v))
}
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
func PasswordHasSuffix(v string) predicate.Storage {
return predicate.Storage(sql.FieldHasSuffix(FieldPassword, v))
}
// PasswordIsNil applies the IsNil predicate on the "password" field.
func PasswordIsNil() predicate.Storage {
return predicate.Storage(sql.FieldIsNull(FieldPassword))
}
// PasswordNotNil applies the NotNil predicate on the "password" field.
func PasswordNotNil() predicate.Storage {
return predicate.Storage(sql.FieldNotNull(FieldPassword))
}
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
func PasswordEqualFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldEqualFold(FieldPassword, v))
}
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
func PasswordContainsFold(v string) predicate.Storage {
return predicate.Storage(sql.FieldContainsFold(FieldPassword, v))
}
// DeletedEQ applies the EQ predicate on the "deleted" field.
func DeletedEQ(v bool) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldDeleted, v))
}
// DeletedNEQ applies the NEQ predicate on the "deleted" field.
func DeletedNEQ(v bool) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldDeleted, v))
}
// DefaultEQ applies the EQ predicate on the "default" field.
func DefaultEQ(v bool) predicate.Storage {
return predicate.Storage(sql.FieldEQ(FieldDefault, v))
}
// DefaultNEQ applies the NEQ predicate on the "default" field.
func DefaultNEQ(v bool) predicate.Storage {
return predicate.Storage(sql.FieldNEQ(FieldDefault, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Storage) predicate.Storage {
return predicate.Storage(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Storage) predicate.Storage {
return predicate.Storage(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Storage) predicate.Storage {
return predicate.Storage(sql.NotPredicates(p))
}

301
ent/storage_create.go Normal file
View File

@@ -0,0 +1,301 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/storage"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// StorageCreate is the builder for creating a Storage entity.
type StorageCreate struct {
config
mutation *StorageMutation
hooks []Hook
}
// SetName sets the "name" field.
func (sc *StorageCreate) SetName(s string) *StorageCreate {
sc.mutation.SetName(s)
return sc
}
// SetImplementation sets the "implementation" field.
func (sc *StorageCreate) SetImplementation(s string) *StorageCreate {
sc.mutation.SetImplementation(s)
return sc
}
// SetPath sets the "path" field.
func (sc *StorageCreate) SetPath(s string) *StorageCreate {
sc.mutation.SetPath(s)
return sc
}
// SetUser sets the "user" field.
func (sc *StorageCreate) SetUser(s string) *StorageCreate {
sc.mutation.SetUser(s)
return sc
}
// SetNillableUser sets the "user" field if the given value is not nil.
func (sc *StorageCreate) SetNillableUser(s *string) *StorageCreate {
if s != nil {
sc.SetUser(*s)
}
return sc
}
// SetPassword sets the "password" field.
func (sc *StorageCreate) SetPassword(s string) *StorageCreate {
sc.mutation.SetPassword(s)
return sc
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (sc *StorageCreate) SetNillablePassword(s *string) *StorageCreate {
if s != nil {
sc.SetPassword(*s)
}
return sc
}
// SetDeleted sets the "deleted" field.
func (sc *StorageCreate) SetDeleted(b bool) *StorageCreate {
sc.mutation.SetDeleted(b)
return sc
}
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
func (sc *StorageCreate) SetNillableDeleted(b *bool) *StorageCreate {
if b != nil {
sc.SetDeleted(*b)
}
return sc
}
// SetDefault sets the "default" field.
func (sc *StorageCreate) SetDefault(b bool) *StorageCreate {
sc.mutation.SetDefault(b)
return sc
}
// SetNillableDefault sets the "default" field if the given value is not nil.
func (sc *StorageCreate) SetNillableDefault(b *bool) *StorageCreate {
if b != nil {
sc.SetDefault(*b)
}
return sc
}
// Mutation returns the StorageMutation object of the builder.
func (sc *StorageCreate) Mutation() *StorageMutation {
return sc.mutation
}
// Save creates the Storage in the database.
func (sc *StorageCreate) Save(ctx context.Context) (*Storage, error) {
sc.defaults()
return withHooks(ctx, sc.sqlSave, sc.mutation, sc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (sc *StorageCreate) SaveX(ctx context.Context) *Storage {
v, err := sc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (sc *StorageCreate) Exec(ctx context.Context) error {
_, err := sc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (sc *StorageCreate) ExecX(ctx context.Context) {
if err := sc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (sc *StorageCreate) defaults() {
if _, ok := sc.mutation.Deleted(); !ok {
v := storage.DefaultDeleted
sc.mutation.SetDeleted(v)
}
if _, ok := sc.mutation.Default(); !ok {
v := storage.DefaultDefault
sc.mutation.SetDefault(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (sc *StorageCreate) check() error {
if _, ok := sc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Storage.name"`)}
}
if _, ok := sc.mutation.Implementation(); !ok {
return &ValidationError{Name: "implementation", err: errors.New(`ent: missing required field "Storage.implementation"`)}
}
if _, ok := sc.mutation.Path(); !ok {
return &ValidationError{Name: "path", err: errors.New(`ent: missing required field "Storage.path"`)}
}
if _, ok := sc.mutation.Deleted(); !ok {
return &ValidationError{Name: "deleted", err: errors.New(`ent: missing required field "Storage.deleted"`)}
}
if _, ok := sc.mutation.Default(); !ok {
return &ValidationError{Name: "default", err: errors.New(`ent: missing required field "Storage.default"`)}
}
return nil
}
func (sc *StorageCreate) sqlSave(ctx context.Context) (*Storage, error) {
if err := sc.check(); err != nil {
return nil, err
}
_node, _spec := sc.createSpec()
if err := sqlgraph.CreateNode(ctx, sc.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)
sc.mutation.id = &_node.ID
sc.mutation.done = true
return _node, nil
}
func (sc *StorageCreate) createSpec() (*Storage, *sqlgraph.CreateSpec) {
var (
_node = &Storage{config: sc.config}
_spec = sqlgraph.NewCreateSpec(storage.Table, sqlgraph.NewFieldSpec(storage.FieldID, field.TypeInt))
)
if value, ok := sc.mutation.Name(); ok {
_spec.SetField(storage.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := sc.mutation.Implementation(); ok {
_spec.SetField(storage.FieldImplementation, field.TypeString, value)
_node.Implementation = value
}
if value, ok := sc.mutation.Path(); ok {
_spec.SetField(storage.FieldPath, field.TypeString, value)
_node.Path = value
}
if value, ok := sc.mutation.User(); ok {
_spec.SetField(storage.FieldUser, field.TypeString, value)
_node.User = value
}
if value, ok := sc.mutation.Password(); ok {
_spec.SetField(storage.FieldPassword, field.TypeString, value)
_node.Password = value
}
if value, ok := sc.mutation.Deleted(); ok {
_spec.SetField(storage.FieldDeleted, field.TypeBool, value)
_node.Deleted = value
}
if value, ok := sc.mutation.Default(); ok {
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
_node.Default = value
}
return _node, _spec
}
// StorageCreateBulk is the builder for creating many Storage entities in bulk.
type StorageCreateBulk struct {
config
err error
builders []*StorageCreate
}
// Save creates the Storage entities in the database.
func (scb *StorageCreateBulk) Save(ctx context.Context) ([]*Storage, error) {
if scb.err != nil {
return nil, scb.err
}
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
nodes := make([]*Storage, len(scb.builders))
mutators := make([]Mutator, len(scb.builders))
for i := range scb.builders {
func(i int, root context.Context) {
builder := scb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*StorageMutation)
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, scb.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, scb.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, scb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (scb *StorageCreateBulk) SaveX(ctx context.Context) []*Storage {
v, err := scb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (scb *StorageCreateBulk) Exec(ctx context.Context) error {
_, err := scb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (scb *StorageCreateBulk) ExecX(ctx context.Context) {
if err := scb.Exec(ctx); err != nil {
panic(err)
}
}

88
ent/storage_delete.go Normal file
View File

@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"polaris/ent/predicate"
"polaris/ent/storage"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// StorageDelete is the builder for deleting a Storage entity.
type StorageDelete struct {
config
hooks []Hook
mutation *StorageMutation
}
// Where appends a list predicates to the StorageDelete builder.
func (sd *StorageDelete) Where(ps ...predicate.Storage) *StorageDelete {
sd.mutation.Where(ps...)
return sd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (sd *StorageDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, sd.sqlExec, sd.mutation, sd.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (sd *StorageDelete) ExecX(ctx context.Context) int {
n, err := sd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (sd *StorageDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(storage.Table, sqlgraph.NewFieldSpec(storage.FieldID, field.TypeInt))
if ps := sd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, sd.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
sd.mutation.done = true
return affected, err
}
// StorageDeleteOne is the builder for deleting a single Storage entity.
type StorageDeleteOne struct {
sd *StorageDelete
}
// Where appends a list predicates to the StorageDelete builder.
func (sdo *StorageDeleteOne) Where(ps ...predicate.Storage) *StorageDeleteOne {
sdo.sd.mutation.Where(ps...)
return sdo
}
// Exec executes the deletion query.
func (sdo *StorageDeleteOne) Exec(ctx context.Context) error {
n, err := sdo.sd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{storage.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (sdo *StorageDeleteOne) ExecX(ctx context.Context) {
if err := sdo.Exec(ctx); err != nil {
panic(err)
}
}

526
ent/storage_query.go Normal file
View File

@@ -0,0 +1,526 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"polaris/ent/predicate"
"polaris/ent/storage"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// StorageQuery is the builder for querying Storage entities.
type StorageQuery struct {
config
ctx *QueryContext
order []storage.OrderOption
inters []Interceptor
predicates []predicate.Storage
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the StorageQuery builder.
func (sq *StorageQuery) Where(ps ...predicate.Storage) *StorageQuery {
sq.predicates = append(sq.predicates, ps...)
return sq
}
// Limit the number of records to be returned by this query.
func (sq *StorageQuery) Limit(limit int) *StorageQuery {
sq.ctx.Limit = &limit
return sq
}
// Offset to start from.
func (sq *StorageQuery) Offset(offset int) *StorageQuery {
sq.ctx.Offset = &offset
return sq
}
// 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 (sq *StorageQuery) Unique(unique bool) *StorageQuery {
sq.ctx.Unique = &unique
return sq
}
// Order specifies how the records should be ordered.
func (sq *StorageQuery) Order(o ...storage.OrderOption) *StorageQuery {
sq.order = append(sq.order, o...)
return sq
}
// First returns the first Storage entity from the query.
// Returns a *NotFoundError when no Storage was found.
func (sq *StorageQuery) First(ctx context.Context) (*Storage, error) {
nodes, err := sq.Limit(1).All(setContextOp(ctx, sq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{storage.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (sq *StorageQuery) FirstX(ctx context.Context) *Storage {
node, err := sq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first Storage ID from the query.
// Returns a *NotFoundError when no Storage ID was found.
func (sq *StorageQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = sq.Limit(1).IDs(setContextOp(ctx, sq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{storage.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (sq *StorageQuery) FirstIDX(ctx context.Context) int {
id, err := sq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single Storage entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Storage entity is found.
// Returns a *NotFoundError when no Storage entities are found.
func (sq *StorageQuery) Only(ctx context.Context) (*Storage, error) {
nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only"))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{storage.Label}
default:
return nil, &NotSingularError{storage.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (sq *StorageQuery) OnlyX(ctx context.Context) *Storage {
node, err := sq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only Storage ID in the query.
// Returns a *NotSingularError when more than one Storage ID is found.
// Returns a *NotFoundError when no entities are found.
func (sq *StorageQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{storage.Label}
default:
err = &NotSingularError{storage.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (sq *StorageQuery) OnlyIDX(ctx context.Context) int {
id, err := sq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of Storages.
func (sq *StorageQuery) All(ctx context.Context) ([]*Storage, error) {
ctx = setContextOp(ctx, sq.ctx, "All")
if err := sq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Storage, *StorageQuery]()
return withInterceptors[[]*Storage](ctx, sq, qr, sq.inters)
}
// AllX is like All, but panics if an error occurs.
func (sq *StorageQuery) AllX(ctx context.Context) []*Storage {
nodes, err := sq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of Storage IDs.
func (sq *StorageQuery) IDs(ctx context.Context) (ids []int, err error) {
if sq.ctx.Unique == nil && sq.path != nil {
sq.Unique(true)
}
ctx = setContextOp(ctx, sq.ctx, "IDs")
if err = sq.Select(storage.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (sq *StorageQuery) IDsX(ctx context.Context) []int {
ids, err := sq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (sq *StorageQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, sq.ctx, "Count")
if err := sq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, sq, querierCount[*StorageQuery](), sq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (sq *StorageQuery) CountX(ctx context.Context) int {
count, err := sq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (sq *StorageQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, sq.ctx, "Exist")
switch _, err := sq.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 (sq *StorageQuery) ExistX(ctx context.Context) bool {
exist, err := sq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the StorageQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (sq *StorageQuery) Clone() *StorageQuery {
if sq == nil {
return nil
}
return &StorageQuery{
config: sq.config,
ctx: sq.ctx.Clone(),
order: append([]storage.OrderOption{}, sq.order...),
inters: append([]Interceptor{}, sq.inters...),
predicates: append([]predicate.Storage{}, sq.predicates...),
// clone intermediate query.
sql: sq.sql.Clone(),
path: sq.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.Storage.Query().
// GroupBy(storage.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (sq *StorageQuery) GroupBy(field string, fields ...string) *StorageGroupBy {
sq.ctx.Fields = append([]string{field}, fields...)
grbuild := &StorageGroupBy{build: sq}
grbuild.flds = &sq.ctx.Fields
grbuild.label = storage.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.Storage.Query().
// Select(storage.FieldName).
// Scan(ctx, &v)
func (sq *StorageQuery) Select(fields ...string) *StorageSelect {
sq.ctx.Fields = append(sq.ctx.Fields, fields...)
sbuild := &StorageSelect{StorageQuery: sq}
sbuild.label = storage.Label
sbuild.flds, sbuild.scan = &sq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a StorageSelect configured with the given aggregations.
func (sq *StorageQuery) Aggregate(fns ...AggregateFunc) *StorageSelect {
return sq.Select().Aggregate(fns...)
}
func (sq *StorageQuery) prepareQuery(ctx context.Context) error {
for _, inter := range sq.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, sq); err != nil {
return err
}
}
}
for _, f := range sq.ctx.Fields {
if !storage.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if sq.path != nil {
prev, err := sq.path(ctx)
if err != nil {
return err
}
sq.sql = prev
}
return nil
}
func (sq *StorageQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Storage, error) {
var (
nodes = []*Storage{}
_spec = sq.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Storage).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Storage{config: sq.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, sq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (sq *StorageQuery) sqlCount(ctx context.Context) (int, error) {
_spec := sq.querySpec()
_spec.Node.Columns = sq.ctx.Fields
if len(sq.ctx.Fields) > 0 {
_spec.Unique = sq.ctx.Unique != nil && *sq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, sq.driver, _spec)
}
func (sq *StorageQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(storage.Table, storage.Columns, sqlgraph.NewFieldSpec(storage.FieldID, field.TypeInt))
_spec.From = sq.sql
if unique := sq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if sq.path != nil {
_spec.Unique = true
}
if fields := sq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, storage.FieldID)
for i := range fields {
if fields[i] != storage.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := sq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := sq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := sq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := sq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (sq *StorageQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(sq.driver.Dialect())
t1 := builder.Table(storage.Table)
columns := sq.ctx.Fields
if len(columns) == 0 {
columns = storage.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if sq.sql != nil {
selector = sq.sql
selector.Select(selector.Columns(columns...)...)
}
if sq.ctx.Unique != nil && *sq.ctx.Unique {
selector.Distinct()
}
for _, p := range sq.predicates {
p(selector)
}
for _, p := range sq.order {
p(selector)
}
if offset := sq.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 := sq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// StorageGroupBy is the group-by builder for Storage entities.
type StorageGroupBy struct {
selector
build *StorageQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (sgb *StorageGroupBy) Aggregate(fns ...AggregateFunc) *StorageGroupBy {
sgb.fns = append(sgb.fns, fns...)
return sgb
}
// Scan applies the selector query and scans the result into the given value.
func (sgb *StorageGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, sgb.build.ctx, "GroupBy")
if err := sgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*StorageQuery, *StorageGroupBy](ctx, sgb.build, sgb, sgb.build.inters, v)
}
func (sgb *StorageGroupBy) sqlScan(ctx context.Context, root *StorageQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(sgb.fns))
for _, fn := range sgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*sgb.flds)+len(sgb.fns))
for _, f := range *sgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*sgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := sgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// StorageSelect is the builder for selecting fields of Storage entities.
type StorageSelect struct {
*StorageQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (ss *StorageSelect) Aggregate(fns ...AggregateFunc) *StorageSelect {
ss.fns = append(ss.fns, fns...)
return ss
}
// Scan applies the selector query and scans the result into the given value.
func (ss *StorageSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ss.ctx, "Select")
if err := ss.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*StorageQuery, *StorageSelect](ctx, ss.StorageQuery, ss, ss.inters, v)
}
func (ss *StorageSelect) sqlScan(ctx context.Context, root *StorageQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(ss.fns))
for _, fn := range ss.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*ss.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 := ss.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}

449
ent/storage_update.go Normal file
View File

@@ -0,0 +1,449 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"polaris/ent/predicate"
"polaris/ent/storage"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// StorageUpdate is the builder for updating Storage entities.
type StorageUpdate struct {
config
hooks []Hook
mutation *StorageMutation
}
// Where appends a list predicates to the StorageUpdate builder.
func (su *StorageUpdate) Where(ps ...predicate.Storage) *StorageUpdate {
su.mutation.Where(ps...)
return su
}
// SetName sets the "name" field.
func (su *StorageUpdate) SetName(s string) *StorageUpdate {
su.mutation.SetName(s)
return su
}
// SetNillableName sets the "name" field if the given value is not nil.
func (su *StorageUpdate) SetNillableName(s *string) *StorageUpdate {
if s != nil {
su.SetName(*s)
}
return su
}
// SetImplementation sets the "implementation" field.
func (su *StorageUpdate) SetImplementation(s string) *StorageUpdate {
su.mutation.SetImplementation(s)
return su
}
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
func (su *StorageUpdate) SetNillableImplementation(s *string) *StorageUpdate {
if s != nil {
su.SetImplementation(*s)
}
return su
}
// SetPath sets the "path" field.
func (su *StorageUpdate) SetPath(s string) *StorageUpdate {
su.mutation.SetPath(s)
return su
}
// SetNillablePath sets the "path" field if the given value is not nil.
func (su *StorageUpdate) SetNillablePath(s *string) *StorageUpdate {
if s != nil {
su.SetPath(*s)
}
return su
}
// SetUser sets the "user" field.
func (su *StorageUpdate) SetUser(s string) *StorageUpdate {
su.mutation.SetUser(s)
return su
}
// SetNillableUser sets the "user" field if the given value is not nil.
func (su *StorageUpdate) SetNillableUser(s *string) *StorageUpdate {
if s != nil {
su.SetUser(*s)
}
return su
}
// ClearUser clears the value of the "user" field.
func (su *StorageUpdate) ClearUser() *StorageUpdate {
su.mutation.ClearUser()
return su
}
// SetPassword sets the "password" field.
func (su *StorageUpdate) SetPassword(s string) *StorageUpdate {
su.mutation.SetPassword(s)
return su
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (su *StorageUpdate) SetNillablePassword(s *string) *StorageUpdate {
if s != nil {
su.SetPassword(*s)
}
return su
}
// ClearPassword clears the value of the "password" field.
func (su *StorageUpdate) ClearPassword() *StorageUpdate {
su.mutation.ClearPassword()
return su
}
// SetDeleted sets the "deleted" field.
func (su *StorageUpdate) SetDeleted(b bool) *StorageUpdate {
su.mutation.SetDeleted(b)
return su
}
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
func (su *StorageUpdate) SetNillableDeleted(b *bool) *StorageUpdate {
if b != nil {
su.SetDeleted(*b)
}
return su
}
// SetDefault sets the "default" field.
func (su *StorageUpdate) SetDefault(b bool) *StorageUpdate {
su.mutation.SetDefault(b)
return su
}
// SetNillableDefault sets the "default" field if the given value is not nil.
func (su *StorageUpdate) SetNillableDefault(b *bool) *StorageUpdate {
if b != nil {
su.SetDefault(*b)
}
return su
}
// Mutation returns the StorageMutation object of the builder.
func (su *StorageUpdate) Mutation() *StorageMutation {
return su.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (su *StorageUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (su *StorageUpdate) SaveX(ctx context.Context) int {
affected, err := su.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (su *StorageUpdate) Exec(ctx context.Context) error {
_, err := su.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (su *StorageUpdate) ExecX(ctx context.Context) {
if err := su.Exec(ctx); err != nil {
panic(err)
}
}
func (su *StorageUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(storage.Table, storage.Columns, sqlgraph.NewFieldSpec(storage.FieldID, field.TypeInt))
if ps := su.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := su.mutation.Name(); ok {
_spec.SetField(storage.FieldName, field.TypeString, value)
}
if value, ok := su.mutation.Implementation(); ok {
_spec.SetField(storage.FieldImplementation, field.TypeString, value)
}
if value, ok := su.mutation.Path(); ok {
_spec.SetField(storage.FieldPath, field.TypeString, value)
}
if value, ok := su.mutation.User(); ok {
_spec.SetField(storage.FieldUser, field.TypeString, value)
}
if su.mutation.UserCleared() {
_spec.ClearField(storage.FieldUser, field.TypeString)
}
if value, ok := su.mutation.Password(); ok {
_spec.SetField(storage.FieldPassword, field.TypeString, value)
}
if su.mutation.PasswordCleared() {
_spec.ClearField(storage.FieldPassword, field.TypeString)
}
if value, ok := su.mutation.Deleted(); ok {
_spec.SetField(storage.FieldDeleted, field.TypeBool, value)
}
if value, ok := su.mutation.Default(); ok {
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{storage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
su.mutation.done = true
return n, nil
}
// StorageUpdateOne is the builder for updating a single Storage entity.
type StorageUpdateOne struct {
config
fields []string
hooks []Hook
mutation *StorageMutation
}
// SetName sets the "name" field.
func (suo *StorageUpdateOne) SetName(s string) *StorageUpdateOne {
suo.mutation.SetName(s)
return suo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableName(s *string) *StorageUpdateOne {
if s != nil {
suo.SetName(*s)
}
return suo
}
// SetImplementation sets the "implementation" field.
func (suo *StorageUpdateOne) SetImplementation(s string) *StorageUpdateOne {
suo.mutation.SetImplementation(s)
return suo
}
// SetNillableImplementation sets the "implementation" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableImplementation(s *string) *StorageUpdateOne {
if s != nil {
suo.SetImplementation(*s)
}
return suo
}
// SetPath sets the "path" field.
func (suo *StorageUpdateOne) SetPath(s string) *StorageUpdateOne {
suo.mutation.SetPath(s)
return suo
}
// SetNillablePath sets the "path" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillablePath(s *string) *StorageUpdateOne {
if s != nil {
suo.SetPath(*s)
}
return suo
}
// SetUser sets the "user" field.
func (suo *StorageUpdateOne) SetUser(s string) *StorageUpdateOne {
suo.mutation.SetUser(s)
return suo
}
// SetNillableUser sets the "user" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableUser(s *string) *StorageUpdateOne {
if s != nil {
suo.SetUser(*s)
}
return suo
}
// ClearUser clears the value of the "user" field.
func (suo *StorageUpdateOne) ClearUser() *StorageUpdateOne {
suo.mutation.ClearUser()
return suo
}
// SetPassword sets the "password" field.
func (suo *StorageUpdateOne) SetPassword(s string) *StorageUpdateOne {
suo.mutation.SetPassword(s)
return suo
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillablePassword(s *string) *StorageUpdateOne {
if s != nil {
suo.SetPassword(*s)
}
return suo
}
// ClearPassword clears the value of the "password" field.
func (suo *StorageUpdateOne) ClearPassword() *StorageUpdateOne {
suo.mutation.ClearPassword()
return suo
}
// SetDeleted sets the "deleted" field.
func (suo *StorageUpdateOne) SetDeleted(b bool) *StorageUpdateOne {
suo.mutation.SetDeleted(b)
return suo
}
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableDeleted(b *bool) *StorageUpdateOne {
if b != nil {
suo.SetDeleted(*b)
}
return suo
}
// SetDefault sets the "default" field.
func (suo *StorageUpdateOne) SetDefault(b bool) *StorageUpdateOne {
suo.mutation.SetDefault(b)
return suo
}
// SetNillableDefault sets the "default" field if the given value is not nil.
func (suo *StorageUpdateOne) SetNillableDefault(b *bool) *StorageUpdateOne {
if b != nil {
suo.SetDefault(*b)
}
return suo
}
// Mutation returns the StorageMutation object of the builder.
func (suo *StorageUpdateOne) Mutation() *StorageMutation {
return suo.mutation
}
// Where appends a list predicates to the StorageUpdate builder.
func (suo *StorageUpdateOne) Where(ps ...predicate.Storage) *StorageUpdateOne {
suo.mutation.Where(ps...)
return suo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (suo *StorageUpdateOne) Select(field string, fields ...string) *StorageUpdateOne {
suo.fields = append([]string{field}, fields...)
return suo
}
// Save executes the query and returns the updated Storage entity.
func (suo *StorageUpdateOne) Save(ctx context.Context) (*Storage, error) {
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (suo *StorageUpdateOne) SaveX(ctx context.Context) *Storage {
node, err := suo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (suo *StorageUpdateOne) Exec(ctx context.Context) error {
_, err := suo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (suo *StorageUpdateOne) ExecX(ctx context.Context) {
if err := suo.Exec(ctx); err != nil {
panic(err)
}
}
func (suo *StorageUpdateOne) sqlSave(ctx context.Context) (_node *Storage, err error) {
_spec := sqlgraph.NewUpdateSpec(storage.Table, storage.Columns, sqlgraph.NewFieldSpec(storage.FieldID, field.TypeInt))
id, ok := suo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Storage.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := suo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, storage.FieldID)
for _, f := range fields {
if !storage.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != storage.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := suo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := suo.mutation.Name(); ok {
_spec.SetField(storage.FieldName, field.TypeString, value)
}
if value, ok := suo.mutation.Implementation(); ok {
_spec.SetField(storage.FieldImplementation, field.TypeString, value)
}
if value, ok := suo.mutation.Path(); ok {
_spec.SetField(storage.FieldPath, field.TypeString, value)
}
if value, ok := suo.mutation.User(); ok {
_spec.SetField(storage.FieldUser, field.TypeString, value)
}
if suo.mutation.UserCleared() {
_spec.ClearField(storage.FieldUser, field.TypeString)
}
if value, ok := suo.mutation.Password(); ok {
_spec.SetField(storage.FieldPassword, field.TypeString, value)
}
if suo.mutation.PasswordCleared() {
_spec.ClearField(storage.FieldPassword, field.TypeString)
}
if value, ok := suo.mutation.Deleted(); ok {
_spec.SetField(storage.FieldDeleted, field.TypeBool, value)
}
if value, ok := suo.mutation.Default(); ok {
_spec.SetField(storage.FieldDefault, field.TypeBool, value)
}
_node = &Storage{config: suo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{storage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
suo.mutation.done = true
return _node, nil
}

View File

@@ -24,6 +24,8 @@ type Tx struct {
Series *SeriesClient
// Settings is the client for interacting with the Settings builders.
Settings *SettingsClient
// Storage is the client for interacting with the Storage builders.
Storage *StorageClient
// lazily loaded.
client *Client
@@ -161,6 +163,7 @@ func (tx *Tx) init() {
tx.Indexers = NewIndexersClient(tx.config)
tx.Series = NewSeriesClient(tx.config)
tx.Settings = NewSettingsClient(tx.config)
tx.Storage = NewStorageClient(tx.config)
}
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.

1
go.mod
View File

@@ -18,6 +18,7 @@ require (
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/emersion/go-webdav v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect

6
go.sum
View File

@@ -22,6 +22,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f/go.mod h1:2MKFUgfNMULRxqZkadG1Vh44we3y5gJAtTBlVsx1BKQ=
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM=
github.com/emersion/go-webdav v0.5.0 h1:Ak/BQLgAihJt/UxJbCsEXDPxS5Uw4nZzgIMOq3rkKjc=
github.com/emersion/go-webdav v0.5.0/go.mod h1:ycyIzTelG5pHln4t+Y32/zBvmrM7+mV7x+V+Gx4ZQno=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
@@ -147,6 +151,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/teambition/rrule-go v1.7.2/go.mod h1:mBJ1Ht5uboJ6jexKdNUJg2NcwP8uUMNvStWXlJD3MvU=
github.com/teambition/rrule-go v1.8.2/go.mod h1:Ieq5AbrKGciP1V//Wq8ktsTXwSwJHDD5mD/wLBGl3p4=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=

15
pkg/doc.go Normal file
View File

@@ -0,0 +1,15 @@
package pkg
type Torrent interface {
Name() string
Progress() int
Stop() error
Start() error
Remove() error
Save() string
}
type Storage interface {
}

59
pkg/storage/local.go Normal file
View File

@@ -0,0 +1,59 @@
package storage
import (
"io"
"io/fs"
"os"
"path/filepath"
"github.com/pkg/errors"
)
type Storage interface {
Move(src, dest string) error
ReadDir(dir string) ([]FileInfo, error)
}
func NewLocalStorage(dir string) *LocalStorage {
return &LocalStorage{dir: dir}
}
type LocalStorage struct {
dir string
}
func (l *LocalStorage) Move(src, dest string) error {
targetDir := filepath.Join(l.dir, dest)
err := filepath.Walk(src, func(path string, info fs.FileInfo, err error) error {
destName := filepath.Join(targetDir, info.Name())
srcName := filepath.Join(src, info.Name())
if info.IsDir() {
if err := os.Mkdir(destName, 0666); err != nil {
return errors.Wrapf(err, "mkdir %v", destName)
}
} else { //is file
if writer, err := os.Create(destName); err != nil {
return errors.Wrapf(err, "create file %s", destName)
} else {
defer writer.Close()
if f, err := os.OpenFile(srcName, os.O_RDONLY, 0666); err != nil {
return errors.Wrapf(err, "read file %v", srcName)
} else { //open success
defer f.Close()
_, err := io.Copy(writer, f)
if err != nil {
return errors.Wrap(err, "transmitting data error")
}
}
}
}
return nil
})
if err != nil {
return errors.Wrap(err, "move file error")
}
return os.RemoveAll(src)
}

98
pkg/storage/webdav.go Normal file
View File

@@ -0,0 +1,98 @@
package storage
import (
"context"
"io"
"io/fs"
"net/http"
"os"
"path/filepath"
"polaris/log"
"time"
"github.com/emersion/go-webdav"
"github.com/pkg/errors"
)
type FileInfo struct {
Path string
Size int64
ModTime time.Time
IsDir bool
MIMEType string
ETag string
}
type WebdavStorage struct {
fs *webdav.Client
}
func NewWebdavStorage(url, user, password string) (*WebdavStorage, error) {
c, err := webdav.NewClient(webdav.HTTPClientWithBasicAuth(http.DefaultClient, user, password), url)
if err != nil {
return nil, errors.Wrap(err, "new webdav")
}
fs, _ := c.ReadDir(context.TODO(), "./", false)
for _, f := range fs {
log.Infof("file: %v", f)
}
return &WebdavStorage{
fs: c,
}, nil
}
func (w *WebdavStorage) Move(local, remote string) error {
err := filepath.Walk(local, func(path string, info fs.FileInfo, err error) error {
name := filepath.Join(remote, info.Name())
if info.IsDir() {
if err := w.fs.Mkdir(context.TODO(), name); err != nil {
return errors.Wrapf(err, "mkdir %v", name)
}
} else {//is file
if writer, err := w.fs.Create(context.TODO(), name); err != nil {
return errors.Wrapf(err, "create file %s", name)
} else {
defer writer.Close()
if f, err := os.OpenFile(name, os.O_RDONLY, 0666); err != nil {
return errors.Wrapf(err, "read file %v", name)
} else { //open success
defer f.Close()
_, err := io.Copy(writer, f)
if err != nil {
return errors.Wrap(err, "transmitting data error")
}
}
}
}
return nil
})
if err != nil {
return errors.Wrap(err, "move file error")
}
return os.RemoveAll(local)
}
func (w *WebdavStorage) ReadDir(dir string) ([]FileInfo,error) {
fi, err := w.fs.ReadDir(context.TODO(), dir, false)
if err != nil {
return nil, err
}
var res []FileInfo = make([]FileInfo, 0, len(fi))
for _, f := range fi {
res = append(res, FileInfo{
Path: f.Path,
Size : f.Size,
ModTime : f.ModTime,
IsDir : f.IsDir,
MIMEType : f.MIMEType,
ETag : f.ETag,
})
}
return res, nil
}

View File

@@ -48,6 +48,10 @@ func (c *Client) GetSeasonDetails(id, seasonNumber int, language string) (*tmdb.
return c.tmdbClient.GetTVSeasonDetails(id, seasonNumber, withLangOption(language))
}
func (c *Client) GetTVAlternativeTitles(id int, language string) (*tmdb.TVAlternativeTitles, error) {
return c.tmdbClient.GetTVAlternativeTitles(id, withLangOption(language))
}
func wrapLanguage(lang string) string {
if lang == "" {
lang = "zh-CN"

View File

@@ -2,6 +2,8 @@ package transmission
import (
"net/url"
"strconv"
"github.com/hekmon/transmissionrpc"
"github.com/pkg/errors"
)
@@ -22,7 +24,48 @@ type Client struct {
c *transmissionrpc.Client
}
func (c *Client) Download(magnet string) (*transmissionrpc.Torrent, error) {
t, err := c.c.TorrentAdd(&transmissionrpc.TorrentAddPayload{Filename: &magnet})
return t, err
func (c *Client) Download(magnet, dir string) (*Torrent, error) {
t, err := c.c.TorrentAdd(&transmissionrpc.TorrentAddPayload{
Filename: &magnet,
DownloadDir: &dir,
})
return &Torrent{
t: t,
c: c.c,
}, err
}
type Torrent struct {
t *transmissionrpc.Torrent
c *transmissionrpc.Client
}
func (t *Torrent) Name() string {
return *t.t.Name
}
func (t *Torrent) Progress() int {
if *t.t.IsFinished {
return 100
}
return int(*t.t.PercentDone*100)
}
func (t *Torrent) Stop() error {
return t.c.TorrentStopIDs([]int64{*t.t.ID})
}
func (t *Torrent) Start() error {
return t.c.TorrentStartIDs([]int64{*t.t.ID})
}
func (t *Torrent) Remove() error {
return t.c.TorrentRemove(&transmissionrpc.TorrentRemovePayload{
IDs: []int64{*t.t.ID},
DeleteLocalData: true,
})
}
func (t *Torrent) Save() string {
return strconv.Itoa(int(*t.t.ID))
}

View File

@@ -3,10 +3,12 @@ package server
import (
"fmt"
"polaris/db"
"polaris/ent"
"polaris/log"
"polaris/pkg/torznab"
"polaris/pkg/transmission"
"strconv"
"strings"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
@@ -88,6 +90,15 @@ func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
if series == nil {
return nil, fmt.Errorf("no tv series of id %v", in.ID)
}
var ep *ent.Episode
for _, e := range series.Episodes {
if e.SeasonNumber == in.Season && e.EpisodeNumber == in.Episode {
ep = e
}
}
if ep == nil {
return nil, errors.Errorf("no episode of season %d episode %d", in.Season, in.Episode)
}
res := s.searchTvWithTorznab(series.OriginalName, in.Season, in.Episode)
if len(res) == 0 {
@@ -95,11 +106,33 @@ func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
}
r1 := res[0]
log.Infof("found resource to download: %v", r1)
torrent, err := trc.Download(r1.Magnet)
torrent, err := trc.Download(r1.Magnet, s.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
s.tasks[r1.Name] = torrent
torrent.Start()
var name = series.NameEn
if name == "" {
name = series.OriginalName
}
var year = strings.Split(series.AirDate, "-")[0]
dir := fmt.Sprintf("%s (%s)/Season %02d", name, year, ep.SeasonNumber)
history, err :=s.db.SaveHistoryRecord(ent.History{
SeriesID: ep.SeriesID,
EpisodeID: ep.ID,
SourceTitle: r1.Name,
TargetDir: dir,
Completed: false,
Saved: torrent.Save(),
})
if err != nil {
return nil, errors.Wrap(err, "save record")
}
s.tasks[history.ID] = torrent
// t, err := downloader.DownloadByMagnet(r1.Magnet, "~")
// if err != nil {
// return nil, errors.Wrap(err, "download torrent")

49
server/scheduler.go Normal file
View File

@@ -0,0 +1,49 @@
package server
import (
"path/filepath"
"polaris/db"
"polaris/log"
"polaris/pkg/storage"
"github.com/pkg/errors"
)
func (s *Server) scheduler() {
s.cron.AddFunc("@every 1m", s.checkTasks)
}
func (s *Server) checkTasks() {
for id, t := range s.tasks {
log.Infof("task %s percentage done: %d%%", t.Name(), t.Progress())
if t.Progress() == 100 {
log.Infof("task is done: %v", t.Name())
s.moveCompletedTask(id)
}
}
}
func (s *Server) moveCompletedTask(id int) error {
torrent := s.tasks[id]
r := s.db.GetHistory(id)
series := s.db.GetSeriesDetails(r.SeriesID)
st := s.db.GetStorage(series.StorageID)
if st.Implementation == db.ImplWebdav {
storageImpl, err := storage.NewWebdavStorage(st.Path, st.User, st.Password)
if err != nil {
return errors.Wrap(err, "new webdav")
}
if err := storageImpl.Move(filepath.Join(s.db.GetDownloadDir(), torrent.Name()), r.TargetDir); err != nil {
return errors.Wrap(err, "move webdav")
}
} else if st.Implementation == db.ImplLocal {
storageImpl := storage.NewLocalStorage(st.Path)
if err := storageImpl.Move(filepath.Join(s.db.GetDownloadDir(), torrent.Name()), r.TargetDir); err != nil {
return errors.Wrap(err, "move webdav")
}
}
log.Infof("move downloaded files to target dir success, file: %v, target dir: %v", torrent.Name(), r.TargetDir)
return nil
}

View File

@@ -3,11 +3,11 @@ package server
import (
"polaris/db"
"polaris/log"
"polaris/pkg"
"polaris/pkg/tmdb"
"polaris/ui"
"github.com/gin-contrib/static"
"github.com/hekmon/transmissionrpc"
"github.com/robfig/cron"
"github.com/gin-gonic/gin"
@@ -20,7 +20,7 @@ func NewServer(db *db.Client) *Server {
r: r,
db: db,
cron: cron.New(),
tasks: make(map[string]*transmissionrpc.Torrent),
tasks: make(map[int]pkg.Torrent),
}
}
@@ -29,18 +29,9 @@ type Server struct {
db *db.Client
cron *cron.Cron
language string
tasks map[string]*transmissionrpc.Torrent
tasks map[int]pkg.Torrent
}
func (s *Server) scheduler() {
s.cron.AddFunc("@every 1m", s.checkTasks)
}
func (s *Server) checkTasks() {
for name, t := range s.tasks {
log.Infof("task %s percentage done: %f", name, *t.PercentDone)
}
}
func (s *Server) Serve() error {
s.scheduler()
@@ -76,6 +67,12 @@ func (s *Server) Serve() error {
downloader.POST("/add", HttpHandler(s.AddDownloadClient))
downloader.DELETE("/del/:id", HttpHandler(s.DeleteDownloadCLient))
}
storage := api.Group("/storage")
{
storage.GET("/", HttpHandler(s.GetAllStorage))
storage.POST("/", HttpHandler(s.AddStorage))
storage.DELETE("/:id", HttpHandler(s.DeleteStorage))
}
s.language = s.db.GetLanguage()
return s.r.Run(":8080")

37
server/storage.go Normal file
View File

@@ -0,0 +1,37 @@
package server
import (
"fmt"
"polaris/db"
"polaris/log"
"strconv"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
func (s *Server) GetAllStorage(c *gin.Context) (interface{}, error) {
data := s.db.GetAllStorage()
return data, nil
}
func (s *Server) AddStorage(c *gin.Context) (interface{}, error) {
var in db.StorageInfo
if err := c.ShouldBindJSON(&in); err != nil {
return nil, errors.Wrap(err, "bind json")
}
log.Infof("received add storage input: %v", in)
err := s.db.AddStorage(in)
return nil, err
}
func (s *Server) DeleteStorage(c *gin.Context) (interface{}, error) {
ids := c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, fmt.Errorf("id is not int: %v", ids)
}
err = s.db.DeleteStorage(id)
return nil, err
}

View File

@@ -1,6 +1,7 @@
package server
import (
"polaris/db"
"polaris/ent"
"polaris/log"
"strconv"
@@ -27,8 +28,8 @@ func (s *Server) SearchTvSeries(c *gin.Context) (interface{}, error) {
}
type addWatchlistIn struct {
ID int `json:"id" binding:"required"`
RootFolder string `json:"folder" binding:"required"`
TmdbID int `json:"id" binding:"required"`
StorageID int `json:"folder"`
}
func (s *Server) AddWatchlist(c *gin.Context) (interface{}, error) {
@@ -36,11 +37,22 @@ func (s *Server) AddWatchlist(c *gin.Context) (interface{}, error) {
if err := c.ShouldBindJSON(&in); err != nil {
return nil, errors.Wrap(err, "bind query")
}
detail, err := s.MustTMDB().GetTvDetails(in.ID, s.language)
detail, err := s.MustTMDB().GetTvDetails(in.TmdbID, s.language)
if err != nil {
return nil, errors.Wrap(err, "get tv detail")
}
log.Infof("find detail for tv id %d: %v", in.ID, detail)
log.Infof("find detail for tv id %d: %v", in.TmdbID, detail)
var nameEn = detail.OriginalName
alterTitles, err := s.MustTMDB().GetTVAlternativeTitles(in.TmdbID, s.language)
if err == nil {
for _, r := range alterTitles.Results {
if r.Iso3166_1 == "US" {
log.Infof("found en name: %s", r.Title)
nameEn = r.Title
}
}
}
var epIds []int
@@ -66,7 +78,7 @@ func (s *Server) AddWatchlist(c *gin.Context) (interface{}, error) {
epIds = append(epIds, epid)
}
}
_, err = s.db.AddWatchlist(in.RootFolder, detail, epIds)
_, err = s.db.AddWatchlist(in.StorageID, nameEn, detail, epIds, db.R1080p)
if err != nil {
return nil, errors.Wrap(err, "add to list")
}

View File

@@ -4,7 +4,7 @@ import 'package:ui/providers/settings.dart';
import 'package:ui/utils.dart';
class SystemSettingsPage extends ConsumerStatefulWidget {
static const route = "/systemsettings";
static const route = "/settings";
const SystemSettingsPage({super.key});
@override