Skip to content

Commit

Permalink
feat: update mariadb connector to v3 (#16139)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: minimum mariadb npm package version is now 3.1.2
  • Loading branch information
ephys committed Jun 18, 2023
1 parent 891b11e commit bc26271
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 55 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"fs-jetpack": "5.1.0",
"ibm_db": "3.2.1",
"lcov-result-merger": "4.1.0",
"mariadb": "2.5.6",
"mariadb": "3.1.2",
"mocha": "10.2.0",
"moment": "2.29.4",
"mysql2": "3.3.5",
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/dialects/mariadb/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ export class MariaDbConnectionManager extends AbstractConnectionManager<MariaDbC
password: config.password,
database: config.database,
timezone: tzOffset,
bigNumberStrings: false,
supportBigNumbers: true,
foundRows: false,
...config.dialectOptions,
typeCast: (field: FieldInfo, next: TypeCastNextFunction) => this.#typeCast(field, next),
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/dialects/mariadb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ export class MariaDbDialect extends AbstractDialect {
);

registerMySqlDbDataTypeParsers(this);
// DECIMAL must be returned as a string, the JS number type is not precise enough.
this.registerDataTypeParser(['NEWDECIMAL'], (value: FieldInfo) => {
// For backwards compatibility, we currently return BIGINTs as strings. We will implement bigint support for all
// dialects in the future: https://github.com/sequelize/sequelize/issues/10468
this.registerDataTypeParser(['BIGINT'], (value: FieldInfo) => {
return value.string();
});
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/dialects/mariadb/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class MariaDbQuery extends AbstractQuery {
const startId = data[this.getInsertIdField()];
result = new Array(data.affectedRows);
const pkColumnName = modelDefinition.attributes.get(this.model.primaryKeyAttribute).columnName;
for (let i = 0; i < data.affectedRows; i++) {
for (let i = 0n; i < data.affectedRows; i++) {
result[i] = { [pkColumnName]: startId + i };
}

Expand All @@ -135,7 +135,6 @@ export class MariaDbQuery extends AbstractQuery {

if (this.isRawQuery()) {
const meta = data.meta;
delete data.meta;

return [data, meta];
}
Expand Down
27 changes: 15 additions & 12 deletions packages/core/src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ ${associationOwner._getAssociationDebugList()}`);
});

// Map attributes to fields for serial identification
const fieldMappedAttributes = {};
const fieldMappedAttributes = Object.create(null);
for (const attrName in model.tableAttributes) {
const attribute = modelDefinition.attributes.get(attrName);
fieldMappedAttributes[attribute.columnName] = attribute;
Expand Down Expand Up @@ -2273,6 +2273,10 @@ ${associationOwner._getAssociationDebugList()}`);
const instance = instances[i];

for (const key in result) {
if (!Object.prototype.hasOwnProperty.call(result, key)) {
continue;
}

if (!instance || key === model.primaryKeyAttribute
&& instance.get(model.primaryKeyAttribute)
&& ['mysql', 'mariadb', 'sqlite'].includes(dialect)) {
Expand All @@ -2282,16 +2286,14 @@ ${associationOwner._getAssociationDebugList()}`);
continue;
}

if (Object.prototype.hasOwnProperty.call(result, key)) {
const record = result[key];

const attr = find(
modelDefinition.attributes.values(),
attribute => attribute.attributeName === key || attribute.columnName === key,
);

instance.dataValues[attr && attr.attributeName || key] = record;
}
const value = result[key];
const attr = find(
modelDefinition.attributes.values(),
attribute => attribute.attributeName === key || attribute.columnName === key,
);
const attributeName = attr?.attributeName || key;
instance.dataValues[attributeName] = value != null && attr?.type instanceof AbstractDataType ? attr.type.parseDatabaseValue(value) : value;
instance._previousDataValues[attributeName] = instance.dataValues[attributeName];
}
}
}
Expand Down Expand Up @@ -3360,7 +3362,7 @@ Instead of specifying a Model, either:

// Bunch of stuff we won't do when it's raw
if (!options.raw) {
// If attribute is not in model definition, return
// If the attribute is not in model definition, return
if (!attributeDefinition) {
const jsonAttributeNames = modelDefinition.jsonAttributeNames;

Expand All @@ -3381,6 +3383,7 @@ Instead of specifying a Model, either:
return this;
}

// TODO: throw an error when trying to set a read only attribute with to a different value
// If attempting to set read only attributes, return
const readOnlyAttributeNames = modelDefinition.readOnlyAttributeNames;
if (!this.isNewRecord && readOnlyAttributeNames.has(key)) {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ export class Sequelize extends SequelizeTypeScript {
* // - currently supported: 'mysql', 'postgres', 'mssql'
* dialectOptions: {
* socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock',
* supportBigNumbers: true,
* bigNumberStrings: true
* },
*
* // the storage engine for sqlite
Expand Down
11 changes: 11 additions & 0 deletions packages/core/test/integration/model/bulk-create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(users[1].secretValue).to.equal('23');
});

it('parses values that come from the database', async function () {
// Because bulkCreate uses a different code path than create,
// there was a bug where values coming back from the database
// weren't being run through the parsers/validators.
// This test ensures that the bug is fixed.
// https://github.com/sequelize/sequelize/issues/15640
const [user] = await this.User.bulkCreate([{ theDate: new Date(), uniqueName: '1' }]);

expect(user.theDate).to.be.instanceOf(Date);
});

it('should set isNewRecord = false', async function () {
const data = [{ username: 'Peter', secretValue: '42', uniqueName: '1' },
{ username: 'Paul', secretValue: '23', uniqueName: '2' }];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/integration/pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe(getTestDialectTeaser('Pooling'), () => {
connection = attachMSSQLUniqueId(connection);
}

if (dialect === 'db2') {
if (dialect === 'db2' || dialect === 'mariadb') {
await sequelize.connectionManager.pool.destroy(connection);
} else {
const error: NodeJS.ErrnoException = new Error('Test ECONNRESET Error');
Expand Down
48 changes: 15 additions & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ __metadata:
inflection: ^2.0.0
lcov-result-merger: 4.1.0
lodash: ^4.17.21
mariadb: 2.5.6
mariadb: 3.1.2
mocha: 10.2.0
moment: 2.29.4
mysql2: 3.3.5
Expand Down Expand Up @@ -1771,7 +1771,7 @@ __metadata:
languageName: node
linkType: hard

"@types/geojson@npm:^7946.0.8":
"@types/geojson@npm:^7946.0.10":
version: 7946.0.10
resolution: "@types/geojson@npm:7946.0.10"
checksum: 12c407c2dc93ecb26c08af533ee732f1506a9b29456616ba7ba1d525df96206c28ddf44a528f6a5415d7d22893e9d967420940a9c095ee5e539c1eba5fefc1f4
Expand Down Expand Up @@ -1858,7 +1858,7 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^17.0.10":
"@types/node@npm:^17.0.45":
version: 17.0.45
resolution: "@types/node@npm:17.0.45"
checksum: aa04366b9103b7d6cfd6b2ef64182e0eaa7d4462c3f817618486ea0422984c51fc69fd0d436eae6c9e696ddfdbec9ccaa27a917f7c2e8c75c5d57827fe3d95e8
Expand Down Expand Up @@ -3994,7 +3994,7 @@ __metadata:
languageName: node
linkType: hard

"denque@npm:^2.0.1, denque@npm:^2.1.0":
"denque@npm:^2.1.0":
version: 2.1.0
resolution: "denque@npm:2.1.0"
checksum: 1d4ae1d05e59ac3a3481e7b478293f4b4c813819342273f3d5b826c7ffa9753c520919ba264f377e09108d24ec6cf0ec0ac729a5686cbb8f32d797126c5dae74
Expand Down Expand Up @@ -7846,7 +7846,7 @@ __metadata:
languageName: node
linkType: hard

"long@npm:^5.2.0, long@npm:^5.2.1":
"long@npm:^5.2.1":
version: 5.2.3
resolution: "long@npm:5.2.3"
checksum: 885ede7c3de4facccbd2cacc6168bae3a02c3e836159ea4252c87b6e34d40af819824b2d4edce330bfb5c4d6e8ce3ec5864bdcf9473fa1f53a4f8225860e5897
Expand Down Expand Up @@ -7891,7 +7891,7 @@ __metadata:
languageName: node
linkType: hard

"lru-cache@npm:^7.14.1, lru-cache@npm:^7.4.4, lru-cache@npm:^7.5.1, lru-cache@npm:^7.7.1":
"lru-cache@npm:^7.14.0, lru-cache@npm:^7.14.1, lru-cache@npm:^7.4.4, lru-cache@npm:^7.5.1, lru-cache@npm:^7.7.1":
version: 7.18.3
resolution: "lru-cache@npm:7.18.3"
checksum: e550d772384709deea3f141af34b6d4fa392e2e418c1498c078de0ee63670f1f46f5eee746e8ef7e69e1c895af0d4224e62ee33e66a543a14763b0f2e74c1356
Expand Down Expand Up @@ -8030,18 +8030,16 @@ __metadata:
languageName: node
linkType: hard

"mariadb@npm:2.5.6":
version: 2.5.6
resolution: "mariadb@npm:2.5.6"
"mariadb@npm:3.1.2":
version: 3.1.2
resolution: "mariadb@npm:3.1.2"
dependencies:
"@types/geojson": ^7946.0.8
"@types/node": ^17.0.10
denque: ^2.0.1
"@types/geojson": ^7946.0.10
"@types/node": ^17.0.45
denque: ^2.1.0
iconv-lite: ^0.6.3
long: ^5.2.0
moment-timezone: ^0.5.34
please-upgrade-node: ^3.2.0
checksum: 5614225514cee36a8f1760b72536a10c4c3ac120ac5f5efc6629d2489df518eacebbaecbc7f143e23ffd235f41ab0b967de592b8d80645ebfdd6f01de137e98b
lru-cache: ^7.14.0
checksum: 70079e09ecc2ae4113b317912419053645aabbcc3e584c7c1dba89306cb0af1a47438ccbf03f1c97f8fee07b952c33952edbc100847d55a30aa9d897b04c729f
languageName: node
linkType: hard

Expand Down Expand Up @@ -8479,7 +8477,7 @@ __metadata:
languageName: node
linkType: hard

"moment-timezone@npm:^0.5.15, moment-timezone@npm:^0.5.34":
"moment-timezone@npm:^0.5.15":
version: 0.5.43
resolution: "moment-timezone@npm:0.5.43"
dependencies:
Expand Down Expand Up @@ -9983,15 +9981,6 @@ __metadata:
languageName: node
linkType: hard

"please-upgrade-node@npm:^3.2.0":
version: 3.2.0
resolution: "please-upgrade-node@npm:3.2.0"
dependencies:
semver-compare: ^1.0.0
checksum: d87c41581a2a022fbe25965a97006238cd9b8cbbf49b39f78d262548149a9d30bd2bdf35fec3d810e0001e630cd46ef13c7e19c389dea8de7e64db271a2381bb
languageName: node
linkType: hard

"pluralize@npm:^8.0.0":
version: 8.0.0
resolution: "pluralize@npm:8.0.0"
Expand Down Expand Up @@ -10824,13 +10813,6 @@ __metadata:
languageName: node
linkType: hard

"semver-compare@npm:^1.0.0":
version: 1.0.0
resolution: "semver-compare@npm:1.0.0"
checksum: dd1d7e2909744cf2cf71864ac718efc990297f9de2913b68e41a214319e70174b1d1793ac16e31183b128c2b9812541300cb324db8168e6cf6b570703b171c68
languageName: node
linkType: hard

"semver@npm:2 || 3 || 4 || 5, semver@npm:^5.0.1, semver@npm:^5.5.0, semver@npm:^5.6.0":
version: 5.7.1
resolution: "semver@npm:5.7.1"
Expand Down

0 comments on commit bc26271

Please sign in to comment.