Fix time and mssql tests
This commit is contained in:
parent
57e73488b5
commit
318dd5e628
|
@ -122,11 +122,8 @@ function generateSelectStatement(
|
|||
const fieldNames = field.split(/\./g)
|
||||
const tableName = fieldNames[0]
|
||||
const columnName = fieldNames[1]
|
||||
if (
|
||||
columnName &&
|
||||
schema?.[columnName] &&
|
||||
knex.client.config.client === SqlClient.POSTGRES
|
||||
) {
|
||||
const columnSchema = schema?.[columnName]
|
||||
if (columnSchema && knex.client.config.client === SqlClient.POSTGRES) {
|
||||
const externalType = schema[columnName].externalType
|
||||
if (externalType?.includes("money")) {
|
||||
return knex.raw(
|
||||
|
@ -134,6 +131,13 @@ function generateSelectStatement(
|
|||
)
|
||||
}
|
||||
}
|
||||
if (
|
||||
knex.client.config.client === SqlClient.MS_SQL &&
|
||||
columnSchema.type === FieldType.DATETIME &&
|
||||
columnSchema.timeOnly
|
||||
) {
|
||||
return knex.raw(`CONVERT(varchar, ${field}, 108) as "${field}"`)
|
||||
}
|
||||
return `${field} as ${field}`
|
||||
})
|
||||
}
|
||||
|
@ -634,13 +638,23 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
|
|||
*/
|
||||
_query(json: QueryJson, opts: QueryOptions = {}): SqlQuery | SqlQuery[] {
|
||||
const sqlClient = this.getSqlClient()
|
||||
const config: { client: string; useNullAsDefault?: boolean } = {
|
||||
const config: Knex.Config = {
|
||||
client: sqlClient,
|
||||
}
|
||||
if (sqlClient === SqlClient.SQL_LITE) {
|
||||
config.useNullAsDefault = true
|
||||
}
|
||||
|
||||
if (sqlClient === SqlClient.MS_SQL) {
|
||||
// config.connection ??= {}
|
||||
// config.connection.typeCast = (field: any, next: any): any => {
|
||||
// if (field.type === "TIME") return field.string()
|
||||
// return next()
|
||||
// }
|
||||
}
|
||||
|
||||
const client = knex(config)
|
||||
|
||||
let query: Knex.QueryBuilder
|
||||
const builder = new InternalBuilder(sqlClient)
|
||||
switch (this._operation(json)) {
|
||||
|
|
|
@ -129,11 +129,12 @@ export function parse(rows: Rows, schema: TableSchema): Rows {
|
|||
return
|
||||
}
|
||||
|
||||
const { type: columnType } = schema[columnName]
|
||||
const columnSchema = schema[columnName]
|
||||
const { type: columnType } = columnSchema
|
||||
if (columnType === FieldType.NUMBER) {
|
||||
// If provided must be a valid number
|
||||
parsedRow[columnName] = columnData ? Number(columnData) : columnData
|
||||
} else if (columnType === FieldType.DATETIME) {
|
||||
} else if (columnType === FieldType.DATETIME && !columnSchema.timeOnly) {
|
||||
// If provided must be a valid date
|
||||
parsedRow[columnName] = columnData
|
||||
? new Date(columnData).toISOString()
|
||||
|
|
Loading…
Reference in New Issue