Browse Source

feat: Add RIGHT and LEFT function support

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/448/head
Pranav C 3 years ago
parent
commit
991a084ce7
  1. 2
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/mssql.ts
  2. 2
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/pg.ts
  3. 8
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/sqlite.ts

2
packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/mssql.ts

@ -48,7 +48,7 @@ const mssql = {
},
INT: (args: MapFnArgs) => {
return args.knex.raw(`CASE WHEN ISNUMERIC(${args.fn(args.pt.arguments[0]).toQuery()}) = 1 THEN FLOOR(${args.fn(args.pt.arguments[0]).toQuery()}) ELSE 0 END${args.colAlias}`)
}
},
}
export default mssql;

2
packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/pg.ts

@ -14,7 +14,7 @@ const pg = {
INT(args: MapFnArgs) {
// todo: correction
return args.knex.raw(`REGEXP_REPLACE(COALESCE(${args.fn(args.pt.arguments[0])}::character varying, '0'), '[^0-9]+|\\.[0-9]+' ,'')${args.colAlias}`)
}
},
}

8
packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/sqlite.ts

@ -23,6 +23,14 @@ const sqlite3 = {
SEARCH:'INSTR',
INT(args: MapFnArgs) {
return args.knex.raw(`CAST(${args.fn(args.pt.arguments[0])} as INTEGER)${args.colAlias}`)
},
LEFT:(args: MapFnArgs)=> {
return args.knex.raw(`SUBSTR(${args.fn(args.pt.arguments[0])},1,${args.fn(args.pt.arguments[1])})${args.colAlias}`)
},
RIGHT:(args: MapFnArgs)=> {
return args.knex.raw(`SUBSTR(${args.fn(args.pt.arguments[0])},-${args.fn(args.pt.arguments[1])})${args.colAlias}`)
}
}

Loading…
Cancel
Save