Browse Source

feat: Formula filter out unsupported functions

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/448/head
Pranav C 3 years ago
parent
commit
38586b2579
  1. 2
      README.md
  2. 2
      packages/nc-gui/components/project/functionTab/functionQuery.vue
  3. 4
      packages/nc-gui/components/project/spreadsheet/components/editColumn.vue
  4. 22
      packages/nc-gui/components/project/spreadsheet/components/editColumn/formulaOptions.vue
  5. 4
      packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue
  6. 3
      packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue
  7. 2
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  8. 1
      packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue
  9. 2
      packages/nc-gui/components/project/spreadsheet/xcTable.vue
  10. 2
      packages/nc-gui/components/project/sqlClient.vue
  11. 2
      packages/nc-gui/components/project/tableTabs/columns.vue
  12. 2
      packages/nc-gui/components/project/viewTabs/viewSpreadsheet.vue
  13. 4
      packages/nc-gui/helpers/sqlUi/MssqlUi.js
  14. 4
      packages/nc-gui/helpers/sqlUi/MysqlUi.js
  15. 4
      packages/nc-gui/helpers/sqlUi/OracleUi.js
  16. 4
      packages/nc-gui/helpers/sqlUi/PgUi.js
  17. 0
      packages/nc-gui/helpers/sqlUi/SqlUiFactory.js
  18. 6
      packages/nc-gui/helpers/sqlUi/SqliteUi.js
  19. 6
      packages/nc-gui/helpers/sqlUi/index.js
  20. 4
      packages/nc-gui/layouts/empty.vue
  21. 2
      packages/nc-gui/pages/index.vue
  22. 2
      packages/nocodb/package-lock.json
  23. 8
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

2
README.md

