Is there a way to specify a multicolumn index in the Knex.js schema? Or must one drop to raw and do an alter table
?
As per Knex's documentation here: primary — column. primary([constraintName]); table. primary(columns, [constraintName]) When called on a single column it will set that column as the primary key for a table.
Sequelize is an ORM that includes some query builder stuff; Knex is just a query builder, not an ORM.
What data type is the output? Knex returns an array for all queries, even if there is only one row returned. The name of the user can be accessed from user[0] .
Knex.js (pronounced /kəˈnɛks/) is a "batteries included" SQL query builder for PostgreSQL, CockroachDB, MSSQL, MySQL, MariaDB, SQLite3, Better-SQLite3, Oracle, and Amazon Redshift designed to be flexible, portable, and fun to use.
Figured this out. You can use the .index chainable on the table directly and pass an array for the index fields and a name for the index.
knex.schema.createTable(function(table) {
table.bigInteger('_id').unsigned().primary();
table.string('fieldA');
table.string('fieldB');
table.index(['fieldA','fieldB'], 'index_name');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With