Fix for #5553 - when importing for SQL databases attempt to manage date and time only column times, handle these when displaying in tables and when filtering.

This commit is contained in:
mike12345567 2022-05-03 14:11:06 +01:00
parent be4b930c8a
commit 107c9e2dfc
11 changed files with 75 additions and 38 deletions

View File

@ -2,17 +2,22 @@
import dayjs from "dayjs"
export let value
export let schema
// adding the 0- will turn a string like 00:00:00 into a valid ISO
// date, but will make actual ISO dates invalid
$: time = new Date(`0-${value}`)
$: isTime = !isNaN(time)
$: isTimeOnly = !isNaN(time) || schema?.timeOnly
$: isDateOnly = schema?.dateOnly
$: format = isTimeOnly
? "HH:mm:ss"
: isDateOnly
? "MMMM D YYYY"
: "MMMM D YYYY, HH:mm"
</script>
<div>
{dayjs(isTime ? time : value).format(
isTime ? "HH:mm:ss" : "MMMM D YYYY, HH:mm"
)}
{dayjs(isTimeOnly ? time : value).format(format)}
</div>
<style>

View File

@ -37,7 +37,7 @@
$: label = meta.name ? capitalise(meta.name) : ""
const timeStamp = resolveTimeStamp(value)
const isTimeStamp = !!timeStamp
const isTimeStamp = !!timeStamp || meta?.timeOnly
</script>
{#if type === "options" && meta.constraints.inclusion.length !== 0}
@ -49,7 +49,12 @@
sort
/>
{:else if type === "datetime"}
<DatePicker {label} timeOnly={isTimeStamp} bind:value />
<DatePicker
{label}
timeOnly={isTimeStamp}
enableTime={!meta?.dateOnly}
bind:value
/>
{:else if type === "attachment"}
<Dropzone {label} bind:value />
{:else if type === "boolean"}

View File

@ -49,6 +49,10 @@
filters = [...filters, duplicate]
}
const getSchema = filter => {
return schemaFields.find(field => field.name === filter.field)
}
const onFieldChange = (expression, field) => {
// Update the field type
expression.type = enrichedSchemaFields.find(x => x.name === field)?.type
@ -150,7 +154,12 @@
bind:value={filter.value}
/>
{:else if filter.type === "datetime"}
<DatePicker disabled={filter.noValue} bind:value={filter.value} />
<DatePicker
disabled={filter.noValue}
enableTime={!getSchema(filter).dateOnly}
timeOnly={getSchema(filter).timeOnly}
bind:value={filter.value}
/>
{:else}
<DrawerBindableInput disabled />
{/if}

View File

@ -88,6 +88,10 @@
const schema = schemaFields.find(x => x.name === field)
return schema?.constraints?.inclusion || []
}
const getSchema = filter => {
return schemaFields.find(field => field.name === filter.field)
}
</script>
<div class="container" class:mobile={$context.device.mobile}>
@ -134,7 +138,12 @@
bind:value={filter.value}
/>
{:else if filter.type === "datetime"}
<DatePicker disabled={filter.noValue} bind:value={filter.value} />
<DatePicker
disabled={filter.noValue}
enableTime={!getSchema(filter).dateOnly}
timeOnly={getSchema(filter).timeOnly}
bind:value={filter.value}
/>
{:else}
<Input disabled />
{/if}

View File

