Browse Source

Merge pull request #1156 from nocodb/fix/uuid

fix: cast search column in custom knex for uuid & fix search issue for bigint
pull/1164/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
8aad60dd08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js
  2. 4
      packages/nc-gui/helpers/sqlUi/MssqlUi.js
  3. 2
      packages/nc-gui/helpers/sqlUi/MysqlUi.js
  4. 2
      packages/nc-gui/helpers/sqlUi/SqliteUi.js
  5. 22
      packages/nocodb/src/lib/dataMapper/lib/sql/CustomKnex.ts
  6. 4
      packages/nocodb/src/lib/sqlUi/MssqlUi.ts
  7. 2
      packages/nocodb/src/lib/sqlUi/MysqlUi.ts
  8. 2
      packages/nocodb/src/lib/sqlUi/SqliteUi.ts

5
packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js

@ -163,7 +163,10 @@ export default {
concatenatedXWhere() {
let where = ''
if (this.searchField && this.searchQuery.trim()) {
if (['text', 'string'].includes(this.sqlUi.getAbstractType(this.availableColumns.find(({ _cn }) => _cn === this.searchField) || this.availableColumns[0]))) {
const col = this.availableColumns.find(({ _cn }) => _cn === this.searchField) || this.availableColumns[0]
// bigint values are displayed in string format in UI
// when searching bigint values, the operator should be 'eq' instead of 'like'
if (['text', 'string'].includes(this.sqlUi.getAbstractType(col)) && col.dt !== 'bigint') {
where = `(${this.searchField},like,%${this.searchQuery.trim()}%)`
} else {
where = `(${this.searchField},eq,${this.searchQuery.trim()})`

4
packages/nc-gui/helpers/sqlUi/MssqlUi.js

@ -921,16 +921,14 @@ export class MssqlUi {
static getAbstractType(col) {
switch ((col.dt || col.dt).toLowerCase()) {
case 'bigint':
case 'smallint':
case 'bit':
case 'tinyint':
case 'int':
return 'integer'
case 'bigint':
case 'binary':
return 'string'
case 'char':
return 'string'

2
packages/nc-gui/helpers/sqlUi/MysqlUi.js

@ -842,7 +842,6 @@ export class MysqlUi {
case 'int':
case 'smallint':
case 'mediumint':
case 'bigint':
case 'bit':
return 'integer'
@ -897,6 +896,7 @@ export class MysqlUi {
case 'set':
return 'set'
case 'bigint':
case 'geometry':
case 'point':
case 'linestring':

2
packages/nc-gui/helpers/sqlUi/SqliteUi.js

@ -683,7 +683,6 @@ export class SqliteUi {
case 'tinyint':
case 'smallint':
case 'mediumint':
case 'bigint':
case 'int2':
case 'int8':
return 'integer'
@ -702,6 +701,7 @@ export class SqliteUi {
case 'blob':
return 'blob'
case 'bigint':
case 'character':
case 'varchar':
return 'string'

22
packages/nocodb/src/lib/dataMapper/lib/sql/CustomKnex.ts

@ -92,9 +92,10 @@ const appendWhereCondition = function(
knexRef,
isHaving = false
) {
const clientType = knexRef?.client?.config?.client;
const opMapping = {
...opMappingGen,
...(knexRef?.client?.config?.client === 'pg' ? { like: 'ilike' } : {})
...(clientType === 'pg' ? { like: 'ilike' } : {})
};
const camKey = isHaving ? 'Having' : 'Where';
const key = isHaving ? 'having' : 'where';
@ -430,11 +431,19 @@ const appendWhereCondition = function(
);
break;
case '':
knexRef[`${key}`](
columnAliases[matches[2]] || matches[2],
opMapping[matches[3]],
matches[4]
);
const column = columnAliases[matches[2]] || matches[2];
const operator = opMapping[matches[3]];
const target = matches[4];
if (matches[3] == 'like' && clientType === 'pg') {
// handle uuid case
knexRef[`${key}`](
knexRef?.client.raw(`??::TEXT ${operator} '${target}'`, [
column
])
);
} else {
knexRef[`${key}`](column, operator, target);
}
break;
default:
throw new Error(`${matches[1] || ''} Invalid operation.`);
@ -991,6 +1000,7 @@ export { Knex };
*
* @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*

4
packages/nocodb/src/lib/sqlUi/MssqlUi.ts

@ -937,16 +937,14 @@ export class MssqlUi {
static getAbstractType(col): any {
switch ((col.dt || col.dt).toLowerCase()) {
case 'bigint':
case 'smallint':
case 'bit':
case 'tinyint':
case 'int':
return 'integer';
case 'bigint':
case 'binary':
return 'string';
case 'char':
return 'string';

2
packages/nocodb/src/lib/sqlUi/MysqlUi.ts

@ -868,7 +868,6 @@ export class MysqlUi {
case 'int':
case 'smallint':
case 'mediumint':
case 'bigint':
case 'bit':
return 'integer';
@ -922,6 +921,7 @@ export class MysqlUi {
case 'set':
return 'set';
case 'bigint':
case 'geometry':
case 'point':
case 'linestring':

2
packages/nocodb/src/lib/sqlUi/SqliteUi.ts

@ -694,7 +694,6 @@ export class SqliteUi {
case 'tinyint':
case 'smallint':
case 'mediumint':
case 'bigint':
case 'int2':
case 'int8':
return 'integer';
@ -713,6 +712,7 @@ export class SqliteUi {
case 'blob':
return 'blob';
case 'bigint':
case 'character':
case 'varchar':
return 'string';

Loading…
Cancel
Save