Skip to main content

6.1 Table and field mappings

Dataway stores API definitions and release records. Saving updates a definition; publishing creates a release record. Database storage uses tables, while Nacos uses JSON objects.

Default storage layout​

Database storage uses two tables by default:

  • interface_info: editable definitions, with api_id for the API ID, api_path for the request path and api_script for the original script.
  • interface_release: release snapshots and history, with pub_id for the release ID, pub_api_id linking to the API and pub_script holding the script at publication time.

See table creation scripts for the complete schema, ready to copy for each database.

Nacos stores both kinds of data under records in one JSON snapshot: INFO holds definitions and RELEASE holds releases. Each collection is keyed by record ID, with fields such as ID, PATH and SCRIPT. For example, API hello stores its script at records.INFO.hello.SCRIPT.

These table names, columns and entity keys are configurable. Use mappings when your project has naming conventions or existing storage with different names. Default names require no configuration.

Configure mappings​

EntityType identifies the data category: INFO for definitions and RELEASE for releases. FieldDef identifies a field's meaning, such as ID or SCRIPT. Use DatawayConfig to map them to storage names:

  • tableMapping: sets a database table name or an entity key under Nacos records.
  • fieldMapping: sets a database column name or a field name within a Nacos record.
Custom storage names
import net.hasor.dataway.dal.EntityType;
import net.hasor.dataway.dal.FieldDef;

config.tableMapping(EntityType.INFO, "api_definitions")
.tableMapping(EntityType.RELEASE, "api_releases")
.fieldMapping(EntityType.INFO, FieldDef.ID, "definition_id")
.fieldMapping(EntityType.RELEASE, FieldDef.API_ID, "definition_ref")
.fieldMapping(EntityType.RELEASE, FieldDef.SCRIPT, "original_script");

The configuration makes these changes. Both providers use the same mapped names:

TargetDatabase: beforeNacos: beforeAfter
INFO table / entityinterface_infoINFOapi_definitions
RELEASE table / entityinterface_releaseRELEASEapi_releases
INFO.ID fieldapi_idIDdefinition_id
RELEASE.API_ID fieldpub_api_idAPI_IDdefinition_ref
RELEASE.SCRIPT fieldpub_scriptSCRIPToriginal_script

For example, a release script moves from interface_release.pub_script to api_releases.original_script in the database mapping, or from records.RELEASE.<recordID>.SCRIPT to records.api_releases.<recordID>.original_script in the Nacos mapping. Unspecified names keep their defaults.

Configure mappings before creating Dataway, using one mapping configuration per access-layer instance. Mappings determine where Dataway reads and writes; the application must update the actual schema and existing data names accordingly.

Storage dictionary​

These are the default names. Use tableMapping for tables / entities and fieldMapping for fields.

Tables and entities​

EntityTypeContentDatabase tableNacos entity key
INFOEditable API definitionsinterface_inforecords.INFO
RELEASERelease snapshots and historyinterface_releaserecords.RELEASE

Fields​

Nacos field names match FieldDef. A dash indicates that the entity does not use that field.

FieldDef / Nacos fieldINFO database columnRELEASE database column
IDapi_idpub_id
API_ID—pub_api_id
METHODapi_methodpub_method
PATHapi_pathpub_path
STATUSapi_statuspub_status
COMMENTapi_commentpub_comment
TYPEapi_typepub_type
SCRIPTapi_scriptpub_script
SCHEMAapi_schemapub_schema
SAMPLEapi_samplepub_sample
OPTIONapi_optionpub_option
REVISIONapi_revisionpub_revision
CREATE_TIMEapi_create_time—
GMT_TIMEapi_gmt_time—
RELEASE_TIME—pub_release_time

Naming rules​

ItemRule
Database table prefixSingle-argument constructors use default names. tablePrefix is prepended to defaults; tableMapping specifies the complete name without adding a prefix
Database table formattable, schema.table or catalog.schema.table, subject to database support
Database name charactersEach table-name segment and column starts with a letter or underscore and contains only letters, digits and underscores
Database column uniquenessNames must be unique within each entity, compared case-insensitively
Nacos namesCase-sensitive; dots are ordinary characters
Nacos name uniquenessEntity keys must be unique, as must field names within each entity
Nacos initial snapshotUse mapped names; see the initialization example

Empty names, unsupported fields and conflicting mappings fail during initialization.