How do we get intellisense when working with Data and Schema Groovy scripts in DataGrip?

已完成

I am trying to develop some Groovy scripts for DataGrip to help us manage our DDL and Patches better within our projects. Is there a way to get intellisense or Groovy debugging to work for this?

Here is what I have so far, but its hard because I can't find any documentation on these classes.

import com.intellij.database.model.DasObjectWithSource
import com.intellij.database.model.DasObject
import com.intellij.database.model.DasSchemaChild
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.DasUtil
import com.intellij.database.util.ObjectPath

LAYOUT.ignoreDependencies = true
LAYOUT.baseName { ctx -> baseName(ctx.object) }
LAYOUT.fileScope { path -> fileScope(path) }

def baseName(obj) {
def schema = DasUtil.getSchema(obj)
def file = fileName(obj)
def type = objectType(obj)
if (schema.isEmpty()) {
return file
}
else {
return sanitize(schema) + "/" + type + "/" + file
}
}

def objectType(obj) {
def objType = obj.getKind()
if(objType == ObjectKind.ROUTINE){
objType = obj.getRoutineType()}

def objName = objType
switch(objType){
case "table":
objName = "tables";
break;
case "index":
objName = "constraints";
break;
case "table-type":
objName = "types";
break;
case "alias-type":
objName = "types";
break;
case "PROC":
objName = "functions";
break;
case "TAB_FUN":
objName = "functions";
break;
case "SCALAR_FUN":
objName = "functions";
break;
case "object types":
objName = "types"
break;
default:
objName = objType
break;
}

return objName
}

def fileName(obj) {
for (def cur = obj; cur != null; cur = cur.dasParent) {
if (storeSeparately(cur)) return sanitize(cur.name)
}
return sanitize(obj.name)
}

def fileScope(path) {
def root = path.getName(0).toString()
if (root.endsWith(".sql")) return null
return ObjectPath.create(root, ObjectKind.SCHEMA)
}

def storeSeparately(obj) {
return obj instanceof DasObjectWithSource || obj instanceof DasSchemaChild
}

def sanitize(name) {
return name.replace('/', 'slash')
}
0

You can get it, follow instructions described in GitHub repo https://github.com/DataGrip/dg-scripted-extensions-environment (actually, just download all dependencies and start coding)

0

请先登录再写评论。