Browse Source

fix: pageInfo

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
feat/0523-export-schema
Raju Udava 3 years ago
parent
commit
4487f00866
  1. 79
      packages/nocodb/tests/export-import/importSchema.js

79
packages/nocodb/tests/export-import/importSchema.js

@ -1,9 +1,6 @@
const Api = require('nocodb-sdk').Api; const Api = require('nocodb-sdk').Api;
const { UITypes } = require('nocodb-sdk'); const { UITypes } = require('nocodb-sdk');
const jsonfile = require("jsonfile"); const jsonfile = require("jsonfile");
const dayjs = require("dayjs");
const axios = require("axios");
const FormData = require("form-data");
let api = {} let api = {}
let ncIn = jsonfile.readFileSync('sample.json') let ncIn = jsonfile.readFileSync('sample.json')
@ -13,6 +10,8 @@ let lookup = []
let rollup = [] let rollup = []
let formula = [] let formula = []
let ncTables = {} let ncTables = {}
let rootLinks = []
const ncConfig = { const ncConfig = {
srcProject: "sample", srcProject: "sample",
@ -79,7 +78,6 @@ async function createFormula() {
} }
} }
let rootLinks = []
async function createLinks() { async function createLinks() {
console.log(`createLinks`) console.log(`createLinks`)
for (let i = 0; i < link.length; i++) { for (let i = 0; i < link.length; i++) {
@ -280,24 +278,30 @@ async function restoreBaseData() {
let tblId = ncTables[tblSchema.id].id; let tblId = ncTables[tblSchema.id].id;
let pk = tblSchema.columns.find(a => a.pk).title let pk = tblSchema.columns.find(a => a.pk).title
// fixme: iterate page information let moreRecords = true;
let recList = await api.dbTableRow.list("nc", ncConfig.srcProject, tblSchema.title, {}, { let offset = 0, limit = 25;
query: { limit: 500 }
})
for (let recCnt = 0; recCnt < recList.list.length; recCnt++) { while(moreRecords) {
let record = await api.dbTableRow.read("nc", ncConfig.srcProject, tblSchema.title, recList.list[recCnt][pk]) let recList = await api.dbTableRow.list("nc", ncConfig.srcProject, tblSchema.title, {}, {
query: { limit: limit, offset: offset }
// post-processing on the record })
for (const [key, value] of Object.entries(record)) { moreRecords = !recList.pageInfo.isLastPage
let table = ncTables[tblId] offset += limit
// retrieve datatype
const dt = table.columns.find(x => x.title === key)?.uidt; for (let recCnt = 0; recCnt < recList.list.length; recCnt++) {
if (dt === UITypes.LinkToAnotherRecord) delete record[key]; let record = await api.dbTableRow.read("nc", ncConfig.srcProject, tblSchema.title, recList.list[recCnt][pk])
if (dt === UITypes.Lookup) delete record[key];
if (dt === UITypes.Rollup) delete record[key]; // post-processing on the record
for (const [key, value] of Object.entries(record)) {
let table = ncTables[tblId]
// retrieve datatype
const dt = table.columns.find(x => x.title === key)?.uidt;
if (dt === UITypes.LinkToAnotherRecord) delete record[key];
if (dt === UITypes.Lookup) delete record[key];
if (dt === UITypes.Rollup) delete record[key];
}
await api.dbTableRow.create("nc", ncConfig.projectName, tblSchema.title, record)
} }
await api.dbTableRow.create("nc", ncConfig.projectName, tblSchema.title, record)
} }
} }
} }
@ -307,22 +311,27 @@ async function restoreLinks() {
for(let i=0; i<rootLinks.length; i++) { for(let i=0; i<rootLinks.length; i++) {
let pk = rootLinks[i].linkSrcTbl.columns.find(a => a.pk).title let pk = rootLinks[i].linkSrcTbl.columns.find(a => a.pk).title
let moreRecords = true;
let offset = 0, limit = 25;
// fixme: iterate page information while(moreRecords) {
let recList = await api.dbTableRow.list("nc", ncConfig.srcProject, rootLinks[i].linkSrcTbl.title, {}, { let recList = await api.dbTableRow.list("nc", ncConfig.srcProject, rootLinks[i].linkSrcTbl.title, {}, {
query: { limit: 500 } query: { limit: limit, offset: offset }
}) })
moreRecords = !recList.pageInfo.isLastPage
for (let recCnt = 0; recCnt < recList.list.length; recCnt++) { offset += limit
let record = await api.dbTableRow.read("nc", ncConfig.srcProject, rootLinks[i].linkSrcTbl.title, recList.list[recCnt][pk])
let linkField = record[rootLinks[i].linkColumn.title]; for (let recCnt = 0; recCnt < recList.list.length; recCnt++) {
if(linkField.length) { let record = await api.dbTableRow.read("nc", ncConfig.srcProject, rootLinks[i].linkSrcTbl.title, recList.list[recCnt][pk])
await api.dbTableRow.nestedAdd("nc", ncConfig.projectName, rootLinks[i].linkSrcTbl.title, let linkField = record[rootLinks[i].linkColumn.title];
record[pk], if (linkField.length) {
rootLinks[i].linkColumn.colOptions.type, await api.dbTableRow.nestedAdd("nc", ncConfig.projectName, rootLinks[i].linkSrcTbl.title,
encodeURIComponent(rootLinks[i].linkColumn.title), record[pk],
linkField[0][pk] rootLinks[i].linkColumn.colOptions.type,
) encodeURIComponent(rootLinks[i].linkColumn.title),
linkField[0][pk]
)
}
} }
} }
} }

Loading…
Cancel
Save