@ -242,12 +242,10 @@ module MSSQLModule {
if (typeof name !== "string") {
continue
}
const type: string = convertSqlType(def.DATA_TYPE)
schema[name] = {
autocolumn: !!autoColumns.find((col: string) => col === name),
name: name,
type,
...convertSqlType(def.DATA_TYPE),
}
}
tables[tableName] = {

View File

@ -15,6 +15,7 @@ import {
} from "./utils"
import { DatasourcePlus } from "./base/datasourcePlus"
import dayjs from "dayjs"
import { FieldTypes } from "../constants"
const { NUMBER_REGEX } = require("../utilities")
module MySQLModule {
@ -215,8 +216,8 @@ module MySQLModule {
schema[columnName] = {
name: columnName,
autocolumn: isAuto,
type: convertSqlType(column.Type),
constraints,
...convertSqlType(column.Type),
}
}
if (!tables[tableName]) {

View File

@ -279,9 +279,9 @@ module OracleModule {
)
}
private internalConvertType(column: OracleColumn): string {
private internalConvertType(column: OracleColumn): { type: string } {
if (this.isBooleanType(column)) {
return FieldTypes.BOOLEAN
return { type: FieldTypes.BOOLEAN }
}
return convertSqlType(column.type)
@ -328,7 +328,7 @@ module OracleModule {
fieldSchema = {
autocolumn: OracleIntegration.isAutoColumn(oracleColumn),
name: columnName,
type: this.internalConvertType(oracleColumn),
...this.internalConvertType(oracleColumn),
}
table.schema[columnName] = fieldSchema
}

View File

@ -227,7 +227,6 @@ module PostgresModule {
}
}
const type: string = convertSqlType(column.data_type)
const identity = !!(
column.identity_generation ||
column.identity_start ||
@ -242,7 +241,7 @@ module PostgresModule {
tables[tableName].schema[columnName] = {
autocolumn: isAuto,
name: columnName,
type,
...convertSqlType(column.data_type),
}
}

View File

@ -35,6 +35,9 @@ const SQL_DATE_TYPE_MAP = {
date: FieldTypes.DATETIME,
}
const SQL_DATE_ONLY_TYPES = ["date"]
const SQL_TIME_ONLY_TYPES = ["time"]
const SQL_STRING_TYPE_MAP = {
varchar: FieldTypes.STRING,
char: FieldTypes.STRING,
@ -137,12 +140,20 @@ export function breakRowIdField(_id: string | { _id: string }): any[] {
}
export function convertSqlType(type: string) {
let foundType = FieldTypes.STRING
const lcType = type.toLowerCase()
for (let [external, internal] of Object.entries(SQL_TYPE_MAP)) {
if (type.toLowerCase().includes(external)) {
return internal
if (lcType.includes(external)) {
foundType = internal
break
}
}
return FieldTypes.STRING
const schema: any = { type: foundType }
if (foundType === FieldTypes.DATETIME) {
schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lcType)
schema.timeOnly = SQL_TIME_ONLY_TYPES.includes(lcType)
}
return schema
}
export function getSqlQuery(query: SqlQuery | string): SqlQuery {

View File

@ -1014,10 +1014,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@1.0.127":
version "1.0.127"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.127.tgz#5d1f4b18b31436ddb770dc1ddf16f201ec95dda7"
integrity sha512-3INFkAIxL0Q8Sa65ELRGQqPs+4baykKyb1z/XuO1MyuDPnbFKXGOjl1V61EMy622gsmLk90IJL6aQfh3Grwhvw==
"@budibase/backend-core@1.0.131":
version "1.0.131"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.131.tgz#4b284405e19a345de1af723d0c1e3fa315463140"
integrity sha512-1r6JjIcSBHogGm2YLB7k712+3LLE1+42C3eITa6n8r/QQIkyK7DJwm0I403IRKeh/93gwgQtBiRpJfhy2p7Pew==
dependencies:
"@techpass/passport-openidconnect" "^0.3.0"
aws-sdk "^2.901.0"
@ -1091,12 +1091,12 @@
svelte-flatpickr "^3.2.3"
svelte-portal "^1.0.0"
"@budibase/pro@1.0.127":
version "1.0.127"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.127.tgz#a8bcffb8ccc6afde64370b3a3dc22e2d0dd04f46"
integrity sha512-dj0SFTmO8JuMQ97/Ik6jVPQsh9AW7U5Wkgpa4yeNfwWw3DvSoktCxpeZ9mND6BR/DWTaeZljFKsQ6uk6nimzdQ==
"@budibase/pro@1.0.131":
version "1.0.131"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.131.tgz#65907e7ca528d237bf12dbe5c159156d03e8d5c3"
integrity sha512-pmK18/1TPDY+3IHUzGh0fG5CEy7+kSPpcl72smri8jvo5OsD4lWQVOTHSdqRn8aIf/qEHHWc2sspEEDGhYMv0Q==
dependencies:
"@budibase/backend-core" "1.0.127"
"@budibase/backend-core" "1.0.131"
node-fetch "^2.6.1"
"@budibase/standard-components@^0.9.139":

View File

@ -293,10 +293,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@1.0.127":
version "1.0.127"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.127.tgz#5d1f4b18b31436ddb770dc1ddf16f201ec95dda7"
integrity sha512-3INFkAIxL0Q8Sa65ELRGQqPs+4baykKyb1z/XuO1MyuDPnbFKXGOjl1V61EMy622gsmLk90IJL6aQfh3Grwhvw==
"@budibase/backend-core@1.0.131":
version "1.0.131"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.131.tgz#4b284405e19a345de1af723d0c1e3fa315463140"
integrity sha512-1r6JjIcSBHogGm2YLB7k712+3LLE1+42C3eITa6n8r/QQIkyK7DJwm0I403IRKeh/93gwgQtBiRpJfhy2p7Pew==
dependencies:
"@techpass/passport-openidconnect" "^0.3.0"
aws-sdk "^2.901.0"
@ -321,12 +321,12 @@
uuid "^8.3.2"
zlib "^1.0.5"
"@budibase/pro@1.0.127":
version "1.0.127"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.127.tgz#a8bcffb8ccc6afde64370b3a3dc22e2d0dd04f46"
integrity sha512-dj0SFTmO8JuMQ97/Ik6jVPQsh9AW7U5Wkgpa4yeNfwWw3DvSoktCxpeZ9mND6BR/DWTaeZljFKsQ6uk6nimzdQ==
"@budibase/pro@1.0.131":
version "1.0.131"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.131.tgz#65907e7ca528d237bf12dbe5c159156d03e8d5c3"
integrity sha512-pmK18/1TPDY+3IHUzGh0fG5CEy7+kSPpcl72smri8jvo5OsD4lWQVOTHSdqRn8aIf/qEHHWc2sspEEDGhYMv0Q==
dependencies:
"@budibase/backend-core" "1.0.127"
"@budibase/backend-core" "1.0.131"
node-fetch "^2.6.1"
"@cspotcode/source-map-consumer@0.8.0":