322 lines
11 KiB
Go
322 lines
11 KiB
Go
// Copyright 2019-present Facebook Inc. All rights reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/entc/integration/ent/document"
|
|
"entgo.io/ent/entc/integration/ent/schema"
|
|
)
|
|
|
|
// Document is the model entity for the Document schema.
|
|
type Document 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"`
|
|
// Attachment holds the value of the "attachment" field.
|
|
Attachment []byte `json:"attachment,omitempty"`
|
|
// Metadata holds the value of the "metadata" field.
|
|
Metadata []byte `json:"metadata,omitempty"`
|
|
// Payload holds the value of the "payload" field.
|
|
Payload *schema.DocPayload `json:"payload,omitempty"`
|
|
// Description holds the value of the "description" field.
|
|
Description string `json:"description,omitempty"`
|
|
content_key *string
|
|
thumbnail_key *string
|
|
attachment_key *string
|
|
metadata_key *string
|
|
payload_key *string
|
|
description_key *string
|
|
archive_key *string
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Document) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case document.FieldAttachment:
|
|
values[i] = new([]byte)
|
|
case document.FieldID:
|
|
values[i] = new(sql.NullInt64)
|
|
case document.FieldName:
|
|
values[i] = new(sql.NullString)
|
|
case document.FieldPayload:
|
|
values[i] = document.ValueScanner.Payload.ScanValue()
|
|
case document.BlobKeys[0]: // content_key
|
|
values[i] = new(sql.NullString)
|
|
case document.BlobKeys[1]: // thumbnail_key
|
|
values[i] = new(sql.NullString)
|
|
case document.BlobKeys[2]: // attachment_key
|
|
values[i] = new(sql.NullString)
|
|
case document.BlobKeys[3]: // metadata_key
|
|
values[i] = new(sql.NullString)
|
|
case document.BlobKeys[4]: // payload_key
|
|
values[i] = new(sql.NullString)
|
|
case document.BlobKeys[5]: // description_key
|
|
values[i] = new(sql.NullString)
|
|
case document.BlobKeys[6]: // archive_key
|
|
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 Document fields.
|
|
func (_m *Document) 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 document.FieldID:
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
}
|
|
_m.ID = int(value.Int64)
|
|
case document.FieldName:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
|
} else if value.Valid {
|
|
_m.Name = value.String
|
|
}
|
|
case document.FieldAttachment:
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
return fmt.Errorf("unexpected type %T for field attachment", values[i])
|
|
} else if value != nil {
|
|
_m.Attachment = *value
|
|
}
|
|
case document.FieldPayload:
|
|
if value, err := document.ValueScanner.Payload.FromValue(values[i]); err != nil {
|
|
return err
|
|
} else {
|
|
_m.Payload = value
|
|
}
|
|
case document.BlobKeys[0]:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field content_key", values[i])
|
|
} else if value.Valid {
|
|
_m.content_key = &value.String
|
|
}
|
|
case document.BlobKeys[1]:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field thumbnail_key", values[i])
|
|
} else if value.Valid {
|
|
_m.thumbnail_key = &value.String
|
|
}
|
|
case document.BlobKeys[2]:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field attachment_key", values[i])
|
|
} else if value.Valid {
|
|
_m.attachment_key = &value.String
|
|
}
|
|
case document.BlobKeys[3]:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field metadata_key", values[i])
|
|
} else if value.Valid {
|
|
_m.metadata_key = &value.String
|
|
}
|
|
case document.BlobKeys[4]:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field payload_key", values[i])
|
|
} else if value.Valid {
|
|
_m.payload_key = &value.String
|
|
}
|
|
case document.BlobKeys[5]:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field description_key", values[i])
|
|
} else if value.Valid {
|
|
_m.description_key = &value.String
|
|
}
|
|
case document.BlobKeys[6]:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field archive_key", values[i])
|
|
} else if value.Valid {
|
|
_m.archive_key = &value.String
|
|
}
|
|
default:
|
|
_m.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the Document.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *Document) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// ContentReader opens a reader for the "content" field from blob storage.
|
|
// The caller must close the returned reader when done.
|
|
func (_m *Document) ContentReader(ctx context.Context) (io.ReadCloser, error) {
|
|
if _m.content_key == nil || *_m.content_key == "" {
|
|
return nil, fmt.Errorf("ent: Document.content_key is nil or empty")
|
|
}
|
|
if _m.blobOpeners.Document == nil {
|
|
return nil, fmt.Errorf("ent: blob storage not configured (missing WithBlobOpeners)")
|
|
}
|
|
b, err := _m.blobOpeners.Document(ctx, document.FieldContent)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ent.BlobReader(ctx, b, *_m.content_key)
|
|
}
|
|
|
|
// ThumbnailReader opens a reader for the "thumbnail" field from blob storage.
|
|
// The caller must close the returned reader when done.
|
|
func (_m *Document) ThumbnailReader(ctx context.Context) (io.ReadCloser, error) {
|
|
if _m.thumbnail_key == nil || *_m.thumbnail_key == "" {
|
|
return nil, fmt.Errorf("ent: Document.thumbnail_key is nil or empty")
|
|
}
|
|
if _m.blobOpeners.Document == nil {
|
|
return nil, fmt.Errorf("ent: blob storage not configured (missing WithBlobOpeners)")
|
|
}
|
|
b, err := _m.blobOpeners.Document(ctx, document.FieldThumbnail)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ent.BlobReader(ctx, b, *_m.thumbnail_key)
|
|
}
|
|
|
|
// AttachmentReader opens a reader for the "attachment" field from blob storage.
|
|
// The caller must close the returned reader when done.
|
|
func (_m *Document) AttachmentReader(ctx context.Context) (io.ReadCloser, error) {
|
|
if _m.attachment_key == nil || *_m.attachment_key == "" {
|
|
return nil, fmt.Errorf("ent: Document.attachment_key is nil or empty")
|
|
}
|
|
if _m.blobOpeners.Document == nil {
|
|
return nil, fmt.Errorf("ent: blob storage not configured (missing WithBlobOpeners)")
|
|
}
|
|
b, err := _m.blobOpeners.Document(ctx, document.FieldAttachment)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ent.BlobReader(ctx, b, *_m.attachment_key)
|
|
}
|
|
|
|
// MetadataReader opens a reader for the "metadata" field from blob storage.
|
|
// The caller must close the returned reader when done.
|
|
func (_m *Document) MetadataReader(ctx context.Context) (io.ReadCloser, error) {
|
|
if _m.metadata_key == nil || *_m.metadata_key == "" {
|
|
return nil, fmt.Errorf("ent: Document.metadata_key is nil or empty")
|
|
}
|
|
if _m.blobOpeners.Document == nil {
|
|
return nil, fmt.Errorf("ent: blob storage not configured (missing WithBlobOpeners)")
|
|
}
|
|
b, err := _m.blobOpeners.Document(ctx, document.FieldMetadata)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ent.BlobReader(ctx, b, *_m.metadata_key)
|
|
}
|
|
|
|
// PayloadReader opens a reader for the "payload" field from blob storage.
|
|
// The caller must close the returned reader when done.
|
|
func (_m *Document) PayloadReader(ctx context.Context) (io.ReadCloser, error) {
|
|
if _m.payload_key == nil || *_m.payload_key == "" {
|
|
return nil, fmt.Errorf("ent: Document.payload_key is nil or empty")
|
|
}
|
|
if _m.blobOpeners.Document == nil {
|
|
return nil, fmt.Errorf("ent: blob storage not configured (missing WithBlobOpeners)")
|
|
}
|
|
b, err := _m.blobOpeners.Document(ctx, document.FieldPayload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ent.BlobReader(ctx, b, *_m.payload_key)
|
|
}
|
|
|
|
// DescriptionReader opens a reader for the "description" field from blob storage.
|
|
// The caller must close the returned reader when done.
|
|
func (_m *Document) DescriptionReader(ctx context.Context) (io.ReadCloser, error) {
|
|
if _m.description_key == nil || *_m.description_key == "" {
|
|
return nil, fmt.Errorf("ent: Document.description_key is nil or empty")
|
|
}
|
|
if _m.blobOpeners.Document == nil {
|
|
return nil, fmt.Errorf("ent: blob storage not configured (missing WithBlobOpeners)")
|
|
}
|
|
b, err := _m.blobOpeners.Document(ctx, document.FieldDescription)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ent.BlobReader(ctx, b, *_m.description_key)
|
|
}
|
|
|
|
// ArchiveReader opens a reader for the "archive" field from blob storage.
|
|
// The caller must close the returned reader when done.
|
|
func (_m *Document) ArchiveReader(ctx context.Context) (io.ReadCloser, error) {
|
|
if _m.archive_key == nil || *_m.archive_key == "" {
|
|
return nil, fmt.Errorf("ent: Document.archive_key is nil or empty")
|
|
}
|
|
if _m.blobOpeners.Document == nil {
|
|
return nil, fmt.Errorf("ent: blob storage not configured (missing WithBlobOpeners)")
|
|
}
|
|
b, err := _m.blobOpeners.Document(ctx, document.FieldArchive)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ent.BlobReader(ctx, b, *_m.archive_key)
|
|
}
|
|
|
|
// Update returns a builder for updating this Document.
|
|
// Note that you need to call Document.Unwrap() before calling this method if this Document
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *Document) Update() *DocumentUpdateOne {
|
|
return NewDocumentClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the Document entity that was returned from a transaction after it was closed,
|
|
// so that all future queries will be executed through the driver which created the transaction.
|
|
func (_m *Document) Unwrap() *Document {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("ent: Document is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *Document) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Document(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
|
builder.WriteString("name=")
|
|
builder.WriteString(_m.Name)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("attachment=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Attachment))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("metadata=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Metadata))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("payload=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Payload))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("description=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Description))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Documents is a parsable slice of Document.
|
|
type Documents []*Document
|