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

DbTable is a DbRelation descendant describing a regular relational database table.

As for all DbObject's descendants, instances of this class should only be created by calling DbSchema's create method (normally, in the course of adding).

Properties

See DbObject's Properties

See DbRelation's Properties

Name Type Description
data [Object] the list of records that must be present in that table
triggers [DbTrigger] the list of table's triggers

Sample description

// module.exports = 
{

    label: 'Some table',

    columns: {
        id:       'int  // PK',
        name:     'text // Technical name',
        label:    'text // Human readable name',
        priority: 'int  // Bigger values first',
    },
    
    pk: 'id',

    data: [             // mandatory data for system dictionaries
        {id: 1, name: 'admin'},
        {id: 2, name: 'user'},
    ],

    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',
          ],
        },
    },

    triggers: [

    	{
//		options: 'CONSTRAINT',
		phase  : 'BEFORE INSERT OR UPDATE',
		action : 'FOR EACH ROW',
		sql    : `
			/* trigger body */
		`,
    	},

    ],

}