# PluginStore API - get row by attribute

**URL:** https://meta.discourse.org/t/pluginstore-api-get-row-by-attribute/46251
**Category:** Development
**Created:** [June 23, 2016, 9:07am UTC](https://meta.discourse.org/t/pluginstore-api-get-row-by-attribute/46251 "2016-06-23T09:07:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![EndruK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/endruk/32/50211_2.png) [@EndruK](https://meta.discourse.org/u/EndruK)
#### Post date: [June 23, 2016, 9:07am UTC](https://meta.discourse.org/t/pluginstore-api-get-row-by-attribute/46251/1 "2016-06-23T09:07:48Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [June 23, 2016, 9:53am UTC](https://meta.discourse.org/t/pluginstore-api-get-row-by-attribute/46251/2 "2016-06-23T09:53:58Z")

</div>

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

The table’s schema is

```plaintext
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

```plaintext
SELECT the_fields, I_want, returned
FROM plugin_store_rows
WHERE appropriate_field LIKE 'some_text_string'

```

---

<div class="post-metadata">

### Author: ![EndruK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/endruk/32/50211_2.png) [@EndruK](https://meta.discourse.org/u/EndruK)
#### Post date: [August 5, 2016, 8:17am UTC](https://meta.discourse.org/t/pluginstore-api-get-row-by-attribute/46251/3 "2016-08-05T08:17:57Z")

</div>

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é

---

<div class="post-metadata">

### Author: ![jafeth.diazc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jafeth.diazc/32/101197_2.png) [@jafeth.diazc](https://meta.discourse.org/u/jafeth.diazc)
#### Post date: [January 30, 2017, 7:46am UTC](https://meta.discourse.org/t/pluginstore-api-get-row-by-attribute/46251/4 "2017-01-30T07:46:55Z")

</div>

Hello André

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

> [@How to create migration files?](https://meta.discourse.org/t/how-to-create-migration-files/48991/3):
>
> Note that if you are developing a plugin, discourse provides a PluginStore to help you avoid migrations, since undoing then when the plugin gets uinstalled is a open problem.

Greetings

---

<div class="post-metadata">

### Author: ![EndruK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/endruk/32/50211_2.png) [@EndruK](https://meta.discourse.org/u/EndruK)
#### Post date: [February 3, 2017, 9:30am UTC](https://meta.discourse.org/t/pluginstore-api-get-row-by-attribute/46251/5 "2017-02-03T09:30:48Z")

</div>

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

```plaintext
rails generate migration modelname

```

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

```plaintext
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é
