Define Multiple-Columns as PK in YDN-DB

184 views Asked by At

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

1

There are 1 answers

0
Kyaw Tun On BEST ANSWER

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