Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable wrapIdentifier for SQLite .hasTable #4915

Merged
merged 10 commits into from Jan 10, 2022
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