Plugin development: using "kong.api.endpoints" with a schema with a non UUID PK


#1

Hi,

We’re in the process of porting in-house plugins developed from Kong 0.8.1 to Kong 1.0.2. The plugin has a custom entity with a primary key that is not auto settable nor a UUID:

local SCHEMA = {
    name = "accounts",
    primary_key = { "name" },
    cache_key = { "name" },
    endpoint_key = "name",
    fields = {
        { name = { type = "string", required = true, unique = true }},
        { status = { type = "string", required = true }},
        { billing = { type = "string", required = true }},
    }
}

We’re trying to port the admin API from using the “crud_helpers” to the new “kong.api.endpoints” package. We would like an endpoint to allow CRUD operations on accounts addressable by the account name that use these endpoint utilities:

    ["/plugins/accounts/:accounts"] = {
        schema = kong.db.accounts.schema,
        methods = {
            GET = endpoints.get_entity_endpoint(kong.db.accounts.schema),
            DELETE = endpoints.delete_entity_endpoint(kong.db.accounts.schema)
        }
    },

I’ve had a bit of trouble using the endpoint utilities in this way. In short, when I try to hit the GET or DELETE endpoint, I get errors in the log indicating that Kong was trying to call the database using the select_by_name pre-computed SQL statement, but no such statement existed. My suspicion is that because “name” makes up part of the primary key, even though it is marked as unique, it does not get a select_by_XXX pre-computed SQL statement.

The only way around this is by adding a generated UUID field to the DAO, which is something we rather not do if we can avoid it.

Has anyone experienced this problem? If so, what would you recommend the best way forward would be for this? I rather not write custom handler methods for these endpoints but I will if it comes to that. Just thought I might ask around first before doing so.

We’re using Kong 1.0.2 with a PostgreSQL database.