Skip to content

Commit

Permalink
feat(MySQL): RLIKE and NOT RLIKE regular expression filters, closes #688
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Oct 18, 2023
1 parent 215ab78 commit e4eb27d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/common/customizations/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const defaults: Customizations = {
dataTypes: [],
indexTypes: [],
foreignActions: [],
operators: ['=', '!=', '>', '<', '>=', '<=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'IS NULL', 'IS NOT NULL'],
// Core
database: false,
collations: false,
Expand Down
1 change: 1 addition & 0 deletions src/common/customizations/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const customizations: Customizations = {
defaultUser: 'root',
defaultDatabase: null,
dataTypes: mysqlTypes,
operators: ['=', '!=', '>', '<', '>=', '<=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'RLIKE', 'NOT RLIKE', 'BETWEEN', 'IS NULL', 'IS NOT NULL'],
indexTypes: [
'PRIMARY',
'INDEX',
Expand Down
2 changes: 2 additions & 0 deletions src/common/interfaces/customizations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TypesGroup } from './antares';
import { TableFilterOperator } from './tableApis';

export interface Customizations {
// Defaults
Expand All @@ -8,6 +9,7 @@ export interface Customizations {
dataTypes?: TypesGroup[];
indexTypes?: string[];
foreignActions?: string[];
operators?: TableFilterOperator[];
// Core
database?: boolean;
collations?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/common/interfaces/tableApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface TableDeleteParams {
rows: {[key: string]: any};
}

export type TableFilterOperator = '=' | '!=' | '>' | '<' | '>=' | '<=' | 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'BETWEEN' | 'IS NULL' | 'IS NOT NULL'
export type TableFilterOperator = '=' | '!=' | '>' | '<' | '>=' | '<=' | 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'RLIKE' | 'NOT RLIKE' | 'BETWEEN' | 'IS NULL' | 'IS NOT NULL'

export interface TableFilterClausole {
active: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/WorkspaceTabTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<WorkspaceTabTableFilters
v-if="isSearch"
:fields="fields"
:is-quering="isQuering"
:conn-client="connection.client"
@filter="updateFilters"
@filter-change="onFilterChange"
Expand Down
14 changes: 9 additions & 5 deletions src/renderer/components/WorkspaceTabTableFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<input
v-model="row.active"
type="checkbox"
:disabled="isQuering"
@change="doFilter"
><i class="form-icon" />
</label>
Expand All @@ -18,24 +19,28 @@
:options="fields"
option-track-by="name"
option-label="name"
:disabled="isQuering"
/>
<BaseSelect
v-model="row.op"
class="form-select ml-2 col-auto select-sm"
:options="operators"
:disabled="isQuering"
/>
<div class="workspace-table-filters-row-value ml-2">
<input
v-if="!row.op.includes('NULL')"
v-model="row.value"
type="text"
class="form-input input-sm"
:disabled="isQuering"
>
<input
v-if="row.op === 'BETWEEN'"
v-model="row.value2"
type="text"
class="form-input ml-2 input-sm"
:disabled="isQuering"
>
</div>
<button
Expand Down Expand Up @@ -87,15 +92,14 @@ const { t } = useI18n();
const props = defineProps({
fields: Array as Prop<TableField[]>,
connClient: String as Prop<ClientCode>
connClient: String as Prop<ClientCode>,
isQuering: Boolean
});
const emit = defineEmits(['filter-change', 'filter']);
const rows = ref([]);
const operators = ref<TableFilterOperator[]>([
'=', '!=', '>', '<', '>=', '<=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'BETWEEN', 'IS NULL', 'IS NOT NULL'
]);
const operators: TableFilterOperator[] = customizations[props.connClient].operators;
const clientCustomizations = computed(() => customizations[props.connClient]);
Expand All @@ -122,7 +126,7 @@ const createClausole = (filter: TableFilterClausole) => {
const { elementsWrapper: ew, stringsWrapper: sw } = clientCustomizations.value;
let value;
if (isNumeric && !['IN', 'NOT IN'].includes(filter.op)) {
if (isNumeric && !['IN', 'NOT IN', 'RLIKE', 'NOT RLIKE'].includes(filter.op)) {
if (isNaN(Number(filter.value)))
filter.value = '';
if (isNaN(Number(filter.value2)))
Expand Down

0 comments on commit e4eb27d

Please sign in to comment.