Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select distinct for plugins #44

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kong-0.0.1beta-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies = {
"luasec ~> 0.5-2",
"yaml ~> 1.1.1-1",
"luaxml ~> 101012-1",
"cassandra ~> 0.5-2",
"cassandra ~> 0.5-3",
"lrexlib-pcre ~> 2.7.2-1",
"stringy ~> 0.2-1",
"inspect ~> 3.0-1",
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/dao/cassandra_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ describe("Cassandra DAO #dao #cassandra", function()

describe("Plugins", function()

it("should find dinstinct plugin names", function()
local plugins, err = dao_factory.plugins:find_distinct()
assert.falsy(err)
assert.truthy(plugins)

local inspect = require "inspect"
print(inspect(plugins))
end)

it("should not insert in DB if invalid", function()
-- Without an api_id, it's a schema error
local plugin_t = dao_factory.faker:fake_entity("plugin")
Expand Down
12 changes: 12 additions & 0 deletions src/kong/dao/cassandra/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function Plugins:new(properties)
params = { "id" },
query = [[ SELECT * FROM plugins WHERE id = ?; ]]
},
select_distinct = {
query = [[ SELECT DISTINCT name FROM plugins; ]]
},
delete = {
params = { "id" },
query = [[ DELETE FROM plugins WHERE id = ?; ]]
Expand Down Expand Up @@ -91,4 +94,13 @@ function Plugins:_unmarshall(t)
return t
end

function Plugins:find_distinct()
local plugins, err = Plugins.super._execute(self, self._statements.select_distinct)
if err then
return nil, err
else
return plugins, err
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do that, you can just return what the _execute returns here.

return Plugins