hexya-erp / hexya

Hexya business application development framework
http://hexya.io
Apache License 2.0
411 stars 125 forks source link

Add PostgreSQL JSONB data type. #15

Closed halybang closed 5 years ago

halybang commented 6 years ago

PostgreSQL JSONB data type support.

codecov[bot] commented 6 years ago

Codecov Report

Merging #15 into master will decrease coverage by 0.52%. The diff coverage is 2.7%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #15      +/-   ##
==========================================
- Coverage   82.34%   81.82%   -0.53%     
==========================================
  Files          50       50              
  Lines        5563     5600      +37     
==========================================
+ Hits         4581     4582       +1     
- Misses        741      777      +36     
  Partials      241      241
Impacted Files Coverage Δ
hexya/models/fields_defs.go 87.03% <0%> (-4.65%) :arrow_down:
hexya/models/db_postgres.go 73.59% <33.33%> (-1%) :arrow_down:

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 cfbc241...2995786. Read the comment docs.

npiganeau commented 6 years ago

Thanks for your proposal.

However, I'm not sure about the use case of this. Actually, I see the interest in a general purpose ORM where you could use it to store arbitrary JSON data while still using the ORM.

But in the case of Hexya, I'm really keen on having its design "business driven". In this respect, each field type is not only a database column type but is above all a business object field type. That is a type which we can find in real life (e.g. a partner name is of type 'char', an invoice date is of type 'date', etc.). Even relation fields (such as Many2One) mimic real life relation (between a partner and a sale order, for instance). Moreover, each type is rendered in the client as a specific widget for user interaction.

In the case of JSONB, I don't see the "real life" aspect of the field type:

halybang commented 6 years ago

Users can use JSONB data type for IoT projects. Use hexya to manage IoT device: Device ID, serial, customer relate with ... etc. Each IoT device can send difference kind of data to Hexya, then Hexya save to database (humanity, gps position ...). With that case, IMHO, using JSONB.

changwuf31 commented 6 years ago

Qor has something like https://github.com/qor/serializable_meta for this kind of use case. It was used for the queue job system, https://github.com/qor/worker. Data is stored in two fields, a kind field (string), eg: "voucher", "shirt", and data field (jsonb), eg:'{"nominal": 10}', '{"size":"M","color":"white"}'.

Another idea would be the polymorphic models.

sylnsr commented 5 years ago

This is actually a feature that I have seen requested a few time from Odoo and long to have myself from Odoo. One major use case is ETL .. as follows (simple outline):

npiganeau commented 5 years ago

Ok, I can consider this new field type for the ETL use case. But to keep it consistent with concept, we should also have a display widget for JSONB type in https://github.com/hexya-addons/web

If any of you want to make a PR over there for that, I will consider merging this one too.

halybang commented 5 years ago

Because of hexya changed struct andc code so much, I close this. See PR https://github.com/hexya-erp/hexya/pull/69