Plug in API DB - czcorpus/kontext GitHub Wiki

Plug-ins / [db]

  • type: required
  • interface: plugins.abstract.general_storage.KeyValueStorage
  • client-side code: -
  • purpose: a common key-value data storage service

The "db" plug-in is kind of specific because it is not used directly by KonText core - only other plug-ins use it. Generally speaking, db is expected to provide an interface to access a data storage engine (SQL/NoSQL/whatever). It actually means that in an extreme case when you implement all the plug-ins yourself there is no need to conform this interface. But to keep things organized, KonText's default plug-ins (as well as Czech National Corpus' custom modifications) use following interface.

The important thing to consider is the fact that there can be only one db plug-in at a time running within KonText. This means that once you implement one or more plug-ins using other data storage you will have to import the adapter by youself.

KonText injects a db instance to factory functions of the following plug-ins:

Default plug-ins rely on the following db plug-in interface which is heavily inspired by the Redis API. Redis is actually the default backend used by KonText.

# KeyValueStorage.list_get(self, key, from_idx=0, to_idx=-1)

# KeyValueStorage.list_push(self, key, value)

# KeyValueStorage.list_len(self, key)

# KeyValueStorage.list_trim(self, key, keep_left, keep_right)

# KeyValueStorage.hash_get(key, field)

# KeyValueStorage.hash_set(key, field, value)

# KeyValueStorage.hash_del(key, *fields)

# KeyValueStorage.hash_get_all(key)

# KeyValueStorage.get(key, default=None)

# KeyValueStorage.set(key, data)

# KeyValueStorage.remove(key)

# KeyValueStorage.exists(key)

# KeyValueStorage.set_ttl(key, ttl) (optional)