# SQL for storing Tags using SDK - Custom Module

**URL:** <https://forum.inductiveautomation.com/t/sql-for-storing-tags-using-sdk-custom-module/90784>\
**Category:** Module Development\
**Tags:** sdk\
**Created:** [May 23, 2024, 11:24am UTC](https://forum.inductiveautomation.com/t/sql-for-storing-tags-using-sdk-custom-module/90784 "2024-05-23T11:24:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srivatsa\_N](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Srivatsa\_N](https://forum.inductiveautomation.com/u/Srivatsa_N)\
**Post date:** [May 23, 2024, 11:24am UTC](https://forum.inductiveautomation.com/t/sql-for-storing-tags-using-sdk-custom-module/90784/1 "2024-05-23T11:24:40Z")

</div>

I'm trying to create a tag group for some of my instruments to store metadata about the instruments, not the actual instrument data. I used `ProviderConfiguration` and `ManagedTagProvider` in `GatewayContext` as shown below and was able to create the tags. However, when the Gateway was restarted, these tags disappeared. Is this the correct way to create them? Also, internally, we decided to store these tags in a database. We started testing with SQLite, which comes default with Ignition.

**Question 1:** Is it normal for the tags to disappear after a Gateway restart?  
**Question 2:** Can these tags be stored and retrieved even after a Gateway restart?  
**Question 3:** Is it better to store these tags in a database like SQL?  
**Question 4:** Is there any example of how this can be achieved?

```python
public class GatewayHook extends AbstractGatewayModuleHook {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private ManagedTagProvider deviceTagProvider;
    private GatewayContext gatewayContext;

    private final DeviceRegistryGatewayScript deviceRegistryGatewayScript = new DeviceRegistryGatewayScript();

    @Override
    public void setup(GatewayContext gatewayContext) {
        logger.info("setup()");

        this.gatewayContext = gatewayContext;

        ProviderConfiguration configuration = new ProviderConfiguration("Test-11");
        configuration.setAllowTagCustomization(true);
        configuration.setPersistTags(false);
        configuration.setPersistValues(false);
        configuration.setAttribute(TagProviderMeta.FLAG_HAS_OPCBROWSE, false);

        deviceTagProvider = gatewayContext.getTagManager().getOrCreateManagedProvider(configuration);

        deviceRegistryGatewayScript.setDeviceTagProvider(deviceTagProvider);

        deviceRegistryGatewayScript.setGatewayContext(gatewayContext);
    }

```

```python
this.deviceTagProvider.configureTag("Devices/instrument-1/" + deviceName + "/Device-ID", DataType.String);
        this.deviceTagProvider.configureTag("Devices/instrument-1/" + deviceName + "/EndPoint", DataType.String);
        this.deviceTagProvider.configureTag("Devices/instrument-1/" + deviceName + "/Floor", DataType.String);

        // Actual values are updated here
        this.deviceTagProvider.updateValue("Devices/instrument-1/" + deviceName + "/Device-ID", deviceID, QualityCode.Good);
        this.deviceTagProvider.updateValue("Devices/instrument-1/" + deviceName + "/Endpoint", ipAddress+":"+port, QualityCode.Good);
        this.deviceTagProvider.updateValue("Devices/instrument-1/" + deviceName + "/Floor", floor, QualityCode.Good);

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 23, 2024, 11:48am UTC](https://forum.inductiveautomation.com/t/sql-for-storing-tags-using-sdk-custom-module/90784/2 "2024-05-23T11:48:42Z")

</div>

1. A managed tag provider doesn't store anything. (?) You (the developer) are still responsible for persistently storing whatever needs to be stored. (Hmm. Try using `true` in the `.setPersistTags()` and `.setPersistValues()` configuration calls.)

2. Sure, by you. Probably should update your persistent store as things change.

3. Totally dependent on quantities and organization. But, likely.

4. Not that I am aware of.

---

<div class="post-metadata">

**Author:** ![msteele](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/msteele/32/77889_2.png) [@msteele](https://forum.inductiveautomation.com/u/msteele)\
**Post date:** [May 23, 2024, 12:31pm UTC](https://forum.inductiveautomation.com/t/sql-for-storing-tags-using-sdk-custom-module/90784/3 "2024-05-23T12:31:47Z")

</div>

Could you store persistent metadata within custom properties on tags/UDT instances/folders?

We've found this to be an effective way to store things, read them with simple tag bindings or system.tag.readBlocking, but not have the performance overhead of tag execution for persistent properties.

For us it works well to have some properties, common across a UDT for example, with the custom property set in the UDT. But other properties, unique per instance or tag, set via a script process.

---

<div class="post-metadata">

**Author:** ![Srivatsa\_N](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Srivatsa\_N](https://forum.inductiveautomation.com/u/Srivatsa_N)\
**Post date:** [May 24, 2024, 7:34am UTC](https://forum.inductiveautomation.com/t/sql-for-storing-tags-using-sdk-custom-module/90784/4 "2024-05-24T07:34:12Z")

</div>

Sorry, I am new to Ignition. Where can I read more about this ? below link ?

> **[User Defined Types - UDTs | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/user-defined-types-udts)**
>
> UDTs (User Defined Types), also referred to as Complex Tags, offer the ability to leverage object-oriented data design principles in Ignition. UDTs are extremely important in Ignition. With UDTs, you can dramatically reduce the amount of work...

Thank you
