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:
Ariel Mashraki
2021-01-31 17:43:28 +02:00
committed by GitHub
parent d87eb0ab32
commit 3930d3c835
25 changed files with 646 additions and 39 deletions

View File

@@ -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.