Import data

View source code

File import function, usually used for Excel table import.

Use the data import component in Tables as a process.

This chapter introduces the Excel import function.

handler list

processDescription
xiang.import.RunStart running the import function
xiang.import.DataGet table data
xiang.import.SettingGet the mapping field setting of the table
xiang.import.DataSettingGet mapping data
xiang.import.MappingGet Mapping
xiang.import.MappingSettingGet mapping data

API list

InterfaceDescription
/api/xiang/import/<table_name>/settingGet the Setting of the table
/api/xiang/import/<table_name>/mappingGet the mapping field of the table
/api/xiang/import/<table_name>/mapping/settingGet the mapping field setting of the table
/api/xiang/import/<table_name>/dataGet data
/api/xiang/import/<table_name>/data/settingsetting to get data
/api/xiang/import/<table_name>Import data interface
{
"setting": "/api/xiang/import/ticket/setting",
"mapping": "/api/xiang/import/ticket/mapping",
"mapping_setting": "/api/xiang/import/ticket/mapping/setting",
"preview": "/api/xiang/import/ticket/data",
"preview_setting": "/api/xiang/import/ticket/data/setting",
"import": "/api/xiang/import/ticket"
}

sample code

Step 1: Add the models directory file /models/ticket.mod.json

View source code

Add the table directory file /tables/ticket.tab.json:

View source code

Step 2: Import the Excel file, add a new directory file /imports/ticket.imp.json

Application directory structure:

├── apis # Used to store interface description files
├──tables
| └──ticket.tab.json #import excel table
|
├── models # Used to store data model description files
├── db
└── imports #map file for importing data
| └── ticket.imp.json
|
|──scripts
| └──imports
| └──ticket.js
|
|
└── app.json

Write the code ticket.imp.json:

View source code

Write the code /scripts/imports/ticket.js:

function Import(columns, data) {
// todo handles import logic
// print the implicit relation
console.log(columns);
// print the obtained data
console.log(data);
var success = 0;
var fail = 0;
return [success, fail];
}
function Output(data) {
// todo handles the logic after import, this function will be called automatically after import: "output": "scripts.imports.ticket.Output",
return data;
}

Step 3: Get the file url

Request URL, request method: POST

  • /api/xiang/storage/upload

parameters

Parameter NameRequiredTypeDescription
fileyesfilefile name

return example

"20220411/0C3A5E7FCA0FE897710DE2CA00240FFE.xlsx"

Step 4: Get the mapping relationship

Request URL, request method GET

  • /api/xiang/import/ticket/mapping

parameters

Parameter NameRequiredTypeDescription
fileyesstringfile name url

Step 5: Pass all the data

request URL, request method POST

  • /api/xiang/import/ticket

parameters

Parameter NameRequiredTypeDescription
fileyesstringfile name
mappingyesstringmapping relation returns all data

Request parameter example

View source code

Import data

View source code

File import function, usually used for Excel table import.

Use the data import component in Tables as a process.

This chapter introduces the Excel import function.

handler list

processDescription
xiang.import.RunStart running the import function
xiang.import.DataGet table data
xiang.import.SettingGet the mapping field setting of the table
xiang.import.DataSettingGet mapping data
xiang.import.MappingGet Mapping
xiang.import.MappingSettingGet mapping data

API list

InterfaceDescription
/api/xiang/import/<table_name>/settingGet the Setting of the table
/api/xiang/import/<table_name>/mappingGet the mapping field of the table
/api/xiang/import/<table_name>/mapping/settingGet the mapping field setting of the table
/api/xiang/import/<table_name>/dataGet data
/api/xiang/import/<table_name>/data/settingsetting to get data
/api/xiang/import/<table_name>Import data interface
{
"setting": "/api/xiang/import/ticket/setting",
"mapping": "/api/xiang/import/ticket/mapping",
"mapping_setting": "/api/xiang/import/ticket/mapping/setting",
"preview": "/api/xiang/import/ticket/data",
"preview_setting": "/api/xiang/import/ticket/data/setting",
"import": "/api/xiang/import/ticket"
}

sample code

Step 1: Add the models directory file /models/ticket.mod.json

View source code

Add the table directory file /tables/ticket.tab.json:

View source code

Step 2: Import the Excel file, add a new directory file /imports/ticket.imp.json

Application directory structure:

├── apis # Used to store interface description files
├──tables
| └──ticket.tab.json #import excel table
|
├── models # Used to store data model description files
├── db
└── imports #map file for importing data
| └── ticket.imp.json
|
|──scripts
| └──imports
| └──ticket.js
|
|
└── app.json

Write the code ticket.imp.json:

View source code

Write the code /scripts/imports/ticket.js:

function Import(columns, data) {
// todo handles import logic
// print the implicit relation
console.log(columns);
// print the obtained data
console.log(data);
var success = 0;
var fail = 0;
return [success, fail];
}
function Output(data) {
// todo handles the logic after import, this function will be called automatically after import: "output": "scripts.imports.ticket.Output",
return data;
}

Step 3: Get the file url

Request URL, request method: POST

  • /api/xiang/storage/upload

parameters

Parameter NameRequiredTypeDescription
fileyesfilefile name

return example

"20220411/0C3A5E7FCA0FE897710DE2CA00240FFE.xlsx"

Step 4: Get the mapping relationship

Request URL, request method GET

  • /api/xiang/import/ticket/mapping

parameters

Parameter NameRequiredTypeDescription
fileyesstringfile name url

Step 5: Pass all the data

request URL, request method POST

  • /api/xiang/import/ticket

parameters

Parameter NameRequiredTypeDescription
fileyesstringfile name
mappingyesstringmapping relation returns all data

Request parameter example

View source code