javascriptnode.jsknex.jsalasql

How to make knex use alasql as a custom dialect


I'm trying to configure knex so I can run seeder and migrations against a test database for integration tests. I chose alasql and found some resources here and here suggesting this is possible. I'm using the knex-alasql module and its setup instructions. Since I'm setting this up for seeding, I'm doing the configuration in the knexfile.js file located in the app root. However I'm consistently running into this error.

image of error

I believe this is related to how knex parses the client key into a useable dialect. My assumption is that this would have worked on an older build of knex but doesn't on the current version I'm on 0.15.2

Some insight on a workaround or a better in memory db that i can run integration tests on would be acceptable answers.


Solution

  • Some help how to create custom dialect is described in

    https://github.com/tgriesser/knex/blob/master/CONTRIBUTING.md#i-would-like-to-add-support-for-new-dialect-to-knex-is-it-possible

    SQlite has inmemory database support if you configure knex like this

    const knexSqlite = Knex({
      client: 'sqlite',
      connection: ':memory:'
    });
    

    However generally I would not recommend using different database for testing and for the actual app for various reasons. Mostly because you will not know if your code will actually work against real database and that you would need to limit to use only those database features, which are supported by test database and real database engine.