keithwhor / nodal

API Services Made Easy With Node.js
http://www.nodaljs.com/
MIT License
4.51k stars 209 forks source link

Create index on multiple column #334

Open ginsuma opened 7 years ago

ginsuma commented 7 years ago

I tried with this.createIndex("table",["col1","col2","col3"],"int") but after run "nodal db:migrate", got error: column "col1,col2,col3" does not exist. Btw, what does "type" in "createIndex(table, column, type)" mean?

maxism commented 7 years ago

You should call createIndex(table, columnName, indexType) method as many times as how many indexes you need to create. For example,

this.createIndex('table', 'col1');
this.createIndex('table', 'col2');
this.createIndex('table', 'col3');

The last parameter of that method describes type of index you are creating. For PostgreSQL database you can use different index types: btree, hash, gist, gin... Read https://www.postgresql.org/docs/9.5/static/indexes-types.html for more information.