Search code examples
ydn-db

Define Multiple-Columns as PK in YDN-DB


When define a schema with ydn-db I can define a single column as PK with this code:

var products = {
    name: 'products',
    keyPath: 'id_product',
    autoIncrement: true,
    indexes: [
        {keyPath: 'id_product'},
        {keyPath: 'id_supplier'}
    ]
};

var schema = {
    stores: [products]
};

How I can define a Store (table) with one PK with two columns or more? Thanks


Solution

  • How I can define a Store (table) with one PK with two columns or more?

    I am not sure answering your question. IndexedDB (ynd-db is very IDB centric) can have only one PK. But primary key can be compound key compose of multiple keyPath (column) using array keypath. It is define like this

    var products = {
      name: 'products',
      keyPath: ['id_category', id_product']
    };