Skip to main content

Schema Inspection

VEF includes a schema inspection service and a built-in resource for reading database structure through the application API.

The built-in implementation inspects the primary data source only. It supports PostgreSQL, MySQL, and SQLite through Atlas. PostgreSQL uses vef.datasource.*.schema when configured and otherwise defaults to public; MySQL inspects the current DATABASE(); SQLite inspects the main schema.

Module Outputs

The schema module provides:

OutputMeaning
schema.Serviceschema inspection service
sys/schemabuilt-in RPC resource

schema.Service Interface

The public schema service exposes:

MethodReturn typePurpose
ListTables(ctx)[]schema.Tablelist tables in the current schema or database
GetTableSchema(ctx, name)*schema.TableSchemainspect one table in detail
ListViews(ctx)[]schema.Viewlist views

Built-In Resource

The schema module registers:

Resource
sys/schema

Current actions:

ActionInput paramsOutput typeNotes
list_tablesnone[]schema.Tablelist current tables
get_table_schemaname: stringschema.TableSchemareturns a dedicated schema-table-not-found business error when the table does not exist
list_viewsnone[]schema.Viewlist current views

Implementation details visible in source:

  • each action currently sets a per-operation rate-limit Max = 60
  • get_table_schema validates that name is present
  • missing tables are mapped to schema.ErrCodeTableNotFound (ErrCodeTableNotFound) and the dedicated schema.ErrTableNotFound (ErrTableNotFound) sentinel
  • the RPC response still uses the standard result envelope; business errors are returned in the body, not as a different HTTP status

Error API

APIMeaning
schema.ErrTableNotFoundbusiness error returned when a requested table does not exist
schema.ErrCodeTableNotFoundnumeric business error code for missing tables
schema.ErrTableMissingplain Go sentinel (v0.38) reported by Service when inspection cannot find the requested table — for Go callers using the service directly; the RPC surface still maps to ErrTableNotFound

Public Schema Types

All public schema DTOs use their JSON field names as the wire contract. Fields tagged with omitempty are omitted when empty: for example, schema, comment, primaryKey, indexes, uniqueKeys, foreignKeys, checks, default, isPrimaryKey, isAutoIncrement, onUpdate, onDelete, and columns on schema.View.

schema.Table

FieldTypeMeaning
namestringtable name
schemastringschema name when available
commentstringtable comment

schema.TableSchema

FieldTypeMeaning
namestringtable name
schemastringschema name
commentstringtable comment
columns[]schema.Columnall columns
primaryKey*schema.PrimaryKeyprimary key definition
indexes[]schema.Indexnon-unique indexes
uniqueKeys[]schema.UniqueKeyunique constraints
foreignKeys[]schema.ForeignKeyforeign key constraints
checks[]schema.Checkcheck constraints

schema.Column

FieldTypeMeaning
namestringcolumn name
typestringraw database type
nullableboolwhether the column is nullable
defaultstringdefault expression
commentstringcolumn comment
isPrimaryKeyboolwhether the column participates in the primary key
isAutoIncrementboolwhether the column is auto-incrementing

isAutoIncrement is detected for MySQL AUTO_INCREMENT, SQLite AUTOINCREMENT, PostgreSQL identity columns, and PostgreSQL serial, bigserial, or smallserial raw types.

schema.PrimaryKey

FieldTypeMeaning
namestringprimary key name
columns[]stringprimary key columns

schema.Index

FieldTypeMeaning
namestringindex name
columns[]stringindexed columns

schema.UniqueKey

FieldTypeMeaning
namestringunique key name
columns[]stringunique columns
predicatestringpartial-index predicate when the unique index is conditional (v0.38; omitted when empty)
hasExpressionsbooltrue when the unique index contains expression columns (v0.38; such keys do not guarantee plain column-tuple uniqueness)

schema.ForeignKey

FieldTypeMeaning
namestringforeign key name
columns[]stringlocal columns
refTablestringreferenced table
refColumns[]stringreferenced columns
onUpdatestringupdate action
onDeletestringdelete action

schema.Check

FieldTypeMeaning
namestringcheck constraint name
exprstringcheck expression

schema.View

FieldTypeMeaning
namestringview name
schemastringschema name
definitionstringview definition SQL
commentstringview comment
columns[]stringprojected columns

View listing uses database-specific queries. PostgreSQL and MySQL read from information_schema.views; SQLite reads sqlite_schema and excludes internal sqlite_% views.

Minimal Request Example

{
"resource": "sys/schema",
"action": "get_table_schema",
"version": "v1",
"params": {
"name": "sys_user"
}
}

Intended Use

This feature is useful for:

  • admin tooling
  • internal developer tooling
  • schema-aware integrations
  • MCP or prompt workflows that need database metadata

Next Step

Read Built-in Resources to see how sys/schema relates to the other framework-provided RPC resources.