Skip to content

Commit

Permalink
feat: support unprepared statement errors. fix #11
Browse files Browse the repository at this point in the history
If Cassandra returns an unprepared error, the DAO will re-prepare it
and try the query again. This fixes #11, and handles the case where
Cassandra would go down, and then up again while Kong is still running.

Other changes:

- docs: base_dao and the factory have been given a better documentation.
- refactor:
  - `kong_query` is now the prefered term for _queries elements.
  - `params` becomes `args_keys` and `values` `args` for consistance with the driver.
  - The `_execute` method was renamed to `_execute_kong_query` and broken into smaller chunks.
  - Batch statements now need to use the raw `_execute` method (the new one, not the one renamed to `_execute_kong_query`.
  - Cassandra errors now also have the error code.
  • Loading branch information
thibaultcha committed Apr 30, 2015
1 parent 3f251ec commit cdf94a0
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 230 deletions.
12 changes: 6 additions & 6 deletions kong/dao/cassandra/apis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ function Apis:new(properties)
self._schema = SCHEMA
self._queries = {
insert = {
params = { "id", "name", "public_dns", "target_url", "created_at" },
args_keys = { "id", "name", "public_dns", "target_url", "created_at" },
query = [[ INSERT INTO apis(id, name, public_dns, target_url, created_at)
VALUES(?, ?, ?, ?, ?); ]]
},
update = {
params = { "name", "public_dns", "target_url", "id" },
args_keys = { "name", "public_dns", "target_url", "id" },
query = [[ UPDATE apis SET name = ?, public_dns = ?, target_url = ? WHERE id = ?; ]]
},
select = {
query = [[ SELECT * FROM apis %s; ]]
},
select_one = {
params = { "id" },
args_keys = { "id" },
query = [[ SELECT * FROM apis WHERE id = ?; ]]
},
delete = {
params = { "id" },
args_keys = { "id" },
query = [[ DELETE FROM apis WHERE id = ?; ]]
},
__unique = {
name = {
params = { "name" },
args_keys = { "name" },
query = [[ SELECT id FROM apis WHERE name = ?; ]]
},
public_dns = {
params = { "public_dns" },
args_keys = { "public_dns" },
query = [[ SELECT id FROM apis WHERE public_dns = ?; ]]
}
}
Expand Down
Loading

0 comments on commit cdf94a0

Please sign in to comment.