Skip to content

Commit

Permalink
feat: add ddl export
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 committed Nov 3, 2022
1 parent f516644 commit d301ab7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 69 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# NebulaGraph Studio

<div align=center>
<img src="./app/static/images/logo_studio.svg" />
</div>

NebulaGraph Studio (Studio for short) is a web-based visualization tool for NebulaGraph. With Studio, you can create a graph schema, import data and edit nGQL statements for data queries.
![](./introduction.png)

Expand Down
3 changes: 2 additions & 1 deletion app/config/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@
"getSchemaTip": "Because there is no strong binding relationship between tags and edges in the current NebulaGraph version, the results will be generated based on randomly obtained data, for reference only.",
"danglingEdge": "Dangling edge",
"showDDL": "View Schema DDL",
"downloadNGQL": "Download.nGQL"
"downloadNGQL": "Download.nGQL",
"getDDLError": "Failed to get the schema DDL, Please try again"
},
"empty": {
"stats": "No Statistics Data",
Expand Down
3 changes: 2 additions & 1 deletion app/config/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@
"getSchemaTip": "因为当前 NebulaGraph 版本下不存在点边的强绑定关系,结果将依据随机捞取到的数据生成,仅供参考。",
"danglingEdge": "悬挂边",
"showDDL": "查看 Schema DDL",
"downloadNGQL": "下载 .NGQL 文件"
"downloadNGQL": "下载 .NGQL 文件",
"getDDLError": "获取 Schema DDL 失败, 请重试"
},
"empty": {
"stats": "暂无统计数据",
Expand Down
13 changes: 6 additions & 7 deletions app/pages/Schema/SchemaConfig/DDLButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ import styles from './index.module.less';
interface IProps {
space: string;
}

const options = {
keyMap: 'sublime',
fullScreen: true,
mode: 'nebula',
readOnly: true,
};
const sleepGql = `:sleep 20;`;
const DDLButton = (props: IProps) => {
const { space } = props;
const [visible, setVisible] = useState(false);
const [loading, setLoading] = useState(false);
const { schema: { getSchemaDDL } } = useStore();
const [ddl, setDDL] = useState('');
const options = {
keyMap: 'sublime',
fullScreen: true,
mode: 'nebula',
readOnly: true,
};
const handleOpen = useCallback(async () => {
setVisible(true);
setLoading(true);
Expand Down
117 changes: 57 additions & 60 deletions app/stores/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { getRootStore } from '@app/stores';
import { IAlterForm, IEdge, IIndexList, ISchemaType, ISpace, ITag, ITree, IndexType, ISchemaEnum } from '@app/interfaces/schema';
import { handleKeyword, handleVidStringName, safeParse } from '@app/utils/function';
import { findIndex } from 'lodash';

import intl from 'react-intl-universal';
import {
getAlterGQL,
getIndexCreateGQL,
} from '@app/utils/gql';
import { message } from 'antd';

export class SchemaStore {
spaces: string[] = [];
Expand Down Expand Up @@ -746,66 +747,62 @@ export class SchemaStore {
edges: [],
indexes: [],
};
await this.switchSpace(space);
const spaceGql = await this.getSpaceCreateGQL(space);
ddlMap.space = spaceGql;
await this.switchSpace(space);
const tags = await this.getTags();
for await (const tag of tags) {
const gql = await this.getTagOrEdgeDetail(ISchemaEnum.Tag, tag);
gql && ddlMap.tags.push(gql);
}
// tags.forEach(async tag => {
// const gql = await this.getTagOrEdgeDetail(ISchemaEnum.Tag, tag);
// gql && ddlMap.tags.push(gql);
// });
const edges = await this.getEdges();
for await (const edge of edges) {
const gql = await this.getTagOrEdgeDetail(ISchemaEnum.Edge, edge);
gql && ddlMap.edges.push(gql);
}
// edges.forEach(async edge => {
// const gql = await this.getTagOrEdgeDetail(ISchemaEnum.Edge, edge);
// gql && ddlMap.edges.push(gql);
// });
const tagIndexes = await this.getIndexes(ISchemaEnum.Tag);
for await (const index of tagIndexes) {
const gql = await this.getIndexGQL({ type: ISchemaEnum.Tag, name: index.name });
gql && ddlMap.indexes.push(gql);
}
// tagIndexes.forEach(async tagIndex => {
// const gql = await this.getIndexGQL({ type: ISchemaEnum.Tag, name: tagIndex.name });
// gql && ddlMap.indexes.push(gql);
// });
const edgeIndexes = await this.getIndexes(ISchemaEnum.Edge);
for await (const index of edgeIndexes) {
const gql = await this.getIndexGQL({ type: ISchemaEnum.Edge, name: index.name });
gql && ddlMap.indexes.push(gql);
try {
await this.switchSpace(space);
const spaceGql = await this.getSpaceCreateGQL(space);
ddlMap.space = spaceGql;
await this.switchSpace(space);
const tags = await this.getTags();
const edges = await this.getEdges();
const tagIndexes = await this.getIndexes(ISchemaEnum.Tag);
const edgeIndexes = await this.getIndexes(ISchemaEnum.Edge);
if(!tags || !edges || !tagIndexes || !edgeIndexes) {
throw new Error(intl.get('schema.getDDLError'));
}
const queryList = [
{
data: tags,
type: ISchemaEnum.Tag,
destination: ddlMap.tags,
},
{
data: edges,
type: ISchemaEnum.Edge,
destination: ddlMap.edges,
},
{
data: tagIndexes,
type: ISchemaEnum.Tag,
isIndex: true,
destination: ddlMap.indexes,
},
{
data: edgeIndexes,
type: ISchemaEnum.Edge,
isIndex: true,
destination: ddlMap.indexes,
},
];
for await (const item of queryList) {
const { data, type, isIndex, destination } = item;
for await (const _item of data) {
if(isIndex) {
const gql = await this.getIndexGQL({ type, name: _item.name });
gql && destination.push(gql);
} else {
const gql = await this.getTagOrEdgeDetail(type, _item);
if(gql) {
destination.push(gql);
} else {
throw new Error(intl.get('schema.getDDLError'));
}
}
}
}
return ddlMap;
} catch (err) {
message.warning(err.toString());
}
// edgeIndexes.forEach(async edgeIndex => {
// const gql = await this.getIndexGQL({ type: ISchemaEnum.Edge, name: edgeIndex.name });
// gql && ddlMap.indexes.push(gql);
// });
// await Promise.all([
// tags.map(async tag => {
// const gql = await this.getTagOrEdgeDetail(ISchemaEnum.Tag, tag);
// gql && ddlMap.tags.push(gql);
// }),
// edges.map(async edge => {
// const gql = await this.getTagOrEdgeDetail(ISchemaEnum.Edge, edge);
// gql && ddlMap.edges.push(gql);
// }),
// tagIndexes.map(async tagIndex => {
// const gql = await this.getIndexGQL({ type: ISchemaEnum.Tag, name: tagIndex.name });
// gql && ddlMap.indexes.push(gql);
// }),
// edgeIndexes.map(async edgeIndex => {
// const gql = await this.getIndexGQL({ type: ISchemaEnum.Edge, name: edgeIndex.name });
// gql && ddlMap.indexes.push(gql);
// })
// ]);
console.log('ddlMap', ddlMap);
return ddlMap;
};
}

Expand Down

0 comments on commit d301ab7

Please sign in to comment.