diff --git a/Dockerfile b/Dockerfile index 6e8bcd3..efc1c80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,6 @@ RUN npm install -q # copy source code ADD . . -ADD config-docker.ls config.ls # build RUN npm run build diff --git a/query-types/curl.ls b/query-types/curl.ls index c8da46a..3b813d8 100644 --- a/query-types/curl.ls +++ b/query-types/curl.ls @@ -16,32 +16,32 @@ export get-context = -> # execute :: (CancellablePromise cp) => OpsManager -> QueryStore -> DataSource -> String -> String -> Parameters -> cp result export execute = (, , data-source, query, transpilation-language, parameters) --> {shell-command, parse} = require \./shell-command-parser - result = parse shell-command, query - + result = parse shell-command, (query.replace /\s/g, '') + # parsing error if !!result.0.1 return (new-promise (, rej) -> rej new Error "Parsing Error #{result.0.1}") - result := result.0.0.args + result := result.0.0.args |> concat-map id - url = result - |> find (-> !!it.opt) + url = result + |> find (-> !!it.opt) |> (.opt) - options = result - |> filter (-> !!it.name) - |> map ({name, value}) -> + options = result + |> filter (-> !!it.name) + |> map ({name, value}) -> (if name.length > 1 then "--" else "-") + name + if !!value then " #value" else "" |> Str.join " " - [err, url] = compile-and-execute-sync do + [err, url] = compile-and-execute-sync do url transpilation-language parameters |> Obj.map -> it ? "" - + if !!err - return (new-promise (, rej) -> rej new Error "Url foramtting failed\n#err") + return (new-promise (, rej) -> rej new Error "Url foramtting failed\n#err") # escape characters url .= replace \{, '\\{' @@ -55,14 +55,14 @@ export execute = (, , data-source, query, transpilation-language, parameters) -- return rej Error "Error in curl #code #output", null if code != 0 res output - with-cancel-and-dispose do + with-cancel-and-dispose do execute-curl - -> + -> curl-process.kill! if !!curl-process returnP \killed # default-document :: DataSourceCue -> String -> Document -export default-document = (data-source-cue, transpilation-language) -> +export default-document = (data-source-cue, transpilation-language) -> query: """curl "https://api.github.com/emojis" """ transformation: "JSON.parse" presentation: "json" diff --git a/query-types/mysql.ls b/query-types/mysql.ls index d76a220..efd7ea9 100644 --- a/query-types/mysql.ls +++ b/query-types/mysql.ls @@ -12,15 +12,15 @@ execute-sql = (data-source, query) --> ..connect! ..query query, (err, rows) -> if !!err then rej err else res rows - with-cancel-and-dispose do + with-cancel-and-dispose do execute-sql-promise -> returnP \killed -> if !!connection then connection.end! # connections :: (CancellablePromise cp) => a -> cp b export connections = -> - returnP do - connections: (config?.connections?.mysql or {}) + returnP do + connections: (config?.connections?.mysql or {}) |> obj-to-pairs |> map ([name, value]) -> label: (value?.label or name) @@ -29,7 +29,7 @@ export connections = -> # keywords :: (CancellablePromise cp) => [DataSource, String] -> cp [String] export keywords = ([data-source, transpilation-language]) -> - results <- bindP (execute-sql data-source, "select table_schema, table_name, column_name from information_schema.columns") + results <- bindP (execute-sql data-source, "select table_schema, table_name, column_name from information_schema.columns") tables = results |> (group-by (-> "#{it.table_schema}.#{it.table_name}")) >> (Obj.map map (.column_name)) returnP { keywords: <[SELECT GROUP BY TOP ORDER WITH DISTINCT INNER OUTER JOIN]> @@ -44,14 +44,15 @@ export get-context = -> # execute :: (CancellablePromise cp) => OpsManager -> QueryStore -> DataSource -> String -> CompiledQueryParameters -> cp result export execute = (, , data-source, query, transpilation, parameters) --> (Obj.keys parameters) |> each (key) -> - query := query.replace "$#{key}$", parameters[key] + pattern = new RegExp "\\$#{key}\\$", \g + query := query.replace pattern, parameters[key] execute-sql data-source, query # default-document :: DataSourceCue -> String -> Document -export default-document = (data-source-cue, transpilation-language) -> +export default-document = (data-source-cue, transpilation-language) -> query: """ - select * - from + select * + from limit 10 """ transformation: "id"