PluginStore API - get row by attribute

Hello,
is there any better way to get data from the plugin store not only by the key?

For example, I have an attribute “name” and I want to get only the row out of the plugin store with a given name.
For now I just get all plugin store entries of my plugin and iterate over all rows until I find the row I am looking for.

Can that be enhanced?

It sounds like your query isn’t using a good enough WHERE

The table’s schema is

plugin_store_rows
id    serial    primary key 
plugin_name    varchar(255) 
key    varchar(255) 
type_name    varchar(255) 
value    text    null 

So the optimal query would be something like

SELECT the_fields, I_want, returned
FROM plugin_store_rows
WHERE appropriate_field LIKE 'some_text_string'
1 Like

Yeah the problem was that the PluginStore is only key-value.
But if a plugin needs multiple attributes assigned to a key, it gets imposible for a sql query to search for a specific attribute.

As a solution I rewrote my plugin to use the ActiveRecord instead, so I can specify my schemes like I want and use the ActiveRecord interface to query for things.

Greetings, André

2 Likes

Hello André

How did you manage to use ActiveRecord in your plugin? Did you face any issue as mentioned here?

Greetings

Hi Jafeth,
I generated a new model for my plugin.
I think I used

rails generate migration modelname

It is no problem to execute another db migration on development in the discourse root

bundle exec rake db:migrate

Sure the data stored in ActiveRecord is persistent and will not be deleted even if you delete your plugin.
But for me it is ok. My plugin doesn’t generate that much data.

On a production system make sure that the model migration file is there before the script executes the migration or you have to migrate by hand.

Hope that helps you.
Greetings, André