Ignition database use from modules

Is there any examples of modules around that use their own table in an existing Ignition database?
Not the SQLite config database, but one of the user defined SQL connections?

In the setup in the gateway hook you can access it via

    @Override
    public void setup(GatewayContext context) {
        context.getDatasourceManager().getDatasource("MyConnection").getConnection()
   }     

I take the context and save it for later to be used for other scopes.

There may be a better way but this is how I figured it out.

1 Like

This is essentially correct. You absolutely should store the context you get in setup in a field in your hook.

Note that there are some potential complications, depending on what you're doing - i.e. you may want to 'fall back' to the project's default database connection. 8.1 vs 8.3 you're going to use the ScriptContext class to do that (in gateway scope) but the API of that class is very different in 8.3. You also get a project name over RPC (if you're adding functionality to the client/designer), though again the API to extract that is different in 8.1 vs 8.3.

2 Likes