Skip to content

truncateDb does not work with objection's knexSnakeCaseMappers #83

Open
@krishnagopinath

Description

@krishnagopinath

I am using knex-db-manager's truncateDb method to remove data after every test. I noticed that when used in conjunction with Objection's knexSnakeCaseMappers, truncateDb does not actually do anything!

I believe this is happening is because of hard-coding of 'table_name' here, while knex is returning 'tableName' - https://github.com/Vincit/knex-db-manager/blob/master/lib/MySqlDatabaseManager.js#L134

Currently, I am removing the fields returning by knexSnakeCaseMappers when I pass knex config into the dbManager's config.

const { omit } = require('lodash')
const { knexSnakeCaseMappers } = require('objection')

// This file has knexSnakeCaseMappers spread into it
// { 
//    // other config props
//    ....knexSnakeCaseMappers()
// }
const knexConfig = require('./knexfile') 

const dbManager = require('knex-db-manager').databaseManagerFactory({
	knex: omit(knexConfig, Object.keys(knexSnakeCaseMappers())),
	dbManager: {...}
})

Is there any other way of dealing with this? Thank you!

I'd be happy to brainstorm and potentially add a PR, if necessary!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions