Skip to content

Commit

Permalink
Enable wrapIdentifier for SQLite .hasTable (#4915)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramos-ph committed Jan 10, 2022
1 parent 4c589a3 commit 40eef5c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dialects/sqlite3/schema/sqlite-compiler.js
Expand Up @@ -17,7 +17,7 @@ class SchemaCompiler_SQLite3 extends SchemaCompiler {
const sql =
`select * from sqlite_master ` +
`where type = 'table' and name = ${this.client.parameter(
tableName,
this.formatter.wrap(tableName).replace(/`/g, ''),
this.builder,
this.bindingsHolder
)}`;
Expand Down
28 changes: 28 additions & 0 deletions test/integration2/schema/misc.spec.js
Expand Up @@ -1576,6 +1576,34 @@ describe('Schema (misc)', () => {
knex.schema.hasTable('').then((resp) => {
expect(resp).to.equal(false);
}));

describe('sqlite only', () => {
it('should not parse table name if wrapIdentifier is not specified', async function () {
if (!isSQLite(knex)) {
return this.skip();
}

knex.client.config.wrapIdentifier = null;

const resp = await knex.schema.hasTable('testTableTwo');
expect(resp).to.be.false;
});

it('should parse table name if wrapIdentifier is specified', async function () {
if (!isSQLite(knex)) {
return this.skip();
}

knex.client.config.wrapIdentifier = (
value,
origImpl,
queryContext
) => origImpl(_.snakeCase(value));

const resp = await knex.schema.hasTable('testTableTwo');
expect(resp).to.be.true;
});
});
});

describe('renameTable', () => {
Expand Down

0 comments on commit 40eef5c

Please sign in to comment.