Browse Source

feat: WEEKDAY logic for sqlite

pull/2706/head
Wing-Kam Wong 2 years ago
parent
commit
3c7d3028e9
  1. 19
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/sqlite.ts

19
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/sqlite.ts

@ -75,6 +75,25 @@ const sqlite3 = {
END${colAlias}`
);
},
WEEKDAY: ({ fn, knex, pt, colAlias }: MapFnArgs) => {
// strftime('%w', date) - day of week 0 - 6 with Sunday == 0
// WEEKDAY() returns an index from 0 to 6 for Monday to Sunday
const m = {
monday: 0,
tuesday: 1,
wednesday: 2,
thursday: 3,
friday: 4,
saturday: 5,
sunday: 6,
};
return knex.raw(
`strftime('%w', ${fn(pt.arguments[0])}, 'weekday ${
m[pt?.arguments[1]?.value.toLowerCase()] || 0
}')${colAlias}`
);
},
};
export default sqlite3;

Loading…
Cancel
Save