You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is pretty important, especially since most large Rails apps have moved to use the automatic connection switching between readers/writers, and probably also for sharding.
It is currently possible to have multiple connections like this:
macroconnection(connection_details)
{%if connection_details.is_a?(StringLiteral) %}
class_getter adapter : Granite::Adapter::Base=Granite::Connections[{{connection_details}}]
{%elsif connection_details.is_a?(TupleLiteral) || connection_details.is_a?(NamedTupleLiteral) %}
# Put the code here to set the reader/writer
{%else%}
# Probably don't actually want to raise here like thisraise"No registered connection with the name '{{name.id}}'"
{%end%}
end
Just throwing this out there for now, but I think it'll be easier than it may first appear to add automatic connection switching.
We would also need:
A variable to track when the last write transaction was done to get the time since the last write
A configuration to set the delay from switching between the writer and the reader, probably 2 seconds to allow for propagation
A way to tell if the action being performed is a read or write action. This is pretty straightforward since writing actions are insert, update & upsert and most other queries will be to read. We want to default to using the reader as often as possible.
The text was updated successfully, but these errors were encountered:
This is pretty important, especially since most large Rails apps have moved to use the automatic connection switching between readers/writers, and probably also for sharding.
It is currently possible to have multiple connections like this:
However, this does not set the actual roles for the db's shown, and you can only select a single database connection from the model.
I think we'll need to modify the
connection
macro to allow accepting aNamedTuple
orTuple
so we can pass in some configuration settings like:The current connection macro is here:
granite/src/granite/table.cr
Line 59 in 3f7a415
Just throwing this out there for now, but I think it'll be easier than it may first appear to add automatic connection switching.
We would also need:
write
transaction was done to get the time since the last writeinsert
,update
&upsert
and most other queries will be to read. We want to default to using the reader as often as possible.The text was updated successfully, but these errors were encountered: