Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateTableRefSDL(schemaName string, ref catalog.TableRef, opts ...SchemaOption) string
- func GenerateTableSDL(schemaName string, table catalog.Table, opts ...SchemaOption) string
- func ToGraphQLName(name string) string
- func ValidGraphQLName(name string) bool
- func WithSDL(table catalog.Table, sdl string) catalog.Table
- func WithScalarFuncSDL(fn catalog.ScalarFunction, sdl string) catalog.ScalarFunction
- func WithTableFuncInOutSDL(fn catalog.TableFunctionInOut, sdl string) catalog.TableFunctionInOut
- func WithTableFuncSDL(fn catalog.TableFunction, sdl string) catalog.TableFunction
- func WithTableRefSDL(ref catalog.TableRef, sdl string) catalog.TableRef
- type AppInfo
- type Application
- type ApplicationDBInitializer
- type ApplicationDBMigrator
- type CatalogMux
- func (m *CatalogMux) HandleFunc(schema, name string, handler HandlerFunc, opts ...Option) error
- func (m *CatalogMux) HandleTableFunc(schema, name string, handler HandlerFunc, opts ...Option) error
- func (m *CatalogMux) SDL() string
- func (m *CatalogMux) SDLWithModules(defaultSchema string) string
- func (m *CatalogMux) ScalarFunc(schema string, fn catalog.ScalarFunction)
- func (m *CatalogMux) Schema(ctx context.Context, name string) (catalog.Schema, error)
- func (m *CatalogMux) Schemas(ctx context.Context) ([]catalog.Schema, error)
- func (m *CatalogMux) Table(schema string, table catalog.Table, opts ...SchemaOption)
- func (m *CatalogMux) TableFunc(schema string, fn catalog.TableFunction)
- func (m *CatalogMux) TableFuncInOut(schema string, fn catalog.TableFunctionInOut)
- func (m *CatalogMux) TableRef(schema string, ref catalog.TableRef, opts ...SchemaOption)
- func (m *CatalogMux) WithSDL(sdl string)
- type DataSourceInfo
- type DataSourceUser
- type HandlerFunc
- type MultiCatalogMux
- type MultiCatalogProvider
- type Option
- func Arg(name string, typ Type) Option
- func ArgDesc(name string, typ Type, description string) Option
- func Col(name string, typ Type) Option
- func ColDesc(name string, typ Type, description string) Option
- func ColNullable(name string, typ Type) Option
- func ColPK(name string, typ Type) Option
- func Desc(description string) Option
- func Return(typ Type) Option
- type Request
- func (r *Request) Bool(name string) bool
- func (r *Request) Bytes(name string) []byte
- func (r *Request) Context() context.Context
- func (r *Request) Float32(name string) float32
- func (r *Request) Float64(name string) float64
- func (r *Request) Geometry(name string) orb.Geometry
- func (r *Request) Get(name string) any
- func (r *Request) Int8(name string) int8
- func (r *Request) Int16(name string) int16
- func (r *Request) Int32(name string) int32
- func (r *Request) Int64(name string) int64
- func (r *Request) String(name string) string
- func (r *Request) Uint8(name string) uint8
- func (r *Request) Uint16(name string) uint16
- func (r *Request) Uint32(name string) uint32
- func (r *Request) Uint64(name string) uint64
- type Result
- type SchemaOption
- func WithDescription(desc string) SchemaOption
- func WithFieldDescription(field, desc string) SchemaOption
- func WithFieldReferences(fieldName, referencesName, query, referencesQuery string) SchemaOption
- func WithFilterRequired(fields ...string) SchemaOption
- func WithM2M() SchemaOption
- func WithM2MReferences(referencesName string, sourceFields, referencesFields []string, ...) SchemaOption
- func WithPK(fields ...string) SchemaOption
- func WithRawSDL(sdl string) SchemaOption
- func WithReferences(referencesName string, sourceFields, referencesFields []string, ...) SchemaOption
- type TLSConfigProvider
- type Type
Constants ¶
const DefaultSchema = "default"
DefaultSchemaName is the schema name treated as root level (no @module directive).
Variables ¶
var ( Boolean = Type{arrow.FixedWidthTypes.Boolean, "Boolean"} Int8 = Type{arrow.PrimitiveTypes.Int8, "Int"} Int16 = Type{arrow.PrimitiveTypes.Int16, "Int"} Int32 = Type{arrow.PrimitiveTypes.Int32, "Int"} Int64 = Type{arrow.PrimitiveTypes.Int64, "BigInt"} Uint8 = Type{arrow.PrimitiveTypes.Uint8, "UInt"} Uint16 = Type{arrow.PrimitiveTypes.Uint16, "UInt"} Uint32 = Type{arrow.PrimitiveTypes.Uint32, "UInt"} Uint64 = Type{arrow.PrimitiveTypes.Uint64, "BigUInt"} Float32 = Type{arrow.PrimitiveTypes.Float32, "Float"} Float64 = Type{arrow.PrimitiveTypes.Float64, "Float"} String = Type{arrow.BinaryTypes.String, "String"} Binary = Type{arrow.BinaryTypes.Binary, "Base64"} Timestamp = Type{arrow.FixedWidthTypes.Timestamp_us, "DateTime"} Date = Type{arrow.FixedWidthTypes.Date32, "Date"} Geometry = Type{catalog.NewGeometryExtensionType(), "Geometry"} )
Arrow type references — use these in Arg(), Return(), Col() options.
var ReservedSchemas = map[string]bool{ "_mount": true, "_funcs": true, }
ReservedSchemas that cannot be used by app developers.
Functions ¶
func GenerateTableRefSDL ¶
func GenerateTableRefSDL(schemaName string, ref catalog.TableRef, opts ...SchemaOption) string
GenerateTableRefSDL generates SDL for a catalog.TableRef from its Arrow schema. Table refs are always @view (read-only). If WithRawSDL is provided, returns that SDL directly.
func GenerateTableSDL ¶
func GenerateTableSDL(schemaName string, table catalog.Table, opts ...SchemaOption) string
GenerateTableSDL generates SDL for a catalog.Table from its Arrow schema. Mutable tables get @table, read-only tables get @view. If WithRawSDL is provided, returns that SDL directly.
func ToGraphQLName ¶
ToGraphQLName transforms a string into a valid GraphQL identifier. Replaces invalid characters with underscores, prepends _ if starts with digit.
func ValidGraphQLName ¶
ValidGraphQLName returns true if name is a valid GraphQL identifier.
func WithScalarFuncSDL ¶
func WithScalarFuncSDL(fn catalog.ScalarFunction, sdl string) catalog.ScalarFunction
WithScalarFuncSDL wraps a catalog.ScalarFunction with its hugr SDL definition.
func WithTableFuncInOutSDL ¶
func WithTableFuncInOutSDL(fn catalog.TableFunctionInOut, sdl string) catalog.TableFunctionInOut
WithTableFuncInOutSDL wraps a catalog.TableFunctionInOut with its hugr SDL definition.
func WithTableFuncSDL ¶
func WithTableFuncSDL(fn catalog.TableFunction, sdl string) catalog.TableFunction
WithTableFuncSDL wraps a catalog.TableFunction with its hugr SDL definition.
Types ¶
type AppInfo ¶
type AppInfo struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
URI string `json:"uri"`
DefaultSchema string `json:"default_schema,omitempty"` // default: "default"
}
func (AppInfo) DefaultSchemaName ¶
DefaultSchemaName returns the schema name treated as root (no @module).
type Application ¶
type Application interface {
Listner() (net.Listener, error)
Info() AppInfo
Catalog(ctx context.Context) (catalog.Catalog, error)
// Init is called during server startup to perform any necessary initialization.
// This performs after registering the application data sources on the hugr side.
// This will be called by the Hugr server
Init(ctx context.Context) error
// Shutdown is called during graceful shutdown to clean up resources.
// Called before unregistering from hugr.
Shutdown(ctx context.Context) error
}
type ApplicationDBMigrator ¶
type CatalogMux ¶
type CatalogMux struct {
// contains filtered or unexported fields
}
CatalogMux is a goroutine-safe catalog multiplexer. Like http.ServeMux routes URLs to handlers, CatalogMux routes schema+name pairs to functions, tables, and table references.
The catalog is static once built — SDL does not change at runtime. For dynamic multi-catalog scenarios, see MultiCatalogProvider in client/apps.
All methods are safe for concurrent use from multiple goroutines.
func (*CatalogMux) HandleFunc ¶
func (m *CatalogMux) HandleFunc(schema, name string, handler HandlerFunc, opts ...Option) error
HandleFunc registers a Go function as a scalar function. The handler is called once per row with typed arguments via Request. Options declare arguments and return type: Arg(), Return().
mux.HandleFunc("math", "add", func(w *app.Result, r *app.Request) error {
return w.Set(r.Int64("a") + r.Int64("b"))
}, app.Arg("a", app.Int64), app.Arg("b", app.Int64), app.Return(app.Int64))
func (*CatalogMux) HandleTableFunc ¶
func (m *CatalogMux) HandleTableFunc(schema, name string, handler HandlerFunc, opts ...Option) error
HandleTableFunc registers a Go function as a table function. The handler is called once and writes rows via Result.Append(). Options declare arguments and result columns: Arg(), Col(), ColPK(), ColNullable().
mux.HandleTableFunc("users", "search", func(w *app.Result, r *app.Request) error {
w.Append(int64(1), "Alice")
return nil
}, app.Arg("query", app.String), app.ColPK("id", app.Int64), app.Col("name", app.String))
func (*CatalogMux) SDL ¶
func (m *CatalogMux) SDL() string
SDL returns the full GraphQL SDL for the catalog. If WithSDL was called, returns that string. Otherwise collects SDL from all registered items.
func (*CatalogMux) SDLWithModules ¶
func (m *CatalogMux) SDLWithModules(defaultSchema string) string
SDLWithModules returns the full GraphQL SDL with module directives. Objects from defaultSchema have no @module. Other schemas get @module(name: schemaName). System schemas (_mount, _funcs) are excluded.
func (*CatalogMux) ScalarFunc ¶
func (m *CatalogMux) ScalarFunc(schema string, fn catalog.ScalarFunction)
ScalarFunc registers a catalog.ScalarFunction directly.
func (*CatalogMux) Table ¶
func (m *CatalogMux) Table(schema string, table catalog.Table, opts ...SchemaOption)
Table registers a catalog.Table directly. If the table doesn't have SDL attached (via WithSDL), SDL is auto-generated from the Arrow schema. Mutable tables → @table, read-only → @view. SchemaOptions configure PK, references, field_references, etc.
func (*CatalogMux) TableFunc ¶
func (m *CatalogMux) TableFunc(schema string, fn catalog.TableFunction)
TableFunc registers a catalog.TableFunction directly.
func (*CatalogMux) TableFuncInOut ¶
func (m *CatalogMux) TableFuncInOut(schema string, fn catalog.TableFunctionInOut)
TableFuncInOut registers a catalog.TableFunctionInOut directly.
func (*CatalogMux) TableRef ¶
func (m *CatalogMux) TableRef(schema string, ref catalog.TableRef, opts ...SchemaOption)
TableRef registers a catalog.TableRef in the given schema. If the ref doesn't have SDL attached (via WithTableRefSDL), SDL is auto-generated from the Arrow schema as a @view. SchemaOptions configure PK, references, field_references, etc.
func (*CatalogMux) WithSDL ¶
func (m *CatalogMux) WithSDL(sdl string)
WithSDL sets a raw SDL string that overrides all auto-generated SDL. When set, SDL() returns this string instead of collecting from registered items.
type DataSourceInfo ¶
type DataSourceUser ¶
type DataSourceUser interface {
Application
DataSources(ctx context.Context) ([]DataSourceInfo, error)
}
type HandlerFunc ¶
HandlerFunc is the function signature for scalar and table function handlers.
type MultiCatalogMux ¶
type MultiCatalogProvider ¶
type MultiCatalogProvider interface {
SetMultiCatalogMux(mux MultiCatalogMux)
InitMultiCatalog(ctx context.Context) error
}
type Option ¶
type Option func(*funcDef)
Option configures function registration.
func ColNullable ¶
ColNullable declares a nullable result column for a table function.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request provides typed access to function arguments.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result writes function output. For scalar functions, use Set() to write the return value. For table functions, use Append() to write rows.
type SchemaOption ¶
type SchemaOption func(*schemaDef)
SchemaOption configures SDL generation for tables, table functions, and table refs.
func WithDescription ¶
func WithDescription(desc string) SchemaOption
WithDescription sets the description for the table/view/function type.
func WithFieldDescription ¶
func WithFieldDescription(field, desc string) SchemaOption
WithFieldDescription sets the description for a specific field.
func WithFieldReferences ¶
func WithFieldReferences(fieldName, referencesName, query, referencesQuery string) SchemaOption
WithFieldReferences adds a field-level @field_references directive.
func WithFilterRequired ¶
func WithFilterRequired(fields ...string) SchemaOption
WithFilterRequired marks fields as requiring a filter when queried.
func WithM2M ¶
func WithM2M() SchemaOption
WithM2M marks the table as a many-to-many junction table.
func WithM2MReferences ¶
func WithM2MReferences(referencesName string, sourceFields, referencesFields []string, query, referencesQuery, m2mName string) SchemaOption
WithM2MReferences adds an object-level @references directive with is_m2m flag.
func WithPK ¶
func WithPK(fields ...string) SchemaOption
WithPK marks fields as primary key. Multiple calls or multiple names for composite PK.
func WithRawSDL ¶
func WithRawSDL(sdl string) SchemaOption
WithRawSDL provides user-written SDL directly, skipping auto-generation.
func WithReferences ¶
func WithReferences(referencesName string, sourceFields, referencesFields []string, query, referencesQuery string) SchemaOption
WithReferences adds an object-level @references directive.