Skip to main content
Version: Next

Defining Schema in Excel

Maintain structure definitions in tables with __tables__.xlsx / __beans__.xlsx / __enums__.xlsx (exact file names depend on the project). Good when business tables add fields often and you want designers to see the structure tables too.

Hook them up in luban.conf

"schemaFiles": [
{"fileName": "Defines", "type": ""},
{"fileName": "Datas/__tables__.xlsx", "type": "table"},
{"fileName": "Datas/__beans__.xlsx", "type": "bean"},
{"fileName": "Datas/__enums__.xlsx", "type": "enum"}
]
typeContent
tableWhich tables exist, input, index, mode, value type, etc.
beanStructs and fields
enumEnum items

The three definition kinds must be kept in separate files (or sheets); column names follow your project template—examples below use logical column names.

__tables__ example

full_namevalue_typeread_schema_from_fileinputindexmodegroupcomment
TbItemItemfalseitem.xlsxid道具表
item.TbEquipitem.Equiptrueitem/equip.xlsxidmapc,s从数据表头读字段
TbDropListDropEntryfalsedrop.xlsxlist无主键列表
TbUnionKeyUnionRowfalseunion.xlsxkey1+key2list联合主键
TbMultiKeyMultiKeyRowfalsemulti.xlsxkey1,key2list两个独立索引
TbGlobalGlobalConfigfalseglobal.xlsxone全局单例

Field meanings:

ColumnDescription
full_nameFull table name; may include a module prefix, e.g. item.TbEquip
value_typeRow-record bean name; may use the same module prefix
read_schema_from_filetrue: infer bean fields from the data table header; do not also define the same-named bean in __beans__
inputData source relative to dataDir; comma for multiple files, or SheetName@file.xlsx
indexPrimary key; composite with a+b, multiple independent indexes with a,b; often empty for list/one
modemap (default) / list / one (or singleton)
groupTable-level export groups; empty uses groups with default: true in luban.conf
comment / tags / outputComment, tags, custom output file name (optional)

mode / index mapping

NeedmodeindexTypical generated usage
Ordinary id tableempty or mapidGet(id) / dictionary
List without primary keylistemptyIterate the list
Composite primary keylista+bMulti-field uniqueness
Independent multi-indexlista,bMultiple lookup dictionaries
Global singletononeemptyOne config per table (or vertical table)
caution

Most languages lack built-in composite-key hash maps. Only a few (e.g. C#, Python) get generated joint-index APIs; data export still validates joint keys regardless of generated code.

When index is omitted and mode is map, the first field of the value bean is often taken by default.

Two ways to build beans

A. Explicit definition in __beans__ (recommended for stable structures)

__tables__: read_schema_from_file=false, value_type=Item; define Item fields in __beans__.

B. Read definition from the data table header (good for quick add-table)

__tables__: read_schema_from_file=true, data table has ##var / ##type:

##varidnameprice
##typeintstringint
1001金币0

In this case do not also define same-named Item/Reward in __beans__, or you get a duplicate-definition error. The table itself must still be registered in __tables__.

__beans__ example

full_nameparentvalueTypesepaliasgroupcommentfields
Vec3true,三维向量(见下)
Cost消耗(见下)
Shape形状基类(可无字段)
CircleShape(见下)

Field lists in Excel are usually nested columns/sub-tables; logically equivalent to:

beannametypegroupcomment
Vec3xfloat
Vec3yfloat
Vec3zfloat
Costidint道具 id
Costcountint数量
Circleradiusfloat
ColumnDescription
full_nameFull bean name, e.g. common.Vec3
parentFull parent name; when there are subclasses the parent is generally abstract
valueTypeWhen true, export with value-type semantics (e.g. vectors)
sepDefault separator for stream/compact filling, e.g. ,
aliasChinese alias etc. usable when filling polymorphic data
fieldsname / type / group / comment / tags

Type string forms: see Type cheat sheet; polymorphism: see Polymorphism.

__enums__ example

full_nameflagsuniquecommentitems
Qualityfalsetrue品质(见下)
OpenFlagtrue开关位(见下)

Enum items, logical sketch:

enumnamealiasvaluecomment
QualityWHITE1
QualityGREEN绿2
QualityBLUE3
OpenFlagNone0
OpenFlagA1
OpenFlagB2
OpenFlagCA|Bflags combination
ColumnDescription
flagsWhether it is a bit-flags enum
uniqueWhether item values must be unique
items.name / alias / valueItem name, fill-in alias, explicit value (decimal/hex, or A\|B)

In data tables you may fill or WHITE (when alias exists).

Coexisting with XML

The same project can have both Defines/*.xml and __*.xlsx:

  • Vectors, shared structures, deep inheritance → XML (Defines)
  • Business table registration, business bean/enum → Excel schema

They merge into one Schema; type names must not conflict.

Common pitfalls

  • Only changed the data table header, but read_schema_from_file=false and __beans__ was not updated.
  • read_schema_from_file=true and also redefined the same bean in __beans__.
  • mode/index does not match lookup style (e.g. want Get(id) but wrote list).
  • input paths are relative to dataDir; wrong paths cause “data not found”.