Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Last active January 22, 2019 21:52
Show Gist options
  • Save beckyconning/b35ffe3839e3358a34cc83b1dcf0bfee to your computer and use it in GitHub Desktop.
Save beckyconning/b35ffe3839e3358a34cc83b1dcf0bfee to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
set -o pipefail
TABLE_INFO=$(cat)
echo "${TABLE_INFO}" | jq -r .name | tr '[:upper:]' '[:lower:]' | while read x ; do printf "create table $x(" ; done
echo "${TABLE_INFO}" | jq -r '.columns | .[] | .type = if .type == "offsetdatetime" then "datetime" elif .type == "number" then "decimal" elif .type == "string" then "varchar(255)" elif .type == "boolean" then "boolean" else null end | [.column, .type] | @csv' | tr -d '"' | tr ' ' '_' | tr '[:upper:]' '[:lower:]' | tr ',' ' ' | perl -pe 'chomp if eof' | tr "\n" ","
printf ')'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment