Exporting date and auto id field, but not importing autocolumns when table is created.

This commit is contained in:
mike12345567 2021-12-02 16:17:10 +00:00
parent 6b13d2ceaa
commit a6de5a4fa1
3 changed files with 13 additions and 8 deletions

View File

@ -75,6 +75,7 @@ exports.handleDataImport = async (appId, user, table, dataImport) => {
if (!dataImport || !dataImport.csvString) {
return table
}
const db = new CouchDB(appId)
// Populate the table with rows imported from CSV in a bulk update
const data = await csvParser.transform({

View File

@ -5,6 +5,7 @@ const exporters = require("./exporters")
const { saveView, getView, getViews, deleteView } = require("./utils")
const { fetchView } = require("../row")
const { getTable } = require("../table/utils")
const { FieldTypes } = require("../../../constants")
exports.fetch = async ctx => {
const db = new CouchDB(ctx.appId)
@ -86,15 +87,15 @@ exports.exportView = async ctx => {
schema = table.schema
}
// remove any auto columns
const autocolumns = Object.entries(schema)
.filter(entry => entry[1].autocolumn)
// remove any relationships
const relationships = Object.entries(schema)
.filter(entry => entry[1].type === FieldTypes.LINK)
.map(entry => entry[0])
rows.forEach(row => {
autocolumns.forEach(column => delete row[column])
relationships.forEach(column => delete row[column])
})
// delete auto columns from schema
autocolumns.forEach(column => {
// delete relationships from schema
relationships.forEach(column => {
delete schema[column]
})

View File

@ -102,8 +102,11 @@ async function transform({ schema, csvString, existingTable }) {
schema = updateSchema({ schema, existingTable })
}
for (let key of Object.keys(schema)) {
colParser[key] = PARSERS[schema[key].type] || schema[key].type
for (let [key, field] of Object.entries(schema)) {
// don't import data to auto columns
if (!field.autocolumn) {
colParser[key] = PARSERS[field.type] || field.type
}
}
try {