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")
|
||||
} else {
|
||||
response.info = response.info || { code: 200 }
|
||||
console.log(response)
|
||||
schema = response.schema
|
||||
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
|
||||
// unique fields returned by the server
|
||||
const schema = {}
|
||||
for (let [field, type] of Object.entries(result.schemaFields)) {
|
||||
schema[field] = type || "string"
|
||||
for (let [field, metadata] of Object.entries(result.schema)) {
|
||||
schema[field] = metadata || { type: "string" }
|
||||
}
|
||||
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 schemaFields: Record<string, QuerySchema> = {}
|
||||
const previewSchema: Record<string, QuerySchema> = {}
|
||||
const makeQuerySchema = (type: FieldType, name: string): QuerySchema => ({
|
||||
type,
|
||||
name,
|
||||
|
@ -178,33 +178,33 @@ export async function preview(ctx: UserCtx) {
|
|||
for (let key of [...new Set(keys)] as string[]) {
|
||||
const field = rows[0][key]
|
||||
let type = typeof field,
|
||||
fieldType = makeQuerySchema(FieldType.STRING, key)
|
||||
fieldMetadata = makeQuerySchema(FieldType.STRING, key)
|
||||
if (field)
|
||||
switch (type) {
|
||||
case "boolean":
|
||||
schemaFields[key] = makeQuerySchema(FieldType.BOOLEAN, key)
|
||||
fieldMetadata = makeQuerySchema(FieldType.BOOLEAN, key)
|
||||
break
|
||||
case "object":
|
||||
if (field instanceof Date) {
|
||||
fieldType = makeQuerySchema(FieldType.DATETIME, key)
|
||||
fieldMetadata = makeQuerySchema(FieldType.DATETIME, key)
|
||||
} else if (Array.isArray(field)) {
|
||||
fieldType = makeQuerySchema(FieldType.ARRAY, key)
|
||||
fieldMetadata = makeQuerySchema(FieldType.ARRAY, key)
|
||||
} else {
|
||||
fieldType = makeQuerySchema(FieldType.JSON, key)
|
||||
fieldMetadata = makeQuerySchema(FieldType.JSON, key)
|
||||
}
|
||||
break
|
||||
case "number":
|
||||
fieldType = makeQuerySchema(FieldType.NUMBER, key)
|
||||
fieldMetadata = makeQuerySchema(FieldType.NUMBER, key)
|
||||
break
|
||||
}
|
||||
schemaFields[key] = fieldType
|
||||
previewSchema[key] = fieldMetadata
|
||||
}
|
||||
}
|
||||
// if existing schema, update to include any previous schema keys
|
||||
if (existingSchema) {
|
||||
for (let key of Object.keys(schemaFields)) {
|
||||
for (let key of Object.keys(previewSchema)) {
|
||||
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)
|
||||
ctx.body = {
|
||||
rows,
|
||||
schemaFields,
|
||||
schema: previewSchema,
|
||||
info,
|
||||
extra,
|
||||
}
|
||||
|
|
|
@ -235,9 +235,9 @@ describe("/queries", () => {
|
|||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
// these responses come from the mock
|
||||
expect(res.body.schemaFields).toEqual({
|
||||
a: "string",
|
||||
b: "number",
|
||||
expect(res.body.schema).toEqual({
|
||||
a: { type: "string", name: "a" },
|
||||
b: { type: "number", name: "b" },
|
||||
})
|
||||
expect(res.body.rows.length).toEqual(1)
|
||||
expect(events.query.previewed).toBeCalledTimes(1)
|
||||
|
@ -300,10 +300,10 @@ describe("/queries", () => {
|
|||
queryString: "test={{ variable2 }}",
|
||||
})
|
||||
// these responses come from the mock
|
||||
expect(res.body.schemaFields).toEqual({
|
||||
opts: "json",
|
||||
url: "string",
|
||||
value: "string",
|
||||
expect(res.body.schema).toEqual({
|
||||
opts: { type: "json", name: "opts" },
|
||||
url: { type: "string", name: "url" },
|
||||
value: { type: "string", name: "value" },
|
||||
})
|
||||
expect(res.body.rows[0].url).toEqual("http://www.google.com?test=1")
|
||||
})
|
||||
|
@ -314,10 +314,10 @@ describe("/queries", () => {
|
|||
path: "www.google.com",
|
||||
queryString: "test={{ variable3 }}",
|
||||
})
|
||||
expect(res.body.schemaFields).toEqual({
|
||||
opts: "json",
|
||||
url: "string",
|
||||
value: "string",
|
||||
expect(res.body.schema).toEqual({
|
||||
opts: { type: "json", name: "opts" },
|
||||
url: { type: "string", name: "url" },
|
||||
value: { type: "string", name: "value" },
|
||||
})
|
||||
expect(res.body.rows[0].url).toContain("doctype%20html")
|
||||
})
|
||||
|
@ -337,10 +337,10 @@ describe("/queries", () => {
|
|||
path: "www.failonce.com",
|
||||
queryString: "test={{ variable3 }}",
|
||||
})
|
||||
expect(res.body.schemaFields).toEqual({
|
||||
fails: "number",
|
||||
opts: "json",
|
||||
url: "string",
|
||||
expect(res.body.schema).toEqual({
|
||||
fails: { type: "number", name: "fails" },
|
||||
opts: { type: "json", name: "opts" },
|
||||
url: { type: "string", name: "url" },
|
||||
})
|
||||
expect(res.body.rows[0].fails).toEqual(1)
|
||||
})
|
||||
|
|
|
@ -376,8 +376,8 @@ export function checkExternalTables(
|
|||
errors[name] = "Table must have a primary key."
|
||||
}
|
||||
|
||||
const schemaFields = Object.keys(table.schema)
|
||||
if (schemaFields.find(f => invalidColumns.includes(f))) {
|
||||
const columnNames = Object.keys(table.schema)
|
||||
if (columnNames.find(f => invalidColumns.includes(f))) {
|
||||
errors[name] = "Table contains invalid columns."
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue