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

Support json type #263

Merged
merged 7 commits into from
Aug 26, 2023
Merged

Support json type #263

merged 7 commits into from
Aug 26, 2023

Conversation

Tigrov
Copy link
Member

@Tigrov Tigrov commented Aug 1, 2023

Q A
Is bugfix?
New feature? ✔️
Breaks BC? ✔️
Fixed issues -

@what-the-diff
Copy link

what-the-diff bot commented Aug 1, 2023

PR Summary

  • New Dependency Added
    The composer.json file has been updated with a new software component yiisoft/json.

  • New File Hosting JSON Expression Builder
    A fresh file named JsonExpressionBuilder.php has been introduced in the src/Builder directory- it helps in constructing expressions in JSON format.

  • Upgrade of ColumnSchema with JSON Typecasting
    The ColumnSchema.php file now includes new methods for converting the JSON data types when interacting with the database, extending its functionality.

  • Inclusion of JsonExpression Builder in DQLQueryBuilder
    The DQLQueryBuilder.php file now supports building expression with JsonExpression.

  • SQLite types mapping with TYPE_JSON in QueryBuilder
    In the QueryBuilder.php file, a mapping has been added to interpret TYPE_JSON data as SQLite types.

  • Schema types mapping to TYPE_JSON
    The Schema.php file now recognizes TYPE_JSON data type, enhancing its data handling capabilities.

  • Test Modifications for JSON Typecasting in ColumnSchema
    The ColumnSchemaTest.php file now includes tests for the new JSON type conversion functionality.

  • Test Addition for JSON Columns in Command
    The CommandTest.php file now tests the functionality of JSON columns.

  • CommandProvider Tests for JSON Parameters in Batch Inserts
    Updated the CommandProvider.php file to verify if JSON parameters in batch insert operations are working correctly.

  • QueryBuilderProvider Tests for JSON Expressions
    The QueryBuilderProvider.php file has been updated to include tests validating the correct operation of JSON expressions.

  • SchemaProvider Addition of JSON Columns
    The SchemaProvider.php file now supports JSON columns in the schema, allowing more diverse data in the database.

  • QueryBuilderTest Upgraded with JSON Column Manipulation
    Tests have been added to QueryBuilderTest.php file for JSON column manipulation.

  • Added JSON Column in SQLite Fixture
    The sqlite.sql fixture file now has a JSON column added to the "type" table. This draft table will assist in testing the JSON column functionality.

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.44% 🎉

Comparison is base (fd9a542) 98.02% compared to head (1ec3ec8) 98.47%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #263      +/-   ##
============================================
+ Coverage     98.02%   98.47%   +0.44%     
- Complexity      328      343      +15     
============================================
  Files            17       19       +2     
  Lines          1013     1046      +33     
============================================
+ Hits            993     1030      +37     
+ Misses           20       16       -4     
Files Changed Coverage Δ
src/QueryBuilder.php 100.00% <ø> (ø)
src/Builder/JsonExpressionBuilder.php 100.00% <100.00%> (ø)
src/ColumnSchema.php 100.00% <100.00%> (ø)
src/DQLQueryBuilder.php 100.00% <100.00%> (ø)
src/Schema.php 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Tigrov Tigrov marked this pull request as ready for review August 1, 2023 08:56
@vjik vjik requested a review from a team August 1, 2023 09:25
@vjik vjik added the status:code review The pull request needs review. label Aug 1, 2023
Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

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

Overall looks good 👍 Please, add line to changelog

src/Builder/JsonExpressionBuilder.php Outdated Show resolved Hide resolved
}

if ($this->getType() === SchemaInterface::TYPE_JSON) {
return json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
return Json::decode((string) $value);

Copy link
Member

Choose a reason for hiding this comment

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

Or you can replace Json::encode() in other place to json_encode and drop dependency yiisoft/json. It's even better this way.

Copy link
Member Author

@Tigrov Tigrov Aug 1, 2023

Choose a reason for hiding this comment

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

Json::encode() is used according to MySQL and PostgreSQL

https://github.com/yiisoft/db-mysql/blob/master/src/Builder/JsonExpressionBuilder.php#L53
https://github.com/yiisoft/db-pgsql/blob/master/src/Builder/JsonExpressionBuilder.php#L56

Json::encode() Pre-processes the data before sending it to json_encode():
https://github.com/yiisoft/json/blob/master/src/Json.php#L100

Json::decode() is the same as json_decode() but with default arguments:
https://github.com/yiisoft/json/blob/master/src/Json.php#L81

Copy link
Member

Choose a reason for hiding this comment

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

Still good idea to use the helper's function

Copy link
Member Author

Choose a reason for hiding this comment

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

Tigrov and others added 3 commits August 21, 2023 11:33
# Conflicts:
#	tests/ColumnSchemaTest.php
#	tests/Provider/SchemaProvider.php
#	tests/Support/Fixture/sqlite.sql
@samdark samdark merged commit 1b375d2 into yiisoft:master Aug 26, 2023
16 of 17 checks passed
@samdark
Copy link
Member

samdark commented Aug 26, 2023

👍

@Tigrov Tigrov deleted the support_json_type branch October 18, 2023 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:code review The pull request needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants