Plugin Development - Accessing the Datastore

    Kong supports two primary datastores: Cassandra and .

    All entities in Kong are represented by:

    • A schema that describes which table the entity relates to in the datastore, constraints on its fields such as foreign keys, non-null constraints etc. This schema is a table described in the plugin configuration chapter.

    Both core entities from Kong and custom entities from plugins are available through kong.db.*.

    The DAO Lua API

    The DAO class is responsible for the operations executed on a given table in the datastore, generally mapping to an entity in Kong. All the underlying supported databases (currently Cassandra and Postgres) comply to the same interface, thus making the DAO compatible with all of them.

    1. local inserted_service, err = kong.db.services:insert({
    2. url = "http://mockbin.org",
    3. name = "key-auth",
    4. })

    For a real-life example of the DAO being used in a plugin, see the Key-Auth plugin source code.


    Next: