Documentation
¶
Overview ¶
Package entx is a package of tools for interacting with ent
Index ¶
- Constants
- Variables
- func CheckEntDialect(d string) (string, error)
- func CheckIsSoftDelete(ctx context.Context) bool
- func CheckMultiwriteSupport(d string) bool
- func CheckSkipSoftDelete(ctx context.Context) bool
- func Healthcheck(client *entsql.Driver) func(ctx context.Context) error
- func IsSoftDelete(parent context.Context) context.Context
- func MarshalRawMessage(t json.RawMessage) graphql.Marshaler
- func SkipSoftDelete(parent context.Context) context.Context
- func UnmarshalRawMessage(v interface{}) (json.RawMessage, error)
- type CascadeAnnotation
- type CascadeThroughAnnotation
- type Config
- type DBOption
- type EntClientConfig
- type Extension
- type ExtensionOption
- type MultiWriteDriver
- func (d *MultiWriteDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)
- func (d *MultiWriteDriver) Close() error
- func (d *MultiWriteDriver) Dialect() string
- func (d *MultiWriteDriver) Exec(ctx context.Context, query string, args, v any) error
- func (d *MultiWriteDriver) Query(ctx context.Context, query string, args, v any) error
- func (d *MultiWriteDriver) Tx(ctx context.Context) (dialect.Tx, error)
- type QueryGenAnnotation
- type SchemaGenAnnotation
- type SearchFieldAnnotation
- type SoftDeleteKey
- type SoftDeleteSkipKey
- type ThroughCleanup
Constants ¶
const (
DefaultCacheTTL = 1 * time.Second
)
Variables ¶
var CascadeAnnotationName = "OPENLANE_CASCADE"
CascadeAnnotationName is a name for our cascading delete annotation
var CascadeThroughAnnotationName = "OPENLANE_CASCADE_THROUGH"
CascadeThroughAnnotationName is a name for our cascading through edge delete annotation
var ( // ErrUnsupportedDialect is returned when an unsupported dialect is used ErrUnsupportedDialect = errors.New("unsupported dialect") )
var QueryGenAnnotationName = "OPENLANE_QUERYGEN"
QueryGenAnnotationName is a name for our graphql query generation annotation
var SchemaGenAnnotationName = "OPENLANE_SCHEMAGEN"
SchemaGenAnnotationName is a name for our graphql schema generation annotation
var SearchFieldAnnotationName = "OPENLANE_SEARCH"
SearchFieldAnnotationName is a name for the search field annotation
Functions ¶
func CheckEntDialect ¶
CheckEntDialect checks if the dialect is supported and returns the ent dialect corresponding to the given dialect
func CheckIsSoftDelete ¶
CheckIsSoftDelete checks if the softDeleteKey is set in the context
func CheckMultiwriteSupport ¶
CheckMultiwriteSupport checks if the dialect supports multiwrite
func CheckSkipSoftDelete ¶
CheckSkipSoftDelete checks if the SoftDeleteSkipKey is set in the context
func Healthcheck ¶
Healthcheck pings the DB to check if the connection is working
func IsSoftDelete ¶
IsSoftDelete returns a new context that informs the delete is a soft-delete for interceptor/hooks.
func MarshalRawMessage ¶
func MarshalRawMessage(t json.RawMessage) graphql.Marshaler
MarshalRawMessage provides a graphql.Marshaler for json.RawMessage
func SkipSoftDelete ¶
SkipSoftDelete returns a new context that skips the soft-delete interceptor/hooks.
func UnmarshalRawMessage ¶
func UnmarshalRawMessage(v interface{}) (json.RawMessage, error)
UnmarshalRawMessage provides a graphql.Unmarshaler for json.RawMessage
Types ¶
type CascadeAnnotation ¶
type CascadeAnnotation struct {
Field string
}
CascadeAnnotation is an annotation used to indicate that an edge should be cascaded
func CascadeAnnotationField ¶
func CascadeAnnotationField(fieldname string) *CascadeAnnotation
CascadeAnnotationField sets the field name of the edge containing the ID of a record from the current schema
func (*CascadeAnnotation) Decode ¶
func (a *CascadeAnnotation) Decode(annotation interface{}) error
Decode unmarshalls the CascadeAnnotation
func (CascadeAnnotation) Name ¶
func (a CascadeAnnotation) Name() string
Name returns the name of the CascadeAnnotation
type CascadeThroughAnnotation ¶
type CascadeThroughAnnotation struct {
Schemas []ThroughCleanup
}
CascadeThroughAnnotation is an annotation used to indicate that an edge should be cascaded through
func CascadeThroughAnnotationField ¶
func CascadeThroughAnnotationField(schemas []ThroughCleanup) *CascadeThroughAnnotation
CascadeThroughAnnotationField sets the field name of the edge containing the ID of a record from the current schema
func (*CascadeThroughAnnotation) Decode ¶
func (a *CascadeThroughAnnotation) Decode(annotation interface{}) error
Decode unmarshalls the CascadeThroughAnnotation
func (CascadeThroughAnnotation) Name ¶
func (a CascadeThroughAnnotation) Name() string
Name returns the name of the CascadeThroughAnnotation
type Config ¶
type Config struct { // Debug to print debug database logs Debug bool `json:"debug" koanf:"debug" jsonschema:"description=debug enables printing the debug database logs" default:"false"` // DatabaseName is the name of the database to use with otel tracing DatabaseName string `` /* 134-byte string literal not displayed */ // DriverName name from dialect.Driver DriverName string `` /* 167-byte string literal not displayed */ // MultiWrite enabled writing to two databases simultaneously MultiWrite bool `json:"multiWrite" koanf:"multiWrite" jsonschema:"description=enables writing to two databases simultaneously" default:"false"` // PrimaryDBSource is the primary database source for all read and write operations PrimaryDBSource string `` /* 135-byte string literal not displayed */ // SecondaryDBSource for when multi write is enabled SecondaryDBSource string `` /* 156-byte string literal not displayed */ // CacheTTL to have results cached for subsequent requests CacheTTL time.Duration `json:"cacheTTL" koanf:"cacheTTL" jsonschema:"description=cache results for subsequent requests, defaults to 1s" default:"1s"` // RunMigrations to run migrations on startup RunMigrations bool `json:"runMigrations" koanf:"runMigrations" jsonschema:"description=run migrations on startup" default:"true"` // MigrationProvider to use for running migrations MigrationProvider string `` /* 140-byte string literal not displayed */ // EnableHistory to enable history data to be logged to the database EnableHistory bool `` /* 132-byte string literal not displayed */ }
Config Settings for the ent database client
type DBOption ¶
type DBOption func(opts *EntClientConfig)
DBOption allows users to optionally supply configuration to the ent connection
func WithSecondaryDB ¶
func WithSecondaryDB() DBOption
WithSecondaryDB sets the secondary db connection if the driver supports multiwrite
type EntClientConfig ¶
type EntClientConfig struct {
// contains filtered or unexported fields
}
EntClientConfig configures the entsql drivers
func NewDBConfig ¶
func NewDBConfig(c Config, opts ...DBOption) (*EntClientConfig, error)
NewDBConfig returns a new ent database configuration
func (*EntClientConfig) GetPrimaryDB ¶
func (c *EntClientConfig) GetPrimaryDB() *entsql.Driver
GetPrimaryDB returns the primary database configuration
func (*EntClientConfig) GetSecondaryDB ¶
func (c *EntClientConfig) GetSecondaryDB() *entsql.Driver
GetSecondaryDB returns the secondary db connection
type Extension ¶
type Extension struct { entc.DefaultExtension // contains filtered or unexported fields }
Extension is an implementation of entc.Extension
func NewExtension ¶
func NewExtension(opts ...ExtensionOption) (*Extension, error)
NewExtension returns an entc Extension that allows the entx package to generate the schema changes and templates needed to function
func (*Extension) GQLSchemaHooks ¶
func (e *Extension) GQLSchemaHooks() []entgql.SchemaHook
GQLSchemaHooks of the extension to seamlessly edit the final gql interface
type ExtensionOption ¶
ExtensionOption allow for control over the behavior of the generator
func WithJSONScalar ¶
func WithJSONScalar() ExtensionOption
WithJSONScalar adds the JSON scalar definition
type MultiWriteDriver ¶
type MultiWriteDriver struct {
// Wp (write-primary), Ws (write-secondary) Drivers
Wp, Ws dialect.Driver
}
MultiWriteDriver allows you to write to a primary and secondary database
func (*MultiWriteDriver) BeginTx ¶
BeginTx adds an log-id for the transaction and calls the underlying driver BeginTx command if it is supported.
func (*MultiWriteDriver) Close ¶
func (d *MultiWriteDriver) Close() error
Close the underlying connections
func (*MultiWriteDriver) Dialect ¶
func (d *MultiWriteDriver) Dialect() string
Dialect returns the dialect name of the primary driver
func (*MultiWriteDriver) Exec ¶
Exec logs its params and calls the underlying driver Exec method for both write drivers
type QueryGenAnnotation ¶
type QueryGenAnnotation struct {
Skip bool
}
QueryGenAnnotation is an annotation used to indicate that query generation should be skipped for this type
func QueryGenSkip ¶
func QueryGenSkip(skip bool) *QueryGenAnnotation
QueryGenSkip sets whether the query generation should be skipped for this type
func (*QueryGenAnnotation) Decode ¶
func (a *QueryGenAnnotation) Decode(annotation interface{}) error
Decode unmarshalls the QueryGenAnnotation
func (QueryGenAnnotation) Name ¶
func (a QueryGenAnnotation) Name() string
Name returns the name of the QueryGenAnnotation
type SchemaGenAnnotation ¶
type SchemaGenAnnotation struct { // Skip indicates that the schema generation should be skipped for this type Skip bool // SkipSearch indicates that the schema should not be searchable // Schemas are also not searchable if not fields are marked as searchable SkipSearch bool }
SchemaGenAnnotation is an annotation used to indicate that schema generation should be skipped for this type When Skip is true, the search schema generation is always skipped SkipSearch allow for schemas to be be opt out of search schema generation
func SchemaGenSkip ¶
func SchemaGenSkip(skip bool) *SchemaGenAnnotation
SchemaGenSkip sets whether the schema generation should be skipped for this type
func SchemaSearchable ¶
func SchemaSearchable(s bool) *SchemaGenAnnotation
SchemaSearchable sets if the schema should be searchable and generated in the search schema template
func (*SchemaGenAnnotation) Decode ¶
func (a *SchemaGenAnnotation) Decode(annotation interface{}) error
Decode unmarshalls the SchemaGenAnnotation
func (SchemaGenAnnotation) Name ¶
func (a SchemaGenAnnotation) Name() string
Name returns the name of the SchemaGenAnnotation
type SearchFieldAnnotation ¶
type SearchFieldAnnotation struct { // Searchable indicates that the field should be searchable Searchable bool // ExcludeAdmin indicates that the field will be excluded from the admin search which includes all fields by default ExcludeAdmin bool // JSONPath is the path to the field in the JSON object JSONPath string // JSONDotPath is the path to the field in the JSON object using dot notation JSONDotPath string }
SearchFieldAnnotation is an annotation used to indicate that the field should be searchable
func FieldAdminSearchable ¶ added in v0.1.5
func FieldAdminSearchable(s bool) *SearchFieldAnnotation
FieldAdminSearchable returns a new SearchFieldAnnotation with the exclude admin searchable flag set
func FieldJSONDotPathSearchable ¶ added in v0.1.7
func FieldJSONDotPathSearchable(path string) *SearchFieldAnnotation
FieldJSONDotPathSearchable returns a new SearchFieldAnnotation with the searchable flag set and the JSONDotPath set
func FieldJSONPathSearchable ¶ added in v0.1.7
func FieldJSONPathSearchable(path string) *SearchFieldAnnotation
FieldJSONPathSearchable returns a new SearchFieldAnnotation with the searchable flag set and the JSONPath set
func FieldSearchable ¶
func FieldSearchable() *SearchFieldAnnotation
FieldSearchable returns a new SearchFieldAnnotation with the searchable flag set
func (*SearchFieldAnnotation) Decode ¶
func (a *SearchFieldAnnotation) Decode(annotation interface{}) error
Decode unmarshalls the SearchFieldAnnotation
func (SearchFieldAnnotation) Name ¶
func (a SearchFieldAnnotation) Name() string
Name returns the name of the SearchFieldAnnotation
type SoftDeleteKey ¶
type SoftDeleteKey struct{}
SoftDeleteKey is used to indicate a soft delete mutation is in progress
type SoftDeleteSkipKey ¶
type SoftDeleteSkipKey struct{}
SoftDeleteSkipKey is used to indicate to allow soft deleted records to be returned in records and to skip soft delete on mutations and proceed with a regular delete
type ThroughCleanup ¶
ThroughCleanup is a struct used to indicate the field and through edge to cascade through
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package genhooks provides a set of entgo hooks for generating files from the ent schema.
|
Package genhooks provides a set of entgo hooks for generating files from the ent schema. |
package history provides code generation to add history tables for an ent schema
|
package history provides code generation to add history tables for an ent schema |
Package mixin contains the mixin package
|
Package mixin contains the mixin package |
vanilla
|
|
_example/ent/enums
Package enums has enums
|
Package enums has enums |