collection.go•12.6 kB
// Code generated by ent, DO NOT EDIT.
package collection
import (
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/rs/xid"
)
const (
// Label holds the string label denoting the collection type in the database.
Label = "collection"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldIndexedAt holds the string denoting the indexed_at field in the database.
FieldIndexedAt = "indexed_at"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldSlug holds the string denoting the slug field in the database.
FieldSlug = "slug"
// FieldDescription holds the string denoting the description field in the database.
FieldDescription = "description"
// FieldCoverAssetID holds the string denoting the cover_asset_id field in the database.
FieldCoverAssetID = "cover_asset_id"
// FieldVisibility holds the string denoting the visibility field in the database.
FieldVisibility = "visibility"
// EdgeOwner holds the string denoting the owner edge name in mutations.
EdgeOwner = "owner"
// EdgeCoverImage holds the string denoting the cover_image edge name in mutations.
EdgeCoverImage = "cover_image"
// EdgePosts holds the string denoting the posts edge name in mutations.
EdgePosts = "posts"
// EdgeNodes holds the string denoting the nodes edge name in mutations.
EdgeNodes = "nodes"
// EdgeCollectionPosts holds the string denoting the collection_posts edge name in mutations.
EdgeCollectionPosts = "collection_posts"
// EdgeCollectionNodes holds the string denoting the collection_nodes edge name in mutations.
EdgeCollectionNodes = "collection_nodes"
// Table holds the table name of the collection in the database.
Table = "collections"
// OwnerTable is the table that holds the owner relation/edge.
OwnerTable = "collections"
// OwnerInverseTable is the table name for the Account entity.
// It exists in this package in order to avoid circular dependency with the "account" package.
OwnerInverseTable = "accounts"
// OwnerColumn is the table column denoting the owner relation/edge.
OwnerColumn = "account_collections"
// CoverImageTable is the table that holds the cover_image relation/edge.
CoverImageTable = "collections"
// CoverImageInverseTable is the table name for the Asset entity.
// It exists in this package in order to avoid circular dependency with the "asset" package.
CoverImageInverseTable = "assets"
// CoverImageColumn is the table column denoting the cover_image relation/edge.
CoverImageColumn = "cover_asset_id"
// PostsTable is the table that holds the posts relation/edge. The primary key declared below.
PostsTable = "collection_posts"
// PostsInverseTable is the table name for the Post entity.
// It exists in this package in order to avoid circular dependency with the "post" package.
PostsInverseTable = "posts"
// NodesTable is the table that holds the nodes relation/edge. The primary key declared below.
NodesTable = "collection_nodes"
// NodesInverseTable is the table name for the Node entity.
// It exists in this package in order to avoid circular dependency with the "node" package.
NodesInverseTable = "nodes"
// CollectionPostsTable is the table that holds the collection_posts relation/edge.
CollectionPostsTable = "collection_posts"
// CollectionPostsInverseTable is the table name for the CollectionPost entity.
// It exists in this package in order to avoid circular dependency with the "collectionpost" package.
CollectionPostsInverseTable = "collection_posts"
// CollectionPostsColumn is the table column denoting the collection_posts relation/edge.
CollectionPostsColumn = "collection_id"
// CollectionNodesTable is the table that holds the collection_nodes relation/edge.
CollectionNodesTable = "collection_nodes"
// CollectionNodesInverseTable is the table name for the CollectionNode entity.
// It exists in this package in order to avoid circular dependency with the "collectionnode" package.
CollectionNodesInverseTable = "collection_nodes"
// CollectionNodesColumn is the table column denoting the collection_nodes relation/edge.
CollectionNodesColumn = "collection_id"
)
// Columns holds all SQL columns for collection fields.
var Columns = []string{
FieldID,
FieldCreatedAt,
FieldUpdatedAt,
FieldIndexedAt,
FieldName,
FieldSlug,
FieldDescription,
FieldCoverAssetID,
FieldVisibility,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "collections"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"account_collections",
}
var (
// PostsPrimaryKey and PostsColumn2 are the table columns denoting the
// primary key for the posts relation (M2M).
PostsPrimaryKey = []string{"collection_id", "post_id"}
// NodesPrimaryKey and NodesColumn2 are the table columns denoting the
// primary key for the nodes relation (M2M).
NodesPrimaryKey = []string{"collection_id", "node_id"}
)
// 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
}
}
for i := range ForeignKeys {
if column == ForeignKeys[i] {
return true
}
}
return false
}
var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// DefaultID holds the default value on creation for the "id" field.
DefaultID func() xid.ID
// IDValidator is a validator for the "id" field. It is called by the builders before save.
IDValidator func(string) error
)
// Visibility defines the type for the "visibility" enum field.
type Visibility string
// VisibilityDraft is the default value of the Visibility enum.
const DefaultVisibility = VisibilityDraft
// Visibility values.
const (
VisibilityDraft Visibility = "draft"
VisibilityUnlisted Visibility = "unlisted"
VisibilityReview Visibility = "review"
VisibilityPublished Visibility = "published"
)
func (v Visibility) String() string {
return string(v)
}
// VisibilityValidator is a validator for the "visibility" field enum values. It is called by the builders before save.
func VisibilityValidator(v Visibility) error {
switch v {
case VisibilityDraft, VisibilityUnlisted, VisibilityReview, VisibilityPublished:
return nil
default:
return fmt.Errorf("collection: invalid enum value for visibility field: %q", v)
}
}
// OrderOption defines the ordering options for the Collection 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()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByIndexedAt orders the results by the indexed_at field.
func ByIndexedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldIndexedAt, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// BySlug orders the results by the slug field.
func BySlug(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSlug, opts...).ToFunc()
}
// ByDescription orders the results by the description field.
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDescription, opts...).ToFunc()
}
// ByCoverAssetID orders the results by the cover_asset_id field.
func ByCoverAssetID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCoverAssetID, opts...).ToFunc()
}
// ByVisibility orders the results by the visibility field.
func ByVisibility(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldVisibility, opts...).ToFunc()
}
// ByOwnerField orders the results by owner field.
func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...))
}
}
// ByCoverImageField orders the results by cover_image field.
func ByCoverImageField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCoverImageStep(), sql.OrderByField(field, opts...))
}
}
// ByPostsCount orders the results by posts count.
func ByPostsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newPostsStep(), opts...)
}
}
// ByPosts orders the results by posts terms.
func ByPosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newPostsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByNodesCount orders the results by nodes count.
func ByNodesCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newNodesStep(), opts...)
}
}
// ByNodes orders the results by nodes terms.
func ByNodes(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newNodesStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByCollectionPostsCount orders the results by collection_posts count.
func ByCollectionPostsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newCollectionPostsStep(), opts...)
}
}
// ByCollectionPosts orders the results by collection_posts terms.
func ByCollectionPosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCollectionPostsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByCollectionNodesCount orders the results by collection_nodes count.
func ByCollectionNodesCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newCollectionNodesStep(), opts...)
}
}
// ByCollectionNodes orders the results by collection_nodes terms.
func ByCollectionNodes(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCollectionNodesStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newOwnerStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(OwnerInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn),
)
}
func newCoverImageStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CoverImageInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, CoverImageTable, CoverImageColumn),
)
}
func newPostsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(PostsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, PostsTable, PostsPrimaryKey...),
)
}
func newNodesStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(NodesInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, NodesTable, NodesPrimaryKey...),
)
}
func newCollectionPostsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CollectionPostsInverseTable, CollectionPostsColumn),
sqlgraph.Edge(sqlgraph.O2M, true, CollectionPostsTable, CollectionPostsColumn),
)
}
func newCollectionNodesStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CollectionNodesInverseTable, CollectionNodesColumn),
sqlgraph.Edge(sqlgraph.O2M, true, CollectionNodesTable, CollectionNodesColumn),
)
}