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