How to insert table with knex

Hello guys,
@Maxime_Joannette

How I can Insert a new table with knex on a sqlite database:
I have modify this tutorial: https://aabingunz.com/how-to-connect-to-mysql-database-using-botpress/
To insert a new table on a sqlite database.

I’m using an action but it’s not working.

function action(bp: typeof sdk, event: sdk.IO.IncomingEvent, args: any, { user, temp, session } = event.state) {
  /** Your code starts below */

  /**
   * This utility can Save/Retrieve/Update data to MySQL DB
   * @title User MySQL DB Utility
   * @category Utility
   * @author Abhishek Raj Simon
   * @param {string} name - Only supports get/set/update operations
   * @param {string} table - Table name
   * @param {string} key - Can contain any key against which value needs to be pushed to DB
   * @param {string} value - Can contain a any value that needs to be pushed to DB
   */
  const userDBUtility = async () => {
    const knex = require('knex')({
      client: 'sqlite3',
      connection: {
        filename: './sys.sqlite3'
      },
      useNullAsDefault: false,
      log: {
        warn(message) {
          console.log(message)
        },
        error(message) {
          console.error(message)
        },
        deprecate(message) {
          console.log(message)
        },
        debug(message) {
          console.log(message)
        }
      }
    })

    console.log(knex)

    console.log('je suis ici -------------')

    /* Inserer la table coco dans la BDD nommer sys*/
    knex.schema.createTable('coco', function(table) {
      table.increments()
      table.string('name')
      table.timestamps()
    })
  }

  return userDBUtility()

  /** Your code ends here */
}

I have no clue, no warning , no error message. Nothing happen
Could you help me please.
Thanks

You might want to check an example in the source code itself to see how we do it, using createTableIfNotExists, and no schema:

I see you’re using the example in the knex documentation! Hopefully someone else has some experience with this and could help us out.

Cheers!

Thanks to my Quebecois friend

1 Like