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

Answered

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?

 

2 comments
Comment actions Permalink

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
Comment actions Permalink

This worked perfectly!  Thank you.

0

Please sign in to leave a comment.