Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type Column
- type ConfigProvider
- type DeleteRowResult
- type Handler
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- func (h *Handler) Trusted() echo.HandlerFunc
- type Identity
- type InMemoryBackend
- func (b *InMemoryBackend) ChangeTableCompartment(ref, ifMatch string, in changeCompartmentIn) (string, error)
- func (b *InMemoryBackend) Compartments() []string
- func (b *InMemoryBackend) CreateIndex(ref string, in createIndexIn) (string, error)
- func (b *InMemoryBackend) CreateTable(in createTableIn) (string, error)
- func (b *InMemoryBackend) DeleteIndex(ref, name, compartment string, ifExists bool) (string, error)
- func (b *InMemoryBackend) DeleteRow(ref, compartment string, key []string, ifMatch string, returnRow bool) (DeleteRowResult, error)
- func (b *InMemoryBackend) DeleteTable(ref, compartment, ifMatch string, ifExists bool) (string, error)
- func (b *InMemoryBackend) GetIndex(ref, name, compartment string) (IndexWire, error)
- func (b *InMemoryBackend) GetRow(ref, compartment string, key []string, consistency string) (RowResult, string, error)
- func (b *InMemoryBackend) GetTable(ref, compartment string) (TableWire, string, error)
- func (b *InMemoryBackend) GetWorkRequest(id string) (WorkRequestWire, error)
- func (b *InMemoryBackend) ListIndexes(ref, compartment, name, state string, o ListOpts) (page.Page[IndexWire], error)
- func (b *InMemoryBackend) ListTableUsage(ref, compartment, start, end string, o ListOpts) (page.Page[UsageWire], error)
- func (b *InMemoryBackend) ListTables(compartment, name, state string, o ListOpts) (page.Page[TableWire], TableList, error)
- func (b *InMemoryBackend) ListWorkRequests(compartment string, o ListOpts) (page.Page[WorkRequestWire], error)
- func (b *InMemoryBackend) PrepareStatement(compartment, statement string, withPlan bool) (PreparedStatement, error)
- func (b *InMemoryBackend) Query(in queryIn, limit int, token string) (page.Page[map[string]any], usageWire, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetCompartmentChecker(fn func(string) bool)
- func (b *InMemoryBackend) SetTransition(d time.Duration)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) SummarizeStatement(compartment, statement string) (StatementSummary, error)
- func (b *InMemoryBackend) Sweep()
- func (b *InMemoryBackend) SweepRows()
- func (b *InMemoryBackend) UpdateRow(ref, ifMatch string, in updateRowIn) (UpdateRowResult, error)
- func (b *InMemoryBackend) UpdateTable(ref, ifMatch string, in updateTableIn) (string, error)
- func (b *InMemoryBackend) WorkRequestExists(id string) error
- func (b *InMemoryBackend) WorkRequestLogs(id string, o ListOpts) (page.Page[wrLogWire], error)
- type Index
- type IndexKey
- type IndexWire
- type Limits
- type ListOpts
- type PreparedStatement
- type Provider
- type QueryResult
- type Row
- type RowResult
- type Settings
- type StatementSummary
- type Table
- type TableList
- type TableWire
- type Tags
- type UpdateRowResult
- type Usage
- type UsageWire
- type WorkRequest
- type WorkRequestWire
Constants ¶
const DefaultPort = 8162
DefaultPort is the dedicated listener's default TCP port.
const (
// Region is the fixed region baked into emulated OCIDs.
Region = "us-ashburn-1"
)
Variables ¶
var ErrNilAppContext = errors.New("ocinosql: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
var ErrSnapshotNull = errors.New("ocinosql: null entry in snapshot")
ErrSnapshotNull is returned when a snapshot contains a null entry.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is an OCI error response: HTTP status plus the `code` and `message` body fields.
type Column ¶
type Column struct {
Name string `json:"name"`
Type string `json:"type"`
Default json.RawMessage `json:"default,omitempty"`
NotNull bool `json:"notNull,omitempty"`
AsUUID bool `json:"asUuid,omitempty"`
Gen bool `json:"generated,omitempty"`
}
Column is one table column.
type ConfigProvider ¶
type ConfigProvider interface {
GetOCINoSQLSettings() Settings
}
ConfigProvider extracts OCI NoSQL configuration from the AppContext Config.
type DeleteRowResult ¶
type DeleteRowResult struct {
ExistingVersion *string `json:"existingVersion,omitempty"`
ExistingValue json.RawMessage `json:"existingValue,omitempty"`
IsSuccess bool `json:"isSuccess"`
Usage usageWire `json:"usage"`
}
DeleteRowResult is the DeleteRow response body.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
Port int
EnforceAuth bool
// contains filtered or unexported fields
}
Handler serves OCI NoSQL Database: tables, indexes, rows, queries and work requests.
func NewHandler ¶
func NewHandler(backend *InMemoryBackend) *Handler
NewHandler creates a Handler; callers override Port and EnforceAuth from Settings.
func (*Handler) ExtractOperation ¶
ExtractOperation returns the operation name for metrics.
func (*Handler) ExtractResource ¶
ExtractResource returns the addressed resource id for metrics.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists the supported operations.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the Echo handler for all OCINoSQL requests.
func (*Handler) MatchPriority ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: OCINoSQL runs on its own listener.
func (*Handler) Snapshot ¶
Snapshot implements persistence.Persistable by delegating to the backend.
func (*Handler) StartWorker ¶
StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.
func (*Handler) Trusted ¶
func (h *Handler) Trusted() echo.HandlerFunc
Trusted returns a handler that skips request-signature verification, for the in-process dashboard proxy.
type Identity ¶
type Identity struct {
Column string `json:"column"`
Always bool `json:"always"`
OnNull bool `json:"onNull,omitempty"`
Next int64 `json:"next"`
Increment int64 `json:"increment"`
}
Identity is the table's identity column spec and its counter.
type InMemoryBackend ¶
InMemoryBackend holds every table and work request under one lock.
func NewInMemoryBackend ¶
func NewInMemoryBackend() *InMemoryBackend
NewInMemoryBackend creates an empty backend.
func (*InMemoryBackend) ChangeTableCompartment ¶
func (b *InMemoryBackend) ChangeTableCompartment(ref, ifMatch string, in changeCompartmentIn) (string, error)
ChangeTableCompartment moves a table to another compartment.
func (*InMemoryBackend) Compartments ¶
func (b *InMemoryBackend) Compartments() []string
Compartments lists the distinct compartments that hold tables.
func (*InMemoryBackend) CreateIndex ¶
func (b *InMemoryBackend) CreateIndex(ref string, in createIndexIn) (string, error)
CreateIndex adds a secondary index to a table and returns its work request id.
func (*InMemoryBackend) CreateTable ¶
func (b *InMemoryBackend) CreateTable(in createTableIn) (string, error)
CreateTable creates a table from a CREATE TABLE statement and returns its work request id.
func (*InMemoryBackend) DeleteIndex ¶
func (b *InMemoryBackend) DeleteIndex(ref, name, compartment string, ifExists bool) (string, error)
DeleteIndex removes an index; ifExists turns a missing index into a no-op (empty work request id).
func (*InMemoryBackend) DeleteRow ¶
func (b *InMemoryBackend) DeleteRow( ref, compartment string, key []string, ifMatch string, returnRow bool, ) (DeleteRowResult, error)
DeleteRow removes one row by primary key.
func (*InMemoryBackend) DeleteTable ¶
func (b *InMemoryBackend) DeleteTable(ref, compartment, ifMatch string, ifExists bool) (string, error)
DeleteTable drops a table; ifExists turns a missing table into a no-op (empty work request id).
func (*InMemoryBackend) GetIndex ¶
func (b *InMemoryBackend) GetIndex(ref, name, compartment string) (IndexWire, error)
GetIndex returns one index.
func (*InMemoryBackend) GetRow ¶
func (b *InMemoryBackend) GetRow(ref, compartment string, key []string, consistency string) (RowResult, string, error)
GetRow reads one row by primary key.
func (*InMemoryBackend) GetTable ¶
func (b *InMemoryBackend) GetTable(ref, compartment string) (TableWire, string, error)
GetTable returns one table and its etag.
func (*InMemoryBackend) GetWorkRequest ¶
func (b *InMemoryBackend) GetWorkRequest(id string) (WorkRequestWire, error)
GetWorkRequest returns one work request.
func (*InMemoryBackend) ListIndexes ¶
func (b *InMemoryBackend) ListIndexes(ref, compartment, name, state string, o ListOpts) (page.Page[IndexWire], error)
ListIndexes lists the indexes of a table.
func (*InMemoryBackend) ListTableUsage ¶
func (b *InMemoryBackend) ListTableUsage( ref, compartment, start, end string, o ListOpts, ) (page.Page[UsageWire], error)
ListTableUsage reports per-minute consumption recorded for a table.
func (*InMemoryBackend) ListTables ¶
func (b *InMemoryBackend) ListTables( compartment, name, state string, o ListOpts, ) (page.Page[TableWire], TableList, error)
ListTables lists tables of a compartment.
func (*InMemoryBackend) ListWorkRequests ¶
func (b *InMemoryBackend) ListWorkRequests(compartment string, o ListOpts) (page.Page[WorkRequestWire], error)
ListWorkRequests lists the work requests of a compartment, optionally for one resource.
func (*InMemoryBackend) PrepareStatement ¶
func (b *InMemoryBackend) PrepareStatement(compartment, statement string, withPlan bool) (PreparedStatement, error)
PrepareStatement validates a SELECT against its table and returns an opaque prepared form.
func (*InMemoryBackend) Query ¶
func (b *InMemoryBackend) Query(in queryIn, limit int, token string) (page.Page[map[string]any], usageWire, error)
Query runs a SELECT statement and returns one page of results.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads backend state from a snapshot.
func (*InMemoryBackend) SetClock ¶
func (b *InMemoryBackend) SetClock(now func() time.Time)
SetClock injects the time source used for lifecycle transitions and TTL expiry.
func (*InMemoryBackend) SetCompartmentChecker ¶
func (b *InMemoryBackend) SetCompartmentChecker(fn func(string) bool)
SetCompartmentChecker validates compartmentId arguments against another service (OCI Identity).
func (*InMemoryBackend) SetTransition ¶
func (b *InMemoryBackend) SetTransition(d time.Duration)
SetTransition sets how long CREATING, UPDATING and DELETING states last.
func (*InMemoryBackend) Snapshot ¶
func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
Snapshot serialises the backend state, including registered API keys.
func (*InMemoryBackend) SummarizeStatement ¶
func (b *InMemoryBackend) SummarizeStatement(compartment, statement string) (StatementSummary, error)
SummarizeStatement classifies a statement and reports syntax errors without executing anything.
func (*InMemoryBackend) Sweep ¶
func (b *InMemoryBackend) Sweep()
Sweep applies lifecycle transitions against the backend clock.
func (*InMemoryBackend) SweepRows ¶
func (b *InMemoryBackend) SweepRows()
SweepRows removes expired rows from every table.
func (*InMemoryBackend) UpdateRow ¶
func (b *InMemoryBackend) UpdateRow(ref, ifMatch string, in updateRowIn) (UpdateRowResult, error)
UpdateRow puts a row into a table.
func (*InMemoryBackend) UpdateTable ¶
func (b *InMemoryBackend) UpdateTable(ref, ifMatch string, in updateTableIn) (string, error)
UpdateTable alters a table's schema, limits or tags.
func (*InMemoryBackend) WorkRequestExists ¶
func (b *InMemoryBackend) WorkRequestExists(id string) error
WorkRequestExists reports whether a work request exists (its error list is always empty).
func (*InMemoryBackend) WorkRequestLogs ¶
WorkRequestLogs returns the log entries of a work request.
type Index ¶
type Index struct {
Created time.Time `json:"created"`
TransitionAt *time.Time `json:"transitionAt,omitempty"`
Name string `json:"name"`
State string `json:"state"`
Keys []IndexKey `json:"keys"`
}
Index is a secondary index on a table.
type IndexKey ¶
type IndexKey struct {
Column string `json:"column"`
JSONPath string `json:"jsonPath,omitempty"`
JSONType string `json:"jsonType,omitempty"`
}
IndexKey is one key of a secondary index.
type IndexWire ¶
type IndexWire struct {
Name string `json:"name"`
CompartmentID string `json:"compartmentId,omitempty"`
TableName string `json:"tableName,omitempty"`
TableID string `json:"tableId,omitempty"`
LifecycleState string `json:"lifecycleState"`
Keys []indexKeyWire `json:"keys"`
}
IndexWire is the full index representation.
type Limits ¶
type Limits struct {
Mode string `json:"mode"`
ReadUnits int `json:"readUnits"`
WriteUnits int `json:"writeUnits"`
StorageGB int `json:"storageGb"`
}
Limits are a table's throughput and storage limits.
type PreparedStatement ¶
type PreparedStatement struct {
QueryPlan any `json:"queryPlan,omitempty"`
Statement string `json:"statement"`
Usage usageWire `json:"usage"`
}
PreparedStatement is the PrepareStatement response body.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for OCI NoSQL. It runs on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
type QueryResult ¶
QueryResult is the Query response body.
type Row ¶
type Row struct {
Expire *time.Time `json:"expire,omitempty"`
Version string `json:"version"`
Value json.RawMessage `json:"value"`
}
Row is one stored table row.
type RowResult ¶
type RowResult struct {
TimeOfExpiration *time.Time `json:"timeOfExpiration,omitempty"`
Value json.RawMessage `json:"value"`
Usage usageWire `json:"usage"`
}
RowResult is the GetRow response body.
type Settings ¶
type Settings struct {
Port int `` //nolint:lll // config struct tags are intentionally verbose
/* 187-byte string literal not displayed */
EnforceAuth bool `` //nolint:lll // config struct tags are intentionally verbose
/* 221-byte string literal not displayed */
}
Settings holds service-level configuration, embedded in the root CLI as CLI.OCINoSQL.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings returns the settings used when no ConfigProvider is available.
type StatementSummary ¶
type StatementSummary struct {
SyntaxError *string `json:"syntaxError,omitempty"`
Operation string `json:"operation,omitempty"`
TableName string `json:"tableName,omitempty"`
IndexName string `json:"indexName,omitempty"`
IsIfExists bool `json:"isIfExists"`
IsIfNotExists bool `json:"isIfNotExists"`
}
StatementSummary is the SummarizeStatement response body.
type Table ¶
type Table struct {
TimeCreated time.Time `json:"timeCreated"`
TimeUpdated time.Time `json:"timeUpdated"`
Tags Tags `json:"tags"`
TransitionAt *time.Time `json:"transitionAt,omitempty"`
Rows map[string]*Row `json:"rows,omitempty"`
Indexes map[string]*Index `json:"indexes,omitempty"`
Usage map[int64]*Usage `json:"usage,omitempty"`
Identity *Identity `json:"identity,omitempty"`
CompartmentID string `json:"compartmentId"`
ID string `json:"id"`
Name string `json:"name"`
State string `json:"state"`
DDL string `json:"ddl"`
Etag string `json:"etag"`
Columns []Column `json:"columns"`
PrimaryKey []string `json:"primaryKey"`
ShardKey []string `json:"shardKey"`
Limits Limits `json:"limits"`
TTLHours int `json:"ttlHours"`
RowSeq int64 `json:"rowSeq"`
AutoReclaim bool `json:"autoReclaimable,omitempty"`
}
Table is a NoSQL table with its rows and indexes.
type TableList ¶
type TableList struct {
Items []TableWire `json:"items"`
AutoReclaimableTables int `json:"autoReclaimableTables"`
OnDemandCapacityTables int `json:"onDemandCapacityTables"`
}
TableList is the ListTables result body.
type TableWire ¶
type TableWire struct {
TimeCreated time.Time `json:"timeCreated"`
TimeUpdated time.Time `json:"timeUpdated"`
Schema *schemaWire `json:"schema,omitempty"`
FreeformTags map[string]string `json:"freeformTags,omitempty"`
DefinedTags map[string]map[string]any `json:"definedTags,omitempty"`
DDLStatement string `json:"ddlStatement,omitempty"`
ID string `json:"id"`
CompartmentID string `json:"compartmentId"`
Name string `json:"name"`
LifecycleState string `json:"lifecycleState"`
SchemaState string `json:"schemaState"`
TableLimits limitsWire `json:"tableLimits"`
IsAutoReclaimable bool `json:"isAutoReclaimable"`
IsMultiRegion bool `json:"isMultiRegion"`
}
TableWire is the full table representation.
type Tags ¶
type Tags struct {
FreeformTags map[string]string `json:"freeformTags,omitempty"`
DefinedTags map[string]map[string]any `json:"definedTags,omitempty"`
}
Tags are the shared freeform and defined tag sets of a resource.
type UpdateRowResult ¶
type UpdateRowResult struct {
Version *string `json:"version"`
ExistingVersion *string `json:"existingVersion,omitempty"`
GeneratedValue *string `json:"generatedValue,omitempty"`
ExistingValue json.RawMessage `json:"existingValue,omitempty"`
Usage usageWire `json:"usage"`
}
UpdateRowResult is the UpdateRow response body.
type UsageWire ¶
type UsageWire struct {
TimeStarted time.Time `json:"timeStarted"`
SecondsInPeriod int `json:"secondsInPeriod"`
ReadUnits int `json:"readUnits"`
WriteUnits int `json:"writeUnits"`
StorageInGBs int `json:"storageInGBs"`
ReadThrottleCount int `json:"readThrottleCount"`
WriteThrottleCount int `json:"writeThrottleCount"`
StorageThrottleCount int `json:"storageThrottleCount"`
}
UsageWire is one ListTableUsage item.
type WorkRequest ¶
type WorkRequest struct {
Accepted time.Time `json:"accepted"`
FinishAt time.Time `json:"finishAt"`
ID string `json:"id"`
Operation string `json:"operation"`
CompartmentID string `json:"compartmentId"`
EntityID string `json:"entityId"`
Action string `json:"action"`
Seq int64 `json:"seq"`
}
WorkRequest records an asynchronous admin operation.
type WorkRequestWire ¶
type WorkRequestWire struct {
TimeAccepted time.Time `json:"timeAccepted"`
TimeStarted *time.Time `json:"timeStarted,omitempty"`
TimeFinished *time.Time `json:"timeFinished,omitempty"`
OperationType string `json:"operationType"`
Status string `json:"status"`
ID string `json:"id"`
CompartmentID string `json:"compartmentId"`
Resources []wrResourceWire `json:"resources"`
PercentComplete float32 `json:"percentComplete"`
}
WorkRequestWire is the wire form of a work request.