|
|
|
@ -18,25 +18,27 @@ const mysql2 = {
|
|
|
|
|
INT: async (args: MapFnArgs) => { |
|
|
|
|
return { |
|
|
|
|
builder: args.knex.raw( |
|
|
|
|
`CAST(${(await args.fn(args.pt.arguments[0])).builder} as SIGNED)${args.colAlias}`, |
|
|
|
|
`CAST(${(await args.fn(args.pt.arguments[0])).builder} as SIGNED)${ |
|
|
|
|
args.colAlias |
|
|
|
|
}` |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
LEFT: async (args: MapFnArgs) => { |
|
|
|
|
return { |
|
|
|
|
builder: args.knex.raw( |
|
|
|
|
`SUBSTR(${(await args.fn(args.pt.arguments[0])).builder},1,${(await args.fn( |
|
|
|
|
args.pt.arguments[1], |
|
|
|
|
)).builder})${args.colAlias}`,
|
|
|
|
|
`SUBSTR(${(await args.fn(args.pt.arguments[0])).builder},1,${ |
|
|
|
|
(await args.fn(args.pt.arguments[1])).builder |
|
|
|
|
})${args.colAlias}` |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
RIGHT: async (args: MapFnArgs) => { |
|
|
|
|
return { |
|
|
|
|
builder: args.knex.raw( |
|
|
|
|
`SUBSTR(${(await args.fn(args.pt.arguments[0])).builder}, -(${(await args.fn( |
|
|
|
|
args.pt.arguments[1], |
|
|
|
|
)).builder}))${args.colAlias}`,
|
|
|
|
|
`SUBSTR(${(await args.fn(args.pt.arguments[0])).builder}, -(${ |
|
|
|
|
(await args.fn(args.pt.arguments[1])).builder |
|
|
|
|
}))${args.colAlias}` |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
@ -45,9 +47,9 @@ const mysql2 = {
|
|
|
|
|
return { |
|
|
|
|
builder: args.knex |
|
|
|
|
.raw( |
|
|
|
|
`CAST(CAST(${(await args.fn(args.pt.arguments[0])).builder} as CHAR) AS DOUBLE)${ |
|
|
|
|
args.colAlias |
|
|
|
|
}`,
|
|
|
|
|
`CAST(CAST(${ |
|
|
|
|
(await args.fn(args.pt.arguments[0])).builder |
|
|
|
|
} as CHAR) AS DOUBLE)${args.colAlias}` |
|
|
|
|
) |
|
|
|
|
.wrap('(', ')'), |
|
|
|
|
}; |
|
|
|
@ -58,17 +60,15 @@ const mysql2 = {
|
|
|
|
|
`CASE
|
|
|
|
|
WHEN ${(await fn(pt.arguments[0])).builder} LIKE '%:%' THEN |
|
|
|
|
DATE_FORMAT(DATE_ADD(${(await fn(pt.arguments[0])).builder}, INTERVAL |
|
|
|
|
${(await fn(pt.arguments[1])).builder} ${String((await fn(pt.arguments[2])).builder).replace( |
|
|
|
|
/["']/g, |
|
|
|
|
'', |
|
|
|
|
)}), '%Y-%m-%d %H:%i') |
|
|
|
|
${(await fn(pt.arguments[1])).builder} ${String( |
|
|
|
|
(await fn(pt.arguments[2])).builder |
|
|
|
|
).replace(/["']/g, '')}), '%Y-%m-%d %H:%i') |
|
|
|
|
ELSE |
|
|
|
|
DATE(DATE_ADD(${(await fn(pt.arguments[0])).builder}, INTERVAL |
|
|
|
|
${(await fn(pt.arguments[1])).builder} ${String((await fn(pt.arguments[2])).builder).replace( |
|
|
|
|
/["']/g, |
|
|
|
|
'', |
|
|
|
|
)})) |
|
|
|
|
END${colAlias}`,
|
|
|
|
|
${(await fn(pt.arguments[1])).builder} ${String( |
|
|
|
|
(await fn(pt.arguments[2])).builder |
|
|
|
|
).replace(/["']/g, '')})) |
|
|
|
|
END${colAlias}` |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
@ -77,7 +77,9 @@ const mysql2 = {
|
|
|
|
|
const datetime_expr2 = (await fn(pt.arguments[1])).builder; |
|
|
|
|
|
|
|
|
|
const unit = convertUnits( |
|
|
|
|
pt.arguments[2] ? (await fn(pt.arguments[2])).builder.bindings[0] : 'seconds', |
|
|
|
|
pt.arguments[2] |
|
|
|
|
? (await fn(pt.arguments[2])).builder.bindings[0] |
|
|
|
|
: 'seconds', |
|
|
|
|
'mysql' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
@ -86,13 +88,13 @@ const mysql2 = {
|
|
|
|
|
// hence change from MICROSECOND to millisecond manually
|
|
|
|
|
return { |
|
|
|
|
builder: knex.raw( |
|
|
|
|
`TIMESTAMPDIFF(${unit}, ${datetime_expr2}, ${datetime_expr1}) div 1000 ${colAlias}`, |
|
|
|
|
`TIMESTAMPDIFF(${unit}, ${datetime_expr2}, ${datetime_expr1}) div 1000 ${colAlias}` |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
builder: knex.raw( |
|
|
|
|
`TIMESTAMPDIFF(${unit}, ${datetime_expr2}, ${datetime_expr1}) ${colAlias}`, |
|
|
|
|
`TIMESTAMPDIFF(${unit}, ${datetime_expr2}, ${datetime_expr1}) ${colAlias}` |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
@ -102,11 +104,13 @@ const mysql2 = {
|
|
|
|
|
builder: knex.raw( |
|
|
|
|
`(WEEKDAY(${ |
|
|
|
|
pt.arguments[0].type === 'Literal' |
|
|
|
|
? `'${dayjs((await fn(pt.arguments[0])).builder).format('YYYY-MM-DD')}'` |
|
|
|
|
? `'${dayjs((await fn(pt.arguments[0])).builder).format( |
|
|
|
|
'YYYY-MM-DD' |
|
|
|
|
)}'` |
|
|
|
|
: (await fn(pt.arguments[0])).builder |
|
|
|
|
}) - ${getWeekdayByText( |
|
|
|
|
pt?.arguments[1]?.value, |
|
|
|
|
)} % 7 + 7) % 7 ${colAlias}`,
|
|
|
|
|
pt?.arguments[1]?.value |
|
|
|
|
)} % 7 + 7) % 7 ${colAlias}` |
|
|
|
|
), |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|