How to get the url in server-side script for all tables

Hi everyone,

I am wirting a server-side script that I want to execute on POST events for all tables.

The first question is:

Is it correct, if I do not want to copy the script for all tables (and if the database is ‘db’) to use the script named: ‘db._table.{table_name}.get.pre_process’ ?

And the second question:

I would need to redirect the requests in the script to the table mentioned in the URL of the request. It seems though, that this information is not accessible via ‘event.request’ in the script. Is there a way to get the URL or the {table_name} somehow? (I am using V8 if it is relevant.)

Thanks in advance,
Auré

Hi @aurerua

In the your first question, the correct event target to POST in all tables, is:
db._table.{table_name}.post.pre_process (works fine)

You do not need redirect request to table, the request is automatically directed to table after execute a pre process scripts.

See a complete flux to request GET api/v2/db/_table/foo/1

1º execute event script db._table.{table_name}.{id}.get.pre_process (validation)
2º execute event script db._table.foo.{id}.get.pre_process (validation)
request data to table foo from db service
4º execute event script db._table.{table_name}.{id}.get.pos_process (extend)
5º execute event script db._table.foo.{id}.get.pos_process (extend)

ps* All validations of session and access role is performed before process.

best regards,
Junior Conte

The table name is available from event.resource
See more this Scripting - DreamFactory

@juniorconte

I dumped the event.resource and could not see the table name there. I will check again.

I didn’t realise at the time, that the request is automatically directed to table, so I do not even need to know about the table. ( I had a flash about it on my bike this morning and then I find your explanations :slight_smile: )

Thank you very much for your help and have a nice day!

1 Like