Skip to content

Filtering data

Keyword: match

Prefs offers a fairly basic matching functionality to filter out values during .read() or .delete() operations. Filter applies to values only. It uses SQL LIKE patterns: % matches any run of characters and _ any single character.

When values are stored encrypted

PrefsDB can store your values encrypted. Keys created in a dashboard account are encrypted unless the account turns it off under Settings. When values are encrypted, only exact matches work. A pattern without %, such as .match("blue").delete(), still finds that exact value, letter case included. A pattern with % gets the error FILTER_UNAVAILABLE.


To retrieve all values from a list named "signups", that end with letters 'yahoo.com':

const res = await db.list("signups").match("%yahoo.com").read();
curl -s -b cookies.txt -H "X-Authorization: Token $KEY" -G https://prefsdb.com/api/v1/read/ \
  -d list=signups -d "*=" --data-urlencode "__filter=%yahoo.com"

To delete all values from a list named "products", that start with 'SKU 58':

await db.list("products").match("SKU 58%").delete();
curl -s -b cookies.txt -H "X-Authorization: Token $KEY" -G https://prefsdb.com/api/v1/delete/ \
  -d list=products -d "*=" --data-urlencode "__filter=SKU 58%"