Accessing the Datastore

    Kong supports two primary datastores: PostgreSQL and .

    We don’t recommend using Cassandra with Kong Gateway, because support for Cassandra is deprecated and planned to be removed.

    • 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.

    The core entities in Kong are: Services, Routes, Consumers and Plugins. All of them are accessible as Data Access Objects (DAOs), through the kong.db global singleton:

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

    The DAO Lua API

    For example, inserting a Service and a Plugin is as easy as:

    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