Wednesday, April 12, 2017

How to store address in database?

I have laravel application where user can select address

area
region
city
locality
street

Every field is simple integer (foreign key to table which contains all addresses with their parent-child relationship). For example, area test has 8 regions and 2 cities.

I want to store this info in mysql database, but there are some problems.

There is a lot of code which works fine and process all updates to all models (stores info about what was changed with diffs of updates).

If I store these fields if 5 different columns, then I have to add some code in different parts of application to process it (select, update, show), because this code relies upon field type (text, integer, select, etc., there is separate config which describes these columns).

I want to store it in json column like this

{"area": 10, "city": 335}

Then I can easily add new columns, but what about speed of this solution, because these fields will be used in filter and there will be at least 50k rows in table.



via Jackson J

Advertisement