1 Star 3 Fork 0

世界的尽头 / CodeMirror5-sqlquery

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

CodeMirror5-sqlquery

介绍

  基于CodeMirror5实现的Sql提示扩展功能,主要是用在Sql控制台场景中,对于经常查询数据库的用户很有帮助。

实现功能
  1. 展示更多信息(字段、标题、类型、详细注释说明)
  2. 模糊匹配关键字,且表、字段高亮
  3. 单表、多表提示
  4. 嵌套子查询提示
  5. 多模式(schema)查询提示
  6. 支持多sql,分号“;”间隔
  7. 支持独立注释,用“--”
  8. 默认快捷表别名(用于快捷引用和查看字段)
  9. 特殊别名处理

软件架构

  • CodeMirror5
  • JavaScript

演示效果

  1. 模糊匹配 输入图片说明

  2. 更多信息展示 输入图片说明

  3. 默认别名defaultMain使用,无别名快捷选择,记不住字段时快捷查看 输入图片说明 输入图片说明

  4. 多模式查询 输入图片说明 输入图片说明

  5. 多条sql识别,支持注释 输入图片说明

  6. 别名识别,`XX`、[XX]、"XX"转义处理,子查询字段处理 输入图片说明

安装教程

  • 引入该项目js和css:  
    lib/sqlquery.css  
    lib/sqlquery.js  
  • 引入CodeMirror5的js和css:  
      /codemirror.min.css  
      /theme/dracula.css  
      /addon/hint/show-hint.css  
      /addon/display/fullscreen.css  
      /addon/dialog/dialog.css  
      /codemirror.min.js  
      /addon/hint/show-hint.js  
      /addon/selection/selection-pointer.js  
      /addon/display/autorefresh.js  
      /addon/display/placeholder.js  
      /addon/display/fullscreen.js  
      /addon/edit/matchbrackets.js  
      /addon/hint/anyword-hint.js  
      /addon/fold/comment-fold.js  
      /addon/comment/comment.js  
      /addon/dialog/dialog.js  

使用说明

  已把初始配置、输入事件、实时查询逻辑封装在一起了,方便使用

  1. 调用以下方法进行初始化(可以查看example页面):
  • //注册CodeMirror自定义mode  
      sqlqueryHandler(CodeMirror); 
  • //注册CodeMirror自定义hint  
      sqlqueryHintHandler(CodeMirror); 
  • //创建编辑器  
      createSqlEditor(selfObj,"sqlcontent");
  • //处理hint触发事件  
      keypressSqlEditor(selfObj, getColsOfSchema, getTablesOfSchema);
  1. 接口需要后台实现(查库、查表、查字段)
  • 获取库信息接口(格式无所谓,按页面需要)  
         自定义  
  • 获取表信息接口,固定格式  
       queryVal={databaseId: "111",schemaType: "public"]}  
       getColsOfSchema(selfObj,queryVal,callbackHint) {  
          //接口实现  
          //接口响应完成后执行回调  
          callbackHint(data);  
       }
  • 获取字段信息接口,固定格式  
       queryVal={databaseId: "111",tableNames: ["public.XXXX1","public.XXXX2"]}  
       getTablesOfSchema(selfObj,queryVal,callbackHint) {  
          //接口实现  
          //接口响应完成后执行回调  
          callbackHint(data);  
       }
  1. 初始对象属性
  •  var selfObj={  
        existTables:{}, //已查询的表  
         existTableCols:{}, //已查询的表字段  
         databaseId: null, //当前数据库id  
         schemaTypes: null, //当前数据库的模式集合  
         mainSchema: null, //当前数据库的主模式  
         sqlEditor: null, //sql编辑器  
         hintOptions: null, //提示框hint对象  
     };  
MIT License Copyright (c) 2024 世界的尽头 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于CodeMirror5实现的Sql提示扩展功能,主要是用在Sql控制台场景中,对于经常查询数据库的用户很有帮助。 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/172463468/codemirror5-sqlquery.git
git@gitee.com:172463468/codemirror5-sqlquery.git
172463468
codemirror5-sqlquery
CodeMirror5-sqlquery
master

搜索帮助