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

feat(mariadb): implementation for MariaDB #10192

Merged
merged 14 commits into from Dec 3, 2018
Merged

feat(mariadb): implementation for MariaDB #10192

merged 14 commits into from Dec 3, 2018

Conversation

rusher
Copy link
Contributor

@rusher rusher commented Nov 22, 2018

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Implementation of MariaDB.
This differs from MySQL mostly for 3 things:

  • the driver is different (mariadb
  • use of schema
  • MariaDB JSON implementation differ from MySQL

Breaking change is the use of schemas. MySQL/MariaDB have schemas, but no "default" public schema.
Current implementation for MySQL will create a table with name mySchema_myTable, using schema, that is mySchema.myTable.
I haven't corrected that for MySQL since it will break every existing application, but for new MariaDB implementation, it seems appropriate to use a better base with real schemas.

Tests have been updated accordingly (defaut method that drop all schemas is replace to keep default schema that is needed for MariaDB)

This differ from MySQL mostly for 3 things:
- driver is different (mariadb)
- use of schema
- MariaDB JSON implementation differ from MySQL
Copy link
Contributor

@SimonSchick SimonSchick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch of nits, looks good over all.

lib/dialects/abstract/query-generator.js Outdated Show resolved Hide resolved
lib/dialects/mariadb/connection-manager.js Outdated Show resolved Hide resolved
lib/dialects/mariadb/connection-manager.js Outdated Show resolved Hide resolved
lib/dialects/mariadb/connection-manager.js Show resolved Hide resolved
lib/dialects/mariadb/query-generator.js Outdated Show resolved Hide resolved
test/integration/dialects/mariadb/associations.test.js Outdated Show resolved Hide resolved
test/integration/dialects/mariadb/associations.test.js Outdated Show resolved Hide resolved
test/integration/dialects/mariadb/dao.test.js Outdated Show resolved Hide resolved
test/integration/query-interface.test.js Show resolved Hide resolved
test/support.js Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Nov 26, 2018

Codecov Report

Merging #10192 into master will decrease coverage by 0.06%.
The diff coverage is 92.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10192      +/-   ##
==========================================
- Coverage   96.34%   96.28%   -0.07%     
==========================================
  Files          63       68       +5     
  Lines        9420     9796     +376     
==========================================
+ Hits         9076     9432     +356     
- Misses        344      364      +20
Impacted Files Coverage Δ
...dialects/abstract/query-generator/helpers/quote.js 100% <ø> (+5.55%) ⬆️
lib/dialects/abstract/connection-manager.js 90.26% <100%> (+0.26%) ⬆️
lib/model.js 96.77% <100%> (ø) ⬆️
lib/dialects/mariadb/index.js 100% <100%> (ø)
lib/utils.js 98.27% <100%> (ø) ⬆️
lib/dialects/mysql/query-generator.js 97.9% <100%> (+0.01%) ⬆️
lib/data-types.js 94.94% <100%> (+0.01%) ⬆️
lib/dialects/mariadb/connection-manager.js 100% <100%> (ø)
lib/query-interface.js 91.95% <100%> (+2.38%) ⬆️
lib/dialects/mysql/query-interface.js 100% <100%> (ø) ⬆️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f2cafcc...7fe7cd1. Read the comment docs.

Correcting padding, simplify implementation according to remarks
Use Set when possible, benchmarks showing better performance
Copy link
Contributor

@SimonSchick SimonSchick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better now, some minor nits.

lib/dialects/mariadb/query.js Outdated Show resolved Hide resolved
lib/dialects/mariadb/query.js Outdated Show resolved Hide resolved
lib/dialects/mariadb/query.js Show resolved Hide resolved
test/integration/dialects/mariadb/associations.test.js Outdated Show resolved Hide resolved
test/integration/dialects/mariadb/associations.test.js Outdated Show resolved Hide resolved
test/integration/dialects/mariadb/associations.test.js Outdated Show resolved Hide resolved
test/integration/dialects/mariadb/associations.test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments for now

lib/dialects/abstract/connection-manager.js Show resolved Hide resolved
lib/dialects/abstract/query-generator.js Outdated Show resolved Hide resolved
lib/dialects/mariadb/connection-manager.js Show resolved Hide resolved
lib/dialects/mariadb/connection-manager.js Show resolved Hide resolved
lib/dialects/mariadb/query-generator.js Outdated Show resolved Hide resolved
lib/dialects/mariadb/query-interface.js Outdated Show resolved Hide resolved
@sushantdhiman
Copy link
Contributor

This looks almost ready @rusher , Please extend documentation so it references mariadb

I'll do some testing locally in the evening, we can hopefully merge this tomorrow

@rusher
Copy link
Contributor Author

rusher commented Nov 28, 2018

@sushantdhiman Just tell me if you think anything else is missing. I don't see any other improvement that i can do, but better bulk implementation (mariadb connector has a dedicated bath API that use a MariaDB specific protocol, but that would be another PR)

.travis.yml Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
lib/dialects/mariadb/query-generator.js Outdated Show resolved Hide resolved
let startWithDot = true;

// Convert .number. to [number].
path = path.replace(/\.(\d+)\./g, '[$1].');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you only need to bottom one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it depends if you want to support JSON dot notation or not.

SET @json = '{"tt": [1, 2, [3, 4]], "tt2" : 3}';
SELECT JSON_EXTRACT(@json, '$.tt.2'); // return null;
SELECT JSON_EXTRACT(@json, '$.tt[2]'); // return [3,4];
SELECT JSON_EXTRACT(@json, '$.tt[2].1'); // return null;
SELECT JSON_EXTRACT(@json, '$.tt[2][1]'); // return 4;

so supporting something like whereItemQuery(Sequelize.json('profile.id.0.1'), '1')
profile.id.0.1 needs to be changed to json_unquote(json_extract(profile,'$.id[0][1]')) = '1'

lib/dialects/mariadb/query-generator.js Outdated Show resolved Hide resolved
resolve(results);
})
.catch(err => {
debug(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really useful to debug log and regular log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, a better thing may be

debug( `executed(${this.connection.uuid || 'default'}) with error : ${this.sql}\n${err}`);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, keep this format

Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @rusher Let me know if there is any thing pending. Will merge this on Monday

@rusher
Copy link
Contributor Author

rusher commented Dec 3, 2018

@sushantdhiman No other changes unless new reviews

@sushantdhiman sushantdhiman merged commit c6d7333 into sequelize:master Dec 3, 2018
@sushantdhiman
Copy link
Contributor

Thanks @rusher 👍 (& @SimonSchick for additonal reviews) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants