Skip to content

Commit

Permalink
fix: fix keyword in schema @common (#25)
Browse files Browse the repository at this point in the history
* fix: fix keyword in schema @common

* mod: limit message number

* mod: code review
  • Loading branch information
hetao92 authored Oct 14, 2021
1 parent bf985ad commit 92a2e00
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
5 changes: 4 additions & 1 deletion app/assets/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { message } from 'antd';
import React from 'react';
import ReactDom from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';

import App from './App';
import { store } from './store';

message.config({
maxCount: 1,
});
ReactDom.render(
<Provider store={store}>
<Router>
Expand Down
2 changes: 1 addition & 1 deletion app/assets/utils/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash';
import { keyWords } from '#assets/config/nebulaQL';

export const handleKeyword = (name: string) => {
return keyWords.includes(name) ? '`' + name + '`' : name;
return keyWords.includes(name.toLowerCase()) ? `\`${name}\`` : name;
};

export const handleVidStringName = (name: string, spaceVidType?: string) => {
Expand Down
56 changes: 28 additions & 28 deletions app/assets/utils/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const getExploreMatchGQL = (params: {
const wheres = _filters ? `AND ALL(l IN e WHERE ${_filters})` : '';
const gql = `MATCH p=(v)${
edgeDirection === 'incoming' ? '<-' : '-'
}[e${edgeTypes.map(edge => `:${edge}`).join('|')}${_step}]${
}[e${edgeTypes.map(edge => `:${handleKeyword(edge)}`).join('|')}${_step}]${
edgeDirection === 'outgoing' ? '->' : '-'
}(v2)
WHERE id(v) IN [${selectVertexes
Expand Down Expand Up @@ -198,40 +198,40 @@ export const getAlterGQL = (params: {
const date = config.fields
.map(item => {
const { name, type, value, fixedLength, allowNull, comment } = item;
const propertyName = handleKeyword(name);
if (action === 'DROP') {
return name;
} else {
let str = `${name} ${
type !== 'fixed_string'
? type
: type + `(${fixedLength ? item.fixedLength : ''})`
} ${allowNull ? 'NULL' : 'NOT NULL'}`;
if (value) {
switch (type) {
case 'string':
case 'fixed_string':
str += ` DEFAULT "${value}"`;
break;
case 'timestamp':
const timestampReg = /^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/;
str += timestampReg.test(value)
? ` DEFAULT "${value}"`
: ` DEFAULT ${value}`;
break;
default:
str += ` DEFAULT ${value}`;
}
}
if (comment) {
str += ` COMMENT "${comment}"`;
return propertyName;
}
let str = `${propertyName} ${
type !== 'fixed_string'
? type
: type + `(${fixedLength ? item.fixedLength : ''})`
} ${allowNull ? 'NULL' : 'NOT NULL'}`;
if (value) {
switch (type) {
case 'string':
case 'fixed_string':
str += ` DEFAULT "${value}"`;
break;
case 'timestamp':
const timestampReg = /^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/;
str += timestampReg.test(value)
? ` DEFAULT "${value}"`
: ` DEFAULT ${value}`;
break;
default:
str += ` DEFAULT ${value}`;
}
return str;
}
if (comment) {
str += ` COMMENT "${comment}"`;
}
return str;
})
.join(', ');
content = `${action} (${date})`;
}
const gql = `ALTER ${type} ${name} ${content}`;
const gql = `ALTER ${type} ${handleKeyword(name)} ${content}`;
return gql;
};

Expand Down

0 comments on commit 92a2e00

Please sign in to comment.