Dynamic connection string

 

Hi, is there a way to give the connection string in a dynamic way?

for example, I tried creating a constant with the user attributes, but i cannot use this constant in the connection of the model

0 7 546
7 REPLIES 7

No not possible, you can either make the connection dynamic via a user attribute (in some attributes of the connection) or you can extend explores from new models that use other connections.

could you elaborate a bit on the second option?

i want to change the connection based on the instance im in. in each instance i have a user_attribute to check in which instance i am. 

hi could you elaborate on the second solution?>

No not possible, you can either make the connection dynamic via a user attribute (in some attributes of the connection) or you can extend explores from new models that use other connections.

Hi,

The correct way to do what you want to do is to create a project per instance, import the LookML base project and override the constant that holds the connection string.

https://cloud.google.com/looker/docs/importing-projects

Hope this helps.

Hi,

The correct way to do what you want to do is to create a project per instance, import the LookML base project and override the constant that holds the connection string.

https://cloud.google.com/looker/docs/importing-projects

Hope this helps.

thanks for answering. the problem is a constant cannot be used for a connection string (when defining a model you write connection: "connection_name”. you cannot use a constant here

Hi,

The correct way to do what you want to do is to create a project per instance, import the LookML base project and override the constant that holds the connection string.

https://cloud.google.com/looker/docs/importing-projects

Hope this helps.

thanks for answering. the problem is a constant cannot be used for a connection string (when defining a model you write connection: "connection_name”. you cannot use a constant here

That’s is not correct. A constant can be used for a connection string. This works fine:

manifest.lkml
constant: db_connection { value: "paris_db"}

project.model
connection: "@{db_connection}"

This works, however when you try to use any if/else logic in the constant, looker errors that it is an unknown connection (even though the "stage" and "prod" connections are properly defined and allowed in the account:

manifest.lkml
constant: db_connection { 
  value: "{% if _user_attributes['env'] == 'stage' %}stage{% else %}prod{% endif %}" 
}

project.model
connection: "@{db_connection}"

 

Top Labels in this Space
Top Solution Authors