WIP on count impl; reworking comparisons
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package solutions.bitbadger.documents.query
|
||||
|
||||
import solutions.bitbadger.documents.Configuration
|
||||
import solutions.bitbadger.documents.Dialect
|
||||
import solutions.bitbadger.documents.Field
|
||||
import solutions.bitbadger.documents.FieldFormat
|
||||
import solutions.bitbadger.documents.*
|
||||
|
||||
/**
|
||||
* Functions to create queries to define tables and indexes
|
||||
@@ -76,4 +73,20 @@ object Definition {
|
||||
*/
|
||||
fun ensureKey(tableName: String, dialect: Dialect? = null) =
|
||||
ensureIndexOn(tableName, "key", listOf(Configuration.idField), dialect).replace("INDEX", "UNIQUE INDEX")
|
||||
|
||||
/**
|
||||
* Create a document-wide index on a table (PostgreSQL only)
|
||||
*
|
||||
* @param tableName The name of the table on which the document index should be created
|
||||
* @param indexType The type of index to be created
|
||||
* @return The SQL statement to create an index on JSON documents in the specified table
|
||||
* @throws DocumentException If the database mode is not PostgreSQL
|
||||
*/
|
||||
fun ensureDocumentIndexOn(tableName: String, indexType: DocumentIndex): String {
|
||||
if (Configuration.dialect("create document index query") != Dialect.POSTGRESQL) {
|
||||
throw DocumentException("'Document indexes are only supported on PostgreSQL")
|
||||
}
|
||||
val (_, tbl) = splitSchemaAndTable(tableName)
|
||||
return "CREATE INDEX IF NOT EXISTS idx_${tbl}_document ON $tableName USING GIN (data${indexType.sql})";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user