5 ms·
> Pass ACCOUNT_ID as part of Query How do you pass the ACCOUNT_ID? Do you parse the SQL query to know where the ACCOUNT_ID is used? Or do you pass it out of ba
by ngrilly 9y ago
> Pass ACCOUNT_ID as part of Query
How do you pass the ACCOUNT_ID? Do you parse the SQL query to know where the ACCOUNT_ID is used? Or do you pass it out of band?
- gshulegaard 9y agoOne SQL Query, middleware is responsible for grabbing the ACCOUNT_ID and connecting to the appropriate shards. This is why ACCOUNT_ID is needed as part of all the models on the shards because we don't want to alter the SQL query after middleware connects, we just want to run the unaltered query.
- ngrilly 9y agoYes. I meant where does the middleware grab the ACCOUNT_ID from?
- gshulegaard 9y agoThe SQL query.
- ngrilly 9y agoDoes your middleware parse the SQL query in order to extract the ACCOUNT_ID?
- gshulegaard 9y agoShort answer is No. We use an ORM/abstraction layer so we can actually get the ACCOUNT_ID as a property of our in memory object before the query is formatted. In this way we can inject the proper connection for the formatted query to be run on before/during handoff to the ORM. Longer answer is you could do this same injection any number of ways...it is just convenient for our existing stack to do it this way. In some places we actually do it differently in order to facilitate direct queries (without the ORM layer).
- ngrilly 9y agoVery clear. Thanks!