DbIndex - do-/node-doix-db GitHub Wiki

DbIndex is a DbObject descendant describing a (secondary) index (normally, a bound to a DbTable).

Though omnipresent, indexes are completely vendor specific, they are not covered by any ANSI SQL section.

Nevertheless, most popular SQL dialects support statements like

CREATE           /* ...options... */ 
INDEX            /* ...options... */ 
${index.qName}   /* ...options... */ 
ON               /* ...options... */ 
${table.qName}   /* ...options... */ 
(${index.parts}) /* ...options... */

So, this class represent all components mentioned above, where all options are collected in one array. It's up to each DbLang descendant to distribute them properly.

Properties

Name Type Description Notes
relation DbRelation Table, view etc. which this index belongs to may be undefined
schemaName String Part of name from the beginning to the first '.' char, or null. Normally, copied from relation
localName String The name of this index in its schema
qName String Quoted name of this index, good for SQL (DDL etc.)
parts [String] The list of expressions for the ON clause mandatory; interpolated as is; typically, just column names
options [String] The list of global options for this index [] by default
message Error => String Custom error message generator For unique indexes

Sample fragment of a DbTable description file

    keys: {
        bad_idea :   null,                     // this index will be removed, if not yet
        label    :  'label',                   // like {parts: ['label']}
        priority : ['priority DESC', 'label'], // like {parts: ['priority DESC', 'label']}
        a_very_custom_index : {
//        localName :  ['ix_some_table_cust'],
          parts     :  ['SUBSTR(name, 1, 10) DESC NULLS FIRST'],
          options   :  [
            'UNIQUE',
            'USING BTREE',
            'WHERE priority = 10',
          ],
//        message : err => `You're so wrong: ${err.details}`,
        },
    },