@ -13,7 +13,7 @@ Turns any MySQL, PostgreSQL, SQL Server, SQLite & MariaDB into a smart-spreadshe
[![Build Status](https://travis-ci.org/dwyl/esta.svg?branch=master)](https://travis-ci.com/github/NocoDB/NocoDB)
[![Node version](https://badgen.net/npm/node/next)](http://nodejs.org/download/)
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/NocoDB.svg?style=social&label=Follow%20%40NocoDB)](https://twitter.com/NocoDB)
<img src="https://static.scarf.sh/a.png?x-pxid=c12a77cc-855e-4602-8a0f-614b2d0da56a" />
</div>
<p align="center">

2
packages/nc-gui/components/project/functionTab/functionQuery.vue

@ -75,7 +75,7 @@ import { mapGetters, mapActions } from 'vuex'
import MonacoEditor from '../../monaco/Monaco'
import dlgLabelSubmitCancel from '../../utils/dlgLabelSubmitCancel'
import { SqlUI } from '../../../helpers/SqlUiFactory'
import { SqlUI } from '../../../helpers/sqlUi/SqlUiFactory'
export default {
components: { MonacoEditor, dlgLabelSubmitCancel },

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

@ -338,6 +338,7 @@
:is-s-q-lite="isSQLite"
:alias="newColumn.cn"
:is-m-s-s-q-l="isMSSQL"
:sql-ui="sqlUi"
v-on="$listeners"
/>
@ -389,8 +390,7 @@ import CustomSelectOptions from '@/components/project/spreadsheet/components/edi
import RelationOptions from '@/components/project/spreadsheet/components/editColumn/relationOptions'
import DlgLabelSubmitCancel from '@/components/utils/dlgLabelSubmitCancel'
import LinkedToAnotherOptions from '@/components/project/spreadsheet/components/editColumn/linkedToAnotherOptions'
import { SqliteUi } from '@/helpers/SqliteUi'
import { MssqlUi } from '@/helpers/MssqlUi'
import { SqliteUi, MssqlUi } from '@/helpers/sqlUi'
export default {
name: 'EditColumn',

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

@ -7,7 +7,7 @@
nudge-bottom="-25px"
allow-overflow
>
<template #activator>
<template #activator="_args">
<!-- todo: autocomplete based on available functions and metadata -->
<!-- <v-tooltip color="info" right>-->
<!-- <template #activator="{on}">-->
@ -61,13 +61,13 @@
<script>
import NcAutocompleteTree from '@/helpers/NcAutocompleteTree'
import {getWordUntilCaret, insertAtCursor} from '@/helpers'
import { getWordUntilCaret, insertAtCursor } from '@/helpers'
import debounce from 'debounce'
import jsep from 'jsep'
export default {
name: 'FormulaOptions',
props: ['nodes', 'column', 'meta', 'isSQLite', 'alias', 'value'],
props: ['nodes', 'column', 'meta', 'isSQLite', 'alias', 'value', 'sqlUi'],
data: () => ({
formula: {},
// formulas: ['AVERAGE()', 'COUNT()', 'COUNTA()', 'COUNTALL()', 'SUM()', 'MIN()', 'MAX()', 'AND()', 'OR()', 'TRUE()', 'FALSE()', 'NOT()', 'XOR()', 'ISERROR()', 'IF()', 'LEN()', 'MID()', 'LEFT()', 'RIGHT()', 'FIND()', 'CONCATENATE()', 'T()', 'VALUE()', 'ARRAYJOIN()', 'ARRAYUNIQUE()', 'ARRAYCOMPACT()', 'ARRAYFLATTEN()', 'ROUND()', 'ROUNDUP()', 'ROUNDDOWN()', 'INT()', 'EVEN()', 'ODD()', 'MOD()', 'LOG()', 'EXP()', 'POWER()', 'SQRT()', 'CEILING()', 'FLOOR()', 'ABS()', 'RECORD_ID()', 'CREATED_TIME()', 'ERROR()', 'BLANK()', 'YEAR()', 'MONTH()', 'DAY()', 'HOUR()', 'MINUTE()', 'SECOND()', 'TODAY()', 'NOW()', 'WORKDAY()', 'DATETIME_PARSE()', 'DATETIME_FORMAT()', 'SET_LOCALE()', 'SET_TIMEZONE()', 'DATESTR()', 'TIMESTR()', 'TONOW()', 'FROMNOW()', 'DATEADD()', 'WEEKDAY()', 'WEEKNUM()', 'DATETIME_DIFF()', 'WORKDAY_DIFF()', 'IS_BEFORE()', 'IS_SAME()', 'IS_AFTER()', 'REPLACE()', 'REPT()', 'LOWER()', 'UPPER()', 'TRIM()', 'SUBSTITUTE()', 'SEARCH()', 'SWITCH()', 'LAST_MODIFIED_TIME()', 'ENCODE_URL_COMPONENT()', 'REGEX_EXTRACT()', 'REGEX_MATCH()', 'REGEX_REPLACE()']
@ -100,10 +100,15 @@ export default {
}),
computed: {
suggestionsList() {
console.log(this)
const unsupportedFnList = this.sqlUi.getUnsupportedFnList()
return [
...this.availableFunctions.map(fn => ({text: fn, type: 'function'})),
...this.meta.columns.map(c => ({text: c._cn, type: 'column', c})),
...this.availableBinOps.map(op => ({text: op, type: 'op'}))
...this.availableFunctions.filter(fn => !unsupportedFnList.includes(fn)).map(fn => ({
text: fn,
type: 'function'
})),
...this.meta.columns.map(c => ({ text: c._cn, type: 'column', c })),
...this.availableBinOps.map(op => ({ text: op, type: 'op' }))
]
},
acTree() {
@ -115,7 +120,7 @@ export default {
}
},
created() {
this.formula = this.value ? {...this.value} : {}
this.formula = this.value ? { ...this.value } : {}
},
methods: {
async save() {
@ -185,6 +190,7 @@ export default {
if (err.length) {
return err.join(', ')
}
return true
} catch (e) {
return e.message
}
@ -217,7 +223,7 @@ export default {
this.$set(this.formula, 'value', insertAtCursor(this.$refs.input.$el.querySelector('input'), text, len))
}
},
_handleInputDeb: debounce(async function (self) {
_handleInputDeb: debounce(async function(self) {
await self.handleInput()
}, 250),
handleInputDeb() {

4
packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue

@ -44,6 +44,7 @@
:nodes="nodes"
:meta="meta"
:alias="newColumn._cn"
:sql-ui="sqlUi"
/>
</v-col>
</v-row>
@ -62,7 +63,8 @@ export default {
nodes: Object,
meta: Object,
value: Boolean,
column: Object
column: Object,
sqlUi: [Function, Object]
},
data: () => ({
valid: false,

3
packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue

@ -104,6 +104,7 @@
:edit-column="true"
:column="column"
:meta="meta"
:sql-ui="sqlUi"
v-on="$listeners"
/>
</v-menu>
@ -115,7 +116,7 @@ import EditVirtualColumn from '@/components/project/spreadsheet/components/editV
export default {
name: 'VirtualHeaderCell',
components: { EditVirtualColumn },
props: ['column', 'nodes', 'meta', 'isForm'],
props: ['column', 'nodes', 'meta', 'isForm', 'sqlUi'],
data: () => ({
columnDeleteDialog: false,
editColumnMenu: false

2
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

@ -461,7 +461,6 @@
<script>
import DebugMetas from '@/components/project/spreadsheet/components/debugMetas'
import { SqlUI } from '@/helpers/SqlUiFactory'
import { mapActions } from 'vuex'
import AdditionalFeatures from '@/components/project/spreadsheet/overlay/additinalFeatures'
@ -477,6 +476,7 @@ import spreadsheet from '@/components/project/spreadsheet/mixins/spreadsheet'
import LockMenu from '@/components/project/spreadsheet/components/lockMenu'
import ExpandedForm from '@/components/project/spreadsheet/components/expandedForm'
import Pagination from '@/components/project/spreadsheet/components/pagination'
import { SqlUI } from '~/helpers/sqlUi'
import ColumnFilter from '~/components/project/spreadsheet/components/columnFilterMenu'
export default {

1
packages/nc-gui/components/project/spreadsheet/views/xcGridView.vue

@ -34,6 +34,7 @@
:column="col"
:nodes="nodes"
:meta="meta"
:sql-ui="sqlUi"
@saved="onNewColCreation"
/>

2
packages/nc-gui/components/project/spreadsheet/xcTable.vue

@ -172,7 +172,7 @@
import ApiFactory from '@/components/project/spreadsheet/apis/apiFactory'
// import EditableCell from "@/components/project/spreadsheet/editableCell";
import { SqlUI } from '@/helpers/SqlUiFactory'
import { SqlUI } from '@/helpers/sqlUi'
import FieldsMenu from '@/components/project/spreadsheet/components/fieldsMenu'
import SortListMenu from '@/components/project/spreadsheet/components/sortListMenu'
import ColumnFilterMenu from '@/components/project/spreadsheet/components/columnFilterMenu'

2
packages/nc-gui/components/project/sqlClient.vue

@ -325,7 +325,7 @@ import { VueTreeList, Tree, TreeNode } from 'vue-tree-list'
import { Splitpanes, Pane } from 'splitpanes'
import sqlRightClickOptions from '../../helpers/sqlRightClickOptions'
import dlgLabelSubmitCancel from '../utils/dlgLabelSubmitCancel.vue'
import { SqlUI } from '../../helpers/SqlUiFactory'
import { SqlUI } from '../../helpers/sqlUi/SqlUiFactory'
import Utils from '../../helpers/Utils'

2
packages/nc-gui/components/project/tableTabs/columns.vue

@ -713,7 +713,7 @@ import uiTypes from '@/components/project/spreadsheet/helpers/uiTypes'
import addRelationDlg from '../dlgs/dlgAddRelation.vue'
import dlgLabelSubmitCancel from '../../utils/dlgLabelSubmitCancel.vue'
import { SqlUI } from '../../../helpers/SqlUiFactory'
import { SqlUI } from '../../../helpers/sqlUi/SqlUiFactory'
import jsonToColumn from './columnActions/jsonToColumn'
// const {path} = require("electron").remote.require(

2
packages/nc-gui/components/project/viewTabs/viewSpreadsheet.vue

@ -222,7 +222,7 @@
import ApiFactory from '@/components/project/spreadsheet/apis/apiFactory'
// import Table from '@/components/project/table'
// import EditableCell from "@/components/project/spreadsheet/editableCell";
import { SqlUI } from '@/helpers/SqlUiFactory'
import { SqlUI } from '@/helpers/sqlUi/SqlUiFactory'
import FieldsMenu from '@/components/project/spreadsheet/components/fieldsMenu'
import SortListMenu from '@/components/project/spreadsheet/components/sortListMenu'
import ColumnFilterMenu from '@/components/project/spreadsheet/components/columnFilterMenu'

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

@ -1321,6 +1321,10 @@ export class MssqlUi {
return dbTypes
}
}
static getUnsupportedFnList() {
return []
}
}
// module.exports = PgUiHelp;

4
packages/nc-gui/helpers/MysqlUi.js → packages/nc-gui/helpers/sqlUi/MysqlUi.js

@ -1245,6 +1245,10 @@ export class MysqlUi {
return dbTypes
}
}
static getUnsupportedFnList() {
return []
}
}
// module.exports = MysqlUiHelp;

4
packages/nc-gui/helpers/OracleUi.js → packages/nc-gui/helpers/sqlUi/OracleUi.js

@ -889,6 +889,10 @@ export class OracleUi {
}
return colProp
}
static getUnsupportedFnList() {
return []
}
}
// module.exports = PgUiHelp;

4
packages/nc-gui/helpers/PgUi.js → packages/nc-gui/helpers/sqlUi/PgUi.js

@ -1928,6 +1928,10 @@ export class PgUi {
return dbTypes
}
}
static getUnsupportedFnList() {
return []
}
}
// module.exports = PgUiHelp;

0
packages/nc-gui/helpers/SqlUiFactory.js → packages/nc-gui/helpers/sqlUi/SqlUiFactory.js

6
packages/nc-gui/helpers/SqliteUi.js → packages/nc-gui/helpers/sqlUi/SqliteUi.js

@ -1087,6 +1087,12 @@ export class SqliteUi {
return dbTypes
}
}
static getUnsupportedFnList() {
return [
'LOG', 'EXP', 'POWER', 'SQRT'
]
}
}
// module.exports = PgUiHelp;

6
packages/nc-gui/helpers/sqlUi/index.js

@ -0,0 +1,6 @@
export * from './MysqlUi'
export * from './PgUi'
export * from './MssqlUi'
export * from './OracleUi'
export * from './SqliteUi'
export * from './SqlUiFactory'

4
packages/nc-gui/layouts/empty.vue

@ -1,12 +1,12 @@
<template>
<v-app>
<snackbar />
<v-content>
<v-main>
<v-app-bar v-show="false" dark />
<v-container fluid style="">
<nuxt />
</v-container>
</v-content>
</v-main>
</v-app>
</template>

2
packages/nc-gui/pages/index.vue

@ -93,7 +93,7 @@
<div v-else>
<p class="display-4 text-center font-weight-bold textColor--text text--lighten-1 welcome-msg">
<vue-typer
repeat="0"
:repeat="0"
text="Every once in a while,
a revolutionary tech comes
along that changes everything."

2
packages/nocodb/package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "nocodb",
"version": "0.11.15",
"version": "0.11.16",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

8
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

@ -123,7 +123,7 @@ class BaseModelSql extends BaseModel {
return this.dbDriver(this.tnPath);
}
public get tnPath(){
public get tnPath() {
const schema = (this.dbDriver as any).searchPath?.();
const table = this.isMssql() && schema ? this.dbDriver.raw('??.??', [schema, this.tn]) : this.tn;
return table;
@ -328,8 +328,10 @@ class BaseModelSql extends BaseModel {
const driver = trx ? trx : this.dbDriver
// this.validate(data);
const response = await this._run(driver(this.tnPath).update(mappedData).where(this._wherePk(id)));
await this.afterUpdate(data, trx, cookie);
await this._run(driver(this.tnPath).update(mappedData).where(this._wherePk(id)));
const response = await this.nestedRead(id, this.defaultNestedQueryParams)
await this.afterUpdate(response, trx, cookie);
return response;
} catch (e) {
console.log(e);

Loading…
Cancel
Save