Restore sqlite3 package (#5136)

This commit is contained in:
Olivier Cavadenti 2022-04-21 19:05:40 +02:00 committed by GitHub
parent 3279e87815
commit b8fc16f867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 24 additions and 26 deletions

View File

@ -1,5 +1,10 @@
## Upgrading to new knex.js versions
### Upgrading to version 2.0.0+
* The package `sqlite3` is again maintained, we restore it and remove `@vscode/sqlite3` driver dependency, please
replace it in the `package.json`;
### Upgrading to version 1.0.0+
* Node.js older than 12 is no longer supported, make sure to update your environment;

View File

@ -189,10 +189,7 @@ class Client extends EventEmitter {
try {
this.driver = this._driver();
} catch (e) {
const driverName = this.aliasDriverName
? this.aliasDriverName
: this.driverName;
const message = `Knex: run\n$ npm install ${driverName} --save`;
const message = `Knex: run\n$ npm install ${this.driverName} --save`;
this.logger.error(`${message}\n${e.message}\n${e.stack}`);
throw new Error(`${message}\n${e.message}`);
}

View File

@ -30,7 +30,7 @@ class Client_SQLite3 extends Client {
}
_driver() {
return require('@vscode/sqlite3');
return require('sqlite3');
}
schemaCompiler() {
@ -232,8 +232,6 @@ Object.assign(Client_SQLite3.prototype, {
dialect: 'sqlite3',
driverName: 'sqlite3',
// SqlLite3 driver package name is different from driver name.
aliasDriverName: '@vscode/sqlite3',
});
module.exports = Client_SQLite3;

View File

@ -101,7 +101,6 @@
},
"devDependencies": {
"@types/node": "^17.0.25",
"@vscode/sqlite3": "^5.0.7",
"better-sqlite3": "^7.5.1",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
@ -131,6 +130,7 @@
"sinon": "^13.0.1",
"sinon-chai": "^3.7.0",
"source-map-support": "^0.5.21",
"sqlite3": "^5.0.4",
"tap-spec": "^5.0.0",
"tape": "^5.5.3",
"tedious": "^14.4.0",
@ -205,7 +205,6 @@
"pg-query-stream": false,
"oracle": false,
"sqlite3": false,
"@vscode/sqlite3": false,
"better-sqlite3": false,
"oracledb": false
},

View File

@ -1,4 +1,4 @@
require('@vscode/sqlite3');
require('sqlite3');
const Knex = require('knex');
const knexSqlite = Knex({

View File

@ -3,7 +3,7 @@ const assert = require('assert');
const path = require('path');
const fs = require('fs');
const { execCommand } = require('cli-testlab');
const sqlite3 = require('@vscode/sqlite3');
const sqlite3 = require('sqlite3');
const semver = require('semver');
const { createTable } = require('./cli-test-utils');
const KNEX = path.normalize(__dirname + '/../../bin/cli.js');

View File

@ -1,7 +1,7 @@
'use strict';
const path = require('path');
const sqlite3 = require('@vscode/sqlite3');
const sqlite3 = require('sqlite3');
const { expect } = require('chai');
const { execCommand } = require('cli-testlab');
const { getRootDir } = require('./cli-test-utils');

View File

@ -1,7 +1,7 @@
'use strict';
const path = require('path');
const sqlite3 = require('@vscode/sqlite3');
const sqlite3 = require('sqlite3');
const { expect } = require('chai');
const { execCommand } = require('cli-testlab');
const { getRootDir, setupFileHelper } = require('./cli-test-utils');

View File

@ -125,7 +125,7 @@ describe('Schema', () => {
knex('alter_table').insert({ column_notNullable: 'text' })
).to.be.rejectedWith(
Error,
"insert into `alter_table` (`column_notNullable`) values ('text') - SQLITE_CONSTRAINT_NOTNULL: NOT NULL constraint failed: alter_table.column_string"
"insert into `alter_table` (`column_notNullable`) values ('text') - SQLITE_CONSTRAINT: NOT NULL constraint failed: alter_table.column_string"
);
expect(tableAfter).to.equal(
"CREATE TABLE \"alter_table\" (`column_integer` integer DEFAULT '0', `column_string` varchar(255) NOT NULL, `column_datetime` datetime NOT NULL DEFAULT '0', `column_defaultTo` integer DEFAULT '0', `column_notNullable` varchar(255) NOT NULL, `column_defaultToAndNotNullable` datetime NOT NULL DEFAULT '0', `column_nullable` boolean NULL)"
@ -163,7 +163,7 @@ describe('Schema', () => {
knex('alter_table').insert({ column_notNullable: 'text' })
).to.be.rejectedWith(
Error,
"insert into `alter_table` (`column_notNullable`) values ('text') - SQLITE_CONSTRAINT_NOTNULL: NOT NULL constraint failed: alter_table.column_nullable"
"insert into `alter_table` (`column_notNullable`) values ('text') - SQLITE_CONSTRAINT: NOT NULL constraint failed: alter_table.column_nullable"
);
expect(tableAfter).to.equal(
"CREATE TABLE \"alter_table\" (`column_integer` integer, `column_string` varchar(255), `column_datetime` datetime, `column_defaultTo` integer DEFAULT '0', `column_notNullable` varchar(255) NOT NULL, `column_defaultToAndNotNullable` datetime NOT NULL DEFAULT '0', `column_nullable` boolean NOT NULL)"

View File

@ -206,7 +206,7 @@ describe('Schema', () => {
);
} else if (isSQLite(knex)) {
expect(err.message).to.equal(
`insert into \`foreign_keys_table_one\` (\`fkey_three\`, \`fkey_two\`) values (99, 9999) - SQLITE_CONSTRAINT_FOREIGNKEY: FOREIGN KEY constraint failed`
`insert into \`foreign_keys_table_one\` (\`fkey_three\`, \`fkey_two\`) values (99, 9999) - SQLITE_CONSTRAINT: FOREIGN KEY constraint failed`
);
}
if (isPostgreSQL(knex)) {
@ -366,7 +366,7 @@ describe('Schema', () => {
);
} else if (isSQLite(knex)) {
expect(err.message).to.equal(
`insert into \`foreign_keys_table_one\` (\`fkey_four_part1\`, \`fkey_four_part2\`, \`fkey_three\`, \`fkey_two\`) values ('a', 'b', 99, 9999) - SQLITE_CONSTRAINT_FOREIGNKEY: FOREIGN KEY constraint failed`
`insert into \`foreign_keys_table_one\` (\`fkey_four_part1\`, \`fkey_four_part2\`, \`fkey_three\`, \`fkey_two\`) values ('a', 'b', 99, 9999) - SQLITE_CONSTRAINT: FOREIGN KEY constraint failed`
);
}
if (isPostgreSQL(knex)) {

View File

@ -52,7 +52,7 @@ describe('Schema', () => {
);
} else if (isSQLite(knex)) {
expect(err.message).to.equal(
'insert into `primary_table` (`id_four`) values (1) - SQLITE_CONSTRAINT_PRIMARYKEY: UNIQUE constraint failed: primary_table.id_four'
'insert into `primary_table` (`id_four`) values (1) - SQLITE_CONSTRAINT: UNIQUE constraint failed: primary_table.id_four'
);
}
if (isPgBased(knex)) {
@ -184,7 +184,7 @@ describe('Schema', () => {
);
} else if (isSQLite(knex)) {
expect(err.message).to.equal(
'insert into `primary_table` (`id_four`) values (1) - SQLITE_CONSTRAINT_PRIMARYKEY: UNIQUE constraint failed: primary_table.id_four'
'insert into `primary_table` (`id_four`) values (1) - SQLITE_CONSTRAINT: UNIQUE constraint failed: primary_table.id_four'
);
}
if (isPgBased(knex)) {
@ -224,7 +224,7 @@ describe('Schema', () => {
);
} else if (isSQLite(knex)) {
expect(err.message).to.equal(
'insert into `primary_table` (`id_three`, `id_two`) values (1, 1) - SQLITE_CONSTRAINT_PRIMARYKEY: UNIQUE constraint failed: primary_table.id_two, primary_table.id_three'
'insert into `primary_table` (`id_three`, `id_two`) values (1, 1) - SQLITE_CONSTRAINT: UNIQUE constraint failed: primary_table.id_two, primary_table.id_three'
);
}
if (isPgBased(knex)) {
@ -270,7 +270,7 @@ describe('Schema', () => {
);
} else if (isSQLite(knex)) {
expect(err.message).to.equal(
'insert into `primary_table` (`id_three`, `id_two`) values (1, 1) - SQLITE_CONSTRAINT_PRIMARYKEY: UNIQUE constraint failed: primary_table.id_two, primary_table.id_three'
'insert into `primary_table` (`id_three`, `id_two`) values (1, 1) - SQLITE_CONSTRAINT: UNIQUE constraint failed: primary_table.id_two, primary_table.id_three'
);
}
if (isPgBased(knex)) {

View File

@ -142,7 +142,7 @@ describe('Schema', () => {
'insert into `primary_table` (`id_not_nullable`, `id_nullable`) values (1, NULL) - NOT NULL constraint failed: primary_table.id_nullable';
} else if (isSQLite(knex)) {
errorMessage =
'insert into `primary_table` (`id_not_nullable`, `id_nullable`) values (1, NULL) - SQLITE_CONSTRAINT_NOTNULL: NOT NULL constraint failed: primary_table.id_nullable';
'insert into `primary_table` (`id_not_nullable`, `id_nullable`) values (1, NULL) - SQLITE_CONSTRAINT: NOT NULL constraint failed: primary_table.id_nullable';
}
await expect(

View File

@ -6,7 +6,7 @@ const os = require('os');
const fs = require('fs');
const rimrafSync = require('rimraf').sync;
const path = require('path');
const sqlite3 = require('@vscode/sqlite3');
const sqlite3 = require('sqlite3');
const { assert } = require('chai');
const {
assertExec,

View File

@ -2,7 +2,7 @@ const Knex = require('../../lib/index');
const QueryBuilder = require('../../lib/query/querybuilder');
const { expect } = require('chai');
const sqliteConfig = require('../knexfile').sqlite3;
const sqlite3 = require('@vscode/sqlite3');
const sqlite3 = require('sqlite3');
const { noop } = require('lodash');
const sinon = require('sinon');
@ -357,8 +357,7 @@ describe('knex', () => {
ClientFoobar.prototype._driver = () => {
throw new Error('Cannot require...');
};
ClientFoobar.prototype.driverName = ClientFoobar.prototype.aliasDriverName =
'foo-bar';
ClientFoobar.prototype.driverName = 'foo-bar';
expect(() => {
Knex({ client: ClientFoobar, connection: {} });