Skip to content

findKeys functionality

spcsser edited this page Jan 10, 2013 · 1 revision

ueberDB.findKeys(key, notkey, callback) provides functionality to retrieve a list of key values. The param key defines which data we want to find, excluding data that matches the param notKey (can be null).

How it works

Consider the following entries as example:

test:id1
test:id1:chat:id2
chat:id3:test:id4

We want to find all unique entries for the key part test like in test:test1 but not the other two entries. We would issue the following search: ueberDB.findKeys("test:*","*:*:*");. The first params says we're looking for entries that match test: with anything that follows, but not entries that have multiple colons to exclude entries like test:id1:chat:id2.

Internal details

Depending on the database type, there are currently two strategies too perform queries. For document based dbms like mongodb, dirty or couch we use a regex and tranform the params into regex. The parameters test:* and *:*:* will be transformed into a regular expression: /(?=^test:.*$)(?!^.*:.*:.*$)/.

For relational dbms like mysql or postgres we use the like operator. The parameters test:* and *:*:* translate to this where condition: store.key LIKE 'test:%' AND store.key NOT LIKE '%:%:%'.