Get rid of schemaFields on backend.
This commit is contained in:
parent
db7c2c804b
commit
2a21556402
|
@ -231,6 +231,7 @@
|
||||||
notifications.info("Request did not return any data")
|
notifications.info("Request did not return any data")
|
||||||
} else {
|
} else {
|
||||||
response.info = response.info || { code: 200 }
|
response.info = response.info || { code: 200 }
|
||||||
|
console.log(response)
|
||||||
schema = response.schema
|
schema = response.schema
|
||||||
notifications.success("Request sent successfully")
|
notifications.success("Request sent successfully")
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,8 +89,8 @@ export function createQueriesStore() {
|
||||||
// Assume all the fields are strings and create a basic schema from the
|
// Assume all the fields are strings and create a basic schema from the
|
||||||
// unique fields returned by the server
|
// unique fields returned by the server
|
||||||
const schema = {}
|
const schema = {}
|
||||||
for (let [field, type] of Object.entries(result.schemaFields)) {
|
for (let [field, metadata] of Object.entries(result.schema)) {
|
||||||
schema[field] = type || "string"
|
schema[field] = metadata || { type: "string" }
|
||||||
}
|
}
|
||||||
return { ...result, schema, rows: result.rows || [] }
|
return { ...result, schema, rows: result.rows || [] }
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ export async function preview(ctx: UserCtx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { rows, keys, info, extra } = (await Runner.run(inputs)) as any
|
const { rows, keys, info, extra } = (await Runner.run(inputs)) as any
|
||||||
const schemaFields: Record<string, QuerySchema> = {}
|
const previewSchema: Record<string, QuerySchema> = {}
|
||||||
const makeQuerySchema = (type: FieldType, name: string): QuerySchema => ({
|
const makeQuerySchema = (type: FieldType, name: string): QuerySchema => ({
|
||||||
type,
|
type,
|
||||||
name,
|
name,
|
||||||
|
@ -178,33 +178,33 @@ export async function preview(ctx: UserCtx) {
|
||||||
for (let key of [...new Set(keys)] as string[]) {
|
for (let key of [...new Set(keys)] as string[]) {
|
||||||
const field = rows[0][key]
|
const field = rows[0][key]
|
||||||
let type = typeof field,
|
let type = typeof field,
|
||||||
fieldType = makeQuerySchema(FieldType.STRING, key)
|
fieldMetadata = makeQuerySchema(FieldType.STRING, key)
|
||||||
if (field)
|
if (field)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "boolean":
|
case "boolean":
|
||||||
schemaFields[key] = makeQuerySchema(FieldType.BOOLEAN, key)
|
fieldMetadata = makeQuerySchema(FieldType.BOOLEAN, key)
|
||||||
break
|
break
|
||||||
case "object":
|
case "object":
|
||||||
if (field instanceof Date) {
|
if (field instanceof Date) {
|
||||||
fieldType = makeQuerySchema(FieldType.DATETIME, key)
|
fieldMetadata = makeQuerySchema(FieldType.DATETIME, key)
|
||||||
} else if (Array.isArray(field)) {
|
} else if (Array.isArray(field)) {
|
||||||
fieldType = makeQuerySchema(FieldType.ARRAY, key)
|
fieldMetadata = makeQuerySchema(FieldType.ARRAY, key)
|
||||||
} else {
|
} else {
|
||||||
fieldType = makeQuerySchema(FieldType.JSON, key)
|
fieldMetadata = makeQuerySchema(FieldType.JSON, key)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "number":
|
case "number":
|
||||||
fieldType = makeQuerySchema(FieldType.NUMBER, key)
|
fieldMetadata = makeQuerySchema(FieldType.NUMBER, key)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
schemaFields[key] = fieldType
|
previewSchema[key] = fieldMetadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if existing schema, update to include any previous schema keys
|
// if existing schema, update to include any previous schema keys
|
||||||
if (existingSchema) {
|
if (existingSchema) {
|
||||||
for (let key of Object.keys(schemaFields)) {
|
for (let key of Object.keys(previewSchema)) {
|
||||||
if (existingSchema[key]?.type) {
|
if (existingSchema[key]?.type) {
|
||||||
schemaFields[key] = existingSchema[key].type
|
previewSchema[key] = existingSchema[key].type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ export async function preview(ctx: UserCtx) {
|
||||||
await events.query.previewed(datasource, query)
|
await events.query.previewed(datasource, query)
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
rows,
|
rows,
|
||||||
schemaFields,
|
schema: previewSchema,
|
||||||
info,
|
info,
|
||||||
extra,
|
extra,
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,9 +235,9 @@ describe("/queries", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
// these responses come from the mock
|
// these responses come from the mock
|
||||||
expect(res.body.schemaFields).toEqual({
|
expect(res.body.schema).toEqual({
|
||||||
a: "string",
|
a: { type: "string", name: "a" },
|
||||||
b: "number",
|
b: { type: "number", name: "b" },
|
||||||
})
|
})
|
||||||
expect(res.body.rows.length).toEqual(1)
|
expect(res.body.rows.length).toEqual(1)
|
||||||
expect(events.query.previewed).toBeCalledTimes(1)
|
expect(events.query.previewed).toBeCalledTimes(1)
|
||||||
|
@ -300,10 +300,10 @@ describe("/queries", () => {
|
||||||
queryString: "test={{ variable2 }}",
|
queryString: "test={{ variable2 }}",
|
||||||
})
|
})
|
||||||
// these responses come from the mock
|
// these responses come from the mock
|
||||||
expect(res.body.schemaFields).toEqual({
|
expect(res.body.schema).toEqual({
|
||||||
opts: "json",
|
opts: { type: "json", name: "opts" },
|
||||||
url: "string",
|
url: { type: "string", name: "url" },
|
||||||
value: "string",
|
value: { type: "string", name: "value" },
|
||||||
})
|
})
|
||||||
expect(res.body.rows[0].url).toEqual("http://www.google.com?test=1")
|
expect(res.body.rows[0].url).toEqual("http://www.google.com?test=1")
|
||||||
})
|
})
|
||||||
|
@ -314,10 +314,10 @@ describe("/queries", () => {
|
||||||
path: "www.google.com",
|
path: "www.google.com",
|
||||||
queryString: "test={{ variable3 }}",
|
queryString: "test={{ variable3 }}",
|
||||||
})
|
})
|
||||||
expect(res.body.schemaFields).toEqual({
|
expect(res.body.schema).toEqual({
|
||||||
opts: "json",
|
opts: { type: "json", name: "opts" },
|
||||||
url: "string",
|
url: { type: "string", name: "url" },
|
||||||
value: "string",
|
value: { type: "string", name: "value" },
|
||||||
})
|
})
|
||||||
expect(res.body.rows[0].url).toContain("doctype%20html")
|
expect(res.body.rows[0].url).toContain("doctype%20html")
|
||||||
})
|
})
|
||||||
|
@ -337,10 +337,10 @@ describe("/queries", () => {
|
||||||
path: "www.failonce.com",
|
path: "www.failonce.com",
|
||||||
queryString: "test={{ variable3 }}",
|
queryString: "test={{ variable3 }}",
|
||||||
})
|
})
|
||||||
expect(res.body.schemaFields).toEqual({
|
expect(res.body.schema).toEqual({
|
||||||
fails: "number",
|
fails: { type: "number", name: "fails" },
|
||||||
opts: "json",
|
opts: { type: "json", name: "opts" },
|
||||||
url: "string",
|
url: { type: "string", name: "url" },
|
||||||
})
|
})
|
||||||
expect(res.body.rows[0].fails).toEqual(1)
|
expect(res.body.rows[0].fails).toEqual(1)
|
||||||
})
|
})
|
||||||
|
|
|
@ -376,8 +376,8 @@ export function checkExternalTables(
|
||||||
errors[name] = "Table must have a primary key."
|
errors[name] = "Table must have a primary key."
|
||||||
}
|
}
|
||||||
|
|
||||||
const schemaFields = Object.keys(table.schema)
|
const columnNames = Object.keys(table.schema)
|
||||||
if (schemaFields.find(f => invalidColumns.includes(f))) {
|
if (columnNames.find(f => invalidColumns.includes(f))) {
|
||||||
errors[name] = "Table contains invalid columns."
|
errors[name] = "Table contains invalid columns."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue