mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
upload first, then store the key as virtual fk
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package field
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"encoding"
|
||||
@@ -1485,6 +1486,18 @@ func (b *blobBuilder) Deprecated(reason ...string) *blobBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// Key sets the function used to generate the blob storage key.
|
||||
// The function is called at create/update time to produce a unique key
|
||||
// for storing the blob data. If not set, a random key is generated.
|
||||
//
|
||||
// field.Blob("content").Key(func(ctx context.Context) (string, error) {
|
||||
// return uuid.NewString(), nil
|
||||
// })
|
||||
func (b *blobBuilder) Key(fn func(context.Context) (string, error)) *blobBuilder {
|
||||
b.desc.BlobKey = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *blobBuilder) Descriptor() *Descriptor {
|
||||
return b.desc
|
||||
@@ -1492,26 +1505,27 @@ func (b *blobBuilder) Descriptor() *Descriptor {
|
||||
|
||||
// A Descriptor for field configuration.
|
||||
type Descriptor struct {
|
||||
Tag string // struct tag.
|
||||
Size int // varchar size.
|
||||
Name string // field name.
|
||||
Info *TypeInfo // field type info.
|
||||
ValueScanner any // custom field codec.
|
||||
Unique bool // unique index of field.
|
||||
Nillable bool // nillable struct field.
|
||||
Optional bool // nullable field in database.
|
||||
Immutable bool // create only field.
|
||||
Default any // default value on create.
|
||||
UpdateDefault any // default value on update.
|
||||
Validators []any // validator functions.
|
||||
StorageKey string // sql column or gremlin property.
|
||||
Enums []struct{ N, V string } // enum values.
|
||||
Sensitive bool // sensitive info string field.
|
||||
SchemaType map[string]string // override the schema type.
|
||||
Annotations []schema.Annotation // field annotations.
|
||||
Comment string // field comment.
|
||||
Deprecated bool // mark the field as deprecated.
|
||||
DeprecatedReason string // deprecation reason.
|
||||
Tag string // struct tag.
|
||||
Size int // varchar size.
|
||||
Name string // field name.
|
||||
Info *TypeInfo // field type info.
|
||||
ValueScanner any // custom field codec.
|
||||
Unique bool // unique index of field.
|
||||
Nillable bool // nillable struct field.
|
||||
Optional bool // nullable field in database.
|
||||
Immutable bool // create only field.
|
||||
Default any // default value on create.
|
||||
UpdateDefault any // default value on update.
|
||||
Validators []any // validator functions.
|
||||
StorageKey string // sql column or gremlin property.
|
||||
Enums []struct{ N, V string } // enum values.
|
||||
Sensitive bool // sensitive info string field.
|
||||
SchemaType map[string]string // override the schema type.
|
||||
Annotations []schema.Annotation // field annotations.
|
||||
Comment string // field comment.
|
||||
Deprecated bool // mark the field as deprecated.
|
||||
DeprecatedReason string // deprecation reason.
|
||||
BlobKey func(context.Context) (string, error) // blob key generation function: func(context.Context) (string, error).
|
||||
Err error
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user