Browse Source

chore(nocodb): lint

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5392/head
Pranav C 2 years ago
parent
commit
2539aba5d9
  1. 54
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts
  2. 24
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts

54
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts

@ -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}`
),
};
},

24
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts

@ -37,7 +37,11 @@ const pg = {
FLOAT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex
.raw(`CAST(${(await fn(pt.arguments[0])).builder} as DOUBLE PRECISION)${colAlias}`)
.raw(
`CAST(${
(await fn(pt.arguments[0])).builder
} as DOUBLE PRECISION)${colAlias}`
)
.wrap('(', ')'),
};
},
@ -53,7 +57,9 @@ const pg = {
DATEADD: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`${(await fn(pt.arguments[0])).builder} + (${(await fn(pt.arguments[1])).builder} ||
`${(await fn(pt.arguments[0])).builder} + (${
(await fn(pt.arguments[1])).builder
} ||
'${String((await fn(pt.arguments[2])).builder).replace(
/["']/g,
''
@ -133,11 +139,13 @@ const pg = {
builder: args.knex.raw(
`CASE WHEN ${args.knex
.raw(
`${(await Promise.all(args.pt.arguments
.map(async (ar) =>
(await args.fn(ar, '', 'AND')).builder.toQuery()
)))
.join(' AND ')}`
`${(
await Promise.all(
args.pt.arguments.map(async (ar) =>
(await args.fn(ar, '', 'AND')).builder.toQuery()
)
)
).join(' AND ')}`
)
.wrap('(', ')')
.toQuery()} THEN TRUE ELSE FALSE END ${args.colAlias}`
@ -160,7 +168,7 @@ const pg = {
),
};
},
SUBSTR:async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
SUBSTR: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const str = (await fn(pt.arguments[0])).builder;
const positionFrom = (await fn(pt.arguments[1] ?? 1)).builder;
const numberOfCharacters = (await fn(pt.arguments[2] ?? '')).builder;

Loading…
Cancel
Save