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 SoftDeleteKey
- type SoftDeleteSkipKey
- type ThroughCleanup
Constants ¶
const (
DefaultCacheTTL = 1 * time.Second
)
Variables ¶
var CascadeAnnotationName = "DATUM_CASCADE"
CascadeAnnotationName is a name for our cascading delete annotation
var CascadeThroughAnnotationName = "DATUM_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 = "DATUM_QUERYGEN"
QueryGenAnnotationName is a name for our graphql query generation annotation
var SchemaGenAnnotationName = "DATUM_SCHEMAGEN"
SchemaGenAnnotationName is a name for our graphql schema generation annotation
Functions ¶
func CheckEntDialect ¶ added in v0.0.2
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 ¶ added in v0.0.2
CheckMultiwriteSupport checks if the dialect supports multiwrite
func CheckSkipSoftDelete ¶
CheckSkipSoftDelete checks if the SoftDeleteSkipKey is set in the context
func Healthcheck ¶ added in v0.0.2
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 ¶ added in v0.3.1
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 ¶ added in v0.3.1
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 ¶ added in v0.0.2
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 `` /* 131-byte string literal not displayed */ // DriverName name from dialect.Driver DriverName string `` /* 146-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 `` /* 132-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 ¶ added in v0.0.2
type DBOption func(opts *EntClientConfig)
DBOption allows users to optionally supply configuration to the ent connection
func WithLogger ¶ added in v0.0.2
func WithLogger(l *zap.SugaredLogger) DBOption
WithLogger sets the logger for the ent client
func WithSecondaryDB ¶ added in v0.0.2
func WithSecondaryDB() DBOption
WithSecondaryDB sets the secondary db connection if the driver supports multiwrite
type EntClientConfig ¶ added in v0.0.2
type EntClientConfig struct {
// contains filtered or unexported fields
}
EntClientConfig configures the entsql drivers
func NewDBConfig ¶ added in v0.0.2
func NewDBConfig(c Config, opts ...DBOption) (*EntClientConfig, error)
NewDBConfig returns a new ent database configuration
func (*EntClientConfig) GetPrimaryDB ¶ added in v0.0.2
func (c *EntClientConfig) GetPrimaryDB() *entsql.Driver
GetPrimaryDB returns the primary database configuration
func (*EntClientConfig) GetSecondaryDB ¶ added in v0.0.2
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 ¶ added in v0.0.2
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 ¶ added in v0.0.2
BeginTx adds an log-id for the transaction and calls the underlying driver BeginTx command if it is supported.
func (*MultiWriteDriver) Close ¶ added in v0.0.2
func (d *MultiWriteDriver) Close() error
Close the underlying connections
func (*MultiWriteDriver) Dialect ¶ added in v0.0.2
func (d *MultiWriteDriver) Dialect() string
Dialect returns the dialect name of the primary driver
func (*MultiWriteDriver) Exec ¶ added in v0.0.2
Exec logs its params and calls the underlying driver Exec method for both write drivers
type QueryGenAnnotation ¶ added in v0.3.1
type QueryGenAnnotation struct {
Skip bool
}
QueryGenAnnotation is an annotation used to indicate that query generation should be skipped for this type
func QueryGenSkip ¶ added in v0.3.1
func QueryGenSkip(skip bool) *QueryGenAnnotation
QueryGenSkip sets whether the query generation should be skipped for this type
func (*QueryGenAnnotation) Decode ¶ added in v0.3.1
func (a *QueryGenAnnotation) Decode(annotation interface{}) error
Decode unmarshalls the QueryGenAnnotation
func (QueryGenAnnotation) Name ¶ added in v0.3.1
func (a QueryGenAnnotation) Name() string
Name returns the name of the QueryGenAnnotation
type SchemaGenAnnotation ¶
type SchemaGenAnnotation struct {
Skip bool
}
SchemaGenAnnotation is an annotation used to indicate that schema generation should be skipped for this type
func SchemaGenSkip ¶
func SchemaGenSkip(skip bool) *SchemaGenAnnotation
SchemaGenSkip sets whether the schema generation should be skipped for this type
func (*SchemaGenAnnotation) Decode ¶ added in v0.3.1
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 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 mixin contains the mixin package
|
Package mixin contains the mixin package |
vanilla
|
|
_example/ent/enums
Package enums has enums
|
Package enums has enums |
_example/graphapi
Package graphapi does graphi stuff
|
Package graphapi does graphi stuff |