Browse Source

feat: Add MID/SUBSTR function support

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/448/head
Pranav C 3 years ago
parent
commit
1b9f1bafcd
  1. 4
      packages/nc-gui/components/project/spreadsheet/components/editColumn/formulaOptions.vue
  2. 1
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/mssql.ts
  3. 3
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/mysql.ts
  4. 1
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/pg.ts
  5. 3
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/sqlite.ts

4
packages/nc-gui/components/project/spreadsheet/components/editColumn/formulaOptions.vue

@ -87,7 +87,9 @@ export default {
'SEARCH', 'SEARCH',
'INT', 'INT',
'RIGHT', 'RIGHT',
'LEFT' 'LEFT',
'SUBSTR',
'MID'
], ],
availableBinOps: ['+', '-', '*', '/'], availableBinOps: ['+', '-', '*', '/'],
autocomplete: false, autocomplete: false,

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

@ -49,6 +49,7 @@ const mssql = {
INT: (args: MapFnArgs) => { 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}`) 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}`)
}, },
MID:'SUBSTR'
} }
export default mssql; export default mssql;

3
packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/mysql.ts

@ -19,7 +19,8 @@ const mysql2 = {
}, },
RIGHT:(args: MapFnArgs)=> { RIGHT:(args: MapFnArgs)=> {
return args.knex.raw(`SUBSTR(${args.fn(args.pt.arguments[0])},-${args.fn(args.pt.arguments[1])})${args.colAlias}`) return args.knex.raw(`SUBSTR(${args.fn(args.pt.arguments[0])},-${args.fn(args.pt.arguments[1])})${args.colAlias}`)
} },
MID:'SUBSTR'
} }

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

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

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

@ -31,7 +31,8 @@ const sqlite3 = {
}, },
RIGHT:(args: MapFnArgs)=> { RIGHT:(args: MapFnArgs)=> {
return args.knex.raw(`SUBSTR(${args.fn(args.pt.arguments[0])},-${args.fn(args.pt.arguments[1])})${args.colAlias}`) return args.knex.raw(`SUBSTR(${args.fn(args.pt.arguments[0])},-${args.fn(args.pt.arguments[1])})${args.colAlias}`)
} },
MID:'SUBSTR'
} }

Loading…
Cancel
Save