Okipa / laravel-model-json-storage

Storing your models in a json file rather than in database (single or few lines recording) can be a good option. This package saves you to create a table for a ridiculous amount of lines, improves the data recovery performances, and allows you to store and access to your models from a json files as you would do it in database.
MIT License
25 stars 16 forks source link

Pretty print the stored JSON #4

Open zulfajuniadi opened 5 years ago

zulfajuniadi commented 5 years ago

One of the more appealing advantage of storing data in JSON rather than say sqlite is that it has potential to be properly versioned controlled via git. This cannot be leveraged upon as the current implementation stores the JSON data as a single line.

I would like to propose passing the JSON_PRETTY_PRINT constant in the toJson method during model saving so that it would pretty print the JSON. This would allow git to detect changed lines (single property inside the JSON) as opposed to replacing the whole collection should a merge conflict occur.

However this does increase the file size, if this is a concern, which it shouldn't be, you might want to expose this in the config file.

This would open up new possibilities and usecases for this package. Think of a team of devs working with a same set of versioned controlled JSON data without worrying much when a conflict occur.

Okipa commented 5 years ago

I agree, it would be nice with a config value. I would accept a full tested PR for this.