mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/field: implement field.Other (#1218)
* Implement Other Field * Implement Other Field * Changed dialect types * run generate * doc typo * docs added * schema/field: additional validation and tests for Other type Co-authored-by: Ciaran Liedeman <ciaran@stackworx.io>
This commit is contained in:
@@ -54,6 +54,7 @@ The following types are currently supported by the framework:
|
||||
- `JSON` (SQL only).
|
||||
- `Enum` (SQL only).
|
||||
- `UUID` (SQL only).
|
||||
- `Other` (SQL only).
|
||||
|
||||
<br/>
|
||||
|
||||
@@ -237,6 +238,38 @@ func (Card) Fields() []ent.Field {
|
||||
}
|
||||
```
|
||||
|
||||
## Other Field
|
||||
|
||||
Other represents a field that is not a good fit for any of the standard field types.
|
||||
Examples are a Postgres Range type or Geospatial type
|
||||
|
||||
```go
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
|
||||
"github.com/jackc/pgtype"
|
||||
)
|
||||
|
||||
// User schema.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Other("duration", &pgtype.Tstzrange{}).
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: "tstzrange",
|
||||
}),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Default Values
|
||||
|
||||
**Non-unique** fields support default values using the `Default` and `UpdateDefault` methods.
|
||||
|
||||
Reference in New Issue
Block a user