Home  >  Q&A  >  body text

Convert a mysql query to its equivalent Knex query

I'm trying to convert my mysql query to its equivalent Knex query

This is the query Create table test ( id INT UNSIGNED NOT NULL AUTO_INCRMENT, name VARCHAR(100), unique (id) ) AUTO_INCRMENT = 1001;

So basically I want to create a table with a column called "id" that is of type autoincrement and whose values ​​start at 1001.

I want it's equivalent to the Knex query. Tried browsing the documentation but couldn't get much help.

P粉412533525P粉412533525235 days ago275

reply all(1)I'll reply

  • P粉098417223

    P粉0984172232024-02-27 00:17:25

    The Knex.js architecture from SQL is like :

    knex.schema.createTable('test', function(table) {
      table.increments('id').unsigned().notNullable().unique().defaultTo(1001);
      table.string('name', 100);
    })

    reply
    0
  • Cancelreply