How can I get a list of primary keys for a specified table

已回答

I'm writing an extractor and need to know how I can identify what are the primary keys of a table.  I didn't see this functionality in extractor bindings.  Is there an API I can use to get this?

 

0

Hello Jim,
We don't publish this API because it's internal and we don't guarantee that it will not change.
Here is how you can find primary key and iterate over it's column names:

import com.intellij.database.model.ObjectKind

NEWLINE = System.getProperty("line.separator")


def key = TABLE.getDasChildren(ObjectKind.KEY).find { it.isPrimary() }

if (key != null) {
OUT.append(key.getName())
OUT.append(NEWLINE)
key.getColumnsRef().names().each { colName ->
OUT.append(" ")
OUT.append(colName)
OUT.append(NEWLINE)
}
}
1

This worked perfectly!  Thank you.

0

请先登录再写评论。