mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-22 08:28:35 +00:00
Refactor dynamodb query service
This commit is contained in:
parent
ad2c7ffb09
commit
49f3da59ee
1 changed files with 30 additions and 27 deletions
|
|
@ -27,34 +27,9 @@ class DynamodbQueryService
|
|||
operation = options["operation"]
|
||||
|
||||
begin
|
||||
connection = get_connection
|
||||
|
||||
if operation === 'list_tables'
|
||||
tables = connection.list_tables
|
||||
data = tables.to_h
|
||||
end
|
||||
|
||||
if operation === 'get_item'
|
||||
table = options["table"]
|
||||
key = JSON.parse(options["key"])
|
||||
|
||||
item = {
|
||||
table_name: table,
|
||||
key: key
|
||||
}
|
||||
data = connection.get_item(item).to_h
|
||||
end
|
||||
|
||||
if operation === 'delete_item'
|
||||
table = options["table"]
|
||||
key = JSON.parse(options["key"])
|
||||
|
||||
item = {
|
||||
table_name: table,
|
||||
key: key
|
||||
}
|
||||
data = connection.delete_item(item).to_h
|
||||
end
|
||||
connection = get_connection
|
||||
data = send("exec_#{operation}", connection, options)
|
||||
|
||||
rescue StandardError => e
|
||||
puts e
|
||||
|
|
@ -81,4 +56,32 @@ class DynamodbQueryService
|
|||
|
||||
connection
|
||||
end
|
||||
|
||||
def exec_list_tables(connection, options)
|
||||
tables = connection.list_tables
|
||||
tables.to_h
|
||||
end
|
||||
|
||||
def exec_get_item(connection, options)
|
||||
table = options["table"]
|
||||
key = JSON.parse(options["key"])
|
||||
|
||||
item = {
|
||||
table_name: table,
|
||||
key: key
|
||||
}
|
||||
|
||||
connection.get_item(item).to_h
|
||||
end
|
||||
|
||||
def exec_delete_item(connection, options)
|
||||
table = options["table"]
|
||||
key = JSON.parse(options["key"])
|
||||
|
||||
item = {
|
||||
table_name: table,
|
||||
key: key
|
||||
}
|
||||
data = connection.delete_item(item).to_h
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue