php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

Using json middleware and mapping

Open informsnca opened this issue 2 years ago • 3 comments

Hi there.

I am trying to rename columns and get some columns to output json, but i cant get it to work.

This is my configs: 'tables' => 'e506b823df49_survey_513632,demo', 'middlewares' => 'cors,errors,basicAuth,json', 'controllers' => 'records,geojson,openapi,status', 'customControllers' => '', 'customOpenApiBuilders' => '', 'cacheType' => 'TempFile', 'cachePath' => '', 'cacheTime' => 10, 'debug' => false, 'basePath' => '', 'openApiBase' => '{"info":{"title":"PHP-CRUD-API","version":"1.0.0"}}', 'json.tables' => 'demo', 'json.columns' => 'two', 'mapping' => 'demo2=demo3,wp_posts.one=demo2.ones',

And this is my json structure: {"records":[{"one":"{"depth": false, "model": "TRX-120", "width": 100, "height": null}","two":"{"depth": false, "model": "TRX-120", "width": 100, "height": null}","3":0,"4":null,"5":null,"key":0}]}

What am i doing wrong?

informsnca avatar Aug 30 '23 08:08 informsnca

What is the request you are doing and what is the expected output? Also, what is the table structure you are using (SQL create statement)?

mevdschee avatar Sep 01 '23 07:09 mevdschee

I am using SQL. I am trying both to rename the table columns with this line: 'mapping' => 'demo2=demo3,wp_posts.one=demo2.ones', And i am trying to use the JSON middleware to get this structure turned into propper json: {"depth": false, "model": "TRX-120", "width": 100, "height": null}

Regarding the JSON middleware, i have both tried to make the fields a JSON field and a text field in the database :)

informsnca avatar Sep 02 '23 04:09 informsnca

'mapping' => 'demo2=demo3,wp_posts.one=demo2.ones',

It seems you are renaming the table twice. I think that that is not supported.

mevdschee avatar Mar 19 '24 09:03 mevdschee